Adjusted angle snapping to be somewhat more precise and made world alignment work for nonphysical bone positioning gizmo

This commit is contained in:
penolakushari 2023-10-26 23:04:03 +03:00
parent 1647561c33
commit 3c52cd4473
4 changed files with 74 additions and 23 deletions

View File

@ -348,7 +348,7 @@ function ENT:Think()
end
if not pl.rgm.Moving then -- Prevent whole thing from rotating when we do localized rotation - needed for proper angle reading
if localstate or scale or not pl.rgm.IsPhysBone then -- Non phys bones don't go well with world coordinates. Well, I didn't make them to behave with those
if localstate or scale or (not pl.rgm.IsPhysBone and rotate) then -- Non phys bones don't go well with world coordinates. Well, I didn't make them to behave with those
self:SetAngles(ang or angle_zero)
if not pl.rgm.IsPhysBone then
self.DiscP:SetLocalAngles(Angle(0, 90 + ent:GetManipulateBoneAngles(bone).y, 0)) -- Pitch follows Yaw angles

View File

@ -28,11 +28,33 @@ function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, mo
ang = obj:GetAngles()
pos = LocalToWorld(Vector(offpos.x,0,0),angle_zero,intersect - offset,selfangle)
elseif movetype == 2 then
pos = ent:GetManipulateBonePosition(bone)
localized = Vector(localized.x - StartGrab.x,0,0)
local posadd = NPhysPos[self.axistype] + localized.x
local finalpos, boneang
local pl = self:GetParent().Owner
if ent:GetBoneParent(bone) ~= -1 then
local matrix = ent:GetBoneMatrix(ent:GetBoneParent(bone))
boneang = matrix:GetAngles()
if not (ent:GetClass() == "prop_physics") then
local _ , pang = ent:GetBonePosition(ent:GetBoneParent(bone))
local _, diff = WorldToLocal(vector_origin, boneang, vector_origin, pang)
_, boneang = LocalToWorld(vector_origin, diff, vector_origin, pl.rgm.GizmoParent)
end
else
if IsValid(ent) then
boneang = ent:GetAngles()
else
boneang = angle_zero
end
end
intersect = self:LocalToWorld(Vector(localized.x,0,0))
localized = LocalToWorld(Vector(offpos.x,0,0),angle_zero,intersect,self:GetAngles())
localized = WorldToLocal(localized, angle_zero, self:GetPos(), boneang)
finalpos = NPhysPos + localized
ang = ent:GetManipulateBoneAngles(bone)
pos[self.axistype] = posadd
pos = finalpos
elseif movetype == 0 then
localized = Vector(localized.x,0,0)
intersect = self:LocalToWorld(localized)

View File

@ -50,16 +50,28 @@ function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, mo
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
local localAng = math.fmod(localized.y, 360)
if localAng > 181 then localAng = localAng - 360 end
if localAng < -181 then localAng = localAng + 360 end
local localStart = math.fmod(startAngle.y, 360)
if localStart > 181 then localStart = localStart - 360 end
if localStart < -181 then localStart = localStart + 360 end
local diff = math.fmod(localStart - localAng, 360)
if diff > 181 then diff = diff - 360 end
if diff < -181 then diff = diff + 360 end
local mathfunc = nil
if diff >= 0 then
mathfunc = math.floor
else
mathfunc = math.ceil
end
rotationangle = startAngle.y - (mathfunc(diff / snapamount) * snapamount)
end
@ -103,11 +115,16 @@ 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
local localAng = math.fmod(localized.y, 360)
if localAng > 181 then localAng = localAng - 360 end
if localAng < -181 then localAng = localAng + 360 end
local mathfunc = math.floor
if localAng < 0 then mathfunc = math.ceil end
rotationangle = mathfunc(localAng / snapamount) * snapamount
end
if self.axistype == 4 then
@ -136,16 +153,28 @@ function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, mo
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
local localAng = math.fmod(localized.y, 360)
if localAng > 181 then localAng = localAng - 360 end
if localAng < -181 then localAng = localAng + 360 end
local localStart = math.fmod(startAngle.y, 360)
if localStart > 181 then localStart = localStart - 360 end
if localStart < -181 then localStart = localStart + 360 end
local diff = math.fmod(localStart - localAng, 360)
if diff > 181 then diff = diff - 360 end
if diff < -181 then diff = diff + 360 end
local mathfunc = nil
if diff >= 0 then
mathfunc = math.floor
else
mathfunc = math.ceil
end
rotationangle = startAngle.y - (mathfunc(diff / snapamount) * snapamount)
end

View File

@ -25,7 +25,7 @@ function ENT:ProcessMovement(offpos,offang,eyepos,eyeang,ent,bone,ppos,pnorm, mo
ang = obj:GetAngles()
pos = LocalToWorld(offpos,angle_zero,intersect - offset,self:GetAngles())
elseif movetype == 2 then
local localized, startmove, finalpos, boneang
local localized, finalpos, boneang
if ent:GetBoneParent(bone) ~= -1 then
local matrix = ent:GetBoneMatrix(ent:GetBoneParent(bone))
boneang = matrix:GetAngles()