Jump to content
  • Advertisement
Sign in to follow this  

Bizarre camera rotation

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

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:

m_view = Matrix::CreateLookAt(m_position, m_position + m_foward, m_up);

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

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();

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
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!