quaternion rot between two vectors, but with an axis

This topic is 3491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I saw another thread on how to find a quaternion between two vectors: http://www.gamedev.net/community/forums/topic.asp?topic_id=429507 you do get the shortest rotation, but often the axis of the rotation (of the quaternion here..) is not necessarily the best for gameplay uses. I'd imagine in games, if this was for a camera related purpose, the best axis of rotation is that which is closest to the up vector (0, 1, 0). But how do you get such a quaternion? I was thinking of getting the average of the two vectors and the cross product to form a plane, and then project the up vector into this plane. Then, somehow using this new found vector, create the quaternion.. But that's as far as I got, as it seems too messy. Is there a better way?

Share on other sites
If you want to do a rotation around the y axis, just drop the y coordinates from the two vectors and use those to calculate the angle of rotation.

Share on other sites
Hmm.. that's true, but what if the game is a space sim and the up vector is not necessarily (0,1,0)? As it happens, I didn't think of doing that and it's probably a great hack for what I need (thanks).. but if there's a more general way of doing it, I'd implement it..

Share on other sites
It can be done with an arbitrary axis. If you've got an axis A and two vectors B and C, you'd take the projection of B on to A and subtract that from B to get D. And then take the projection of C on to A and subtract that from C to get E. Then you would use D and E to create your rotation. For A (0, 1, 0) the projection of B and C are just the y components of B and C, which leads to just dumping the components.

Share on other sites
Thanks, didn't think of that :D

1. 1
2. 2
3. 3
Rutin
25
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• Forum Statistics

• Total Topics
633650
• Total Posts
3013118
×