You can also just get your euler rotations directly without having to first
get a quaternion...

In Ryan's code you would just do this:

vec = mTM.eulerRotation().asVector()

if you wanted it as a vector obviously...




On Tue, Feb 24, 2009 at 11:34 PM, ryant <[email protected]> wrote:

>
> MQuaternion is a good way to get the MEulerRotation. At least its the
> only way I have used. There is actually a bug in the Maya API that
> does not even let you get the rotation from the MTransformationMatrix
> class.
>
> This will error:
>
> import maya.OpenMaya as OpenMaya
>
> getMatrix = OpenMaya.MMatrix()
> matrixList = ( 0.673, 1.545 , 0.0, 0.0,
>    -0.327, 2.545, 0.0, 0.0,
>    -0.327, 1.545, 1.0, 0.0,
>    -0.327, 1.545, 0.0, 1.0)
>
> OpenMaya.MScriptUtil().createMatrixFromList(matrixList, getMatrix)
>
> mTM = OpenMaya.MTransformationMatrix( getMatrix )
>
> rotDoubleArray = OpenMaya.MScriptUtil()
> rotDoubleArray.createFromList( [0.0, 0.0, 0.0], 3 )
> rotDoubleArrayPtr = rotDoubleArray.asDoublePtr()
> rotOrder = OpenMaya.MTransformationMatrix().kXYZ
>
> mTM.getRotation( rotDoubleArrayPtr, rotOrder )
>
> # Error: Wrong number of arguments for overloaded function
> 'MTransformationMatrix_getRotation'.
>  Possible C/C++ prototypes are:
>    getRotation(double [3],MTransformationMatrix::RotationOrder &)
>    getRotation(double [3],MTransformationMatrix::RotationOrder
> &,MSpace::Space)
> # Traceback (most recent call last):
> #   File "", line 1, in
> #   File "C:\buildforge\Maya_Main_Win32_Build\build\wrk\optim\runTime
> \Python\Lib\site-packages\maya\OpenMaya.py", line 8044, in getRotation
> # NotImplementedError: Wrong number of arguments for overloaded
> function 'MTransformationMatrix_getRotation'.
> #   Possible C/C++ prototypes are:
> #     getRotation(double [3],MTransformationMatrix::RotationOrder &)
> #     getRotation(double [3],MTransformationMatrix::RotationOrder
> &,MSpace::Space)
> #  #
>
> The only way around it is with MQuaternion() example here:
>
> import maya.OpenMaya as OpenMaya
>
> getMatrix = OpenMaya.MMatrix()
> matrixList = ( 0.673, 1.545 , 0.0, 0.0,
>    -0.327, 2.545, 0.0, 0.0,
>    -0.327, 1.545, 1.0, 0.0,
>    -0.327, 1.545, 0.0, 1.0)
>
> OpenMaya.MScriptUtil().createMatrixFromList(matrixList, getMatrix)
>
> mTM = OpenMaya.MTransformationMatrix( getMatrix )
> rotOrder = OpenMaya.MTransformationMatrix().kXYZ
>
> # Get the rotation as a quaternion then convert to Euler as needed
> rotateOrder = 0
> mquat = mTM.rotation()
> rot = mquat.asEulerRotation()
> rot.reorderIt( rotateOrder )
>
> print rot.x, rot.y, rot.z
>
> RyanT
> Technical Artist
> www.rtrowbridge.com/blog
> Naughty Dog Inc.
>
>
> On Feb 24, 9:01 pm, ugly bob <[email protected]> wrote:
> > does any one else think its kinda funny you have to call it as a
> > quaternion, then convert to euler? I looked to do it straight from
> > Mvector to MEulerRotation but it appeared to not exist ?
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to