noizfactory
Can someone help me with this head hurting stuff?
Given a 4x4 transformation matrix, how can I decompose it and retrieve the X, Y and Z rotations in degrees? MEL/Python/PseudoCode is also fine.
Reply 0 0
pshipkov
There is already node in Maya that does that but here is one way:

m = yourMatrix;
MTransformationMatrix tm(m);
MEulerRotation er = tm.eulerRotation() // euler rotation in radians
// rotation in degrees
double rx = er[0] * 57.2957795;
double ry = er[1] * 57.2957795;
double rz = er[2] * 57.2957795;
Reply 0 0
noizfactory
Thanks Peter. I've tried the decompose matrix node in Maya. But wanted to understand what happens behind the scene.
On similar lines, is it also possible to retrieve the transformations in "camera" space in Maya? I believe the samplerInfo node does that but at the shading level.
Reply 0 0
pshipkov
just multiply your matrix by the inverse matrix of the camera and the rest is the same. result will be in camera space.
Reply 0 0
noizfactory
Thanks Peter. Will try that out.
Reply 0 0
noizfactory
On similar lines, Peter, is it possible to generate per particle transformation matrix given the PP position, rotation and scale arrays? The transformToArrays and arrayToDynArray is doing something similar I guess but I need this info to write the transformation matrix data into ribs for prman.
Reply 0 0
pshipkov
yes. easily.
MTransformationMatrix tm;
tm.setTranslate(positionVectorHere);
tm.setRotate(rotationVectorHere); // or it needed quaternions/eulers ? not in front of maya right now, but you get the idea
tm.setScale()

that's per particle.
Reply 0 0
noizfactory
Thanks again Peter!
Reply 0 0
Andrei2k
Hi Peter,

I noticed this post and since I have been looking for similar info regarding an inverse matrix I thought I would try asking here. Much like the way you described I am looking at a similar solution for making/getting an inverseMatrix since Maya 2012 does not have one. Thank you.
Reply 0 0
pshipkov
DAG nodes in Maya have attributes that provide all sorts of matrix data. Including inverse matrices.
You can do getAttr transform1.inverseMatrix for example.

Otherwise you take a look at the MMatrix::inverse() and MTransformationMatrix::asInverseMatrix().
Or something like that - cannot remember the exact method names right now.
Reply 0 0
Reply