Jump to content
  • Advertisement
Sign in to follow this  
bargasteh

Question about Camera rotation

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

Hello I can get the x and y valuse (x,y mouse coordination) of mouse in my screen, but i dont know how to use them in a way to rotate my camera to UP, Down, Left and Right. do you know the maths behind this? I mean how can i calculate the Pitch and Heading of my camera from x and y? Thank you in advance

Share this post


Link to post
Share on other sites
Advertisement
i have my camera set so that when i use the mouse wheel the camera's Distance value is changed in/out and when mouse button 2 is pressed any changes in mouseX or MouseY are added to camera yaw and height.

my camera is positioned based on its own distance, yaw, and height from that of the player.

but it depends on how you defined the camera. mine is just a vector for position, and target < always the players location > and then distance, height, and yaw.

Share this post


Link to post
Share on other sites
You're going to have to (well, one way is to) use sin and cos with angles, where the angles are incrememnted/decrememnted by moving the mouse.

For a third person camera,

y = distance * sin(phi);
y_distance = distance * cos(phi);

x = y_distance * sin(theta);
z = y_distance * cos(theta);

Where phi is the vertical angle, and theta the horizontal angle. We calculate the y_distance so that the movement is spherical, rather than cylindrical.

Share this post


Link to post
Share on other sites
what he means by distance, is that you have to assume that the lookat coordinate will always be a fixed distance away from the camera.

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!