Jump to content
  • Advertisement
Sign in to follow this  
underthesun

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!