views:

57

answers:

2

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

A: 

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.

Throwback1986
I'm not talking about origins, but rather the axis upon which I should rotate. Local Axis rotation means that the X/Y/Z axis planes rotate with the object. Global Axis rotation means that the X/Y/Z planes do NOT change with each step.
Jenko
@Jenko, the origins define the axes of rotation (in the context of this question, anyway). If you want to achieve rotation about the local axis, you must translate the object such that the rotations occur about the point (0,0,0). This achieves a "spin" type of rotation. If you want to rotate about the global axis, then simply apply the rotations with no preceding translation. If you use a 4x4 matrix, then you may concatenate the matrices to accomplish the translation and rotation in one operation
Throwback1986
+2  A: 

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

Jaime Soto
@Jenko - I neglected to comment on the 4x4 matrix part of the question, but -yes- 4x4 matrices are the best way to go
Throwback1986
Would 4x4 matrices rotate upon Local Axis as I have shown? Or would they return results like Global Axis rotation?
Jenko
The order of the terms matters when multiplying transformation matrices, so I think it's Local Axis. It seems like the order of operations would not matter in Global Axis rotation.
Jaime Soto
Would this 4x3 rotation matrix class work for Local Axis? http://www.bgstaal.net/docs/perspectiveprojection/net/bgstaal/perspectiveprojection/Matrix3d.html (from this tutorial - http://bgstaal.net/blog/?p=57)
Jenko
I could be wrong, but a 3x4 (3-row, 4-column) matrix is treated internally as a 4x4 matrix with the bottom row equal to [0 0 0 1]. Otherwise, it don't know if it's possible to concatenate transformations through matrix multiplication. So you can probably use that specific class, but need to make sure that your matrices are the 4x4 when calculating your own transformation products. Here's a 2D example with 2x3 matrices interpreted as 3x3 with [0 0 1] as the bottom row: http://www.wiley.com/legacy/products/subject/life/biological_anthropology/0471205079_virtual_reconstruction/chapter5_trafo.html
Jaime Soto