Question about Camera rotation

Started by
4 comments, last by bargasteh 18 years, 10 months ago
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
OpenGl + C++
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.
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.
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]
Thank you

How can I calculate phi and theta from x,y ?
Its extremly annoying.
OpenGl + C++
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.
Thank you for everybody, I figured it out now, it took me ages but its really sweet. cool I love it.
OpenGl + C++

This topic is closed to new replies.

Advertisement