Sign in to follow this  
redneon

Bizarre camera rotation

Recommended Posts

I'm getting unexpected results when I add a rotation to my camera. I'm sure it's really obvious bug but I'm having a bit of a blank so I was hoping someone could help me.

In my camera class I store four vectors. One for position and then one each for left, up and forward for the rotation. Then at the end of my camera's update I create the view matrix via something like:

[CODE]
m_view = Matrix::CreateLookAt(m_position, m_position + m_foward, m_up);
[/CODE]

Anyway, my camera has a function for adding rotation which gets called from the input component and it looks something like this:

[CODE]
void Camera::AddRotation(const Matrix& rRotAdd)
{
Matrix tempMat(m_left, m_up, m_forward);
tempMat = rRotAdd * tempMat;

m_left = tempMat.GetColumn0();
m_up = tempMat.GetColumn1();
m_forward = tempMat.GetColumn2();
}
[/CODE]

As you can see, I create a temporary matrix from the rotation member variables so that I can add on the rotation that's passed in and then re-set the vectors from the resulting matrix.

This seems to work fine if I only update the rotation on one axis, so just the pitch or just the yaw. But if I try to rotate in both pitch and yaw I'm not seeing the results I expect. The camera actually appears to roll and the effect is worse the more pitch/yaw I put on.

I can record a video of what it looks like if the issue isn't immediately obvious.

Share this post


Link to post
Share on other sites
A bit more information as I've just noticed something.

I noticed if I set the camera up pointing down the Z axis and yaw 90 degrees so it's facing down the X axis, if I then try and pitch it appears to roll. This leads me to believe that it is pitching correctly but as if the camera was still pointing down the Z axis. What I'm expecting is it to pitch up and down whilst still pointing down the X axis. So could it be an order of operations issue? It's essentially a free camera I'm after.

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