This may require trigonometry. blink.gif

Blarg, how to even describe this. I'm sure I'm not the first to notice it... Okay, if you do do this to an object:
CODE
set MyZ to GetAngle Z
SetAngle Z, MyZ

Sometimes that will change the object's angle, though clearly it shouldn't. Specifically this happens if the object had a rotation on more than one axis. I'm guessing this has something to do with confusing between world and (object? local? relative? what's the term?) rotation. So basically I'm asking if anyone knows how to work around this. If all else fails, I suppose it would be possible to convert between these with some advanced math...

[Edit] I wasn't really using GetPos and SetAngle, I wish it were that simple.
Have you checked to see if this is a gimbal lock problem?

EDIT:
Rotating an object on the x axis by 90, will cause the objects y axis to become the objects z axis, and then as you said, getAngle doesn't work with the same axis as setAngle (one work with world axis, the other local axis)

EDIT:
I don't have a clue how to fix this at present, but it is 1am and I sat a maths exam today, so I am brain dead.
QUOTE(ManaUser @ May 15 2008, 07:15 PM) *
This may require trigonometry. blink.gif

Blarg, how to even describe this. I'm sure I'm not the first to notice it... Okay, if you do do this to an object:
CODE
set MyZ to GetPos Z
SetAngle Z, MyZ

Sometimes that will change the object's angle, though clearly it shouldn't. Specifically this happens if the object had a rotation on more than one axis. I'm guessing this has something to do with confusing between world and (object? local? relative? what's the term?) rotation. So basically I'm asking if anyone knows how to work around this. If all else fails, I suppose it would be possible to convert between these with some advanced math...


Well, the first issue I see is the use of GetPos in the first line and SetAngle in the second. That'll make it rotate depending on height relative to world origin, so it'll spin as it goes up and down...
Otherwise, it all depends on whether the functions use degrees or radians as input. If Get returns it in degrees and Set takes radians, it'll stick you in a rotating loop, until it comes up with some number that convert into the same angle in both (prolly 360 * max radians).
QUOTE(Yacoby @ May 15 2008, 03:36 PM) *
Have you checked to see if this is a gimbal lock problem?

EDIT:
Rotating an object on the x axis by 90, will cause the objects y axis to become the objects z axis, and then as you said, getAngle doesn't work with the same axis as setAngle (one work with world axis, the other local axis)

Yes, I think that's related. I think maybe what's going on is that the values reported by GetAngle are not affected by this, so they're not the values I need to use with SetAngle.

QUOTE
EDIT:
I don't have a clue how to fix this at present, but it is 1am and I sat a maths exam today, so I am brain dead.

Understandable. I look forward to you're input when you're more fully awake.


QUOTE(peachykeen @ May 15 2008, 03:57 PM) *
Well, the first issue I see is the use of GetPos in the first line and SetAngle in the second. That'll make it rotate depending on height relative to world origin, so it'll spin as it goes up and down...

Oops, I wasn't really doing that. Just a typo in my example, sorry.

QUOTE
Otherwise, it all depends on whether the functions use degrees or radians as input. If Get returns it in degrees and Set takes radians, it'll stick you in a rotating loop, until it comes up with some number that convert 7c6 into the same angle in both (prolly 360 * max radians).

No, I don't think that's it. All the values appear to be degrees, it only gets weird if an object has been rotated on two or more axes.
Oh my poor brain... I think I at least have a good grasp of the problem now. When an object is loaded from a plug-in (or save game, it turns out) the rotations are done in Z-Y-X order, but when you rotate an object with SetAngle, the rotations are re-done in X-Y-Z order. GetAngle just reports the rotation values, regardless of which method was used to apply them.

To visualize the difference, hold your right hand out as if to say "stop" (or cast a touch spell). Now rotate your hand 90° on the X axis and and 90° on the Y axis. If you do X first, you turn your hand palm-down, then twist so your palm faces left (like you had just done a karate chop). If you do Y first you rotate your hand at an awkward angle so you fingers point to your right, then turn your hand so the is palm down and your thumb is away from you. (I can't be responsible if anyone injures their wrist trying that.)

This was interesting to learn as it also explains why objects positioned with SetAngle sometimes appear to "lose" their orientation after a reload. But my original problem still remains.
Submit a Thread