I basically have this problem:
Generic Simple 3D Matrix Rotation Issue
and it is driving me mad. I have been on Google for hours but cannot find any posts about solving the problem mathematically. How do I successfully rotate an object around 3 axis with a matrix and avoid this issue?
Thanks.
The solution/workaraound is to apply the rotations in the correct order.
If you have rotation matrices A, B and C and want to apply them to matrix M in order A, B, C then the solution is:
First apply A:
Then B:
And finally C:
If you want to apply ABC frequently you can precalculate the combined rotation matrix R:
and then you can apply R to M:
Thanks for all your help. I have found the answer here:
http://www.learnopengles.com/tag/rotation/
The solution is: "One easy way to work around this problem is to keep a second matrix around that will store all of the accumulated rotations." :-)
If I get it right you want to rotate direct object transform matrix around its own axises.
M0
is original object matrixR
is transformation you want to apply (rotation)M1
is the result new object matrixM1 = Inverse(Inverse(M0)*R)
That is all. you just have to add 4x4 inverse matrix routine to your code for example here is mine
matrix_inv(dst,src)
src
todst
src
anddst
aredouble[16]
linear arrays representing 4x4 transform matrix[Edit1] 3x3 matrix
Mine matrix layout is this (OpenGL like):
a??
is ??-th value fromM[]
Now if you want to use 4x4 inverse of 3x3 matrix just do this
b??
is ??-th value from your 3x3m[]
just to be sure you get it right m[3*3] -> M[4*4] will be like this:
And backwards m[3*3] <- M[4*4] will be like this: