Game Development Community

Torque Rotation Manipulation help: "x y z angle

by Kuju Manila · in Technical Issues · 05/14/2008 (2:39 am) · 2 replies

Ok. I know how Torque has it's rotation as a four element vector "x y z angle". Now, I need some guides on how to actually make rotations on arbitrary angles. For instance, in APIs like OpenGL, we can achieve this rotation we want by creating a sequence of Rotation commands on what ever elementary axis you can give (X-Axis, Y-Axis, and Z-Axis). How can we do the same in TorqueScript?


I really want an answer on how to manipulate this form of rotation because problems that need this are often encountered.


For instance, I am trying to make the tip of a 3d gun always point towards a certain point in the 3d scene. I can do a rotation on Z-axis easily, which helps me have a "yaw" functionality. But how about pitch?

#1
05/14/2008 (7:45 am)
For inputs, Torque uses an "axis angle" system, a vector axis, and an angle of rotation about that axis. It is a 4 element attitude specification that includes a full 3x3 matrix worth of attitude information. (Similar in capability to a quaternion.)

MatrixCreateFromEuler is a console function (available from TorqueScript) that takes an Euler sequence of three rotations and returns a torque "transform" "matrix" with a "0 0 0" position vector and then an axis angle set of 4 elements. (seven total fields, see below.) The Z axis in Torque is Up, wth Y forward, X to the right. In stock Torque, The only Euler rotation sequence available is: Z X Y (yaw, pitch, then roll)
tdn.garagegames.com/wiki/TorqueScript_Console_Functions_21#MatrixCreateFromEuler...
MatrixCreateFromEuler ( rotVec ) 
Purpose
Use the MatrixCreateFromEuler function to calculate a transform matrix from a three-element floating-point rotation vector.

Syntax
rotVec - A three-element floating-point rotation vector: "RotX RotY RotZ". These are rotations about the specified axes.


Returns
Returns a transform matrix of the form "0 0 0 X Y Z theta".

See Also
MatrixCreate

Unfortunately, Torque documentation (and the game industry in general) never met a variable for which it felt the coordinate system or units should be documented for ;). remember that although you input the angles in X,Y,Z order, the order of the rotations is Z then X then Y. Express the angles in radians. The sign convention is the normal right handed one.

This example is a 90 deg rotation about the +Z (up), resulting in facing along the -X axis:
==>echo(MatrixCreateFromEuler("0 0 1.57"));
0 0 0 0 -0 -1 1.57

For more background, here is a thread discussing the opposite problem: axis angle back to an Euler sequence.
www.garagegames.com/mg/forums/result.thread.php?qt=70257

Please be aware that in input situations (as in mission files), the Torque axis angle's angle element is in degrees. In the C++ code, radians are used. In script, it seems to depend on when you do it (mostly in radians, e.g.: for setTransform() and MatrixCreateFromEuler calls). I would suggest doing a lot of experimentation. Also, make no assumptions about the sign of the angle element. It has always seemed backward to me. If you want to place something facing along +X, you give it a "0 0 1 90" axis angle in the mission file. (Or "0 0 -1 -90" would also work.)
#2
05/14/2008 (8:38 pm)
Groovy!

That's cool! It worked and I learned something new. Thanks.