Jump to content
  • Advertisement
Sign in to follow this  
markww

OpenGL orbiting a camera around its focal point?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!