Question

I'm building a quick 3D engine for a game I'm developing.

Currently I'm handling rotation of 3D objects by rotating around the global axis Y, X then Z. Is this the correct way to do it, or should I be rotating objects about its local axis?

Which do you recommend and why?

If the local axis method is the correct way, would a 3D 3x3 or 4x4 matrix have to be used to calculate the rotations correctly? How?

alt text

Was it helpful?

Solution

4x4 matrices give you more flexibility. For example, you can concatenate several transformations (translation, rotation, etc) through matrix multiplication.

OTHER TIPS

What are you trying to accomplish? If you want to see the object "spin", then rotations should be performed about the local origin. On the other hand, rotation about the global origin will cause the object to "orbit" the global origin.

Look at the discussion regarding transformation order here for an illustration.

There really isn't a correct order of rotations. If you are making your own game engine, the order is really up to you.

However, that's not to say you can't choose to be consistent with other game engines. Unity, for example, applies Euler-angle rotations in the order Z, X, Y. (source) And I can't confirm 100%, but my experience with Unity leads me to believe that is uses global axes, not local.

If you take the approach mentioned in other answers and concatenate 4x4 rotation matrices, you will probably get local-axis behavior.

But really, if you want to avoid all these problems, you should probably just learn about quaternions...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top