SetTransform - angle - angle axis, quaternion or Euler?
by Nathan Bowhay - ESAL · in Torque Game Engine · 08/01/2007 (9:16 pm) · 2 replies
I have a slight understanding of angles and how they work, but it is still pretty foggy to me.
Note: Please answer my question or help me solve what I am trying to do first, and then discuss or inform me about the Additional clarification questions.
WHAT I AM TRYING TO DO:
What I am trying to do is take a quaternion angle in the form (qw,qx,qy,qz) where qw is the magnitude and (qx,qy,qz) is the direction x, y, and z, and pass it to setTransform (in script) to rotate the unit correctly.
QUESTION:
I would really like an answer on how to do that, but rotation is still confusing to me a bit so after the answer on how to do what I want, any explanation of it all would be great!
ADDITION CLARIFICATION (Not needed, but cool if I get it):
First off: setTransform(x,y,z,ax,ay,az,theta); takes an x,yz position then an ax,ay,az axis and theta theta rotating around the axis created from ax,ay,az;
is this angle axis? I am guessing it is and if so is angle axis the same as Euler? is angle axis just a different way of displaying Euler? Or is angle axis the same as quaternion (really don't think so)?
These angle axis and Euler are thrown around quite a bit.
Also from what I have seen in the engine rotation is stored in a matrix and calculated in quaternions. Is this correct? How does this all work (from script to engine - as far as conversions and storing - I know how script and engine communicate).
Also is there anything is script or engine code (In TGE) that is used for conversion or do people write their own functions for conversion. http://www.gamedev.net/reference/articles/article1095.asp talks about it all and conversion formulas. I also got a different formula to go from quaternion to Euler (slightly different), that was specified in the spec docs:
angle = 2* acos(qw)
s= sqrt(1-qw*qw)
if(s < 1e-10)
x = qx/s;
y = qy/s;
z = qz/s;
else
x = qx;
y = qy;
z = qz;
Note: Please answer my question or help me solve what I am trying to do first, and then discuss or inform me about the Additional clarification questions.
WHAT I AM TRYING TO DO:
What I am trying to do is take a quaternion angle in the form (qw,qx,qy,qz) where qw is the magnitude and (qx,qy,qz) is the direction x, y, and z, and pass it to setTransform (in script) to rotate the unit correctly.
QUESTION:
I would really like an answer on how to do that, but rotation is still confusing to me a bit so after the answer on how to do what I want, any explanation of it all would be great!
ADDITION CLARIFICATION (Not needed, but cool if I get it):
First off: setTransform(x,y,z,ax,ay,az,theta); takes an x,yz position then an ax,ay,az axis and theta theta rotating around the axis created from ax,ay,az;
is this angle axis? I am guessing it is and if so is angle axis the same as Euler? is angle axis just a different way of displaying Euler? Or is angle axis the same as quaternion (really don't think so)?
These angle axis and Euler are thrown around quite a bit.
Also from what I have seen in the engine rotation is stored in a matrix and calculated in quaternions. Is this correct? How does this all work (from script to engine - as far as conversions and storing - I know how script and engine communicate).
Also is there anything is script or engine code (In TGE) that is used for conversion or do people write their own functions for conversion. http://www.gamedev.net/reference/articles/article1095.asp talks about it all and conversion formulas. I also got a different formula to go from quaternion to Euler (slightly different), that was specified in the spec docs:
angle = 2* acos(qw)
s= sqrt(1-qw*qw)
if(s < 1e-10)
x = qx/s;
y = qy/s;
z = qz/s;
else
x = qx;
y = qy;
z = qz;
#2
From TorqueScript, all transforms are represented in a "X Y Z Xaxis Yaxis Zaxis Rotation" format. "Xaxis Yaxis Zaxis" is a unit vector that describes a vector from the origin, and Rotation is the angle about this axis where the rotation occurs. I think that is accurately described as angle axis format for rotation, but honestly I'm not sure.
This is a standardized convention for TorqueScript only--"under the covers", each class may use different representations for tracking translation and rotation information, based on class needs. For example, the Player class uses a basic matrix to store information, while the vehicle classes uses quaternions. Throughout the engine, you will see various conversions to different representations based on ease of use for a particular functionality, needs of the class behavior itself, or simply programmer preference.
Each class is responsible for providing a ConsoleMethod "setTransform" that accepts information in the format described above, and then performs conversions to the appropriate internal format for that class. The reverse of course applies for "getTransform".
08/03/2007 (11:26 am)
I wish I had time to respond to this more completely, but I can give the short version:From TorqueScript, all transforms are represented in a "X Y Z Xaxis Yaxis Zaxis Rotation" format. "Xaxis Yaxis Zaxis" is a unit vector that describes a vector from the origin, and Rotation is the angle about this axis where the rotation occurs. I think that is accurately described as angle axis format for rotation, but honestly I'm not sure.
This is a standardized convention for TorqueScript only--"under the covers", each class may use different representations for tracking translation and rotation information, based on class needs. For example, the Player class uses a basic matrix to store information, while the vehicle classes uses quaternions. Throughout the engine, you will see various conversions to different representations based on ease of use for a particular functionality, needs of the class behavior itself, or simply programmer preference.
Each class is responsible for providing a ConsoleMethod "setTransform" that accepts information in the format described above, and then performs conversions to the appropriate internal format for that class. The reverse of course applies for "getTransform".
Torque 3D Owner Nathan Bowhay - ESAL
ESALPllc
%scale = mSqrt(mPow(%qx,2)+mPow(%qy,2)+mPow(%qz,2));
if(%scale == 0)
{
%theta = 3.1416;
%xA = 0;
%yA = 0;
%zA = 1;
}
else
{
%theta = 2 * mAcos(%mag);
%xA = %qx/%scale;
%yA = %qy/%scale;
%zA = %qz/%scale;
}
were qx,qy,qz and mag are the quaternion and xA,yA,zA, and mag are the angle axis.
Still a bit confused about Euler and angle axis and what setTransform takes. I am pretty sure it is angle axis though.
I am also still wondering about what torque uses in the engine for storage and calculations and how general rotation is handled.