Class: Matrix4x4

Matrix4x4


new Matrix4x4()

Author:
  • derschmale <http://www.derschmale.com>

Members


lookAt

Initializes as a "lookAt" matrix at the given eye position oriented toward a target


<static> IDENTITY

Preset for the identity matrix


<static> ZERO

Preset for the all-zero matrix

Methods


add()

Adds the elements of another matrix to this one.


addAffine()

Adds the elements of another matrix to this one, assuming both are affine.


append()

Post-multiplication (M x this)


appendAffine()

Post-multiplication (M x this) assuming affine matrices


appendQuaternion()

Post-multiplies a quaternion rotation


appendRotationAxisAngle()

Post-multiplies an axis/angle rotation


appendScale()

Post-multiplies a scale


appendTranslation()

Post-multiplies a translation


clone()

Returns a copy of this object.


cofactor()

Calculates the cofactor for the given row and column


compose()

Initializes as an affine transformation based on a transform object


copyColumn(index, m)

Copies a column from another matrix.

Parameters:
Name Type Description
index Number

The index of the column.

m Matrix4x4

The matrix from which to copy.


copyFrom()

Copies its elements from another matrix.


decompose(targetOrPos, quat, quat)

Decomposes an affine transformation matrix into a Transform object, or a triplet position, quaternion, scale.

Parameters:
Name Type Description
targetOrPos

An optional target object to store the values. If this is a Float4, quat and scale need to be provided. If omitted, a new Transform object will be created and returned.

quat

An optional quaternion to store rotation. Unused if targetOrPos is a Transform object.

quat

An optional Float4 to store scale. Unused if targetOrPos is a Transform object.


determinant()

Calculates the determinant of the matrix.


fromEuler()

Initializes the matrix as a rotation matrix from 3 Euler angles


fromOrthographicOffCenterProjection(left, right, top, bottom, nearDistance, farDistance)

Initializes as an off-center orthographic projection matrix.

Parameters:
Name Type Description
left

The distance to the left plane

right

The distance to the right plane

top

The distance to the top plane

bottom

The distance to the bottom plane

nearDistance

The near plane distance

farDistance

The far plane distance


fromOrthographicProjection(width, top, nearDistance, farDistance)

Initializes as a symmetrical orthographic projection matrix.

Parameters:
Name Type Description
width

The width of the projection

top

The height of the projection

nearDistance

The near plane distance

farDistance

The far plane distance


fromPerspectiveProjection(vFOV, aspectRatio, nearDistance, farDistance)

Initializes as a perspective projection matrix (from right-handed Y-up to left-handed NDC!).

Parameters:
Name Type Description
vFOV

The vertical field of view in radians.

aspectRatio

The aspect ratio

nearDistance

The near plane distance

farDistance

The far plane distance


fromQuaternion()

Initializes the matrix as a rotation matrix based on a quaternion.


fromRotationAxisAngle(axis, radians)

Initializes the matrix as a rotation matrix around a given axis

Parameters:
Name Type Description
axis

The axis around which the rotation takes place.

radians

The angle of rotation


fromRotationPitchYawRoll()

Initializes the matrix as a rotation matrix from Tait-Bryan angles (pitch, yaw, roll).


fromScale(x, y, z)

Initializes as a scale matrix.

Parameters:
Name Type Description
x
y
z

fromTranslation(xOrV, y, z)

Initializes as a translation matrix.

Parameters:
Name Type Description
xOrV

A Float4 or a Number as x-coordinate

y

The y-translation. Omitted if xOrV is a Float4.

z

The z-translation. Omitted if xOrV is a Float4.


getAdjugate()

Calculates teh adjugate matrix.


getCofactorMatrix()

Creates a matrix containing all the cofactors.


getColumn(index [, target])

Gets the given column from the matrix.

Parameters:
Name Type Argument Description
index Number

The index of the column

target Float4 <optional>

An optional target. If omitted, a new object will be created.


getElement(row, col)

Gets the value of a single element.

Parameters:
Name Type Description
row

The row index

col

The column index


getRow(index [, target])

Gets the given row from the matrix.

Parameters:
Name Type Argument Description
index Number

The index of the row

target Float4 <optional>

An optional target. If omitted, a new object will be created.


inverseAffineOf()

Initializes as the inverse of the given matrix, assuming it is affine. It's faster than regular inverse. If the matrix is not invertible, the method returns null and the matrix remains unchanged.


inverseOf()

Initializes as the inverse of the given matrix. If the matrix is not invertible, the method returns null and the matrix remains unchanged. Otherwise, it returns itself.


invert()

Inverts the matrix. If the matrix is not invertible, the method returns null and the matrix remains unchanged. Otherwise, it returns itself.


invertAffine()

Inverts the matrix, assuming it's affine (faster than regular inverse). If the matrix is not invertible, the method returns null and the matrix remains unchanged. Otherwise, it returns itself.


multiply(a, b)

Multiplies two matrix objects and stores the result in this one

Parameters:
Name Type Description
a
b

multiplyAffine(a, b)

Multiplies two matrix objects, assuming they're affine transformations, and stores the result in this one

Parameters:
Name Type Description
a
b

prepend()

Pre-multiplication (this x M)


prependAffine()

Pre-multiplication (M x this) assuming affine matrices


prependQuaternion()

Pre-multiplies a quaternion rotation


prependRotationAxisAngle()

Pre-multiplies an axis/angle rotation


prependScale()

Pre-multiplies a scale


prependTranslation()

Pre-multiplies a translation


projectPoint(v [, target])

Transforms a Float4 point (assuming its w component is 1) and divides by the resulting w

Parameters:
Name Type Argument Description
v

The Float4 object to transform.

target <optional>

An optional target. If not provided, a new object will be created and returned.


set()

Sets the values of the matrix directly.


setColumn(index, v)

Sets a column in the matrix.

Parameters:
Name Type Description
index Number

The index of the column.

v Float4

The vector to assign to the column


setElement(row, col, value)

Sets the value of a single element.

Parameters:
Name Type Description
row

The row index

col

The column index

value

The value to assign to the element


setRow(index, v)

Sets a row in the matrix.

Parameters:
Name Type Description
index Number

The index of the row.

v Float4

The vector to assign to the row


subtract()

Subtracts the elements of another matrix from this one.


subtractAffine()

Subtracts the elements of another matrix from this one, assuming both are affine.


swapColums()

Swaps two columns


transform(v [, target])

Transforms a Float4 object (use for homogeneous general case of Float4, perspective or when "type" (w) of Float4 is unknown)

Parameters:
Name Type Argument Description
v

The Float4 object to transform.

target <optional>

An optional target. If not provided, a new object will be created and returned.


transformExtent(v [, target])

Transforms a Float4 object, treating it as a vector (ie: disregarding translation) containing a size (so always abs)! Slightly faster than transform for vectors.

Parameters:
Name Type Argument Description
v

The Float4 object to transform.

target <optional>

An optional target. If not provided, a new object will be created and returned.


transformNormal(v [, target])

Transforms a Float4 object, treating it as a normal vector.

Parameters:
Name Type Argument Description
v

The Float4 object to transform.

target <optional>

An optional target. If not provided, a new object will be created and returned.


transformPoint(v [, target])

Transforms a Float4 object, treating it as a point. Slightly faster than transform for points.

Parameters:
Name Type Argument Description
v

The Float4 object to transform.

target <optional>

An optional target. If not provided, a new object will be created and returned.


transformQuaternion(q [, target])

Transforms a Quaternion.

Parameters:
Name Type Argument Description
q Quaternion

The quaternion to transform

target Quaternion <optional>

An optional target. If not provided, a new object will be created and returned.


transformVector(v [, target])

Transforms a Float4 object, treating it as a vector (ie: disregarding translation). Slightly faster than transform for vectors.

Parameters:
Name Type Argument Description
v

The Float4 object to transform.

target <optional>

An optional target. If not provided, a new object will be created and returned.


transpose()

Transposes the matrix.


writeData()

Writes the matrix into an array for upload


writeData4x3()

Writes the matrix into an array for upload, ignoring the bottom row (for affine matrices)


writeNormalMatrix()

Writes the inverse transpose into an array for upload (must support 9 elements)


<static> add()

Adds two matrices together


<static> multiply()

Multiplies two matrices. The order of the parameters are the order of the multiplication. M1 is appended to M2