• Advertisement
Sign in to follow this  

Orbiting camera

This topic is 4961 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement