Added angle snapping feature

This commit is contained in:
penolakushari 2023-07-03 09:42:09 +03:00
parent 3ac58f813a
commit 4bb8ab741e
6 changed files with 59 additions and 13 deletions

View File

@ -3,7 +3,7 @@ include("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, StartGrab, NPhysPos)
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, garbage, StartGrab, NPhysPos)
local intersect = self:GetGrabPos(eyepos,eyeang,ppos)
local localized = self:WorldToLocal(intersect)
local axis = self:GetParent()

View File

@ -3,7 +3,7 @@ include("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
local VECTOR_FRONT, VECTOR_SIDE = Vector(1,0,0), Vector(0,1,0)
local VECTOR_FRONT, VECTOR_SIDE = Vector(1,0,0), Vector(0,1,0)
local function ConvertVector(vec, axistype)
local rotationtable, result
@ -21,7 +21,7 @@ local function ConvertVector(vec, axistype)
return result
end
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, startAngle, garbage, NPhysAngle) -- initially i had a table instead of separate things for initial bone pos and angle, but sync command can't handle tables and i thought implementing a way to handle those would be too much hassle
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, snapamount, startAngle, garbage, NPhysAngle) -- initially i had a table instead of separate things for initial bone pos and angle, but sync command can't handle tables and i thought implementing a way to handle those would be too much hassle
local intersect = self:GetGrabPos(eyepos,eyeang,ppos,pnorm)
local localized = self:WorldToLocal(intersect)
local _p, _a
@ -43,8 +43,22 @@ function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, mo
end
localized = Vector(localized.y,localized.z,0):Angle()
startAngle = Vector(startAngle.y, startAngle.z, 0):Angle()
local diff = startAngle.y - localized.y
local mathfunc = nil
if diff >= 0 then
mathfunc = math.floor
else
mathfunc = math.ceil
end
local rotationangle = localized.y
if snapamount ~= 0 then
rotationangle = startAngle.y - (mathfunc(diff / snapamount) * snapamount)
end
local pos = self:GetPos()
local ang = self:LocalToWorldAngles(Angle(0,0,localized.y))
local ang = self:LocalToWorldAngles(Angle(0,0,rotationangle))
if axis.relativerotate then
offset = WorldToLocal(axis.BonePos, angle_zero, axis:GetPos(), axis.LocalAngles)
_p,_a = LocalToWorld(vector_origin,offang,pos,ang)
@ -68,12 +82,19 @@ function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, mo
localized = localized:Angle() - startlocal:Angle()
local mathfunc = math.floor
if localized.y < 0 then mathfunc = math.ceil end
local rotationangle = localized.y
if snapamount ~= 0 then
rotationangle = mathfunc(localized.y / snapamount) * snapamount
end
if self.axistype == 4 then
rotateang = NPhysAngle + localized
_a = rotateang
else
_a = ent:GetManipulateBoneAngles(bone)
rotateang = NPhysAngle[self.axistype] + localized.y
rotateang = NPhysAngle[self.axistype] + rotationangle
_a[self.axistype] = rotateang
end
@ -87,8 +108,22 @@ function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, mo
end
localized = Vector(localized.y,localized.z,0):Angle()
startAngle = Vector(startAngle.y, startAngle.z, 0):Angle()
local diff = startAngle.y - localized.y
local mathfunc = nil
if diff >= 0 then
mathfunc = math.floor
else
mathfunc = math.ceil
end
local rotationangle = localized.y
if snapamount ~= 0 then
rotationangle = startAngle.y - (mathfunc(diff / snapamount) * snapamount)
end
local pos = self:GetPos()
local ang = self:LocalToWorldAngles(Angle(0,0,localized.y))
local ang = self:LocalToWorldAngles(Angle(0,0,rotationangle))
if axis.relativerotate then
offset = WorldToLocal(axis.BonePos, angle_zero, axis:GetPos(), axis.LocalAngles)
_p,_a = LocalToWorld(vector_origin,offang,pos,ang)

View File

@ -3,7 +3,7 @@ include("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, StartGrab, garbage, garbage, NPhysScale)
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, garbage, StartGrab, garbage, garbage, NPhysScale)
local intersect = self:GetGrabPos(eyepos,eyeang,ppos)
local localized = self:WorldToLocal(intersect)
local pos, ang

View File

@ -3,7 +3,7 @@ include("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, startGrab, garbage, garbage, NPhysScale)
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, garbage, startGrab, garbage, garbage, NPhysScale)
local intersect = self:GetGrabPos(eyepos,eyeang,ppos,pnorm)
local pos, ang
local pl = self:GetParent().Owner

View File

@ -3,7 +3,7 @@ include("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, startGrab, NPhysPos)
function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, movetype, garbage, startGrab, NPhysPos)
local intersect = self:GetGrabPos(eyepos,eyeang,ppos,pnorm)
local axis = self:GetParent()
local offset = axis.Owner.rgm.GizmoOffset

View File

@ -15,6 +15,8 @@ TOOL.ClientConVar["disablefilter"] = 0
TOOL.ClientConVar["lockselected"] = 0
TOOL.ClientConVar["scalechildren"] = 0
TOOL.ClientConVar["drawskeleton"] = 0
TOOL.ClientConVar["snapenable"] = 0
TOOL.ClientConVar["snapamount"] = 30
TOOL.ClientConVar["ik_leg_L"] = 0
TOOL.ClientConVar["ik_leg_R"] = 0
@ -979,19 +981,25 @@ if SERVER then
return
end
local snapamount = 0
if self:GetClientNumber("snapenable",0) ~= 0 then
snapamount = self:GetClientNumber("snapamount", 1)
snapamount = snapamount < 1 and 1 or snapamount
end
local physbonecount = ent:GetBoneCount() - 1
if physbonecount == nil then return end
if not scale then
if IsValid(ent:GetParent()) and bone == 0 and not ent:IsEffectActive(EF_BONEMERGE) and not (ent:GetClass() == "prop_ragdoll") then
local pos, ang = apart:ProcessMovement(pl.rgmOffsetPos,pl.rgmOffsetAng,eyepos,eyeang,ent,bone,pl.rgmISPos,pl.rgmISDir,0)
local pos, ang = apart:ProcessMovement(pl.rgmOffsetPos,pl.rgmOffsetAng,eyepos,eyeang,ent,bone,pl.rgmISPos,pl.rgmISDir,0,snapamount,pl.rgm.StartAngle)
ent:SetLocalPos(pos)
ent:SetLocalAngles(ang)
elseif pl.rgm.IsPhysBone then
local isik,iknum = rgm.IsIKBone(self,ent,bone)
local pos,ang = apart:ProcessMovement(pl.rgmOffsetPos,pl.rgmOffsetAng,eyepos,eyeang,ent,bone,pl.rgmISPos,pl.rgmISDir, 1)
local pos,ang = apart:ProcessMovement(pl.rgmOffsetPos,pl.rgmOffsetAng,eyepos,eyeang,ent,bone,pl.rgmISPos,pl.rgmISDir,1,snapamount,pl.rgm.StartAngle)
local obj = ent:GetPhysicsObjectNum(bone)
if not isik or iknum == 3 or (rotate and (iknum == 1 or iknum == 2)) then
@ -1064,7 +1072,7 @@ if SERVER then
-- if not pl:GetNWBool("ragdollmover_keydown") then
else
local pos, ang = apart:ProcessMovement(pl.rgmOffsetPos,pl.rgmOffsetAng,eyepos,eyeang,ent,bone,pl.rgmISPos,pl.rgmISDir, 2, pl.rgm.StartAngle, pl.rgm.NPhysBonePos, pl.rgm.NPhysBoneAng) -- if a bone is not physics one, we pass over "start angle" thing
local pos, ang = apart:ProcessMovement(pl.rgmOffsetPos,pl.rgmOffsetAng,eyepos,eyeang,ent,bone,pl.rgmISPos,pl.rgmISDir,2,snapamount, pl.rgm.StartAngle, pl.rgm.NPhysBonePos, pl.rgm.NPhysBoneAng) -- if a bone is not physics one, we pass over "start angle" thing
ent:ManipulateBoneAngles(bone, ang)
ent:ManipulateBonePosition(bone, pos)
@ -1072,7 +1080,7 @@ if SERVER then
else
bone = pl.rgm.Bone
local prevscale = ent:GetManipulateBoneScale(bone)
local sc, ang = apart:ProcessMovement(pl.rgmOffsetPos,pl.rgmOffsetAng,eyepos,eyeang,ent,bone,pl.rgmISPos,pl.rgmISDir, 2, pl.rgm.StartAngle, pl.rgm.NPhysBonePos, pl.rgm.NPhysBoneAng, pl.rgm.NPhysBoneScale)
local sc, ang = apart:ProcessMovement(pl.rgmOffsetPos,pl.rgmOffsetAng,eyepos,eyeang,ent,bone,pl.rgmISPos,pl.rgmISDir,2,snapamount, pl.rgm.StartAngle, pl.rgm.NPhysBonePos, pl.rgm.NPhysBoneAng, pl.rgm.NPhysBoneScale)
if axis.scalechildren then
local scalediff = sc - prevscale
@ -2116,6 +2124,9 @@ function TOOL.BuildCPanel(CPanel)
CCheckBox(Col4,"#tool.ragdollmover.scalechildren","ragdollmover_scalechildren")
CCheckBox(Col4, "Enable angle snapping", "ragdollmover_snapenable")
CNumSlider(Col4, "Angle snap amount", "ragdollmover_snapamount", 1, 180, 0)
local ColBones = CCol(Col4, "#tool.ragdollmover.bonelist")
RGMMakeBoneButtonPanel(ColBones, CPanel)
BonePanel = vgui.Create("DTree", ColBones)