# NeHe Camera Class

## Recommended Posts

skyfire360    228
I'm working on a quaternion camera of my own and would like to use the approach that NeHe used in his camera class. I understand what quaternions are, what they are used for, and how they store their information. However, I only understand what actually is going on in the SetPerspective function, and not why it happens. Here's NeHe's SetPerspective funcion:
void glCamera::SetPrespective()
{
GLfloat Matrix[16];
glQuaternion q;

// Make the Quaternions that will represent our rotations
m_qPitch.CreateFromAxisAngle(1.0f, 0.0f, 0.0f, m_PitchDegrees);

// Combine the pitch and heading rotations and store the results in q
q.CreateMatrix(Matrix);

// Let OpenGL set our new prespective on the world!
glMultMatrixf(Matrix);

// Create a matrix from the pitch Quaternion and get the j vector
// for our direction.
m_qPitch.CreateMatrix(Matrix);
m_DirectionVector.j = Matrix[9];

// Combine the heading and pitch rotations and make a matrix to get
// the i and j vectors for our direction.
q.CreateMatrix(Matrix);
m_DirectionVector.i = Matrix[8];
m_DirectionVector.k = Matrix[10];

// 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);
}


For instance, why do you multiply pitch then heading to get the world-to-camera matrix then multiply the heading by the pitch to get the up and forward direction vectors? Are the two matricies that result inverses of each other? What do these two matricies that result from 'q' represent?