[math] inverting one axis in rotation matrix

Hi there,

basicly my setup is the following:

There is one object (“guide”), which is controled by logic bricks. Then there is another object (“follow”), which reads the orientation of “guide” and rotates the same way, but with one difference: I want on of the local axis (Z in this case) to be inverted.
This does work (“guide” turns positive on z-axis, “follow” does it negative) by inverting the sinus values for the z-rotation in the matrix:

rotationMatrix[0][1] = -rotationMatrix[0][1]
rotationMatrix[1][0] = -rotationMatrix[1][0]

But this does only work, as long as “guide” only rotates around one axis. When I let it rotate around another axis too, I get strange deformations of “follow”:
http://yfrog.com/06rotationproblemj

Maybe someone could give me a hint or some help for some “clean” setup to realize this. I am not that good at math, so I guess there is a much better way than inverting the values.

Thanks,
Quen

To obtain euler angles from the rotation matrix I have developed a dedicated function, eulAngs (see below). In your case I would proceed as follows::


from math import *
from Mathutils import *

def eulAngs(gameObj,local):
    if local==1:
        Mat=gameObj.localOrientation
    else:
        Mat=gameObj.worldOrientation
    M=Matrix(Mat[0],Mat[1],Mat[2]).transpose()
    eulVec=M.toEuler()    # in gradi!!!
    fi,tet,psi=map(radians,eulVec)
    return (fi, tet, psi)

[rotX, rotY, rotZ] = eulAngs(guide, 0)             # calculate the euler angles of "guide"
follow.worldOrientation = [rotX, rotY, -rotZ]      # set the euler angles of "follow"

This allows a direct and more “readable” control over object orientations.
For example, if you want that “follow” mirrors the orientation of “guide” with respect to the world x-z plane you should reverse the sign of rotX as well:

follow.worldOrientation = [-rotX, rotY, -rotZ]

mb