Quote:Original post by Jiia
edit2: What happens as R's right vector is filled with some Y? As in what would happen if the character leaned left or right by a great deal. His orientation right vector would be like xyz(0.6, 0.4, 0.0). atan2 would only get 0.0, 0.6. So it dismisses Y changes. Is this good or bad? What if I took this right vector, set Y to zero, renormalized it, then used it that way? So (0.6, 0.4, 0.0) would change to (1.0, 0.0, 0.0). Does this matter at all? Sorry to be such a bother [smile]
It's "a solution", there's of course no always-good way to "extract a rotation" , it's ill'defined.(except that, you can convert into some weird form of Euler angles).
It will work the "best" if x direction it's character's front direction. If z it's front direction you just need to replace(in my formule) all x by z and z by -x, or by -z and x, as you like. So you'll need to use last column of matrix, and do
atan2(-v.x,v.z);
Yes, there's even a singularities possible with that turn, and that angle have almost no physical meaning, etc.
But i think it all should not matter if everything is implemented properly. That angle it's only a helper to let you position your object. So you must choose "global" frame of reference of your object that suits the best for your animation.
This frame dorsn't even have to be global, it doesn't even have to be a frame...say, if you have character with long nose(or big gun), it may be not bad at all to calculate turns using his nose direction instead of 1,0,0 vector.... So at each animation key, if you want his nose(or gun) to have heading h, you need to compensate horisontal rotation of his nose/gun at this frame(and it can be just storen for each animation key) and consequent frames like in my post with "TW" transform idea.
You basically just need to store Ti-1 transform at each key, so you can multiply yout TW by it and it will cancel it's position at that key in some reasonable way, way that makes most sense. Ti doesn't have to be a reference frame or global reference frame, it,say, may be a transform that flat-turn nose or gun to direction x from it's orientation at that animationframe.