lgc_ustc

01-04-2004, 07:02 PM

Hi,all,

I have recently made a camera class for my project. Although all the code has been written and it works perfectly, I still have some questions. The key code section in the class is from http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Quaternion_Camera_Class, and it looks like:

void glCamera::SetPrespective()

{

GLfloat Matrix[16];

glRotatef(m_HeadingDegrees, 0.0f, 1.0f, 0.0f);

glRotatef(m_PitchDegrees, 1.0f, 0.0f, 0.0f);

glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);

m_DirectionVector.i = Matrix[8];

m_DirectionVector.k = Matrix[10];

glLoadIdentity();

glRotatef(m_PitchDegrees, 1.0f, 0.0f, 0.0f);

glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);

m_DirectionVector.j = Matrix[9];

glRotatef(m_HeadingDegrees, 0.0f, 1.0f, 0.0f);

// Scale the direction by our speed.

m_DirectionVector *= m_ForwardVelocity;

// Increment our position by the vector

m_Position.x += m_DirectionVector.i;

m_Position.y += m_DirectionVector.j;

m_Position.z += m_DirectionVector.k;

// Translate to our new position.

glTranslatef(-m_Position.x, -m_Position.y, m_Position.z);

}

This code sets up the model/view matrix using the camera's heading and pitch degrees. It works perfectly. What I do not get is the way it gets the direction vector from the model/view matrix using glGetFloat. Can anybody explain this a little bit or introduce some theoretic materials? Can I get the up vector in the similar way? Thanks a lot. http://www.opengl.org/discussion_boards/ubb/smile.gif

I have recently made a camera class for my project. Although all the code has been written and it works perfectly, I still have some questions. The key code section in the class is from http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Quaternion_Camera_Class, and it looks like:

void glCamera::SetPrespective()

{

GLfloat Matrix[16];

glRotatef(m_HeadingDegrees, 0.0f, 1.0f, 0.0f);

glRotatef(m_PitchDegrees, 1.0f, 0.0f, 0.0f);

glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);

m_DirectionVector.i = Matrix[8];

m_DirectionVector.k = Matrix[10];

glLoadIdentity();

glRotatef(m_PitchDegrees, 1.0f, 0.0f, 0.0f);

glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);

m_DirectionVector.j = Matrix[9];

glRotatef(m_HeadingDegrees, 0.0f, 1.0f, 0.0f);

// Scale the direction by our speed.

m_DirectionVector *= m_ForwardVelocity;

// Increment our position by the vector

m_Position.x += m_DirectionVector.i;

m_Position.y += m_DirectionVector.j;

m_Position.z += m_DirectionVector.k;

// Translate to our new position.

glTranslatef(-m_Position.x, -m_Position.y, m_Position.z);

}

This code sets up the model/view matrix using the camera's heading and pitch degrees. It works perfectly. What I do not get is the way it gets the direction vector from the model/view matrix using glGetFloat. Can anybody explain this a little bit or introduce some theoretic materials? Can I get the up vector in the similar way? Thanks a lot. http://www.opengl.org/discussion_boards/ubb/smile.gif