Section Index


1. OpenAL || 2. Debugging || 3. String Manipulation || 4. Networking || 5. Console || 6. Device I/O || 7. File I/O
8. Packages || 9. Objects || 10. Event Scheduling || 11. Datablocks || 12. Video / Texturing || 13. Special || 14. Resource Management
15. Scene || 16. Containers and Raycasts || 17. Editors || 18. Build || 19. Time || 20. GUIs || 21. Math


This quick reference guide was taken directly out of The Game Programmer's Guide to Torque by Edward Maurina. It's an outstanding resource - a must for anyone wanting to get serious about programming in Torque.


Contents

Math

getBoxCenter( box )

Purpose
Use the getBoxCenter function to find the centroid of a cube (box).

Syntax
box
– A vector containing two three-element floating-point position vectors: "X1 Y1 Z1 X2 Y2 Z2".

Returns
Returns a vector containg a three-element floating-point position vector equal to the centroid of the area defined by box.

%pos = getBoxCenter( %this.getWorldBox() );



getRandom( )
getRandom( max )
getRandom( min , max )

Purpose
Use the getRandom function to get a random floating-point or integer value. This function comes in three forms.

The first getRandom() takes no arguments and will return a random floating-point value in the range of 0.0 to 1.0.

The second getRandom( max ) takes one argument representing the max integer value this will return. It will return an integer value between 0 and max.

The third getRandom( min , max ) takes two arguments representing the min and max integer values this will return. It will return an integer value between min and max.

Syntax
min
– Minimum inclusive integer value to return.
max - Maximum inclusive integer value to return.

Returns
If no arguments are passed, will return a floating-point value between 0.0 and 1.0. If one argument is passed, will return an integer value between 0 and max inclusive. If two arguments are passed, will return an integer value between min and max inclusive.

Notes
Be sure to recognize the difference between the three variants of getRandom. Only the no-args version will return a floating point.

See Also
getRandomSeed



getRandomSeed()

Purpose
Use the getRandomSeed function to get the current seed for the random generator.

Returns
Returns an integer value representing the current seed of the random generator.

Notes
You can re-seed the generator with this value to allow you to recreate a random sequence. Merely save the seed and execute your random sequence. Later, to reproduce this sequence re-seed the generator with setRandomSeed and your saved value. Then, the generator will produce the same random sequence that followed the call to getRandomSeed.

See Also
getRandom, setRandomSeed

%seed = getRandomSeed();



mAbs( val )

Purpose
Use the mAbs function to get the magnitude of val.

Syntax
val
– An integer or a floating-point value.

Returns
Returns the magnitude of val.

%abs = mAbs(76.3);



mAcos( val )

Purpose
Use the mAcos function to get the inverse cosine of val in radians.

Syntax
val
– A value between -1.0 and 1.0 equal to the cosine of some angle theta.

Returns
Returns the inverse cosine of val in radians. This value will be in the range [ 0 , 3.14159 ].

See Also
mCos

%acos = mAcos(-8,3);



mAsin( val )

Purpose
Use the mAsin function to get the inverse sine of val in radians.

Syntax
val
– A value between -1.0 and 1.0 equal to the sine of some angle theta.

Returns
Returns the inverse sine of val in radians. This value will be in the range
[ - 3.14159/2 , 3.14159/2 ].

See Also
mSin



mAtan( val )

Purpose
Use the mAtan function to get the inverse tangent of val in radians.

Syntax
val
– A value between -inf.0 and inf.0 equal to the tangent of some angle theta.

Returns
Returns the inverse tangent of val in radians. This value will be in the range
[ - 3.14159/2 , 3.14159/2 ].

See Also
mTan



mathInit( extention )

Purpose
Use the MathInit function to install a specified math extentsion, or to detect and enable all extensions.

Syntax
extension
– Can be any of these:
     detect – Detect all supported extentions and enable.
     C - Enable standard C extensions.
     FPU - Enable floating-point-unit extensions.
     MMX - Enable Intel MMX extensions.
     3DNOW - Enable AMD 3DNOW extentions.
     SSE - Enable Intel SSE extensions.

Returns
No return value.

Notes
Generally speaking, the best extension choice is to used detect. This will automatically detected and enable all extensions supported by the current processor. It will also print out a list of the extension that were enabled to the console.

mathInit( detect );



matrixCreate( posVec , rotVec )

Purpose
Use the matrixCreate function to create a transform matrix from a three-element floating-point translation vector and a four-element floating-point rotation vector.

Syntax
posVec
- A three-element floating-point translation vector: "PosX PosY PosZ".
rotVec - A four-element floating-point rotation vector: "RotX RotY RotZ". These are rotations about the specified axes.

Returns
Returns a transform matrix of the form "PosX PosY PosZ RotX RotY RotZ theta".

See Also
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



MatrixMulPoint( transform , point )

Purpose
Use the MatrixMulPoint function to multiply a seven element transform matrix by a three element point vector, producing a three element position vector.

Syntax
transform
– A seven-element transform matrix.
point – A three-element point/position vector.

Returns
Returns a three-element position vector.

See Also
MatrixMultiply, MatrixMulVector



MatrixMultiply( transformA , transformB )

Purpose
Use the MatrixMultiply function to multiply two seven-element transform matricies to produce a new seven element matrix.

Syntax
transformA
– A seven-element transform matrix of the form "PosX PosY PosZ RotX RotY RotZ theta".
transformB – A seven-element transform matrix of the form "PosX PosY PosZ RotX RotY RotZ theta".

Returns
Returns a seven-element matrix resulting from transiformA x transformB.

See Also
MatrixMulPoint, MatrixMulVector



MatrixMulVector( vector, transfrom)

Purpose
Use the MatrixMulVector function to multiply a seven-element transform matrix with a three-element matrix.

Syntax
transform
– A seven-element transform matrix of the form "PosX PosY PosZ RotX RotY RotZ theta".
vector – A three-element vector.


Returns
Returns three-element resulting from vectior * transform.

See Also
MatrixMulPoint, MatrixMultiply



mCeil( val )

Purpose
Use the mCeil function to calculate the next higest integer value from val.

Syntax
val
– A floating-point value.

Returns
Returns an integer representing the next highest integer from val.

See Also
mFloor



mCos( val )

Purpose
Use the mCos function to get the cosine of the radian angle val.

Syntax
val
– A value between -3.14159 and 3.14159.

Returns
Returns the cosine of val. This value will be in the range [ -1.0 , 1.0 ].

See Also
mAcos



mDegToRad( val )

Purpose
Use the mDegToRad function to convert degrees to radians.

Syntax
val
– A floating-point number representing some number of degrees.

Returns
Returns the equivalent of the degree value val in radians.

See Also
mRadToDeg



mFloatLength( val , numDecimals )

Purpose
Use the mFloatLength function to limit the number of decimal places in val to numDecimals.

Syntax
val
– A floating-point value.
numDecimals – An integer between 0 and inf representing the number of decimal places to allow val to have.

Returns
Returns a floating-point value equivalent to a truncated version of val, where the new version has numDecimals decimal places.



mFloor( val )

Purpose
Use the mFloor function to calculate the next lowest integer value from val.

Syntax
val
– A floating-point value.

Returns
Returns an integer representing the next lowest integer from val.

See Also
mCeil



mLog( val )

Purpose
Use the mLog function to calculate the natural logarithm of val.

Syntax
val
– A numeric value.

Returns
Returns the natural logarithm of val.



mPow( val , power )

Purpose
Use the mPow function to calculated val raised to the power of power.

Syntax
val
– A numeric (integer or floating-point) value to be raised to a power.
power - A numeric (integer or floating-point) power to raise val to.

Returns
Returns val^power.



mRadToDeg( val )

Purpose
Use the mRadToDeg function to convert radians to degrees.

Syntax
val
– A floating-point number representing some number of radians.

Returns
Returns the equivalent of the radian value val in degrees.

See Also
mDegToRad



mSin( val )

Purpose
Use the mSin function to get the sine of the radian angle val.

Syntax
val
– A value between -3.14159 and 3.14159.

Returns
Returns the sine of val. This value will be in the range [ -1.0 , 1.0 ].

See Also
mAsin



mSolveCubic( a , b , c , d )

Purpose
Use the mSolveCubic function to solve for x0, x1, x2 in third-order polynomial equation with factors a, b, c, d:

aX^3 + bX^2 + cX + d = 0


Syntax
a, b , c, d
– Polynomial factors (see above).

Returns
Returns x0, x1, x2: ( X + x0 ) ( X + x1 ) ( X + x2 )



mSolveQuadratic( a , b , c )

Purpose
Use the mSolveCubic function to solve for x0, x1 in second-order polynomial equation with factors a, b, c:

aX^2 + bX + c = 0


Syntax
a, b , c
– Polynomial factors (see above).

Returns
Returns x0, x1: ( X + x0 ) ( X + x1 )

Notes
Warning, x0 and x1 are inverted.



mSolveQuartic(a,b,c,d,e)

Purpose
Use the mSolveCubic function to solve for x0, x1, x2, x3 in fourth-order polynomial equation with factors a, b, c, d, e:

aX^4 + bX^3 + cX^2 + dX + e = 0


Syntax
a, b , c, d, e
– Polynomial factors (see above).

Returns
Returns x0, x1, x2, x3: ( X + x0 ) ( X + x1 ) ( X + x2 ) ( X + x3 )

Notes
Broken.



mSqrt( val )

Purpose
Use the mSqrt function to calculated the squareroot of val.

Syntax
val
– A numeric value.

Returns
Returns the the squareroot of val.



mTan( val )

Purpose
Use the mTan function to get the tangent of the radian angle val.

Syntax
val
– A value between -3.14159/2 and 3.14159/2.

Returns
Returns the tangent of val. This value will be in the range [ -inf.0 , inf.0 ].

See Also
mAtan



setRandomSeed( startSeed )

Purpose
Use the setRandomSeed function to initialize the random number generator with the initial seed of startSeed.

Syntax
startSeed
– The new starting seed value for the random generator.

Returns
No return value.

See Also
getRandom, getRandomSeed



VectorAdd( vecA , vecB )

Purpose
Use the VectorAdd function to add two vectors of up to three elements each to each other

Syntax
vecA
– A vector of up to three elements.
vecB – A vector of up to three elements.

Returns
Returns the result of vecA + vecB.

See Also
vectorSub



VectorCross( vecA , vecB )

Purpose
Use the VectorCross function to calculate the cross product of two vectors of up to three elements each.

Syntax
vecA
– A vector of up to three elements.
vecB – A vector of up to three elements.

Returns
Returns the result of vecA x vecB.

Notes
Remember, the resultant vector will always be an right angles to both intput vectors.

See Also
VectorDot



VectorDist( vecA , vecB )

Purpose
Use the VectorDist function to calculate distance beteen two vectors of up to three elements each.

Syntax
vecA
– A vector of up to three elements.
vecB – A vector of up to three elements.

Returns

Returns the result of
 |Xa – Xb| |Ya – Yb| |Za – Zb| 


See Also
VectorLen



VectorDot( vecA , vecB )

Purpose
Use the VectorDot function to calculate the dot product of two unit vectors of up to three elements each.

Warning! Be sure to always normalize both vecA and vecB before attempting to find the dot product. Calculating a dot product using un-normalized vectors (non- unit vectors) will result in meaningless results.

Syntax
vecA
– A unit-vector of up to three elements.
vecB – A unit-vector of up to three elements.

Returns
Returns a scalar value equal to the result of vecA . vecB. This value which will always be a single floating-point value in the range [ -1 , +1 ].

Notes
If the return value is < 0, the inner-angle between the vectors is > 90 degrees.
If the return value is equal to 0, the inner-angle between the vectors is equal to 90 degrees.
If the return value is > 0, the inner-angle between the vectors is < 90 degrees.

See Also
VectorCross



VectorLen( vec )

Purpose
Use the VectorLen function to calculate the length of vector vec.

Syntax
vec
- A vector of up to three elements.

Returns
Returns a scalar representing the length of the vector vec.

See Also
VectorDist



VectorNormalize( vec )

Purpose
Use the VectorNormalize function to calculated the unit vector equivalent of the vector vec.

Syntax
vec
- A vector of up to three elements.

Returns
Returns the unit vector equivalent of the vector vec.

See Also
VectorScale



VectorOrthoBasis( vec )

Purpose
Use the VectorOrthoBasis function to calculate a 3x3 Row-Major formated matrix representing the orthogonal basis for the vector vec.

Syntax
vec
- A four element vector of the form "AxisX AxisY AxisZ theta", where theta is the angle of rotation about the vector formed by the prior three values.

Returns
Returns a 3x3 Row-Major formated matrix.



VectorScale( vec , scale )

Purpose
Use the VectorScale function to scale the vector vec by the scalar scale.

Syntax
vec
- A vector of up to three elements.
scale – A numeric value (integer or floating-point) representing the scaling factor.

Returns
Returns a scaled version of the vector vec, equivalent to:
" ( scale * X ) ( scale * Y ) ( scale * Z ) "

See Also
VectorNormalize



VectorSub( vecA , vecB )

Purpose
Use the VectorSub function to subtract vecB from vecA.

Syntax
vecA
– Left side vector in subtraction equation.
vecB - Right side vector in subtraction equation.

Returns
Returns a new vector equivalent to: "vecA - vecB"

See Also
vectorAdd


Section Index


1. OpenAL || 2. Debugging || 3. String Manipulation || 4. Networking || 5. Console || 6. Device I/O || 7. File I/O
8. Packages || 9. Objects || 10. Event Scheduling || 11. Datablocks || 12. Video / Texturing || 13. Special || 14. Resource Management
15. Scene || 16. Containers and Raycasts || 17. Editors || 18. Build || 19. Time || 20. GUIs || 21. Math