Hey all,
So I've decided to attempt to rewrite my camera class using quaternions, but am running into some difficulties getting my transformations to behave correctly.
Currently, I'm only attempting to implement movement along the view vector, and strafing to ensure that this is setup properly before I move on. Movement along the view vector works fine, but when I try to strafe, it seems to rotate the scene towards the eyepoint, rather than moving along the local right axis of the camera.
Here's my code for calculating my local right axis and moving:
fVec3 fCamera::CalculateStrafe()
{
// retrieve our current orientation matrix
fMatrix4x4 orient;
fQuaternion quat = GetOrientation();
quat.CreateMatrix(orient.GetMatrix());
return fVec3( orient[0], orient[1], orient[2] );
}
//**************************************************************************
// Method: Strafe
// FullName: fCamera::Strafe
// Access: public
// Returns: void
// Description: Moves the camera along the camera's local right axis
// Parameter: const int& direction
// The direction to move the camera
// : 1 for RIGHT
// : -1 for LEFT
//**************************************************************************
void fCamera::Strafe( const int& direction )
{
fVec3 strafe_dir = CalculateStrafe();
Normalize(&strafe_dir, &strafe_dir);
strafe_dir *= (float)direction * m_move_speed;
UpdateLocalPosition( strafe_dir );
m_lookat_point += strafe_dir * Clock::TimeLastFrame();
}
Later in the application, when I attempt to render, I retrieve the parameters for gluLookAt as follows:
fMatrix4x4 fSceneGraph::GetActiveCameraOrientation()
{
fMatrix4x4 ret;
// retrieve our camera's position and orientation
fQuaternion orient = m_active_camera->GetOrientation();
fVec3 pos = m_active_camera->GetWorldPosition();
// convert the camera's current orientation into matrix form
orient.CreateMatrix(ret.GetMatrix());
fVec3 lookat = m_active_camera->GetLookAt();
ret[8] = lookat.x;
ret[9] = lookat.y ;
ret[10] = lookat.z;
// append our position into the translational component of our orientation matrix
ret[12] = pos.x;
ret[13] = pos.y;
ret[14] = pos.z;
ret[15] = 1.f;
return ret;
}
...
...
fMatrix4x4 camera_orient = gpApp->SCENEGRAPH->GetActiveCameraOrientation();
gluLookAt( camera_orient[12], camera_orient[13], camera_orient[14],
camera_orient[8], camera_orient[9], camera_orient[10],
camera_orient[4], camera_orient[5], camera_orient[6] );
I'm really not sure what could be going wrong here. Any help is greatly appreciated. I can also post more code or screenshots if that will help.
*Note: As a debug aide, I drew the world coordinate axis' and found that when I strafe left or right, I never can see the z-axis (the one facing directly into the camera). So it would seem my camera position is never changing, although I am specifying it and passing my updated camera position to gluLookAt. I have stepped through and also confirmed that both my lookat point and position are changing when I strafe, so I'm even more confused.*
Thanks again!