• Angular offset problem
    10 replies, posted
I'm really stuck on this one. How can I get Angle(p, y, r) to be Angle(0, 0, 0) by only using Angle:RotateAroundAxis() and only rotating around it's own axises? [highlight](User was banned for this post ("This isn't what spoiler tags are for" - mahalis))[/highlight]
I'm not sure, but you could maybe use [url=http://wiki.garrysmod.com/?title=Math.AngleDifference]Math.AngleDifference[/url]?
[QUOTE=Dlaor;17120718]I'm not sure, but you could maybe use [url=http://wiki.garrysmod.com/?title=Math.AngleDifference]Math.AngleDifference[/url]?[/QUOTE] That's not what I'm after, but thanks for trying :)
What does math.AngleDifference even do? Is it just something like this? [lua]return math.abs( a % 360 - b % 360 )[/lua]
[QUOTE=Overv;17120854]What does math.AngleDifference even do? Is it just something like this? [lua]return math.abs( a % 360 - b % 360 )[/lua][/QUOTE] Something like that yeah, so that it doesn't return 359 when you calculate the difference between 359° and 0°
If you're working with entities, use LocalToWorldAngles and WorldToLocalAngles.
Maybe try something like this using RotateAroundAxis: [lua]local ang = otherEnt:GetAngles() local offset = Angle( -p, -y, -r ) local fw = ang:Forward() local up = ang:Up() local rt = ang:Right() ang:RotateAroundAxis( fw, p ) ang:RotateAroundAxis( up, y ) ang:RotateAroundAxis( rt, r ) thisEnt:SetAngles( ang )[/lua] Although this may be wrong and it isn't tested.
[QUOTE=Nevec;17120957]If you're working with entities, use LocalToWorldAngles and WorldToLocalAngles.[/QUOTE] Im working with PhysObj's.
[QUOTE=ralle105;17120984]Im working with PhysObj's.[/QUOTE] Damn garry. Robert's code is the answer, except he got the axises wrong. [lua] local angParent = ent_parent:GetAngles( ); local vecPos = ent_parent:GetPos( ); vecPos = vecPos + angParent:Forward( ) * vecDiff.y; vecPos = vecPos + angParent:Right( ) * vecDiff.x; vecPos = vecPos + angParent:Up( ) * vecDiff.z; ent_child:SetPos( vecPos ); angParent:RotateAroundAxis( angParent:Right( ), angDiff.p ); angParent:RotateAroundAxis( angParent:Up( ), angDiff.y ); angParent:RotateAroundAxis( angParent:Forward( ), angDiff.r ); ent_child:SetAngles( angParent ); [/lua] Tested and works perfectly.
[QUOTE=Nevec;17121144]Damn garry. Robert's code is the answer, except he got the axises wrong. [lua] local angParent = ent_parent:GetAngles( ); local vecPos = ent_parent:GetPos( ); vecPos = vecPos + angParent:Forward( ) * vecDiff.y; vecPos = vecPos + angParent:Right( ) * vecDiff.x; vecPos = vecPos + angParent:Up( ) * vecDiff.z; ent_child:SetPos( vecPos ); angParent:RotateAroundAxis( angParent:Right( ), angDiff.p ); angParent:RotateAroundAxis( angParent:Up( ), angDiff.y ); angParent:RotateAroundAxis( angParent:Forward( ), angDiff.r ); ent_child:SetAngles( angParent ); [/lua] Tested and works perfectly.[/QUOTE] Tested, and does not work perfectly. If you take an angle and rotate it around it's own axises with it's negated p,y,r values, it doesn't become 0,0,0.
[QUOTE=ralle105;17121707]Tested, and does not work perfectly. If you take an angle and rotate it around it's own axises with it's negated p,y,r values, it doesn't become 0,0,0.[/QUOTE] That's where we really need matrices and matrix inversions. [url]http://en.wikipedia.org/wiki/Change_of_basis[/url]
Sorry, you need to Log In to post a reply to this thread.