Peter Wirdemo
Peter Wirdemo

Reputation: 526

Calculate object XYZ orientation after XYZ-rotation

I rotate an object in 3D space in XYZ by 90 degree steps, (rX rY rZ). The angle's are limited to 0-360 degree and I use the following commands for rotating the matrix:

Matrix.rotateM(mModelMatrix, 0, rX, 1.0f, 0.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, rY, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(mModelMatrix, 0, rZ, 0.0f, 0.0f, 1.0f);

If the XYZ of the object - before rotation - is right (X+), away (Y+) and up (Z+); How can easily calculate what is right, away and up after an arbitrary rotation?

I have no other information but the rX, rY and rZ rotation variables.

Upvotes: 1

Views: 1103

Answers (1)

Matic Oblak
Matic Oblak

Reputation: 16774

When having a matrix it might make most sense to multiply the base vectors with the same matrix to get transformed vectors. For instance if you are looking for a vector facing from object toward (0,0,1) respecting its internal coordinate system you would first transform the origin (0,0,0) with this matrix to get the new center and then transform the target vector (0,0,1) with the same procedure. The result is then target-origin. This procedure will work for any system and any combination you need but you do need to watch out what matrix you are multiplying with as in most cases the projection should not be included.

Another interesting solution for your specific case might be simply looking at the matrix base vectors. The top-left 3x3 part of the matrix actually represents the 3 axis for x, y and z. So identity is x=(1,0,0), y=(0,1,0), z=(0,0,1). Once rotated or scaled these values will change and can be accessed directly from the matrix.

Upvotes: 1

Related Questions