Jump to content
  • Advertisement
Sign in to follow this  
GamerSg

Quaternion based camera movement

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

Im trying to build a FPS camera and have gotten the looking around code working just fine. Now comes the problem of moving based on your current view direction. The problem is my camera only stores 2 things, 1) Position 2) Orientation in the form of a Quaternion How do i derive the view vector from a Quaternion? Currently i don't mind a ghost mode camera where you can fly in any direction, but what if later on, i want to make so that you cannot move upwards towards the sky?

Share this post


Link to post
Share on other sites
Advertisement
You can use the quaternion to rotate the (0.0f, 0.0f, 1.0f) vector or (0.0f, 0.0f, -1.0f) depending on the API. That will give you the look vector. If you want to stop the player from flying, do something like this:

playerPosition.X += lookVector.X;
playerPosition.Z += lookVector.Z;

don't touch the Y value, that's it.

Share this post


Link to post
Share on other sites
A quaternion is typically overkill for an FPS camera. Euler angles with matrices are a lot easier to use, and you already have all the vectors you'll ever need - forward, right, and up.

But if you're intent on using a quaternion, remember that it represents a rotation from a base view direction. So if the base view direction is [0 0 1] (down the positive Z axis) then just use the standard rotation equation q*v*q' where q is the rotation quaternion and v is the view direction as a quaternion (w = 0).

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!