Sign in to follow this  
Toni Petrina

Orbiting camera

Recommended Posts

I have camera that should be orbiting around some object. I know how to move around object (yaw) but I don't know how to move up-down. I've tried combining yaw and pitch into D3DXMatrixRotationYawPitchRoll but it yields incorrect results. Camera twists and turns and I finish upside down (which in theory cannot happen since roll is always 0). Do you know how to do this?

Share this post


Link to post
Share on other sites
Well, if you want something to orbit another object, the best (and easiest IMHO) way to do it is to move the orbiter so that the target is at (0,0,0) - the origin. Then you can rotate the orbiter around any combination of the 3 axis, and it will rotate ("orbit") around the origin - which conviently we have made the target. Then just translate back to the original position, and voila!

Explanation with (admittedly poorly drawn) pictures:

Step 1: Find the distance between the target and the origin. Store in a vector.

(T)
|---{O} {S}

Step 2: Make the distances between (S) - satellite and (O) - origin the same as that between (O) and (T) - target. Use vector maths for this to find the difference between (T) and (O).

(T)
{O} {S}
(S)<|

Step 3: Rotate (S) however you want.

(T)
(O)

(S)
(this is a rotation)

Step 4: undo the translation that you did in Step 2.

(T)
(O)
|>
(S)

Step 5: relax! You've orbited something!

(T)
(O)
(S)

You really don't need to use the yaw pitch roll stuff if you don't need to. Simple rotations around axis (x,y,z) are easiest...


Mushu - trying to help those he doesn't know, with things he doesn't know.
Why won't he just go away? An question the universe may never have an answer to...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this