View Full Version : can someone help me with quaternions

04-05-2011, 07:57 PM
i got this quaternion camera class from nehe tutorials
but its not behaving as i need it to
it only has up and down movement with velocity
but i need forward and back movement
and left and right movement for strafing
and i need the forward and right vector affected by the yaw
just your typical fps game style controls
the mouse seems to pitch and yaw fine even though the axis set at the top should be y for yaw and z for pitch
so why are they set to x and y then?
also glulookat() i think should be set to position, direction and up but that gave me a black screen
so i set it to position plus forward
you can see the commented code i tried but that didnt work
also the translation is what came with the code
but i need to use glulookat()
plz help

// Set perspective and move the camera
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);

//m_qPitch.CreateFromAxisAngle(1.0f, 0.0f, 0.0f, m_PitchDegrees);
//m_qHeading.CreateFromAxisAngle(0.0f, 0.0f, 1.0f, m_HeadingDegrees);

// Combine the pitch and heading rotations and store the results in q
q = m_qPitch * m_qHeading;
//q = 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;
//q = m_qHeading;

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

m_Position.x, m_Position.y, m_Position.z,
m_Position.x, m_Position.y + 1, m_Position.z,
0, 0, 1