Jump to content
  • Advertisement
Sign in to follow this  
Seabolt

Camera Rotation

This topic is 2617 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

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:




//////////////////////////////////////////////////////////////////////////
// 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.

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!