# OpenGL orbiting a camera around its focal point?

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

## Recommended Posts

Hi, I have a camera in 3d space (using opengl, with a wrapper around it called VTK). The camera has a position, and a focal point. I want to rotate the camera around its focal point so it looks like it's orbiting around the focal point. Something like: for (int i = 0; i < 64; i++) { OrbitCamera(360 / 64 * i); } I'd like to rotate it 64 positions around the focal point. How can I do this? I'd like the orbit path to follow the camera's view up direction, if possible. Thanks

##### Share on other sites
thats the algorithm you want:

Matrix3X3 transform;
transform.SetAsIdentity();
transform.Rotate(360 / 64, MyRotationAxis);

v3d focalpoint = Camera.FocalPoint;

for (int i = 0; i < 64; i++)
{
v3d direction = Camera.Position - Camera.FocalPoint;
direction = transform * direction;
Camera.Position = Camera.FocalPoint+ direction;
}

##### Share on other sites
One way to do this would be to:

a) Position the camera at the origin, with the lookat vector pointing to 1, 0, 0
b) Rotate the lookat, up and left vectors by however many degrees is needed along the y axis (2PI/64*i), and then along the x axis to point it up/down if desired.
c) Translate camera backwards by however many units away from the origin you need it to be.

This will give you all of your vectors and the camera position.

Since your vectors are of unit length, and based on the origin, you can simply rotate them as if they were points using the standard matrix-based transformation.

(Edit: Happygolucky's solution seems simpler).

##### Share on other sites
Hi,

First, thanks for your replies. I am not understand a few parts:

1) How can I get 'MyRotationAxis' - if I was looking at a person from the front and the focal point is their chest, I would want to rotate so that it looks like their head and feet flip. This axis must be the perpendicular to the 'camera up' vector?

2) How do I do this:

direction = transform * direction;

I know this is basic but - how do I multiply 'direction' which is a vector by 'transform' which is a 3x3 matrix?

Other than that I understand everything,

Thanks,
Mark

1. 1
2. 2
3. 3
Rutin
14
4. 4
khawk
11
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633671
• Total Posts
3013269
×