Jump to content
  • Advertisement
Sign in to follow this  

Camera Movement dependet from mouse movement

This topic is 2303 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 have the following question. I have programmed the rotation of the object dependent from the mouse movement. This works. But know I want to make the "object movement" by rotating the camera instead of rotating the object because I need this for a new program code because it would make this program code simplier.

The problem is how to make the rotation of the camera movement? When I have a movement in x-direction and a movement in y-direction of the mouse then I have written the following code:

m_Camera->setRotation(mouseRX, mouseRY, status);
temp_rot = m_Camera->getRotation();
rot1 = m_Camera->getLength() * cos(temp_rot.y) * cos(temp_rot.x);
rot2 = m_Camera->getLength() * cos(temp_rot.y) * sin(temp_rot.x);
rot3 = m_Camera->getLength()* sin(temp_rot.y);

m_Camera->SetPosition(rot1, rot2, rot3);
m_Camera->SetLookVector(nullvector - m_Camera->GetPosition());

So I calcuate the kartesian coordinates (rot1, rot2, rot3 ) which are the x,y,z coordinates and set the position and look vector. This works when one of the angles is zero, but if both of them aren't zero then it does not work. Can anyone help me with this problem?
Thanks a lot.

Share this post

Link to post
Share on other sites
I'm assuming since you posted this in the DirectX forum, that you have access to the Matrix class. Why not use the Matrix method from your API that creates a rotation matrix from a yaw, pitch, and roll value? (Not sure which version of DirectX you're using)

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!