FPS camera: finding forward/right/up vectors?

Started by
1 comment, last by zedz 15 years, 12 months ago
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:

glRotatef(viewAngles.x,1.0f,0.0f,0.0f);
glRotatef(viewAngles.y,0.0f,1.0f,0.0f);
glTranslatef(-playerOrigin.x,-playerOrigin.y,-playerOrigin.z);
Any suggestions for my noobish question? Thanks in advance.
Advertisement
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.
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

This topic is closed to new replies.

Advertisement