I have an Object which is ‘Child’ to an other and i want calculate the Global Rotation of it. I know, there are some Topic’s here to this Theme, but all this Stuff will not work. And i can’t find a working Tutorial. I still working with Blender2.25 and i use the ‘vecf.py’ Modul from eeshlo and theeth. I’ve tried this Code:

Child = Object.getCurrentSelected()
Parent = Child.parent
GlobRot = mulmat(Parent.getInverseMatrix(),Child.getMatrix(),3)
# Also not working is:
GlobRot = mulmat(transp3x3(Parent.getMatrix()),Child.getMatrix(),3)

What’s wrong here? The Results are not OK! (Both Objects are not scaled.) An Other Thing i don’t undersand is this: Obj.getInverseMatrix() gives an other Result as tranp3x3(Obj.getMatrix). Do i have the wrong ‘vecf.py’ Vesion? I have this here: http://www.clubinfo.bdeb.qc.ca/~theeth/vecf.py
Thanks for Help, Doc

Now i’m totally confused. I found this in Your Modul:

# transpose 3X3 matrix, the INVERSE rotation matrix
def transp3x3(m):
r = MtxIdentity3x3()
for i in range(3):
for j in range(3): r[i][j] = m[j][i]
return r

Is this not what i need? There is nothing else, or have i missed something?

Sorry, my bad, I seem to miss the part where you said that both object are not scaled.

In this case, yes, the transposed matrix is the same as the inverse matrix.

I did some test, and the only different between the matrix found by using the transposition function and the one through getInverseMatrix is that getInverseMatrix rounds to the third decimal.

The Matrix obtained with getMatrix already contains the global rotations, you don’t have to multiply by the parent’s matrix. Unless you want the local rotation.

As theeth said, about the transpose matrix being the same as the inverse matrix, this is only true for a 3x3 rotation only matrix. Furthermore, the 225 getInverseMatrix() doesn’t seem to return the correct matrix at all, at least not in the publisher version I tried. So you would have to invert the matrix yourself.
However, I don’t really see the need for that, although the child matrix is the parent and child combined, the rot or RotX/RotY/RotZ parameters of the child object is actually the rotation of the child itself. So unlike GameBlender where you only have access to the matrix, you can simply use that instead, no calculations needed at all.

To the Problem:
Oh … ups! %| Shame on me. I had to see that. You right. To get the global Rotation from an Child-Object, i have to do absolutely NOTHING! Ha! Yes, it’s exactly inverse like in the Game Engine. (eeshlo spend a lot of Time to teach me there. :D) And i thought, i’ve to do that here also. Ok, sorry, my Mistake!
For the next Problem, i’ll have my Eyes open. :o
Thanx Men for Your great Help.
Doc

Oh, no! That hurts. It will not work if the Child has a Grandparent and a Great-Grandparent and so on. Are there any Tricks i should know? I think, i’ve to do some multiplys now. But with or without inverse? I try without first! Am i on the right Way?

Ok! I think i have it now. Nothing with multiply or something … The globals are not stored in Obj.rot or Obj.RotXYZ as i thought at first, but in the Matrix. To get the global Rotation and Position of and Object, with Parent or without i use this Code now:

# Function from 'vecf.py' by theeth and eeshlo
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def mat2euler_rot(mat):
mtx = [list(mat[0][:3]), list(mat[1][:3]), list(mat[2][:3])]
angle_y = -asin(max(min(mtx[0][2], 1.0), -1.0))
C = cos(angle_y)
if C!=0.0: C = 1.0/C
angle_x = atan2(mtx[1][2] * C, mtx[2][2] * C)
angle_z = atan2(mtx[0][1] * C, mtx[0][0] * C)
return [angle_x, angle_y, angle_z]
# get the global Location/Rotation from an Object
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def GlobLocRot(Obj):
return Obj.matrix[3][:3], mat2euler(Obj.matrix)

I have testet it with some Objects (Parent and Free) and it seems to work. Nice!
Thanx again Guys, Doc