Jump to content
  • Advertisement
Sign in to follow this  
MrDoomMaster

Rotation question using quaternions

This topic is 3774 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

Hi, I currently have a planet in my game which I plan to have a character walking on. I need to rotate this character so that his feet are always touching the ground. I have a feeling I'll need to use quaternions for this, but I'm not sure what to do mathematically. Here's what I know: 1) I know the center of the planet (0,0,0) 2) I know the location of the character on the surface in Cartesian coordinates. 3) I know the "up" vector (surface vector) at the current player's location by subtracting #1 and #2. 4) The default "up" vector for a player in world space is (0,1,0) (spine is aligned with the Y axis) I also have a quaternion object I can use. Help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
The only other thing you need is a forward vector. With an up vector and a forward vector, you can take their cross product as a right vector and build a rotation matrix. The columns (or rows, depending on the convention you're using) of a rotation matrix are just a forward, up, and right vector.

Share this post


Link to post
Share on other sites
What should the default quaternion for my model be? Should it be a 0 degree angle around the 0,1,0 axis? And then concatenate the world rotation quaternion to that one?

Share this post


Link to post
Share on other sites
First, the usual admonition: you don't need to use quaternions to accomplish this (although you can certainly use them if you wish).
Quote:
Original post by MrDoomMaster
What should the default quaternion for my model be? Should it be a 0 degree angle around the 0,1,0 axis? And then concatenate the world rotation quaternion to that one?
The 'default' would simply be the identity quaternion (x = y = z = 0, w = 1).

However, you'll probably want to update the orientation incrementally rather than try to build it from scratch each frame. To do this, compute the rotation that will rotate the character's up vector onto the surface normal, and then apply it to the character's orientation (don't forget to normalize occassionally).

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!