• ### What is your GameDev Story?

This topic is 4974 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 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 on other sites
Thank you

How can I calculate phi and theta from x,y ?
Its extremly annoying.

##### 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 on other sites
Thank you for everybody, I figured it out now, it took me ages but its really sweet. cool I love it.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 31
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634121
• Total Posts
3015613
×