Image rotation
by Eric Hartman · in Torque Game Engine · 08/22/2002 (12:41 am) · 1 replies
ok i know one of you smart people has the answer to this:
How do i set the rotation property of an image data block?
say i have something like this:
datablock ShapeBaseImageData(gunImage)
{
shapeFile = "gun.dts";
mountPoint = 1;
offset = "1.0 0.5 2.0"
rotation = "? ? ? ?"
...
I know it has to be a unit vector and an angle, but how to i calculate what it should be based on x y z rotation? this is really starting to get to me as i've got a dozen things now that i need rotated and cant cause i dont understand this so any help would be appreciated thanks.
How do i set the rotation property of an image data block?
say i have something like this:
datablock ShapeBaseImageData(gunImage)
{
shapeFile = "gun.dts";
mountPoint = 1;
offset = "1.0 0.5 2.0"
rotation = "? ? ? ?"
...
I know it has to be a unit vector and an angle, but how to i calculate what it should be based on x y z rotation? this is really starting to get to me as i've got a dozen things now that i need rotated and cant cause i dont understand this so any help would be appreciated thanks.
About the author
Torque Owner Eric Hartman
put this function somewhere before your data blocks are defined.
function eulerToMatrix( %euler )
{
%euler = VectorScale(%euler, $pi / 180); //convert euler rotations to radians
%matrix = MatrixCreateFromEuler(%euler); //make a rotation matrix
%xvec = getWord(%matrix, 3); //get the parts of the matrix you need
%yvec = getWord(%matrix, 4);
%zvec = getWord(%matrix, 5);
%ang = getWord(%matrix, 6); //this is in radians
%ang = %ang * 180 / $pi; //convert back to degrees
%rotationMatrix = %xvec @ " " @ %yvec @ " " @ %zvec @ " " @ %ang; //put it all together
return %rotationMatrix; //send it back
}
then in the rotation field of your images, put eulerToMatrix("x y z"); where x,y and z are angles in degrees