Sign in to follow this  
Seabolt

Camera Rotation

Recommended Posts

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:

[code]


//////////////////////////////////////////////////////////////////////////
// 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;
}
//////////////////////////////////////////////////////////////////////////

[/code]


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.

Share this post


Link to post
Share on other sites
First tell us which one (if not all) of the rotations that fails.
RotateCameraLocalZ() seems to do nothing since you are recreating mRight and mUp every UpdateViewMatrix()


Split it up and run multiple tests to figure out where the problem lies.

How is TCMatrixF::XAxis defined?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this