# 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.

## 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 on other sites
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 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).

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 10
• 13
• 85
• 11
• 10
• ### Forum Statistics

• Total Topics
632969
• Total Posts
3009604
• ### Who's Online (See full list)

There are no registered users currently online

×