Skip to main content
gamedev.net
🔒 Locked

Orbit Rotation

Started by DanielMGClua Mar 28, 2007 at 9:04 AM 1 replies 1.1k views
Original Post
DanielMGClua
DanielMGClua
Does anyone know how I can make the camera rotate around a point in the scene? Let me explain a little better: I have a plane in my scene that can be translated, zoomed and rotated. At first, I was apllying the transformations in this order: Translate (pan and zoom), Rotate in the X axis and Rotate in the Z axis. The result wasn't bad, but the plane rotates around it's center. So if I am focusing at, say, one of it's corners, when I rotate, I loose the focus on the corner and have to pan to get it back... and that can be very inconvenient. So, I was trying to find out a way that, when I rotate, the camera would orbit araund the point of the scene I'm focusing. But I'm having a lot of problems with that. Can someone help me out?
MaliciousDigit
MaliciousDigit
First, i suggest rotating the scene. Otherwise you have to transform to the center of the scene, do your rotation and transform back out to the cameras distance from center. Second, I would put this in a scenegraph where you associate each object or group with a transform. it makes for easy management.
strtok
strtok
Here's how I do it:

1. Keep track of the point that the camera will be orbiting (I call this "center")
2. Keep track of the orientation of the camera, i.e. which direction it is pointing (I use a quaternion to represent this orientation)
3. Keep track of the distance from the "center" to the camera (or the radius of orbit)

When you wish to orbit around the point, you do this:
1. Determine the new camera orientation
2. Rotate the vector <0.0, 0.0, radius> (which represents the position of the camera in eye coordinates) by the camera orientation, then add the "center" point. This gives you the new camera position in world coordinates. Essentially what you are doing is rotating the camera position around the "center" point, in world coordinates.

So now you have the new camera position and the camera orientation. To display, you:
1. Rotate the scene by the inverse of the camera rotation
2. Translate the scene by the negative camera position (<-cam.x, -cam.y, -cam.z>)

Hopefully that explains things...let me know if not.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.