Provides optimized vector and matrix operations.
Compatibility with JavaScript arrays (returned by VMath function calls and JSON.parse)
The MathDevice functions are not compatible with JavaScript arrays this includes the result of VMath functions. To convert between VMath and MathDevice objects see MathDeviceConvert.
Optional destination parameter
Most of the functions on the MathDevice which return a MathDevice object have an optional destination parameter. This optional last parameter specifies the MathDevice object to copy the result into. This functionality is useful to avoid the memory allocation of a new vector. For example, the following code will require memory for 3 Vector3 objects:
var vectorA = mathDevice.v3Build(1, 2, 3);
var vectorB = mathDevice.v3Build(4, 5, 6);
vectorB = mathDevice.v3Add(vectorA, vectorB);
Later on the JavaScript VM will have to garbage collect the unreferenced Vector3 memory costing valuable time. However taking advantage of the destination parameter, the following code will require memory for only 2 Vector3 objects:
var vectorA = mathDevice.v3Build(1, 2, 3);
var vectorB = mathDevice.v3Build(4, 5, 6);
mathDevice.v3Add(vectorA, vectorB, vectorB);
This method doesn’t require the JavaScript VM to do any unneeded garbage collection.
The destination can also be null or undefined in which case the destination is ignored and a new MathDevice object is created.
Function caching
When using the MathDevice object is it always best to cache functions when they are called multiple times. For example:
var a, b;
a = mathDevice.v3Build(1, 1, 1);
b = mathDevice.v3Build(1, 2, 3);
for (var i = 0; i < 6; i += 1)
{
mathDevice.v3Mul(a, b, a);
}
Will be slower than:
var a, b;
a = mathDevice.v3Build(1, 1, 1);
b = mathDevice.v3Build(2, 3, 4);
var v3Mul = mathDevice.v3Mul;
for (var i = 0; i < 6; i += 1)
{
v3Mul.call(mathDevice, a, b, a);
}
For more information, see the section Caching functions.
The format for all Math Device function names is lower case type name, e.g. v3, m44 or quat, followed by the operation in camel case. For example:
mathDevice.typeNameFunctionName();
mathDevice.typeNameFunctionNameTypeName();
A preceding type name is given if the second parameters type is not clear. For example, mathDevice.quatFromM43 rather than mathDevice.quatFromMatrix.
The MathDevice uses arrays of single-precision floats for all of its internal objects. On the other hand the JavaScript representation of numbers uses double-precision floats for all of its number objects. Subsequently, there is a loss of precision between JavaScript values and the MathDevice objects to be careful of.
Summary
Compares two native math device objects and returns true if they are the same object. This method is intended for debugging and validation purposes only.
Syntax
var identical = mathDevice.objectsAreIdentical(v1, v2);
Summary
Converts the given floating point number into an integer, rounding towards zero.
Syntax
var index = mathDevice.truncate(fraction * tableSize);
Summary
Creates a vector with 2 components.
Syntax
var destination = mathDevice.v2Build(a, b, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Creates a vector with 2 components all set to 0.0.
Syntax
var position = mathDevice.v2BuildZero(destination);
destination (Optional)
Returns a Vector2 object.
Summary
Creates a vector with 2 components all set to 1.0.
Syntax
var position = mathDevice.v2BuildOne(destination);
destination (Optional)
Returns a Vector2 object.
Summary
Creates a vector with 2 components set to [1.0, 0.0].
Syntax
var position = mathDevice.v2BuildXAxis(destination);
destination (Optional)
Returns a Vector2 object.
Summary
Creates a vector with 2 components set to [0.0, 1.0].
Syntax
var position = mathDevice.v2BuildYAxis(destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector copy of the given vector.
Syntax
var source = mathDevice.v2Build(0, 20);
var destination = mathDevice.v2Copy(source, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the component-wise absolute of the vector parameter given.
Syntax
var vector = mathDevice.v2Build(-4, 10);
destination = mathDevice.v2Abs(vector, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a boolean specifying whether the two 2 component vectors are equal. Optional third parameter specifies the precision of the comparison with a default of 1E-06.
Syntax
var vectorA = mathDevice.v2Build(2, 0);
var vectorB = mathDevice.v2Build(2.00049, 0);
var equal = mathDevice.v2Equal(vectorA, vectorB, scalar);
Summary
Returns a 2 component vector initialized to the component-wise negation of a given vector.
Syntax
var vector = mathDevice.v2Build(0, 20);
destination = mathDevice.v2Neg(vector, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the component-wise reciprocal of a given vector.
Syntax
var vector = mathDevice.v2Build(0.5, 5);
destination = mathDevice.v2Reciprocal(vector, destination);
destination (Optional)
Returns a Vector2 object.
If any of the components is zero this will cause an “Error calling method on NPObject” JavaScript error.
Summary
Returns a 2 component vector initialized to the component-wise addition of two other vectors.
Syntax
var vectorA = mathDevice.v2Build(2, 0);
var vectorB = mathDevice.v2Build(7, 4);
destination = mathDevice.v2Add(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the component-wise addition of 2 other vectors.
Syntax
var vectorA = mathDevice.v2Build(2, 0);
var vectorB = mathDevice.v2Build(7, 4);
var vectorC = mathDevice.v2Build(1, 2);
destination = mathDevice.v2Add2(vectorA, vectorB, vectorC, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the component-wise addition of 4 other vectors.
Syntax
var vectorA = mathDevice.v2Build(2, 0);
var vectorB = mathDevice.v2Build(7, 4);
var vectorC = mathDevice.v2Build(1, 2);
var vectorD = mathDevice.v2Build(4, 6);
destination = mathDevice.v2Add4(vectorA, vectorB, vectorC, vectorD, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the component-wise subtraction of two other vectors.
Syntax
var vectorA = mathDevice.v2Build(2, 0);
var vectorB = mathDevice.v2Build(7, 4);
destination = mathDevice.v2Sub(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the component-wise multiplication of two other vectors.
Syntax
var vectorA = mathDevice.v2Build(2, 0);
var vectorB = mathDevice.v2Build(7, 4);
destination = mathDevice.v2Mul(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the component-wise minimum of two other vectors.
Syntax
var vectorA = mathDevice.v2Build(2, 0);
var vectorB = mathDevice.v2Build(7, 4);
destination = mathDevice.v2Min(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the component-wise maximum of two other vectors.
Syntax
var vectorA = mathDevice.v2Build(2, 0);
var vectorB = mathDevice.v2Build(7, 4);
destination = mathDevice.v2Max(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns the scalar dot product of two 2 component vectors.
Syntax
var cosAngle = mathDevice.v2Dot(vectorA, vectorB);
Returns a JavaScript number.
Summary
Returns the scalar perp-dot product of two 2 component vectors.
Syntax
var sinAngle = mathDevice.v2PerpDot(vectorA, vectorB);
Returns a JavaScript number.
Summary
Returns a 2 component vector initialized to the normalized value of another 2 component vector.
Syntax
var vector = mathDevice.v2Build(2, 6);
destination = mathDevice.v2Normalize(vector, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns the scalar squared length of a given 2 component vector.
Syntax
var vectorLengthSq = mathDevice.v2LengthSq(vector);
//example usage:
if (1.0 !== vectorLengthSq)
{
normal = mathDevice.v2ScalarMul(vector, (1.0 / Math.sqrt(vectorLengthSq)));
}
Returns a JavaScript number.
Summary
Returns the scalar length of a given 2 component vector.
Syntax
var vectorLength = mathDevice.v2Length(vector);
//example usage:
if (1.0 !== vectorLength)
{
vector = mathDevice.v2ScalarMul(vector, (1.0 / vectorLength));
}
Returns a JavaScript number.
Summary
Returns a 2 component vector initialized to the addition of the third argument with the multiplication of the first two arguments.
Syntax
var vectorMulA = mathDevice.v2Build(2, 2);
var vectorMulB = mathDevice.v2Build(0, 7);
var vectorAdd = mathDevice.v2Build(1, 8);
destination = mathDevice.v2MulAdd(vectorMulA, vectorMulB, vectorAdd, destination);
//example usage:
var newPos = mathDevice.v2MulAdd(velocity, deltaTime, pos);
destination (Optional)
Returns a Vector2 object.
Summary
Creates a vector with 2 components all set to the scalar argument provided.
Syntax
var destination = mathDevice.v2ScalarBuild(100, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the addition of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v2ScalarAdd(vector, scalar, destination);
//example usage:
nodeMaxExtent = mathDevice.v2ScalarAdd(nodeMaxExtent, 0.1);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the subtraction of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v2ScalarSub(vector, scalar, destination);
//example usage:
nodeMinExtent = mathDevice.v2ScalarSub(nodeMinExtent, 0.1);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the multiplication of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v2ScalarMul(vector, scalar, destination);
//example usage:
var paddedExtents = mathDevice.v2ScalarMul(extents, 1.1);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the sum of the first vector with the multiplication of the second vector parameter by the third scalar one.
Syntax
newPosition = mathDevice.v2AddScalarMul(position, velocity, time, newPosition);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the linear interpolation between the first and second vector parameters using the delta passed as the third parameter.
Syntax
var vectorA = mathDevice.v2Build(10, 20);
var vectorB = mathDevice.v2Build(20, 0);
destination = mathDevice.v2Lerp(vectorA, vectorB, scalar, destination);
destination (Optional)
Returns a Vector2 object.
Summary
Returns a 2 component vector initialized to the Catmull Rom interpolation through a set of 4 points.
Syntax
var vectorA = mathDevice.v2Build(10, 0);
var vectorB = mathDevice.v2Build(20, 0);
var vectorC = mathDevice.v2Build(5, 10);
var vectorD = mathDevice.v2Build(10, 10);
destination = mathDevice.v2CatmullRom(t, tension, vectorA, vectorB, vectorC, vectorD, destination);
destination (Optional)
Returns a Vector2 object. The interpolation will be at B with derivative tension * (C - A) for t = 0. The interpolation will be at C with derivative tension * (D - A) for t = 1.
Summary
Creates a vector with 3 components.
Syntax
var destination = mathDevice.v3Build(a, b, c, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a vector with 3 components all set to 0.0.
Syntax
var position = mathDevice.v3BuildZero(destination);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a vector with 3 components all set to 1.0.
Syntax
var position = mathDevice.v3BuildOne(destination);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a vector with 3 components set to [1.0, 0.0, 0.0].
Syntax
var position = mathDevice.v3BuildXAxis(destination);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a vector with 3 components set to [0.0, 1.0, 0.0].
Syntax
var position = mathDevice.v3BuildYAxis(destination);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a vector with 3 components set to [0.0, 0.0, 1.0].
Syntax
var position = mathDevice.v3BuildZAxis(destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector copy of the given vector.
Syntax
var source = mathDevice.v3Build(0, 0, 20);
var destination = mathDevice.v3Copy(source, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the component-wise absolute of the vector parameter given.
Syntax
var vector = mathDevice.v3Build(-4, 0, 10);
destination = mathDevice.v3Abs(vector, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a boolean specifying whether the two 3 component vectors are equal. Optional third parameter specifies the precision of the comparison with a default of 1E-06.
Syntax
var vectorA = mathDevice.v3Build(0, 2, 0);
var vectorB = mathDevice.v3Build(0, 2.00049, 0);
var equal = mathDevice.v3Equal(vectorA, vectorB, scalar);
Summary
Returns a 3 component vector initialized to the component-wise negation of a given vector.
Syntax
var vector = mathDevice.v3Build(0, 0, 20);
destination = mathDevice.v3Neg(vector, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the component-wise reciprocal of a given vector.
Syntax
var vector = mathDevice.v3Build(0.5, 5, 1);
destination = mathDevice.v3Reciprocal(vector, destination);
destination (Optional)
Returns a Vector3 object.
If any of the components is zero this will cause an “Error calling method on NPObject” JavaScript error.
Summary
Returns a 3 component vector initialized to the component-wise addition of two other vectors.
Syntax
var vectorA = mathDevice.v3Build(3, 0, 2);
var vectorB = mathDevice.v3Build(7, 4, 3);
destination = mathDevice.v3Add(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the component-wise addition of 3 other vectors.
Syntax
var vectorA = mathDevice.v3Build(3, 0, 2);
var vectorB = mathDevice.v3Build(7, 4, 3);
var vectorC = mathDevice.v3Build(1, 2, 9);
destination = mathDevice.v3Add3(vectorA, vectorB, vectorC, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the component-wise addition of 4 other vectors.
Syntax
var vectorA = mathDevice.v3Build(3, 0, 2);
var vectorB = mathDevice.v3Build(7, 4, 3);
var vectorC = mathDevice.v3Build(1, 2, 9);
var vectorD = mathDevice.v3Build(4, 6, 0);
destination = mathDevice.v3Add4(vectorA, vectorB, vectorC, vectorD, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the component-wise subtraction of two other vectors.
Syntax
var vectorA = mathDevice.v3Build(3, 0, 2);
var vectorB = mathDevice.v3Build(7, 4, 3);
destination = mathDevice.v3Sub(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the component-wise multiplication of two other vectors.
Syntax
var vectorA = mathDevice.v3Build(3, 0, 2);
var vectorB = mathDevice.v3Build(7, 4, 3);
destination = mathDevice.v3Mul(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the component-wise minimum of two other vectors.
Syntax
var vectorA = mathDevice.v3Build(3, 0, 2);
var vectorB = mathDevice.v3Build(7, 4, 3);
destination = mathDevice.v3Min(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the component-wise maximum of two other vectors.
Syntax
var vectorA = mathDevice.v3Build(3, 0, 2);
var vectorB = mathDevice.v3Build(7, 4, 3);
destination = mathDevice.v3Max(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns the scalar dot product of two 3 component vectors.
Syntax
var cosAngle = mathDevice.v3Dot(vectorA, vectorB);
Returns a JavaScript number.
Summary
Returns a 3 component vector initialized to the cross product of two other 3 component vectors.
Syntax
var vectorA = mathDevice.v3Build(3, 0, 2);
var vectorB = mathDevice.v3Build(7, 4, 3);
destination = mathDevice.v3Cross(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the normalized value of another 3 component vector.
Syntax
var vector = mathDevice.v3Build(3, 2, 6);
destination = mathDevice.v3Normalize(vector, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns the scalar squared length of a given 3 component vector.
Syntax
var vectorLengthSq = mathDevice.v3LengthSq(vector);
//example usage:
if (1.0 !== vectorLengthSq)
{
normal = mathDevice.v3ScalarMul(vector, (1.0 / Math.sqrt(vectorLengthSq)));
}
Returns a JavaScript number.
Summary
Returns the scalar length of a given 3 component vector.
Syntax
var vectorLength = mathDevice.v3Length(vector);
//example usage:
if (1.0 !== vectorLength)
{
vector = mathDevice.v3ScalarMul(vector, (1.0 / vectorLength));
}
Returns a JavaScript number.
Summary
Returns a 3 component vector initialized to the addition of the third argument with the multiplication of the first two arguments.
Syntax
var vectorMulA = mathDevice.v3Build(3, 2, 6);
var vectorMulB = mathDevice.v3Build(0, 7, 3);
var vectorAdd = mathDevice.v3Build(1, 8, 5);
destination = mathDevice.v3MulAdd(vectorMulA, vectorMulB, vectorAdd, destination);
//example usage:
var newPos = mathDevice.v3MulAdd(velocity, deltaTime, pos);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a vector with 3 components all set to the scalar argument provided.
Syntax
var destination = mathDevice.v3ScalarBuild(100, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the addition of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v3ScalarAdd(vector, scalar, destination);
//example usage:
nodeMaxExtent = mathDevice.v3ScalarAdd(nodeMaxExtent, 0.1);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the subtraction of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v3ScalarSub(vector, scalar, destination);
//example usage:
nodeMinExtent = mathDevice.v3ScalarSub(nodeMinExtent, 0.1);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the multiplication of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v3ScalarMul(vector, scalar, destination);
//example usage:
var paddedExtents = mathDevice.v3ScalarMul(extents, 1.1);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the sum of the first vector with the multiplication of the second vector parameter by the third scalar one.
Syntax
newPosition = mathDevice.v3AddScalarMul(position, velocity, time, newPosition);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the linear interpolation between the first and second vector parameters using the delta passed as the third parameter.
Syntax
var vectorA = mathDevice.v3Build(10, 0, 20);
var vectorB = mathDevice.v3Build(20, 0, 6);
destination = mathDevice.v3Lerp(vectorA, vectorB, scalar, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Returns a 3 component vector initialized to the Catmull Rom interpolation through a set of 4 points.
Syntax
var vectorA = mathDevice.v3Build(10, 0, 20);
var vectorB = mathDevice.v3Build(20, 0, 6);
var vectorC = mathDevice.v3Build(5, 10, 6);
var vectorD = mathDevice.v3Build(10, 10, 9);
destination = mathDevice.v3CatmullRom(t, tension, vectorA, vectorB, vectorC, vectorD, destination);
destination (Optional)
Returns a Vector3 object. The interpolation will be at B with derivative tension * (C - A) for t = 0. The interpolation will be at C with derivative tension * (D - A) for t = 1.
Summary
Creates a vector with 4 components.
Syntax
var destination = mathDevice.v4Build(100, 10, 0, 42, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Creates a vector with 4 components all set to 0.0.
Syntax
var destination = mathDevice.v4BuildZero(destination);
destination (Optional)
Returns a Vector4 object.
Summary
Creates a vector with 4 components all set to 1.0.
Syntax
var destination = mathDevice.v4BuildOne(destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector copy of the given vector.
Syntax
var source = mathDevice.v4Build(0, 0, 0, 20);
destination = mathDevice.v4Copy(source, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise negation of a given vector.
Syntax
var vector = mathDevice.v4Build(0, 0, 0, 20);
destination = mathDevice.v4Neg(vector, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise addition of two other vectors.
Syntax
var vectorA = mathDevice.v4Build(7, 4, 3, 2);
var vectorB = mathDevice.v4Build(3, 6, 5, 0);
destination = mathDevice.v4Add(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise addition of 3 other vectors.
Syntax
var vectorA = mathDevice.v4Build(7, 4, 3, 2);
var vectorB = mathDevice.v4Build(3, 8, 5, 0);
var vectorC = mathDevice.v4Build(9, 6, 6, 5);
destination = mathDevice.v4Add3(vectorA, vectorB, vectorC, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise addition of 4 other vectors.
Syntax
var vectorA = mathDevice.v4Build(7, 1, 3, 2);
var vectorB = mathDevice.v4Build(3, 8, 5, 0);
var vectorC = mathDevice.v4Build(9, 6, 6, 5);
var vectorD = mathDevice.v4Build(4, 2, 3, 1);
destination = mathDevice.v4Add3(vectorA, vectorB, vectorC, vectorD, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise subtraction of two other vectors.
Syntax
var vectorA = mathDevice.v4Build(7, 4, 3, 2);
var vectorB = mathDevice.v4Build(3, 6, 5, 0);
destination = mathDevice.v4Sub(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise multiplication of two other vectors.
Syntax
var vectorA = mathDevice.v4Build(7, 4, 3, 2);
var vectorB = mathDevice.v4Build(3, 6, 5, 0);
destination = mathDevice.v4Mul(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise minimum of two other vectors.
Syntax
var vectorA = mathDevice.v4Build(7, 4, 3, 2);
var vectorB = mathDevice.v4Build(3, 6, 5, 0);
destination = mathDevice.v4Min(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise maximum of two other vectors.
Syntax
var vectorA = mathDevice.v4Build(7, 4, 3, 2);
var vectorB = mathDevice.v4Build(3, 6, 5, 0);
destination = mathDevice.v4Max(vectorA, vectorB, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns the scalar dot product of to 4 component vectors.
Syntax
var vectorA = mathDevice.v4Build(7, 4, 3, 2);
var vectorB = mathDevice.v4Build(3, 6, 5, 0);
var dot = mathDevice.v4Dot(vectorA, vectorB);
Returns a JavaScript number.
Summary
Returns a 4 component vector initialized to the normalized value of another 4 component vector.
Syntax
var vector = mathDevice.v4Build(7, 4, 3, 2);
var destination = mathDevice.v4Normalize(vector, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns the scalar squared length of a given 4 component vector.
Syntax
var vectorLengthSq = mathDevice.v4LengthSq(vector);
//example code:
if (1.0 !== vectorLengthSq)
{
vector = mathDevice.v4ScalarMul(vector, (1.0 / Math.sqrt(vectorLengthSq)));
}
Returns a JavaScript number.
Summary
Returns the scalar length of a given 4 component vector.
Syntax
var vectorLength = mathDevice.v4Length(vector);
//example code:
if (1.0 !== vectorLength)
{
vector = mathDevice.v4ScalarMul(vector, (1.0 / vectorLength));
}
Returns a JavaScript number.
Summary
Returns a 4 component vector initialized to the addition of the third argument with the multiplication of the first two arguments.
Syntax
var vectorMulA = mathDevice.v4Build(3, 2, 6);
var vectorMulB = mathDevice.v4Build(0, 7, 3);
var vectorAdd = mathDevice.v4Build(1, 8, 5);
destination = mathDevice.v4MulAdd(vectorMulA, vectorMulB, vectorAdd, destination);
//example usage:
var newPos = mathDevice.v4MulAdd(velocity, deltaTime, pos);
destination (Optional)
Returns a Vector4 object.
Summary
Creates a vector with 4 components all set to the argument given.
Syntax
var destination = mathDevice.v4ScalarBuild(100, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the addition of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v4ScalarAdd(vector, scalar, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the subtraction of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v4ScalarSub(color, scalar, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the multiplication of the first vector parameter to the second scalar one.
Syntax
destination = mathDevice.v4ScalarMul(vector, scalar, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the sum of the first vector with the multiplication of the second vector parameter by the third scalar one.
Syntax
destination = mathDevice.v4AddScalarMul(vector1, vector2, delta, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the linear interpolation between the first and second vector parameters using the delta passed as the third parameter.
Syntax
var vectorA = mathDevice.v4Build(10, 0, 20, 0);
var vectorB = mathDevice.v4Build(20, 0, 6, 0);
destination = mathDevice.v4Lerp(vectorA, vectorB, scalar, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a 4 component vector initialized to the component-wise absolute of the vector parameter given.
Syntax
var vector = mathDevice.v4Build(-4, 0, 10, -5);
destination = mathDevice.v4Abs(vector, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Returns a boolean specifying whether the two 4 component vectors are equal. Optional third parameter specifies the precision of the comparison with a default of 1E-06.
Syntax
var vectorA = mathDevice.v4Build(0, 2, 0, -1);
var vectorB = mathDevice.v4Build(0, 2.00014, 0, -1);
var equal = mathDevice.v4Equal(vectorA, vectorB, scalar);
Summary
Returns a 4D vector initialized to the normalized value of a 4D vector interpreted as a Plane equation.
Syntax
var vector = mathDevice.v4Build(5, 3, 2, 9);
destination = mathDevice.planeNormalize(vector, destination);
destination (Optional)
Returns a Vector4 object.
Summary
Creates an AABB object, containing bounding box defined by two points; a minimum and a maximum.
Syntax
var destination = mathDevice.aabbBuild(minX, minY, minZ, maxX, maxY, maxZ, destination);
// example usage:
var unitBox = mathDevice.aabbBuild(0, 0, 0, 1, 1, 1);
destination (Optional)
Returns a AABB object.
Summary
Creates an AABB object, containing bounding box defined by two points; a minimum and a maximum. The box has its minimum point set to the maximum values possible and its maximum point set to the minimum values possible.
Syntax
var destination = mathDevice.aabbBuildEmpty(destination);
// example usage:
var aabbEmpty = mathDevice.aabbBuildEmpty();
var unitBox = mathDevice.aabbBuild(0, 0, 0, 1, 1, 1);
var union = mathDevice.aabbUnion(aabbEmpty, unitBox);
// union is now equal to unitBox
destination (Optional)
Returns a AABB object.
Summary
Returns a copy of the given AABB object.
Syntax
var source = mathDevice.aabbBuild(0, 0, 0, 1, 1, 1);
var destination = mathDevice.aabbCopy(source, destination);
destination (Optional)
Returns an AABB object.
Summary
Returns a true if the given AABB object is empty, false otherwise.
Syntax
var source = mathDevice.aabbBuildEmpty();
var isEmpty = mathDevice.aabbIsEmpty(aabb);
Returns an JavaScript boolean object.
Summary
Gets the center point and the half extents of the AABB object.
Syntax
var source = mathDevice.aabbBuildEmpty();
mathDevice.aabbGetCenterAndHalf(aabb, center, halfExtents);
//example usage:
var newBox = mathDevice.aabbBuild(center[0] - halfExtents[0],
center[1] - halfExtents[1],
center[2] - halfExtents[2],
center[3] - halfExtents[3],
center[4] - halfExtents[4],
center[5] - halfExtents[5],);
Summary
Returns true if the any point in the AABB object is on the correct side of each plane, false otherwise.
Syntax
var isInside = mathDevice.aabbIsInsidePlanes(aabb, planes);
//example usage:
mathDevice.aabbIsInsidePlanes(aabb, [mathDevice.v4Build(0, 0, -1, 4),
mathDevice.v4Build(0, 0, 1, -4)]);
Returns an JavaScript boolean object.
Summary
Returns true if the all points in the AABB object are on the correct side of each plane, false otherwise.
Syntax
var isFullyInside = mathDevice.aabbIsFullyInsidePlanes(aabb, planes);
//example usage:
mathDevice.aabbIsFullyInsidePlanes(aabb, [mathDevice.v4Build(0, 0, -1, 4),
mathDevice.v4Build(0, 0, 1, -4)]);
Returns an JavaScript boolean object.
Summary
Returns the union of two given AABB objects. The union of any AABB object a and an empty AABB object is a.
Syntax
var boxA = mathDevice.aabbBuild(0, 0, 0, 1, 1, 4);
var boxB = mathDevice.aabbBuild(1, 0, 1, 2, 3, 2);
var destination = mathDevice.aabbUnion(boxA, boxB, destination);
// the result is a box with minimum at the origin and
// maximum at point (2, 3, 4)
destination (Optional)
Returns a AABB object.
Summary
Returns the union of an array of AABB objects. The union of any AABB object a and an empty AABB object is a.
Syntax
var boxA = mathDevice.aabbBuild(0, 0, 0, 1, 1, 4);
var boxB = mathDevice.aabbBuild(1, 0, 1, 2, 3, 2);
var destination = mathDevice.aabbUnionArray([boxA, boxB], destination);
// the result is a box with minimum at the origin and
// maximum at point (2, 3, 4)
destination (Optional)
Returns a AABB object.
Summary
“Stretches” an AABB object to contain a set of points.
Syntax
var box = mathDevice.aabbBuild(0, 0, 0, 1, 1, 1);
var points = [];
points[0] = mathDevice.v3Build(0, 0, 2);
points[1] = mathDevice.v3Build(0, -1, -2);
points[2] = mathDevice.v3Build(1, 0, 1);
mathDevice.aabbAddPoints(box, points);
// box will now have minimum (0, -1, -2) and
// maximum (1, 1, 2)
Summary
Returns a transformed AABB object.
Syntax
var sqrt = Math.sqrt;
var box = mathDevice.aabbBuild(0, 0, 0, sqrt(2), 1, sqrt(2));
var up = mathDevice.v3BuildYAxis();
var matrix = mathDevice.m43FromAxisRotation(up, Math.PI / 4);
var destination = mathDevice.aabbTransform(box, matrix, destination);
// returns a box with roughly minimum (-1, 0, 0) and maximum (1, 1, 2)
destination (Optional)
Returns a AABB object.
Summary
Returns the interception of two given AABB objects. The interception of any AABB object a and an empty AABB object is an empty AABB object.
Syntax
var boxA = mathDevice.aabbBuild(0, 0, 0, 1, 1, 4);
var boxB = mathDevice.aabbBuild(1, 0, 1, 2, 3, 2);
var destination = mathDevice.aabbIntercept(boxA, boxB, destination);
// the result is a box with minimum at (1, 0, 1) and
// maximum at point (1, 1, 2)
destination (Optional)
Returns a AABB object.
Summary
Returns true if the two given AABB objects overlap (including edges), false otherwise. The overlap of any AABB object a and an empty AABB object is false.
Syntax
var boxA = mathDevice.aabbBuild(0, 0, 0, 1, 1, 4);
var boxB = mathDevice.aabbBuild(1, 0, 1, 2, 3, 2);
var bool = mathDevice.aabbOverlaps(boxA, boxB);
// returns true
Returns a JavaScript boolean.
Summary
Returns true if the given AABB object overlaps with the sphere (including edges), false otherwise.
Syntax
var box = mathDevice.aabbBuild(0, 0, 0, 1, 1, 1);
var center = mathDevice.v3Build(0, 0, 0);
var radius = 2;
var bool = mathDevice.aabbSphereOverlaps(box, center, radius);
// returns true
Returns a JavaScript boolean.
Summary
Returns true if the first given AABB object is inside the second given AABB object (including edges), false otherwise.
Syntax
var boxA = mathDevice.aabbBuild(0, 0, 0, 1, 1, 1);
var boxB = mathDevice.aabbBuild(0, 0, 0, 0.5, 0.5, 0.5);
var bool = mathDevice.aabbIsInside(boxA, boxB);
// returns true
Returns a JavaScript boolean.
Summary
Syntax
var boxA = mathDevice.aabbBuild(0, 0, 0, 1, 1, 1);
var boxB = mathDevice.aabbBuild(0, 0, 0, 0.5, 0.5, 0.5);
var bool = mathDevice.aabbTestInside(boxA, boxB);
// returns 2
Returns a JavaScript number.
Summary
Creates a quat object, containing a rotation represented by a quaternion.
Syntax
var destination = mathDevice.quatBuild(a, b, c, d, destination);
Returns a Quaternion object.
destination (Optional)
Summary
Returns a boolean specifying whether the two quaternions are equal. Optional third parameter specifies the precision of the comparison with a default of 1E-06.
Syntax
var quatA = mathDevice.quatBuild(0, 0, 0, 1);
var quatB = mathDevice.quatBuild(0, 0.707, 0, 0.707);
var equal = mathDevice.quatEqual(quatA, quatB, scalar);
Returns a JavaScript boolean.
Summary
Returns a boolean specifying whether the two quaternions are similar. This function differs from mathDevice.quatEqual in that it will evaluate to true for quaternions which have similar rotations rather than similar quaternion component values. Optional third parameter specifies the precision of the comparison with a default of 1E-06.
Syntax
var quatA = mathDevice.quatBuild(0, 0, 0, 1);
var quatB = mathDevice.quatBuild(0, 0.707, 0, 0.707);
var equal = mathDevice.quatIsSimilar(quatA, quatB, scalar);
Returns a JavaScript boolean.
Summary
Returns the scalar length of a given quaternion.
Syntax
var quatLength = mathDevice.quatLength(quat);
Returns a JavaScript number.
Summary
Returns a quaternion initialized to the normalized value of another quaternion.
Syntax
destination = mathDevice.quatNormalize(quat, destination);
destination (Optional)
Returns a Quaternion object.
Summary
Returns a quaternion initialized to the conjugate value of another quaternion.
Syntax
destination = mathDevice.quatConjugate(quat, destination);
destination (Optional)
Returns a Quaternion object.
Summary
Returns a scalar, the dot product of the two given quaternions.
Syntax
var quatA = mathDevice.quatBuild(0, 0, 0, 1);
var quatB = mathDevice.quatBuild(0, 0.707, 0, 0.707);
scalar = mathDevice.quatDot(quatA, quatB);
Returns a JavaScript number.
Summary
Returns a quaternion object representing the multiplication of the two given quaternions.
Syntax
var quatA = mathDevice.quatBuild(0, 0, 0, 1);
var quatB = mathDevice.quatBuild(0, 0.707, 0, 0.707);
destination = mathDevice.quatMul(quatA, quatB, destination);
destination (Optional)
Returns a Quaternion object.
Summary
Creates a vector initialized to the rotation and angle represented by the quaternion parameter.
Syntax
destination = mathDevice.quatToAxisRotation(quat, destination);
//example usage:
var axis = mathDevice.v3Build(destination[0], destination[1], destination[2]);
var rotation = destination[3];
destination (Optional)
Returns a Vector4 object with the first 3 components as the axis of rotation and the 4th component as the rotation in radians.
Summary
Creates a vector initialized to the second vector parameter transformed by the first quaternion parameter.
Syntax
destination = mathDevice.quatTransformVector(quat, vector, destination);
//example usage:
var axis = mathDevice.v3Build(0, 1, 0);
var quat = mathDevice.quatFromAxisRotation(axis, Math.PI * 0.5);
var vec3 = mathDevice.v3Build(1, 0, 0);
var transformedVec = mathDevice.quatTransformVector(quat, vec3);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a quaternion initialized to the rotation represented by the first parameter as the axis vector and second as the rotation in radians.
Syntax
destination = mathDevice.quatFromAxisRotation(vector, scalar, destination);
//example usage:
var up = mathDevice.v3BuildYAxis();
var deltaRotation = mathDevice.quatFromAxisRotation(up, angle);
destination (Optional)
Returns a Quaternion object.
Summary
Creates a quaternion initialized to the rotation part of the given 4x3 orthogonal matrix.
Syntax
destination = mathDevice.quatFromM43(matrix, destination);
//example usage:
var matrix = camera.getMatrix();
var rotation = mathDevice.quatFromM43(matrix);
destination (Optional)
Returns a Quaternion object.
Summary
Returns a quaternion copy of the given quaternion.
Syntax
var quat = mathDevice.quatBuild(0, 0, 0, 1);
destination = mathDevice.quatCopy(quat, destination);
destination (Optional)
Returns a Quaternion object.
Summary
Returns a quaternion initialized to the linear interpolation of the given two quaternions at the given delta between them.
Syntax
var quatA = mathDevice.quatBuild(0, 0, 0, 1);
var quatB = mathDevice.quatBuild(0, 0.707, 0, 0.707);
destination = mathDevice.quatLerp(quatA, quatB, scalar, destination);
destination (Optional)
Returns a Quaternion object.
Summary
Returns a quaternion initialized to the spherical linear interpolation of the given two quaternions at the given delta between them.
Syntax
var quatA = mathDevice.quatBuild(0, 0, 0, 1);
var quatB = mathDevice.quatBuild(0, 0.707, 0, 0.707);
destination = mathDevice.quatSlerp(quatA, quatB, scalar, destination);
destination (Optional)
Returns a Quaternion object.
Summary
Creates a quatPos object, containing a position and a rotation represented by a quaternion.
Syntax
var destination = mathDevice.QuatPosBuild(quatA, quatB, quatC, quatD, v3A, v3B, v3C, destination);
var destination = mathDevice.QuatPosBuild(quat, v3, destination);
destination (Optional)
Returns a QuaternionPosition object. The parameters are given as quaternion components and then position components.
Summary
Multiplies together two pairs of rotations and translations represented as a quaternion and 3 component vector. The result is given in an additional quaternion and 3 component vector passed as the fifth and sixth parameters. This method matches m43Mul in functionality but working with quaternion representations.
Syntax
var quatA = mathDevice.quatBuild(0, 0, 0, 1);
var vectorA = mathDevice.v3Build(0, 20, 0);
var quatB = mathDevice.quatBuild(0, 0.707, 0, 0.707);
var vectorB = mathDevice.v3Build(0, 4, 10);
var destinationQuat = mathDevice.quatBuild(0, 0, 0, 0);
var destinationVector = mathDevice.v3Build(0, 0, 0);
mathDevice.quatMulTranslate(quatA, vectorA, quatB, vectorB, destinationQuat, destinationVector);
Notice that the destinations are not optional here they must be provided, this function returns null.
Summary
Creates a 3x3 matrix initialized to the identity.
Syntax
var destination = mathDevice.m33BuildIdentity(destination);
destination (Optional)
Returns a Matrix33 object.
Summary
Creates a 3x3 matrix initialized to the 3 given 3 component vectors.
Syntax
var destination = mathDevice.m33Build(a, b, c,
d, e, f,
g, h, i,
destination);
var destination = mathDevice.m33Build(right, up, at, destination);
destination (Optional)
Returns a Matrix33 object.
Summary
Copies a 3x3 matrix.
Syntax
var destination = mathDevice.m33Build(matrix, destination);
destination (Optional)
Returns a Matrix33 object.
Summary
Creates a 3x3 matrix initialized to the rotation represented by the first parameter as the axis vector and the second scalar one as the angle.
Syntax
destination = mathDevice.m33FromAxisRotation(vector, scalar, destination);
//example usage:
var up = mathDevice.v3Build(0, 1, 0);
var deltaRotation = mathDevice.m33FromAxisRotation(up, angle);
destination (Optional)
Returns a Matrix33 object.
Summary
Creates a 3x3 matrix initialized to the multiplication of two other 3x3 matrices.
Syntax
var matrixA = mathDevice.m33Build(rightA, upA, atA);
var matrixB = mathDevice.m33Build(rightB, upB, atB);
destination = mathDevice.m33Mul(matrixA, matrixB, destination);
destination (Optional)
Returns a Matrix33 object.
Summary
Creates a Vector3 initialized to the transform of a Vector3 by a 3x3 matrix.
Syntax
destination = mathDevice.m33Transform(matrix, vector, destination);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a 3x3 matrix initialized to the transposed of the given 3x3 matrix.
Syntax
destination = mathDevice.m33Transpose(matrix, destination);
destination (Optional)
Returns a Matrix33 object.
Summary
Creates a 3x3 matrix initialized to the transposed inverse of the given 3x3 matrix.
Syntax
destination = mathDevice.m33InverseTranspose(matrix, destination);
//example usage:
var worldToObjectInverseTranspose = mathDevice.m33InverseTranspose(worldRotation);
destination (Optional)
Returns a Matrix33 object.
Summary
Evaluates the determinant of a 3x3 matrix.
Syntax
var determinant = mathDevice.m33Determinant(matrix);
Returns a JavaScript number.
Summary
Creates a 4x3 matrix initialized to the multiplication of the 3x3 part of a 3x3 or 4x3 matrix with a 4x3 matrix. This operation keeps the 4th row of the second argument.
Syntax
destination = mathDevice.m33MulM43(matrixA, matrixB, destination);
destination (Optional)
Returns a Matrix43 object with matrixB‘s 4th row.
Summary
Creates a 4x4 matrix initialized to the multiplication of a 3x3 matrix with a 4x4 matrix.
Syntax
destination = mathDevice.m33MulM44(matrixA, matrixB, destination);
destination (Optional)
Returns a Matrix44 object.
Creates a 3x3 matrix initialized to the rotation represented by a quaternion.
Syntax
destination = mathDevice.m33FromQuat(quat, destination);
destination (Optional)
Returns a Matrix33 object.
Summary
Creates a 3 component vector initialized to the right element of the given 3x3 matrix.
Syntax
destination = mathDevice.m33Right(matrix, destination);
//example usage:
var right = mathDevice.m33Right(rotation);
destination (Optional)
Returns a Vector3 object. This function returns the first row of the matrix.
Summary
Creates a 3 component vector initialized to the up element of the given 3x3 matrix. Optional second parameter specifies the vector to copy the results to - this destination parameter should be created beforehand and it will also be the return value. This functionality is useful to avoid the memory allocation of a new vector.
Syntax
destination = mathDevice.m33Up(matrix, destination);
destination (Optional)
Returns a Vector3 object. This function returns the second row of the matrix.
Summary
Creates a 3 component vector initialized to the at element of the given 3x3 matrix.
Syntax
destination = mathDevice.m33At(matrix, destination);
destination (Optional)
Returns a Vector3 object. This function returns the last row of the matrix.
Summary
Sets the right element of a 3x3 matrix to the values of the given 3 component vector.
Syntax
mathDevice.m33SetRight(matrix, vector);
This function sets the first row of the matrix.
Summary
Sets the up element of a 3x3 matrix to the values of the given 3 component vector.
Syntax
mathDevice.m33SetUp(matrix, vector);
This function sets the second row of the matrix.
Summary
Sets the at element of a 3x3 matrix to the values of the given 3 component vector.
Syntax
mathDevice.m33SetAt(matrix, vector);
This function sets the last row of the matrix.
Summary
Creates a 3x4 matrix initialized to the identity.
Syntax
var destination = mathDevice.m34BuildIdentity(destination);
destination (Optional)
Returns a Matrix34 object.
Summary
Creates a 3 component vector initialized to the position element of the given 3x4 matrix.
Syntax
destination = mathDevice.m34Pos(matrix, destination);
destination (Optional)
Returns a Vector3 object. This returns the first row of the matrix.
Summary
Creates a 4x3 matrix initialized to the identity.
Syntax
var destination = mathDevice.m43BuildIdentity(destination);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized to the 4 given 3 component vectors.
Syntax
var destination = mathDevice.m43Build(a, b, c,
d, e, f,
g, h, i,
j, k, l,
destination);
var destination = mathDevice.m43Build(right, up, at, pos, destination);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized with the identity matrix for its first 3 rows and a given 3 component vector for the position row.
Syntax
var destination = mathDevice.m43BuildTranslation(a, b, c, destination);
var destination = mathDevice.m43BuildTranslation(vector, destination);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized to a copy of the given 4x3 matrix.
Syntax
destination = mathDevice.m43Copy(matrix, destination);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix with the first 3 rows set equal to the matrix and the last row equal to the vector.
Syntax
destination = mathDevice.m43FromM33V3(matrix, vector, destination);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized to the rotation represented by the first parameter as the axis vector and the second scalar one as the angle. Position element is initialized to zero.
Syntax
destination = mathDevice.m43FromAxisRotation(vector, scalar, destination);
//example usage:
var up = mathDevice.v3Build(0, 1, 0);
var transform = mathDevice.m43FromAxisRotation(up, angle);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized to a quatPos vector.
Syntax
destination = mathDevice.m43FromQuatPos(quatPos, destination);
//example usage:
var boneTransform = mathDevice.quatPos(0, 1, 0, 1,
5, 3, 0);
var transform = mathDevice.m43FromQuatPos(boneTransform);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized from a given Quaternion, 3 component position vector and 3 component scale vector.
Syntax
destination = mathDevice.m43FromRTS(quat, vector, scalar, destination);
//example usage:
var rotation = mathDevice.quatBuild(0, 0, 0, 1);
var translation = mathDevice.v3Build(10, 10, 10);
var scale = mathDevice.v3Build(2, 1, 1);
var transform = mathDevice.m43FromRTS(rotation, translation, scale);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized from a given Quaternion and 3 component position vector.
Syntax
destination = mathDevice.m43FromRT(quat, vector, destination);
//example usage:
var rotation = mathDevice.quatBuild(0, 0, 0, 1);
var translation = mathDevice.v3Build(10, 10, 10);
var transform = mathDevice.m43FromRT(rotation, translation);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 3 component vector initialized to the right element of the given 4x3 matrix.
Syntax
destination = mathDevice.m43Right(matrix, destination);
destination (Optional)
Returns a Vector3 object. This function returns the first row of the matrix.
Summary
Creates a 3 component vector initialized to the up element of the given 4x3 matrix.
Syntax
destination = mathDevice.m43Up(matrix, destination);
destination (Optional)
Returns a Vector3 object. This function returns the second row of the matrix.
Summary
Creates a 3 component vector initialized to the at element of the given 4x3 matrix.
Syntax
destination = mathDevice.m43At(matrix, destination);
destination (Optional)
Returns a Vector3 object. This function returns the third row of the matrix.
Summary
Creates a 3 component vector initialized to the position element of the given 4x3 matrix.
Syntax
destination = mathDevice.m43Pos(matrix, destination);
destination (Optional)
Returns a Vector3 object. This function returns the fourth row of the matrix.
Summary
Creates a 4x3 matrix initialized to the multiplication of two other 4x3 matrices.
Syntax
destination = mathDevice.m43Mul(matrixA, matrixB, destination);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 3x4 matrix initialized to the transposed multiplication of two 4x3 matrices.
Syntax
destination = mathDevice.m43MulTranspose(matrixA, matrixB, destination);
destination (Optional)
Returns a Matrix34 object.
Summary
Creates a 4x4 matrix initialized to the multiplication of a 4x3 matrix by a 4x4 matrix.
Syntax
destination = mathDevice.m43MulM44(matrixA, matrixB, destination);
//example usage:
var worldViewProjection = mathDevice.m43MulM44(worldTransform, viewProjection);
destination (Optional)
Returns a Matrix44 object.
Summary
Creates a 3x4 matrix initialized to the transpose of the given 4x3 matrix.
Syntax
destination = mathDevice.m43Transpose(matrix, destination);
//example usage:
var worldTransformTransposed = mathDevice.m43Transpose(worldTransform);
destination (Optional)
Returns a Matrix34 object.
Summary
Creates a 4x3 matrix initialized to the inverse of a given orthonormal 4x3 matrix.
Syntax
destination = mathDevice.m43InverseOrthonormal(matrix, destination);
//example usage:
var viewTransform = mathDevice.m43InverseOrthonormal(cameraTransform);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized to the othogonalized and normalized value of a given 4x3 matrix.
Syntax
destination = mathDevice.m43Orthonormalize(matrix, destination);
destination (Optional)
Returns a Matrix43 object.
Summary
Evaluates the determinant of a 4x3 matrix.
Syntax
var det = mathDevice.m43Determinant(matrix);
Returns a JavaScript number value.
Summary
Creates a 4x3 matrix initialized to the inverse of a given 4x3 matrix.
Syntax
destination = mathDevice.m43Inverse(matrix, destination);
destination (Optional)
Returns a Matrix43 object.
Summary
Adds component-wise the given 3 component vector to the position element of a 4x3 matrix.
Syntax
mathDevice.m43Translate(matrix, vector);
//example usage:
var deltaPos = mathDevice.v3Build(0, 0, 20);
mathDevice.m43Translate(worldTransform, deltaPos);
Summary
Scales up the 3x3 part of a 4x3 matrix. Each row is multiplied by each component of the scale vector.
Syntax
destination = mathDevice.m43Scale(matrix, vector, destination);
//example usage:
var vecScale = mathDevice.v3ScalarBuild(10);
mathDevice.m43Scale(matrix, vecScale, matrix);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized to the given 4x3 matrix translated to the given relative 3 component vector. The relative vector is first rotated with the 3x3 component of the matrix and then added to its position element.
Syntax
destination = mathDevice.m43Offset(matrix, vector, destination);
//example usage:
var newTransform = mathDevice.m43Offset(initialTransform, relativeOffset);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 4x3 matrix initialized to the given 4x3 matrix translated to the given relative 3 component vector. The relative vector is first rotated with the 3x3 component of the matrix and then subtracted to its position element.
Syntax
destination = mathDevice.m43NegOffset(matrix, vector, destination);
//example usage:
var newTransform = mathDevice.m43NegOffset(initialTransform, negativeRelativeOffset);
destination (Optional)
Returns a Matrix43 object.
Summary
Creates a 3x4 matrix initialized to the transposed inverse of the given 4x3 matrix projected to the given 3 component vector.
Syntax
destination = mathDevice.m43InverseTransposeProjection(matrix, vector, destination);
//example usage:
var worldViewMatrix = mathDevice.m43Mul(worldMatrix, viewMatrix, worldViewMatrix);
var newTransform = mathDevice.m43InverseTransposeProjection(worldViewMatrix, halfExtents);
destination (Optional)
Returns a Matrix34 object.
This function gives the same result as the following function calls::
var inverse = mathDevice.m43InverseOrthonormal(matrix);
var result = mathDevice.m34Transpose(inverse);
For example for applying a texture to a point light. Then matrix would be a transform from object space into view space. The vector would then be the half extents of the light. The result of this example operation would give a transform from world space to light space. This light space is normalized to have its extents from (0, 0, 0) to (1, 1, 1).
Summary
Creates a 3 component vector initialized to the transformation as a point of the given 3 component vector by the given 4x3 matrix.
Syntax
destination = mathDevice.m43TransformPoint(matrix, vector, destination);
//example usage:
var worldPosition = mathDevice.m43TransformPoint(worldTransform, localPosition);
destination (Optional)
Returns a Vector3 object.
Summary
Creates a 3 component vector initialized to the transformation as a direction of the given 3 component vector by the given 4x3 matrix.
Syntax
destination = mathDevice.m43TransformVector(matrix, vector, destination);
//example usage:
var worldNormal = mathDevice.m43TransformVector(worldTransform, localNormal);
destination (Optional)
Returns a Vector3 object.
Summary
Sets the right element of a 4x3 matrix to the values of the given 3 component vector.
Syntax
mathDevice.m43SetRight(matrix, vector);
Summary
Sets the up element of a 4x3 matrix to the values of the given 3 component vector.
Syntax
mathDevice.m43SetUp(matrix, vector);
Summary
Sets the at element of a 4x3 matrix to the values of the given 3 component vector.
Syntax
mathDevice.m43SetAt(matrix, vector);
Summary
Sets the position element of a 4x3 matrix to the values of the given 3 component vector.
Syntax
mathDevice.m43SetPos(matrix, vector);
Summary
Sets the 3x3 rotation component of a 4x3 matrix to the rotation defined by the given 3D axis and the given scalar angle.
Syntax
mathDevice.m43SetAxisRotation(matrix, vector, scalar);
Summary
Creates a 4x4 matrix initialized to the identity.
Syntax
var matrix = mathDevice.m44BuildIdentity(destination);
destination (Optional)
Returns a Matrix44 object.
Summary
Creates a 4x4 matrix initialized to the 4 given 4 component vectors.
Syntax
var destination = mathDevice.m44Build(a, b, c, d,
e, f, g, h,
i, j, k, l,
m, n, o, p,
destination);
var destination = mathDevice.m44Build(right, up, at, pos, destination);
destination (Optional)
Returns a Matrix44 object.
Summary
Copies a 4x4 matrix.
Syntax
var destination = mathDevice.m44Build(matrix, destination);
destination (Optional)
Returns a Matrix44 object.
Summary
Creates a 4x4 matrix initialized to the multiplication of two other 4x4 matrices.
Syntax
destination = mathDevice.m44Mul(matrixA, matrixB, destination);
//example usage:
var newTransform = mathDevice.m44Mul(initialTransform, deltaTransform);
destination (Optional)
Returns a Matrix44 object.
Summary
Creates a 4x4 matrix initialized to the inverse of a given non-orthonormal 4x4 matrix.
Syntax
destination = mathDevice.m44Inverse(matrix, destination);
destination (Optional)
Returns a Matrix44 object.
Summary
Creates a 4x4 matrix initialized to the transpose of the given 4x4 matrix.
Syntax
destination = mathDevice.m44Transpose(matrix, destination);
destination (Optional)
Returns a Matrix44 object.
Summary
Creates a 4 component vector initialized to the transformation of the given 4 component vector by the given 4x4 matrix.
Syntax
destination = mathDevice.m44Transform(matrix, vector, destination);
//example usage:
var worldPosition = mathDevice.m44Transform(worldTransform, localPosition);
destination (Optional)
Returns a Vector4 object.
Summary
Adds component-wise the given 3 component vector to the position element of a 4x4 matrix.
Syntax
mathDevice.m44Translate(matrix, vector);
//example usage:
var deltaPos = mathDevice.v3Build(0, 0, 20);
mathDevice.m44Translate(worldTransform, deltaPos);
Summary
Scales up the 3x3 part of a 4x4 matrix. Each row is multiplied by each component of the scale vector.
Syntax
destination = mathDevice.m44Scale(matrix, vector, destination);
//example usage:
var vecScale = mathDevice.v4ScalarBuild(10);
mathDevice.m44Scale(matrix, vecScale, matrix);
destination (Optional)
Returns a Matrix44 object.
Summary
Sets the right element of a 4x4 matrix to the values of the given 4 component vector.
Syntax
mathDevice.m44SetRight(matrix, vector);
Summary
Sets the up element of a 4x4 matrix to the values of the given 4 component vector.
Syntax
mathDevice.m44SetUp(matrix, vector);
Summary
Sets the at element of a 4x4 matrix to the values of the given 4 component vector.
Syntax
mathDevice.m44SetAt(matrix, vector);
Summary
Sets the position element of a 4x4 matrix to the values of the given 4 component vector.
Syntax
mathDevice.m44SetPos(matrix, vector);
Summary
Creates a 4 component vector initialized to the right element of the given 4x4 matrix.
Syntax
destination = mathDevice.m44Right(matrix, destination);
destination (Optional)
Returns a Vector4 object. This function returns the first row of the matrix.
Summary
Creates a 4 component vector initialized to the up element of the given 4x4 matrix.
Syntax
destination = mathDevice.m44Up(matrix, destination);
destination (Optional)
Returns a Vector4 object. This function returns the second row of the matrix.
Summary
Creates a 4 component vector initialized to the at element of the given 4x4 matrix.
Syntax
destination = mathDevice.m44At(matrix, destination);
destination (Optional)
Returns a Vector4 object. This function returns the third row of the matrix.
Summary
Creates a 4 component vector initialized to the position element of the given 4x4 matrix.
Syntax
destination = mathDevice.m44Pos(matrix, destination);
destination (Optional)
Returns a Vector4 object. This function returns the fourth row of the matrix.
Summary
Returns true if the axis-aligned bounding box defined by the extents is inside the planes array.
Syntax
var boolean = mathDevice.isInsidePlanesAABB(extents, planes);
//example usage:
var isVisible = mathDevice.isInsidePlanesAABB(extents, camera.frustumPlanes);
Returns a True or False.
Summary
Returns true if the axis-aligned bounding box defined by the extents is fully inside the planes array.
Syntax
var boolean = mathDevice.isFullyInsidePlanesAABB(extents, planes);
//example usage:
var isVisible = mathDevice.isFullyInsidePlanesAABB(extents, camera.frustumPlanes);
Returns true or false.
Summary
Returns true if the box defined by the center and half extents 3 component vectors is inside the projection space defined by the given 4x4 matrix.
Syntax
var boolean = mathDevice.isVisibleBox(center, halfExtents, matrix);
//example usage:
var isVisible = mathDevice.isVisibleBox(center, halfExtents, worldViewProjection);
Returns true or false.
Summary
Returns true if the box located at the local origin with the given half extents 3 component vector is inside the projection space defined by the given 4x4 matrix.
Syntax
var boolean = mathDevice.isVisibleBoxOrigin(halfExtents, matrix);
//example usage:
var isVisible = mathDevice.isVisibleBoxOrigin(halfExtents, worldViewProjection);
Returns true or false.