applying rotation
by Ian Omroth Hardingham · in Torque Game Engine · 04/10/2003 (4:09 am) · 12 replies
Hi everyone.
%transform = $item.getTranform();
I want to rotate %transform by 180 degrees around the y axis. How do I go about doing that?
Thanks,
Ian
%transform = $item.getTranform();
I want to rotate %transform by 180 degrees around the y axis. How do I go about doing that?
Thanks,
Ian
About the author
Designer and lead programmer on Frozen Synapse, Frozen Endzone, and Determinance. Co-owner of Mode 7 Games.
#2
set the transform relative to the current transform state of the item? Or do you need to get the current do some matrix math and then set the transform?
04/10/2003 (6:40 am)
Will the $item.setTransform(%transform);set the transform relative to the current transform state of the item? Or do you need to get the current do some matrix math and then set the transform?
#3
What maths do I need to do?
Thanks,
Ian
04/10/2003 (7:48 am)
I need to rotate *%transform* by 180 degrees, NOT $item.What maths do I need to do?
Thanks,
Ian
#4
the first 3 are it's location.
The other 4 are the rotation (in quaternion form)
If you want to add 180 degrees around the y axis to the rotation of your transform you simly do.
%rotation1 = GetWords(%transform,3,6);
%rotation2 = "0 1 0 3.14" //1 being y axis, 3.14 being 180 degrees.
%v1 = "0 0 0" SPC %rotation1;
%v2 = "0 0 0" SPC %rotation2;
%v3 = MatrixMultiply(%v1,%v2);
%newtrans = getWords(%transform,0,2) SPC GetWords(%v3,3,6);
Note.. this only modifies the rotation.. for actually offsetting the whole transform there's more code required...
but assuming you want $item2 with %newtrans to be 180 degrees rotated from $item with %transform... you've got it.
**edit.. I meant 1 being the y axis ("x y z r") but you get the picture.. ;)
04/10/2003 (11:09 am)
Transforms consists of 7 numbersthe first 3 are it's location.
The other 4 are the rotation (in quaternion form)
If you want to add 180 degrees around the y axis to the rotation of your transform you simly do.
%rotation1 = GetWords(%transform,3,6);
%rotation2 = "0 1 0 3.14" //1 being y axis, 3.14 being 180 degrees.
%v1 = "0 0 0" SPC %rotation1;
%v2 = "0 0 0" SPC %rotation2;
%v3 = MatrixMultiply(%v1,%v2);
%newtrans = getWords(%transform,0,2) SPC GetWords(%v3,3,6);
Note.. this only modifies the rotation.. for actually offsetting the whole transform there's more code required...
but assuming you want $item2 with %newtrans to be 180 degrees rotated from $item with %transform... you've got it.
**edit.. I meant 1 being the y axis ("x y z r") but you get the picture.. ;)
#6
08/27/2004 (1:11 pm)
This post also helped me see what torque's vector environment is all about. thanks, sebastian.
#7
08/28/2004 (11:29 am)
I thought the rotation being in angular axis notation. Quats are a different notation (angle independent, in fact).
#8
08/28/2004 (12:27 pm)
And I thought 3.14 was a full 360 degrees.
#9
2 Pi equals 6.28 equals 360 degrees of rotation.
It may sound silly that pie is only half a rotation (or half a pie for that matter ^_^).. but it works better when you do stuff with area's of circles and all that stuff. (or so the ancient greek and probbly even people before them thought).
the idea of quaternions are very simple.. their idea is that any rotation (or an addition of multiple rotation for that matter) can be created by using the base (non rotated) object and rotating it less than 2pi around an axis.
If we look back at the notation of quaternions ("x y z r") we see that the axis is noted by "x y z" and the rotation about that axis by "r".
In this example we use torque's ability to add multiple rotations by adding the required rotation to a previous rotation (of the original $item).
In most games/3d engines you find your rotating with "euler angles" wich simply are 3 set of rotations (around the x,y and z axis) in a fixed order.
The real limitation is that this fixed order prohibits total freedom of rotation.
Quaternions fix this by allowing any number of rotations around any axis in any order.
Anyway.. I could go on for hours about quaternions (or rather the torque ones).
It's nice to know the ins and outs of them.. but you need the extra vector math to back them up if you really want to use them for something complex.
08/28/2004 (8:55 pm)
3.14 is Pi equals 180 degrees of rotation.2 Pi equals 6.28 equals 360 degrees of rotation.
It may sound silly that pie is only half a rotation (or half a pie for that matter ^_^).. but it works better when you do stuff with area's of circles and all that stuff. (or so the ancient greek and probbly even people before them thought).
the idea of quaternions are very simple.. their idea is that any rotation (or an addition of multiple rotation for that matter) can be created by using the base (non rotated) object and rotating it less than 2pi around an axis.
If we look back at the notation of quaternions ("x y z r") we see that the axis is noted by "x y z" and the rotation about that axis by "r".
In this example we use torque's ability to add multiple rotations by adding the required rotation to a previous rotation (of the original $item).
In most games/3d engines you find your rotating with "euler angles" wich simply are 3 set of rotations (around the x,y and z axis) in a fixed order.
The real limitation is that this fixed order prohibits total freedom of rotation.
Quaternions fix this by allowing any number of rotations around any axis in any order.
Anyway.. I could go on for hours about quaternions (or rather the torque ones).
It's nice to know the ins and outs of them.. but you need the extra vector math to back them up if you really want to use them for something complex.
#11
07/15/2005 (10:04 am)
Ok I think I know what values I need so now I can look into getting the correct ones :)
#12
Sort of. They are related, but it's not as simple as "x y z" is the axis and r is the rotation.
If the values X Y Z are the components of a vector that describe your axis of rotation and
R describes your rotation, the quaternion describing that rotation is actually the following.
Qx = sin(R/2) * X
Qy = sin(R/2) * Y
Qz = sin(R/2) * Z
Qw = cos(R/2)
12/28/2006 (11:38 am)
Quote:If we look back at the notation of quaternions ("x y z r") we see that the axis is noted by "x y z" and the rotation about that axis by "r".
Sort of. They are related, but it's not as simple as "x y z" is the axis and r is the rotation.
If the values X Y Z are the components of a vector that describe your axis of rotation and
R describes your rotation, the quaternion describing that rotation is actually the following.
Qx = sin(R/2) * X
Qy = sin(R/2) * Y
Qz = sin(R/2) * Z
Qw = cos(R/2)
Associate Ron Yacketta
IE:
%transform = "0 1 0 180";
$item.setTransform(%transform);
-Ron