Simple Quaternion Tasks

Started by
30 comments, last by Jiia 19 years, 7 months ago
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.
Advertisement
Ahh man, there is nothing better than seeing something work perfectly [grin]

I actually had some strange problems. My turning animation actually moves the character a bit, just as any human probably shifts around somewhat as he turns. But since this movement was relative to the direction he was facing in the animation, and I since removed that direction from the animation, his movement motion was all backwards. Makes sense? So I had to not only remove the Y rotations from his rotation, but also from the translation. Easy enough, if only I had grasped right away what the problem was [smile]

I also started out trying to extract the rotation incorrectly. I was trying to key = key * invertedYrotate, when I should have been key = invertedYrotate * key. It makes perfect sense, considering he could have tilted forward/right slightly somewhere, and that Y rotation would then rotate way more than just the Y axis, in the first method.

It looks so cool [grin]
I'll upload a demo soon. Thanks much for all of your help [smile]

This topic is closed to new replies.

Advertisement