# Cam rotation prob

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

## Recommended Posts

Hi, I posted this same question in OpenGl (wrong place).. Given that the viewer / cam is at point x,y,z and that the center of gravity, of some rock in space, is at 0,0,0. I have a heading controlled by the mouse x. this heading is an angle around the axis created by 0,0,0 -> Cam x,y,z, and have the view aligned to that axis. Basically as if you were standing on the surface. So If I were to use glLookAt the cam is at x,y,z, lets say up is x*2,y*2,z*2 and the target is the vector perpendicular to cam x,y,z rotated by "Heading". I have a good FPS cam working no problem, but cant seem to get my head around the additional ground orientation, that is the cam being on the surface of a sphere. I think I need to do the following but am not sure of the math. If the vector made by CamX,Y,Z is normalized that that normal can be said to belong to a plane on witch I would find a point (via Sin,Cos) of my Heading angle this point will be translated by the cam position and become the lookat or eye point for the glLookAt function. Any thoughts.

##### Share on other sites
The problem may be that you need a frame of reference to find your direction vector via sin() and cos(). Perhaps the best way to solve this involves aligning your object to the surface normal, either instantaneously or via slerp(). However, I'll take a shot at a more quick-and-dirty solution.

Maintain a position vector and a forward direction vector. The position vector also serves as the surface normal and up vector, as you've described.

When updating, start by rotating the direction vector about the up vector in response to user input. Normalize the up vector to get a unit-length normal, and then perform an axis-angle rotation rotating the forward vector about this normal. The formula for axis-angle rotation should be easy to find online, either in direct or matrix form.

Now move your object along the direction vector. After the step the object will probably be a bit above the surface, so adjust its height accordingly.

At this point the forward vector will no longer be perpendicular to the up vector. This can be fixed as follows:

Vector3 n = up.GetNormalized();
forward -= forward.Dot(n) * n;
forward.Normalize();

Anyway, that's just off the top of my head, and I may have missed something somewhere. But you might give it a try.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632936
• Total Posts
3009312
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!