PDA

View Full Version : OpenGL camera



dslprog
04-16-2004, 08:12 AM
I've created a camera using functions such as glRotate and glTranslate to move the camera, but retrieving the modelview matrix with:

glGetFloatv(GL_MODELVIEW_MATRIX,&m);

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?

Thanks.

yooyo
04-16-2004, 10:07 AM
If you know what are you doing in matrices you can use glLoadMatrixf or glMultMatrixf.

yooyo

SirKnight
04-16-2004, 04:16 PM
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;

camRot.ToIdentity();
cx.ToIdentity();
cy.ToIdentity();

cx.RotateX( m_fPitchAngle * DEGTORAD );
cy.RotateY( m_fYawAngle * DEGTORAD );

camRot = cy * cx;

VectorAdd( &amp;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.

-SirKnight