Why is a KX_GameObject.orientation a 3x3 matrix instead of just a [x, y, z] list?

Why is a KX_GameObject.orientation a 3x3 matrix instead of just a [x, y, z] list?

Because orientation consists of more than just x, y, and z rotation angles. It also can be used to stretch/skew/scale objects, and means that it’s a much more flexible and mathematically correct function.

-Sam

Ok, so how do I get the x,y, and z rotation from this?

You can convert the orientation matrix to a list of euler angles using Mathutils:

from Mathutils import Matrix

orientation = object.orientation
ori_mat = Matrix(orientation[0], orientation[1], orientation[2])
ori_eul = ori_mat.toEuler()

The ori_eul will be more like how you rotate the object in edit mode.

Thanks a bunch.

I know its been awhile, but how would you get the Euler angle in 2.5 without mathutils?

You don’t need to import mathutils in this case, because own.worldOrientataion is already a mathutils Matrix in 2.5.

Now you can just do this:


print(own.worldOrientation.to_euler())

New documentation: http://www.blender.org/documentation/250PythonDoc/mathutils.html#mathutils.Matrix

Thanks again social, I was wondering where the new documentation was!