Jump to content
  • Advertisement
Sign in to follow this  
r2d2rigo

FPS camera: finding forward/right/up vectors?

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

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.

Share this post


Link to post
Share on other sites
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!