Matrix

Description

class Matrix

Constructor

new Matrix()

Members

updateFlag : number

m : Float32Array

static IdentityReadOnly : Matrix

Static identity matrix to be used as matrix

Must not be updated.

Methods

isIdentity(considerAsTextureMatrix) boolean

Boolean : True is the matrix is the identity matrix

Parameters

Name Type Description
optional considerAsTextureMatrix boolean

determinant() number

Returns the matrix determinant (float).

toArray() Float32Array

Returns the matrix underlying array.

asArray() Float32Array

Returns the matrix underlying array.

invert() Matrix

Inverts in place the Matrix.

Returns the Matrix inverted.

reset() Matrix

Sets all the matrix elements to zero.

Returns the Matrix.

add(other) Matrix

Returns a new Matrix as the addition result of the current Matrix and the passed one.

Parameters

Name Type Description
other Matrix

addToRef(other, result) Matrix

Sets the passed matrix "result" with the ddition result of the current Matrix and the passed one.

Returns the Matrix.

Parameters

Name Type Description
other Matrix
result Matrix

addToSelf(other) Matrix

Adds in place the passed matrix to the current Matrix.

Returns the updated Matrix.

Parameters

Name Type Description
other Matrix

invertToRef(other) Matrix

Sets the passed matrix with the current inverted Matrix.

Returns the unmodified current Matrix.

Parameters

Name Type Description
other Matrix

setTranslationFromFloats(x, y, z) Matrix

Inserts the translation vector (using 3 x floats) in the current Matrix.

Returns the updated Matrix.

Parameters

Name Type Description
x number
y number
z number

setTranslation(vector3) Matrix

Inserts the translation vector in the current Matrix.

Returns the updated Matrix.

Parameters

Name Type Description
vector3 Vector3

getTranslation() Vector3

Returns a new Vector3 as the extracted translation from the Matrix.

getTranslationToRef(result) Matrix

Fill a Vector3 with the extracted translation from the Matrix.

Parameters

Name Type Description
result Vector3

removeRotationAndScaling() Matrix

Remove rotation and scaling part from the Matrix.

Returns the updated Matrix.

multiply(other) Matrix

Returns a new Matrix set with the multiplication result of the current Matrix and the passed one.

Parameters

Name Type Description
other Matrix

copyFrom(other) Matrix

Updates the current Matrix from the passed one values.

Returns the updated Matrix.

Parameters

Name Type Description
other Matrix

copyToArray(array, offset) Matrix

Populates the passed array from the starting index with the Matrix values.

Returns the Matrix.

Parameters

Name Type Description
array Float32Array
optional offset number

multiplyToRef(other, result) Matrix

Sets the passed matrix "result" with the multiplication result of the current Matrix and the passed one.

Parameters

Name Type Description
other Matrix
result Matrix

multiplyToArray(other, result, offset) Matrix

Sets the Float32Array "result" from the passed index "offset" with the multiplication result of the current Matrix and the passed one.

Parameters

Name Type Description
other Matrix
result Float32Array
offset number

equals(value) boolean

Boolean : True is the current Matrix and the passed one values are strictly equal.

Parameters

Name Type Description
value Matrix

clone() Matrix

Returns a new Matrix from the current Matrix.

getClassName() string

Returns the string "Matrix"

getHashCode() number

Returns the Matrix hash code.

decompose(scale, rotation, translation) boolean

Decomposes the current Matrix into :

Returns the boolean true.

Parameters

Name Type Description
scale Vector3
rotation Quaternion
translation Vector3

getRotationMatrix() Matrix

Returns a new Matrix as the extracted rotation matrix from the current one.

getRotationMatrixToRef(result) Matrix

Extracts the rotation matrix from the current one and sets it as the passed "result".

Returns the current Matrix.

Parameters

Name Type Description
result Matrix

static FromArray(array, offset) Matrix

Returns a new Matrix set from the starting index of the passed array.

Parameters

Name Type Description
array ArrayLike<number>
optional offset number

static FromArrayToRef(array, offset, result) void

Sets the passed "result" matrix from the starting index of the passed array.

Parameters

Name Type Description
array ArrayLike<number>
offset number
result Matrix

static FromFloat32ArrayToRefScaled(array, offset, scale, result) void

Sets the passed "result" matrix from the starting index of the passed Float32Array by multiplying each element by the float "scale".

Parameters

Name Type Description
array Float32Array
offset number
scale number

static FromValuesToRef(initialM11, initialM12, initialM13, initialM14, initialM21, initialM22, initialM23, initialM24, initialM31, initialM32, initialM33, initialM34, initialM41, initialM42, initialM43, initialM44, result) void

Sets the passed matrix "result" with the 16 passed floats.

Parameters

Name Type Description
initialM11 number
initialM12 number
initialM13 number
initialM14 number
initialM21 number
initialM22 number
initialM23 number
initialM24 number
initialM31 number
initialM32 number
initialM33 number
initialM34 number
initialM41 number
initialM42 number
initialM43 number
initialM44 number

getRow(index) Nullable<Vector4>

Returns the index-th row of the current matrix as a new Vector4.

Parameters

Name Type Description
index number

setRow(index, row) Matrix

Sets the index-th row of the current matrix with the passed Vector4 values.

Returns the updated Matrix.

Parameters

Name Type Description
index number
row Vector4

transpose() Matrix

Compute the transpose of the matrix.

Returns a new Matrix.

transposeToRef(result) Matrix

Compute the transpose of the matrix.

Returns the current matrix.

Parameters

Name Type Description
result Matrix

setRowFromFloats(index, x, y, z, w) Matrix

Sets the index-th row of the current matrix with the passed 4 x float values.

Returns the updated Matrix.

Parameters

Name Type Description
index number
x number
y number
z number

static FromValues(initialM11, initialM12, initialM13, initialM14, initialM21, initialM22, initialM23, initialM24, initialM31, initialM32, initialM33, initialM34, initialM41, initialM42, initialM43, initialM44) Matrix

Returns a new Matrix set from the 16 passed floats.

Parameters

Name Type Description
initialM11 number
initialM12 number
initialM13 number
initialM14 number
initialM21 number
initialM22 number
initialM23 number
initialM24 number
initialM31 number
initialM32 number
initialM33 number
initialM34 number
initialM41 number
initialM42 number
initialM43 number

static Compose(scale, rotation, translation) Matrix

Returns a new Matrix composed by the passed scale (vector3), rotation (quaternion) and translation (vector3).

Parameters

Name Type Description
scale Vector3
rotation Quaternion
translation Vector3

static ComposeToRef(scale, rotation, translation, result) void

Update a Matrix with values composed by the passed scale (vector3), rotation (quaternion) and translation (vector3).

Parameters

Name Type Description
scale Vector3
rotation Quaternion
translation Vector3

static Identity() Matrix

Returns a new indentity Matrix.

static IdentityToRef(result) void

Sets the passed "result" as an identity matrix.

Parameters

Name Type Description
result Matrix

static Zero() Matrix

Returns a new zero Matrix.

static RotationX(angle) Matrix

Returns a new rotation matrix for "angle" radians around the X axis.

Parameters

Name Type Description
angle number

static Invert(source) Matrix

Returns a new Matrix as the passed inverted one.

Parameters

Name Type Description
source Matrix

static RotationXToRef(angle, result) void

Sets the passed matrix "result" as a rotation matrix for "angle" radians around the X axis.

Parameters

Name Type Description
angle number
result Matrix

static RotationY(angle) Matrix

Returns a new rotation matrix for "angle" radians around the Y axis.

Parameters

Name Type Description
angle number

static RotationYToRef(angle, result) void

Sets the passed matrix "result" as a rotation matrix for "angle" radians around the Y axis.

Parameters

Name Type Description
angle number
result Matrix

static RotationZ(angle) Matrix

Returns a new rotation matrix for "angle" radians around the Z axis.

Parameters

Name Type Description
angle number

static RotationZToRef(angle, result) void

Sets the passed matrix "result" as a rotation matrix for "angle" radians around the Z axis.

Parameters

Name Type Description
angle number
result Matrix

static RotationAxis(axis, angle) Matrix

Returns a new rotation matrix for "angle" radians around the passed axis.

Parameters

Name Type Description
axis Vector3
angle number

static RotationAxisToRef(axis, angle, result) void

Sets the passed matrix "result" as a rotation matrix for "angle" radians around the passed axis.

Parameters

Name Type Description
axis Vector3
angle number
result Matrix

static RotationYawPitchRoll(yaw, pitch, roll) Matrix

Returns a new Matrix as a rotation matrix from the Euler angles (y, x, z).

Parameters

Name Type Description
yaw number
pitch number
roll number

static RotationYawPitchRollToRef(yaw, pitch, roll, result) void

Sets the passed matrix "result" as a rotation matrix from the Euler angles (y, x, z).

Parameters

Name Type Description
yaw number
pitch number
roll number

static Scaling(x, y, z) Matrix

Returns a new Matrix as a scaling matrix from the passed floats (x, y, z).

Parameters

Name Type Description
x number
y number
z number

static ScalingToRef(x, y, z, result) void

Sets the passed matrix "result" as a scaling matrix from the passed floats (x, y, z).

Parameters

Name Type Description
x number
y number
z number

static Translation(x, y, z) Matrix

Returns a new Matrix as a translation matrix from the passed floats (x, y, z).

Parameters

Name Type Description
x number
y number
z number

static TranslationToRef(x, y, z, result) void

Sets the passed matrix "result" as a translation matrix from the passed floats (x, y, z).

Parameters

Name Type Description
x number
y number
z number

static Lerp(startValue, endValue, gradient) Matrix

Returns a new Matrix whose values are the interpolated values for "gradien" (float) between the ones of the matrices "startValue" and "endValue".

Parameters

Name Type Description
startValue Matrix
endValue Matrix
gradient number

static DecomposeLerp(startValue, endValue, gradient) Matrix

Returns a new Matrix whose values are computed by :

Parameters

Name Type Description
startValue Matrix
endValue Matrix
gradient number

static LookAtLH(eye, target, up) Matrix

Returns a new rotation Matrix used to rotate a mesh so as it looks at the target Vector3, from the eye Vector3, the UP vector3 being orientated like "up".

This methods works for a Left-Handed system.

Parameters

Name Type Description
eye Vector3
target Vector3
up Vector3

static LookAtLHToRef(eye, target, up, result) void

Sets the passed "result" Matrix as a rotation matrix used to rotate a mesh so as it looks at the target Vector3, from the eye Vector3, the UP vector3 being orientated like "up".

This methods works for a Left-Handed system.

Parameters

Name Type Description
eye Vector3
target Vector3
up Vector3

static LookAtRH(eye, target, up) Matrix

Returns a new rotation Matrix used to rotate a mesh so as it looks at the target Vector3, from the eye Vector3, the UP vector3 being orientated like "up".

This methods works for a Right-Handed system.

Parameters

Name Type Description
eye Vector3
target Vector3
up Vector3

static LookAtRHToRef(eye, target, up, result) void

Sets the passed "result" Matrix as a rotation matrix used to rotate a mesh so as it looks at the target Vector3, from the eye Vector3, the UP vector3 being orientated like "up".

This methods works for a Left-Handed system.

Parameters

Name Type Description
eye Vector3
target Vector3
up Vector3

static OrthoLH(width, height, znear, zfar) Matrix

Returns a new Matrix as a left-handed orthographic projection matrix computed from the passed floats : width and height of the projection plane, z near and far limits.

Parameters

Name Type Description
width number
height number
znear number

static OrthoLHToRef(width, height, znear, zfar, result) void

Sets the passed matrix "result" as a left-handed orthographic projection matrix computed from the passed floats : width and height of the projection plane, z near and far limits.

Parameters

Name Type Description
width number
height number
znear number
zfar number

static OrthoOffCenterLH(left, right, bottom, top, znear, zfar) Matrix

Returns a new Matrix as a left-handed orthographic projection matrix computed from the passed floats : left, right, top and bottom being the coordinates of the projection plane, z near and far limits.

Parameters

Name Type Description
left number
right number
bottom number
top number
znear number

static OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result) void

Sets the passed matrix "result" as a left-handed orthographic projection matrix computed from the passed floats : left, right, top and bottom being the coordinates of the projection plane, z near and far limits.

Parameters

Name Type Description
left number
right number
bottom number
top number
znear number
zfar number

static OrthoOffCenterRH(left, right, bottom, top, znear, zfar) Matrix

Returns a new Matrix as a right-handed orthographic projection matrix computed from the passed floats : left, right, top and bottom being the coordinates of the projection plane, z near and far limits.

Parameters

Name Type Description
left number
right number
bottom number
top number
znear number

static OrthoOffCenterRHToRef(left, right, bottom, top, znear, zfar, result) void

Sets the passed matrix "result" as a right-handed orthographic projection matrix computed from the passed floats : left, right, top and bottom being the coordinates of the projection plane, z near and far limits.

Parameters

Name Type Description
left number
right number
bottom number
top number
znear number
zfar number

static PerspectiveLH(width, height, znear, zfar) Matrix

Returns a new Matrix as a left-handed perspective projection matrix computed from the passed floats : width and height of the projection plane, z near and far limits.

Parameters

Name Type Description
width number
height number
znear number

static PerspectiveFovLH(fov, aspect, znear, zfar) Matrix

Returns a new Matrix as a left-handed perspective projection matrix computed from the passed floats : vertical angle of view (fov), width/height ratio (aspect), z near and far limits.

Parameters

Name Type Description
fov number
aspect number
znear number

static PerspectiveFovLHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed) void

Sets the passed matrix "result" as a left-handed perspective projection matrix computed from the passed floats : vertical angle of view (fov), width/height ratio (aspect), z near and far limits.

Parameters

Name Type Description
fov number
aspect number
znear number
zfar number
result Matrix

static PerspectiveFovRH(fov, aspect, znear, zfar) Matrix

Returns a new Matrix as a right-handed perspective projection matrix computed from the passed floats : vertical angle of view (fov), width/height ratio (aspect), z near and far limits.

Parameters

Name Type Description
fov number
aspect number
znear number

static PerspectiveFovRHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed) void

Sets the passed matrix "result" as a right-handed perspective projection matrix computed from the passed floats : vertical angle of view (fov), width/height ratio (aspect), z near and far limits.

Parameters

Name Type Description
fov number
aspect number
znear number
zfar number
result Matrix

static PerspectiveFovWebVRToRef(fov, znear, zfar, result, rightHanded) void

Sets the passed matrix "result" as a left-handed perspective projection matrix for WebVR computed from the passed floats : vertical angle of view (fov), width/height ratio (aspect), z near and far limits.

Parameters

Name Type Description
fov { upDegrees: number, downDegrees: number, leftDegrees: number, rightDegrees: number }
znear number
zfar number
result Matrix

static GetFinalMatrix(viewport, world, view, projection, zmin, zmax) Matrix

Returns the final transformation matrix : world view projection * viewport

Parameters

Name Type Description
viewport Viewport
world Matrix
view Matrix
projection Matrix
zmin number

static GetAsMatrix2x2(matrix) Float32Array

Returns a new Float32Array array with 4 elements : the 2x2 matrix extracted from the passed Matrix.

Parameters

Name Type Description
matrix Matrix

static GetAsMatrix3x3(matrix) Float32Array

Returns a new Float32Array array with 9 elements : the 3x3 matrix extracted from the passed Matrix.

Parameters

Name Type Description
matrix Matrix

static Transpose(matrix) Matrix

Compute the transpose of the passed Matrix.

Returns a new Matrix.

Parameters

Name Type Description
matrix Matrix

static TransposeToRef(matrix, result) void

Compute the transpose of the passed Matrix and store it in the result matrix.

Parameters

Name Type Description
matrix Matrix
result Matrix

static Reflection(plane) Matrix

Returns a new Matrix as the reflection matrix across the passed plane.

Parameters

Name Type Description
plane Plane

static ReflectionToRef(plane, result) void

Sets the passed matrix "result" as the reflection matrix across the passed plane.

Parameters

Name Type Description
plane Plane
result Matrix

static FromXYZAxesToRef(xaxis, yaxis, zaxis, result) void

Sets the passed matrix "mat" as a rotation matrix composed from the 3 passed left handed axis.

Parameters

Name Type Description
xaxis Vector3
yaxis Vector3
zaxis Vector3

static FromQuaternionToRef(quat, result) void

Sets the passed matrix "result" as a rotation matrix according to the passed quaternion.

Parameters

Name Type Description
quat Quaternion
result Matrix