# Orbiting camera

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

## 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 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...

1. 1
2. 2
3. 3
Rutin
24
4. 4
JoeJ
18
5. 5

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

• Total Topics
631766
• Total Posts
3002232
×