Maya Quaternion Solved
by Jeff Murray · in Artist Corner · 06/06/2007 (1:21 pm) · 2 replies
This is a post by Mike Paixao:
I have fixed the code and it works properly now
to use the script simply select your object and run it, it will print out your information needed for rotation
NOTICE!!
only Rotate in GIMBAL this way your sure to not touch the extra axis by mistake
you cannot more than 2 rotations Z and X together OR Y and Z...
this is because the torque engine uses ZXY rotation order, Maya is ZYX
so by moving a 3rd rotation, its no longer the same as torque, and I dont feel like changing the way Maya's rotate works at its core programming...
pretty much just got the math right from the torque source code
enjoy!
////////////////////////////////////////////////////
// Written by Mike Paixao //
// date: June 06, 2007 //
// //
// mdeschamps@fuelindustries.com //
// www.fuelindustries.com //
///////////////////////////////////////////////
global proc torqueQuant()
{
float $ParamX;
float $ParamY;
float $ParamZ;
float $x;
float $y;
float $z;
float $cx;
float $cy;
float $cz;
float $sx;
float $sy;
float $sz;
float $cycz;
float $sysz;
float $sycz;
float $cysz;
float $Qx;
float $Qy;
float $Qz;
float $Qw;
float $l;
$ParamX = 'getAttr .rx';
$ParamY = 'getAttr .ry';
$ParamZ = 'getAttr .rz';
$x = deg_to_rad($ParamX );
$y = deg_to_rad($ParamY );
$z = deg_to_rad($ParamZ );
$x = -$x * 0.5;
$y = -$y * 0.5;
$z = -$z * 0.5;
$cx = 'cos($x)';
$cy = 'cos($y)';
$cz = 'cos($z)';
$sx = 'sin($x)';
$sy = 'sin($y)';
$sz = 'sin($z)';
$cycz = $cy * $cz;
$sysz = $sy * $sz;
$sycz = $sy * $cz;
$cysz = $cy * $sz;
$Qw = $cycz * $cx + $sysz * $sx;
$Qx = $cycz * $sx + $sysz * $cx;
$Qy = $sycz * $cx - $cysz * $sx;
$Qz = $cysz * $cx - $sycz * $sx;
$l = sqrt( $Qx*$Qx + $Qy*$Qy + $Qz*$Qz + $Qw*$Qw );
if( $l == 0 )
{
$Qx = 0;
$Qy = 0;
$Qz = 0;
}
else
{
$Qx /= $l;
$Qy /= $l;
$Qz /= $l;
$Qw /= $l;
}
$angle = acosd($Qw) * 2;
$sinHalfAngle = sqrt(1 - ($Qw * $Qw));
if ($sinHalfAngle != 0)
{
$Qx = $Qx / $sinHalfAngle;
$Qy = $Qy / $sinHalfAngle;
$Qz = $Qz / $sinHalfAngle;
}
else
{
$Qx = 1;
$Qy = 0;
$Qz = 0;
}
$angleN = $angle;
// this is just for the other print that truncates to 0.00//
int $rAngle = $angle;
int $rX = $Qx*100; float $fx = $rX; float $xxx = $fx/100;
int $rY = $Qy*100; float $fy = $rY; float $yyy = $fy/100;
int $rZ = $Qz*100; float $fz = $rZ; float $zzz = $fz/100;
// truncated print is muted, DOES NOT ROUND OFF //
//print ($xxx+" "+-$zzz+" "+$yyy+" "+$rAngle);
print ($Qx+" "+-$Qz+" "+$Qy+" "+$angleN);
}
torqueQuant;
I have fixed the code and it works properly now
to use the script simply select your object and run it, it will print out your information needed for rotation
NOTICE!!
only Rotate in GIMBAL this way your sure to not touch the extra axis by mistake
you cannot more than 2 rotations Z and X together OR Y and Z...
this is because the torque engine uses ZXY rotation order, Maya is ZYX
so by moving a 3rd rotation, its no longer the same as torque, and I dont feel like changing the way Maya's rotate works at its core programming...
pretty much just got the math right from the torque source code
enjoy!
////////////////////////////////////////////////////
// Written by Mike Paixao //
// date: June 06, 2007 //
// //
// mdeschamps@fuelindustries.com //
// www.fuelindustries.com //
///////////////////////////////////////////////
global proc torqueQuant()
{
float $ParamX;
float $ParamY;
float $ParamZ;
float $x;
float $y;
float $z;
float $cx;
float $cy;
float $cz;
float $sx;
float $sy;
float $sz;
float $cycz;
float $sysz;
float $sycz;
float $cysz;
float $Qx;
float $Qy;
float $Qz;
float $Qw;
float $l;
$ParamX = 'getAttr .rx';
$ParamY = 'getAttr .ry';
$ParamZ = 'getAttr .rz';
$x = deg_to_rad($ParamX );
$y = deg_to_rad($ParamY );
$z = deg_to_rad($ParamZ );
$x = -$x * 0.5;
$y = -$y * 0.5;
$z = -$z * 0.5;
$cx = 'cos($x)';
$cy = 'cos($y)';
$cz = 'cos($z)';
$sx = 'sin($x)';
$sy = 'sin($y)';
$sz = 'sin($z)';
$cycz = $cy * $cz;
$sysz = $sy * $sz;
$sycz = $sy * $cz;
$cysz = $cy * $sz;
$Qw = $cycz * $cx + $sysz * $sx;
$Qx = $cycz * $sx + $sysz * $cx;
$Qy = $sycz * $cx - $cysz * $sx;
$Qz = $cysz * $cx - $sycz * $sx;
$l = sqrt( $Qx*$Qx + $Qy*$Qy + $Qz*$Qz + $Qw*$Qw );
if( $l == 0 )
{
$Qx = 0;
$Qy = 0;
$Qz = 0;
}
else
{
$Qx /= $l;
$Qy /= $l;
$Qz /= $l;
$Qw /= $l;
}
$angle = acosd($Qw) * 2;
$sinHalfAngle = sqrt(1 - ($Qw * $Qw));
if ($sinHalfAngle != 0)
{
$Qx = $Qx / $sinHalfAngle;
$Qy = $Qy / $sinHalfAngle;
$Qz = $Qz / $sinHalfAngle;
}
else
{
$Qx = 1;
$Qy = 0;
$Qz = 0;
}
$angleN = $angle;
// this is just for the other print that truncates to 0.00//
int $rAngle = $angle;
int $rX = $Qx*100; float $fx = $rX; float $xxx = $fx/100;
int $rY = $Qy*100; float $fy = $rY; float $yyy = $fy/100;
int $rZ = $Qz*100; float $fz = $rZ; float $zzz = $fz/100;
// truncated print is muted, DOES NOT ROUND OFF //
//print ($xxx+" "+-$zzz+" "+$yyy+" "+$rAngle);
print ($Qx+" "+-$Qz+" "+$Qy+" "+$angleN);
}
torqueQuant;
#2
sorry for the dalay in my response, Ive been busy with other projects,
to answer your question, Quaternion is the way in wich rotations are handled compared to Maya... it will take one rotation at a time, and doing so eliminates any possibility for Gimble lock
and as for update I may be able to change Maya's rotation interp order to make this work with all 3 rotates, just dont have any spare time at the moment... I have pretty much built a tool that allows you to select as many objects in your scene at once, and it exports to the selected directory, supports LOD objects and flags etc.... so no need to do things one at a time ( great for building entire levels within Maya, then exporting and not needing to place things in torque ) as it also generates your mission file :P
soon as I get around to making this a plugin I believe I will be able to share this tool with the comunity (or so I am told)
07/04/2007 (3:06 pm)
This is a post by Mike Paixao:sorry for the dalay in my response, Ive been busy with other projects,
to answer your question, Quaternion is the way in wich rotations are handled compared to Maya... it will take one rotation at a time, and doing so eliminates any possibility for Gimble lock
and as for update I may be able to change Maya's rotation interp order to make this work with all 3 rotates, just dont have any spare time at the moment... I have pretty much built a tool that allows you to select as many objects in your scene at once, and it exports to the selected directory, supports LOD objects and flags etc.... so no need to do things one at a time ( great for building entire levels within Maya, then exporting and not needing to place things in torque ) as it also generates your mission file :P
soon as I get around to making this a plugin I believe I will be able to share this tool with the comunity (or so I am told)
Torque Owner James Brad Barnette
3Dmotif LLC