Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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);
	m_qHeading.CreateFromAxisAngle(0.0f, 1.0f, 0.0f, m_HeadingDegrees);
	// Combine the pitch and heading rotations and store the results in q
	q = m_qPitch * m_qHeading;

	// Let OpenGL set our new prespective on the world!
	// Create a matrix from the pitch Quaternion and get the j vector 
	// for our direction.
	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 = m_qHeading * m_qPitch;
	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?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!