0

Let's say I have Rotation(0, 0, 180) [pitch, yaw, roll]. How to do it that I would have Rotation(180, 180, 0) which is exactly the same?

  • You're not strictly guaranteed that every orientation that can be described in terms of three Euler/Tait-Bryan angles has an equivalent representation with just two. One maps a 3-dimensional space, the other a 2-dimensional subset of that space. Can you give us some context for why you're trying to do this conversion, and where these angles arise in your game? That might help us identify whether there are constraints that keep them usually/mostly within the set representable with only pitch & yaw. – DMGregory Oct 06 '18 at 15:19
  • I have tanks which are rotated whole as objects and can rotate their turrets and guns. When the tank has all 3 rotations (for example on hillside) and I want to calculate rotation between gun and their target opponents (this is the rotation in which turret and gun must rotate to point at opponent), I receive rotator with roll rotation too but I can only rotate turret and gun in pitch and yaw. – dowiemsiewkoncumoze Oct 06 '18 at 17:48
  • Ah, that's a much better framing of the question. The context tells us a lot. Want to edit that into the main title & body, and we can clear out the redundant comments? – DMGregory Oct 06 '18 at 17:50
  • I am afraid it will not help a lot. Answer on this question is probably the only thing I can do. – dowiemsiewkoncumoze Oct 06 '18 at 17:53

1 Answers1

1

To keep track of orientation, and orientation changes, you are often better off using two perpendicular vectors, as opposed to three angles.

  • A "look-at" or "forward" vector.
  • An up-vector.

Taking the cross product of these two will give you a vector perpendicular to both, and can be used for your transformation matrix.

To derive the basis, remember:

X = Y × Z
Y = Z × X
X = X × Y

If you were to switch the order of the product's arguments, you switch between LH and RH coordinate systems.

Using three angles is called "Euler Angles."

There are also Quaternions that can be used to keep track of orientation and orientation changes. But I find two vectors to be more intuitive.

To summarize: two perpendicular unit vectors uniquely describe an orientation.

Bram
  • 3,729
  • 18
  • 23