new MatrixArray()
A helper class for performing vector math using array-based matrices.
These are 16-item column-major transformation matrix arrays. This means that, when represented as a table with 4 columns and 4 rows, the X, Y and Z direction each of the local axis are read downwards in the first three columns and the 4th row gives the offset in each of those axis.
Any Float32Array with at least 16 items in the same format can also be used
entirely interchangeably as both output or input in all matrix array methods.
Methods
-
compose(out, translation, rotation, scale) <static>
-
Composes a flat 4x4 column-major matrix from the given translation, rotation and scaling factors.
Once created, you can use the
PD.VectorArray.applyMatrix4method to modify points and vertices.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to receive the result.
translationArray.<number> The [x,y,z] vector array defining the spatial translation in each axis.
rotationArray.<number> The normalised [x,y,z,w] quaternion array defining the spatial rotation.
scaleArray.<number> The [x,y,z] vector array defining the spatial scaling in each axis.
Returns:
Returns the modified
outmatrix.- Type
- Array.<number>
-
create() <static>
-
Creates a new 16-item column-major matrix array.
Returns:
Returns a new 16-item column-major matrix array.
- Type
- Array.<number>
-
decompose(matrix, translation, rotation, scale) <static>
-
Composes a flat 4x4 column-major matrix from the given translation, rotation and scaling factors.
Once created, you can use the
PD.VectorArray.applyMatrix4method to modify points and vertices.NOTE: This method changes values within the
translate,rotateandscaleparameters.Parameters:
Name Type Description matrixArray.<number> The 16-item column-major matrix array to receive the result.
translationArray.<number> The [x,y,z] vector array defining the spatial translation in each axis.
rotationArray.<number> The normalised [x,y,z,w] quaternion array defining the spatial rotation.
scaleArray.<number> The [x,y,z] vector array defining the spatial scaling in each axis.
Returns:
Returns the
matrixargument.- Type
- Array.<number>
-
determinant(mtx) <static>
-
Computes the determinant of the given 4x4 column-major matrix.
The determinant of a 4×4 matrix is a unique number calculated from a square matrix using a special formula. There are several formulas that can be used, and this method uses one, but the upshot is that it returns a single numerical value which is used when calculating the inverse or when solving systems of linear equations.
Parameters:
Name Type Description mtxArray.<number> The 16-item column-major matrix array.
Returns:
Returns the computed determinant.
- Type
- number
-
getRotation(quat, mtx) <static>
-
Retrieves the rotational component of a matrix as a quaternion.
Parameters:
Name Type Description quatArray.<number> The [x,y,z,w] quaternion array to receive the rotation.
mtxArray.<number> The 16-item column-major matrix array to get it from.
Returns:
Returns the modified
out[x,y,z,w] quaternion array.- Type
- Array.<number>
-
getScale(vec, mtx) <static>
-
Retrieves the scaling factor component of a matrix.
Parameters:
Name Type Description vecArray.<number> The [x,y,z] vector array to receive the scale.
mtxArray.<number> The 16-item column-major matrix array to get it from.
Returns:
Returns the modified
vec[x,y,z] vector array.- Type
- Array.<number>
-
getTranslation(vec, mtx) <static>
-
Retrieves the translation vector component of the matrix.
Parameters:
Name Type Description vecArray.<number> The [x,y,z] vector array to receive the translation.
mtxArray.<number> The 16-item column-major matrix array to get it from.
Returns:
Returns the modified
vec[x,y,z] vector array.- Type
- Array.<number>
-
identity(out) <static>
-
Resets a 16-item column-major matrix to identity values.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to set.
Returns:
Returns the updated
outmatrix.- Type
- Array.<number>
-
invert(out [, mtx]) <static>
-
Inverts a 4x4 column-major matrix and stores the result in
out.NOTE: This method changes values within the
outparameter, however it is safe to use the same array in both arguments, or simply give only one argument to change it in-place.Parameters:
Name Type Argument Description outArray.<number> The 16-item column-major matrix array to receive the result.
mtxArray.<number> <optional>
The 16-item column-major source matrix array, defaults to
outif not supplied.Returns:
Returns the modified
outmatrix array.- Type
- Array.<number>
-
multiply(out, mtx2, mtx1) <static>
-
Multiply two 16-item column-major matrices together.
Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to set.
mtx2Array.<number> The first 16-item column-major matrix array to multiply.
mtx1Array.<number> The second 16-item column-major matrix array to multiply.
Returns:
Returns the updated
outmatrix.- Type
- Array.<number>
-
rotate(out, mtx, axis, angle) <static>
-
Rotate a flat 4x4 column-major matrix array by the given angle around the given axis.
Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to receive the result.
mtxArray.<number> The 16-item column-major matrix array to scale.
axisArray.<number> The normalised [x,y,z] vector array defining the axis of rotation.
anglenumber The angle or rotation in radians.
Returns:
Returns the modified
outmatrix.- Type
- Array.<number>
-
scale(out, mtx, scale) <static>
-
Scale a flat 4x4 column-major matrix array by the given factors.
Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to receive the result.
mtxArray.<number> The 16-item column-major matrix array to scale.
scaleArray.<number> The [sx,sy,sz] vector array defining the spatial scaling in each axis.
Returns:
Returns the modified
outmatrix.- Type
- Array.<number>
-
setFromThreeAxis(out, xAxis, yAxis, zAxis [, origin]) <static>
-
Sets a 16-item column-major matrix to use the given three axis and origin.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Argument Description outArray.<number> The 16-item column-major matrix array to set.
xAxisArray.<number> The normalised [x,y,z] vector array defining the X-axis.
yAxisArray.<number> The normalised [x,y,z] vector array defining the Y-axis.
zAxisArray.<number> The normalised [x,y,z] vector array defining the Z-axis.
originArray.<number> <optional>
The [x,y,z] vector array position of the origin, defaults to [0,0,0].
Returns:
Returns the updated
outmatrix.- Type
- Array.<number>
-
setRotation(out, axis, angle) <static>
-
Sets a 16-item column-major matrix to the given rotation.
Using this method is the same as, but notably faster than, having to separately call the
PD.MatrixArray#identityand thenPD.MatrixArray#rotatemethods.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to set.
axisArray.<number> The normalised [x,y,z] vector array defining the axis of rotation.
anglenumber The angle or rotation in radians.
Returns:
Returns the modified
outmatrix.- Type
- Array.<number>
-
setScale(out, scale) <static>
-
Sets a 16-item column-major matrix to the given scaling.
Using this method is the same as, but notably faster than, having to separately call the
PD.MatrixArray#identityand thenPD.MatrixArray#scalemethods.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to set.
scaleArray.<number> The [sx,sy,sz] vector array defining the spatial scaling in each axis.
Returns:
Returns the modified
outmatrix.- Type
- Array.<number>
-
setTranslation(out, translation) <static>
-
Sets a 16-item column-major matrix to the given translation.
Using this method is the same as, but notably faster than, having to separately call the
PD.MatrixArray#identityand thenPD.MatrixArray#translatemethods.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to set.
translationArray.<number> The [x,y,z] vector array defining the spatial translation in each axis.
Returns:
Returns the modified
outmatrix.- Type
- Array.<number>
-
translate(out, mtx, translation) <static>
-
Translate a flat 4x4 column-major matrix array by the given vector.
Parameters:
Name Type Description outArray.<number> The 16-item column-major matrix array to receive the result.
mtxArray.<number> The 16-item column-major matrix array to translate.
translationArray.<number> The [x,y,z] vector array defining the spatial translation in each axis.
Returns:
Returns the modified
outmatrix.- Type
- Array.<number>