Game Development Community

Vector Rotation

by Xavier "eXoDuS" Amado · in Torque Game Engine · 06/16/2002 (11:26 pm) · 4 replies

How would you rotate a vector in the scripts?
For example i have a muzzle vector and i want to rotate it 90 degrees.

#1
06/17/2002 (12:11 am)
Here's an easy way to rotate a vector based on Euler parameters (X Y Z axis rotation) in script:

Since you mentioned muzzle, I assume you're doing this in the onFire method of a ShapeBaseImage (so %data, %obj, and %slot are given).

%vector = %obj.getMuzzleVector( %slot );
%xAngle = 0;
%yAngle = 0;
%zAngle = 90 * 3.1415926 / 180;

%matrix = MatrixCreateFromEuler( %xAngle SPC %yAngle SPC %zAngle);

%resultVector = MatrixMulVector( %matrix, %vector );

Remember the angle needs to be in radians.
#2
06/17/2002 (1:05 am)
Thanks a lot luigi!
#3
06/17/2002 (8:38 am)
One would advise your degrees-to-radians pi / 180 be predefined somewhere, save you that calculation each time.
#4
06/18/2002 (8:25 am)
Agreed, I just had it there for clarity's sake.