Original Post
[font=arial, verdana, tahoma, sans-serif][size=2]Hey guys, I've currently got a camera class, and I can't get it to rotate properly.
Currently I'm rotate my camera by it's Up, Right, and Forward axis. But when I rotate the camera it is doing a very strange rotation, almost like it's rotating around the orgin. Here is my basic setup:
Do you guys see anything terribly off? And I understand there are other option to doing this, such as Quaternions, and there are inherit issue involving Gimbal Lock, but I'd like to get this working, then attempt a quaternion solution. Also I wrote ( re: googled and copied the formula ) for the math functions.[/font]
Currently I'm rotate my camera by it's Up, Right, and Forward axis. But when I rotate the camera it is doing a very strange rotation, almost like it's rotating around the orgin. Here is my basic setup:
//////////////////////////////////////////////////////////////////////////
// TranslateCamera
void
TCCamera::TranslateCamera( TCVector3F vector )
{
mEye.X = mEye.X + vector.X;
mEye.Y = mEye.Y + vector.Y;
mEye.Z = mEye.Z + vector.Z;
UpdateViewMatrix();
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// RotateCameraLocalX
void
TCCamera::RotateCameraLocalX( f32 rotationValue )
{
TCMatrixF rotationMatrix;
// Create our rotation matrix.
rotationMatrix.MakeAxisAngle( mRight, rotationValue );
// Transform our Up and our Forward
mUp = rotationMatrix.TransformVector( mUp );
mForward = rotationMatrix.TransformVector( mForward );
// Reconstruct our matrix
UpdateViewMatrix();
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// RotateCameraLocalY
void
TCCamera::RotateCameraLocalY( f32 rotationValue )
{
TCMatrixF rotationMatrix;
// Create our rotation matrix.
rotationMatrix.MakeAxisAngle( m_matViewMatrix.YAxis, rotationValue );
// Transform our Up and our Forward
mRight = rotationMatrix.TransformVector( mRight );
mForward = rotationMatrix.TransformVector( mForward );
// Reconstruct our matrix
UpdateViewMatrix();
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// RotateCameraLocalZ
void
TCCamera::RotateCameraLocalZ( f32 rotationValue )
{
TCMatrixF rotationMatrix;
// Create our rotation matrix.
rotationMatrix.MakeAxisAngle( mForward, rotationValue );
// Transform our Up and our Forward
mRight = rotationMatrix.TransformVector( mRight );
mUp = rotationMatrix.TransformVector( mUp );
// Reconstruct our matrix
UpdateViewMatrix();
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// UpdateViewMatrix
void
TCCamera::UpdateViewMatrix()
{
TCMatrixF translation;
// Normalize our forward
mForward.Normalize();
// Calculate our right axis
mRight = CrossProduct( WorldUpVector, mForward );
mRight.Normalize();
// Calculate our up axis
mUp = CrossProduct( mForward, mRight );
mUp.Normalize();
// Set our axis
m_matViewMatrix.XAxis = mRight;
m_matViewMatrix.YAxis = mUp;
m_matViewMatrix.ZAxis = mForward;
// Recalculate our translation
m_matViewMatrix.Translation.MakeZero();
translation.MakeIdentity();
translation.Translation = mEye;
m_matViewMatrix = m_matViewMatrix * translation;
// Get our View Proj
m_matViewProjectionMatrix = m_matViewMatrix * m_matProjectionMatrix;
}
//////////////////////////////////////////////////////////////////////////
Do you guys see anything terribly off? And I understand there are other option to doing this, such as Quaternions, and there are inherit issue involving Gimbal Lock, but I'd like to get this working, then attempt a quaternion solution. Also I wrote ( re: googled and copied the formula ) for the math functions.[/font]