I’ve created a camera using functions such as glRotate and glTranslate to move the camera, but retrieving the modelview matrix with:
I call this function everytime I change it’s attributes.
I’ve also created a camera using math functions and modifying eye, center, and up vectors with sinus, cosinus, etc.
Anybody knows which method is better and why?
If you know what are you doing in matrices you can use glLoadMatrixf or glMultMatrixf.
Here is a code snippet of how I do it. It works really well. I had some weird issues w/ using glLoadMatrix and glMultMatrix for some reason so this is how I do it now:
if( m_fPitchAngle > 90.0f )
m_fPitchAngle = 90.0f;
else if( m_fPitchAngle < -90.0f )
m_fPitchAngle = -90.0f;
Matrix4 camRot, cx, cy;
cx.RotateX( m_fPitchAngle * DEGTORAD );
cy.RotateY( m_fYawAngle * DEGTORAD );
camRot = cy * cx;
VectorAdd( &m_vEye, m_vEye, camRot * m_vVelocity );
glRotatef( m_fPitchAngle, 1, 0, 0 );
glRotatef( m_fYawAngle, 0, 1, 0 );
glTranslatef( m_vEye.x, m_vEye.y, m_vEye.z );
That’s pretty much the “meat and potatoes” of my camera class. The only other thing is extracting the pitch and yaw from the inverse view matrix which is done before this code obviously.
EDIT: Man that dang code block sure does make the code really small. Almost hard to read.