PDA

View Full Version : matrix to euler

 alredha04-02-2008, 11:19 AMhello everyone! it sounds a simple question, but how can we get the rotation values from a matrix? if someone will answer (xform), show me how please! what i like is to find a solution with nodes, so any help? thanks...
shibumenon
04-02-2008, 01:48 PM
If you apply a transform matrix value to any transform node, the node will show the Euler rotation values in the channel box as the usual rotx, roty and rotz

alredha
04-02-2008, 02:08 PM
If you apply a transform matrix value to any transform node, the node will show the Euler rotation values in the channel box as the usual rotx, roty and rotz

niiiiiiiiiice :scream: ... someone has replyed :bounce:

thanks aaaaCHoooo, xform does the job,
but instead of using xform "inside an expression", is there a way to feed this transformation matrix using a node? like the fourByFourMatrix node

cause i want interactivity in my scene!.... an expression is updated only when time change, not an attribute change....

i'm reading right now the complete maya programming Vol2 book, but i don't find such a thing on how to read a matrix....

i tried to calculate the angle between every two axis, like :

anglebetween row1 and 1 0 0
anglebetween row2 and 0 1 0
anglebetween row3 and 0 0 1

it gives nice result, but sometime unexpected!.....so i said it's not the right thing to do.

shibumenon
04-02-2008, 02:11 PM
example,
If \$mtx is your 16 member float array,

string \$tempLoc[] = `spaceLocator`;
xform -m \$mtx[0] \$mtx[1] \$mtx[2] \$mtx[3] \$mtx[4] \$mtx[5] \$mtx[6] \$mtx[7] \$mtx[8] \$mtx[9] \$mtx[10] \$mtx[11] \$mtx[12] \$mtx[13] \$mtx[14] \$mtx[15] \$tempLoc[0];

float \$EulerRotX = `getAttr (\$tempLoc[0] + ".rotateX")`;
float \$EulerRotY = `getAttr (\$tempLoc[0] + ".rotateY")`;
float \$EulerRotZ = `getAttr (\$tempLoc[0] + ".rotateZ")`;

delete \$tempLoc;

so, \$EulerRotX, \$EulerRotY and \$EulerRotZ will be the euler rots extracted from the matrix.
I wish mel had a way of accepting a matrix as a matrix ... I mean it feels so stupid to type out all 16 components of the matrix !

cheers
shibu

shibumenon
04-02-2008, 02:19 PM
ooops !
saw your post only after I posted mine !

shibumenon
04-02-2008, 02:26 PM
when you say sometimes unexpected, is it a difference of +- 180 deg?

alredha
04-02-2008, 02:58 PM
when you say sometimes unexpected, is it a difference of +- 180 deg?

let me show you what i'm doing :

i have a curve and a cube,

pointOnCurve.position --> pCube1.translate
//so here whatever i change the parameter (%) the cube move on that curve

curve1 -> pointOnCurve --> normalizedTangent -->angleBetween.vector1
------------------------------------------------>angleBetween.vector2 (<<1,0,0>>)
=======================================================
------------------------------------------------> angle

angleBetween.angle --> pCube1.rotateY

so, the cube is rotated on Yaxis in a way that Xaxis becomes parallel to the tangent
it works fine, but once the parameter is closer to 0 or 1, the result is not as expected...
take a look in the attached file and youll understand... thanks :)

alredha
04-02-2008, 03:49 PM
you know what, your locator stuff is really nice, it solved half my problem, look:

expression has input and output by only matching two attributes like
pCube1.translateX = pSphere1.rotateY

by getting the matrix as input (matching the attrs), xform it to a locator, then assign this locator attributes to the pCube1,

so like this i can use xform (the only command to change matrix values) and not using xform for output stuff, the scene update as expected. But the result once you try to change the curve's topo or it's CVs, BAD!

so, point/orient/scale constrained the pCube to the locator, the result are exact but the DG is not updating (need to slide the timeline to see the result).....

shibumenon
04-02-2008, 04:13 PM
hey, i also had a play with it, and I think if you use a aim constraint, along with a new locator and a +-Avg node, then you could have real time updates ..
Though, it solves the issue of incorrect rotation when nearing 0 and 1 params, it could have possibly initiated other issues that i haven't tested...

try this
create a locator(named say, loc) and a +-avg node(named say plusNode).
give the plusNode 2 inputs:
1: position (from poc) &
2. tangent (from poc)
Keeping the plusNode operation as `sum`, use the o/p of plusNode as a position input to loc.

Now, aim constraint pCube1 to this locator.

cheers
shibu

alredha
04-02-2008, 05:19 PM
thanks a lot, it works fine, i like the trick ;)

by the way! what is shibu?... :)

shibumenon
04-02-2008, 06:20 PM
name of the person who sneezed :D

alredha
04-02-2008, 06:24 PM
niice...

well shibu! :)

strarup
04-03-2008, 10:33 PM
Hi,

yeah it's quite annoying when you can't get it into an matrix with that function call...
however you can make a little proc which convert an float array with 16 indexes as a matrix...

proc printDaMatrix()
{
string \$tempLoc[] = `spaceLocator`;
matrix \$daMatrix[4][4] = returnFloat16ArrayAsMatrix(`xform -q -m \$tempLoc[0]`) ;
print("\n");
print(\$daMatrix);
print("\n");
}
printDaMatrix;
proc matrix returnFloat16ArrayAsMatrix(float \$daFloatArr[])
{
matrix \$daMatrix[4][4] = << \$daFloatArr[0], \$daFloatArr[1], \$daFloatArr[2], \$daFloatArr[3];
\$daFloatArr[4], \$daFloatArr[5], \$daFloatArr[6], \$daFloatArr[7];
\$daFloatArr[8], \$daFloatArr[9], \$daFloatArr[10], \$daFloatArr[11];
\$daFloatArr[12], \$daFloatArr[13], \$daFloatArr[14], \$daFloatArr[15]>>;
return \$daMatrix;
}

lol... damn the worldMatrix is also a 16 floatArray value... so need the floatArray to Matrix proc there aswell...

proc printDaMatrix()
{
string \$tempLoc[] = `spaceLocator`;
matrix \$daMatrix[4][4] = returnFloat16ArrayAsMatrix(`getAttr (\$tempLoc[0]+".wm")`);
print("\n");
print(\$daMatrix);
print("\n");
}
printDaMatrix;
//just copy paste use the proc from the other code example for the floatArray to Matrix...

however in the expression instead of using xform you could use the worldMatrix... e.g.
float \$myMatrix[16] = (\$object+".wm"); //where \$object = the name of the object you use...
hope that helps a bit... :)

kind regards

Strarup

CGTalk Moderation
04-03-2008, 10:33 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.