Sign in to follow this  

FPS camera: finding forward/right/up vectors?

Recommended Posts

Okay, so I have a simple "camera" that uses Euler angles (only pitch and yaw for now). The problem is, I want to do some basic raycasting but I don't know how to get the forward/right/up vectors from those angles, without messing everything up. FYI, the nomenclature I use for my rotations/translations is this:
Any suggestions for my noobish question? Thanks in advance.

Share this post

Link to post
Share on other sites
FindViewVectors ( float yaw, float pitch )
float sinp = (float) sin(pitch);
float cosp = (float) cos(pitch);
float siny = (float) sin(yaw);
float cosy = (float) cos(yaw);

// apply yaw and pitch to get forward vector
m_vecForward.x = -siny * cosp;
m_vecForward.y = cosy * cosp;
m_vecForward.z = sinp;

// apply yaw and pitch to get right vector
m_vecRight.x = cosy;
m_vecRight.y = siny;
m_vecRight.z = 0;

// take cross product of yaw and pitch to get up vector
m_vecUp = CrossProduct(m_vecRight, m_vecForward);

Make sure your coordinate system is the same as mine.

Share this post

Link to post
Share on other sites
u can get the side/up/forward vectors from the modelview matrix

eg side = mv.00 mv.10 mv.20
though this maybe mv.00 mv.01 mv.02
depending on how u store the data

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this