I have a small question regarding inverse of a matrix.
So, i have a modelview matrix and it’s inverse. I see that the inverse matrix neatly cancels my rotation, and i use this for billboards.
However, when i obtain Euler angles from both matrices, i see that they don’t negate each other. i.e
Say angles obtained from MV matrix = a1, a2, a3.
I would have expected the Euler angles from the inverse matrix as -a1, -a2, -a3
However, i see this is not the case. Can anyone please explain what i’m missing here?
To reverse a Euler angle transformation around x,y and then z, you need to rotate by the negative angles around z, y and then x. Rotating by the negative angles around x, y then z isn’t the reverse operation.
There are multiple solutions that can be found when converting a rotation matrix to Euler angles, see: http://www.soi.city.ac.uk/~sbbh653/publications/euler.pdf. Converting rotation matrices to quaternions is usually a better choice.
I’m not quite sure what you you’re doing with the inverse matrix, but when you apply a transformation and then it’s inverse transformation you almost certainly won’t end up with exactly the original state due to numerical inaccuracies. Be careful not to keep repeating this operation or the errors will build up and become more noticeable.
It’s better to push the matrix to the stack, modify it, then pop from the stack than to multiply by a matrix and it’s inverse and hope to end up with the original value.
This ensures the matrix will be exactly the same after modification:
This will drift with repeat operations:
Thanks for the reply Dan Bartlett!