# NeHe Camera Class

This topic is 4961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631424
• Total Posts
3000008
×