Matrix4

Math.Matrix4 exported from @manycore/aholo-viewer.

Math Class

Constructors

Constructor

new Matrix4(): Matrix4

Returns

Matrix4

Properties

isMatrix4

isMatrix4: boolean

Check the type whether it belongs to Matrix4. This value should not be changed by user.

Accessors

elements

Get Signature

get elements(): Float32Array

A column-major list of matrix values.

Returns

Float32Array

Set Signature

set elements(v): void

Deprecated

use fromArray instead;

Parameters
v

Float32Array

Returns

void

Methods

set()

set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44): Matrix4

Set the elements of this matrix to the supplied row-major values n11, n12, … n44.

Parameters

n11

number

n12

number

n13

number

n14

number

n21

number

n22

number

n23

number

n24

number

n31

number

n32

number

n33

number

n34

number

n41

number

n42

number

n43

number

n44

number

Returns

Matrix4


identity()

identity(): Matrix4

Resets this matrix to the identity matrix.

Returns

Matrix4


clone()

clone(): Matrix4

Creates a new Matrix4 with identical elements to this one.

Returns

Matrix4


cloneReadonly()

cloneReadonly(): Readonly<Pick<ReadonlyMarked, "_readonly_mark" | "cloneReadonly" | "clone" | "equals" | "getSerializeData" | "getNumberCount" | "toArray" | "elements" | "applyToBufferAttribute" | "determinant" | "applyToArray" | "decompose" | "extractBasis" | "getPosition" | "getMaxScaleOnAxis" | "decompose2D">>

Returns

Readonly<Pick<ReadonlyMarked, "_readonly_mark" | "cloneReadonly" | "clone" | "equals" | "getSerializeData" | "getNumberCount" | "toArray" | "elements" | "applyToBufferAttribute" | "determinant" | "applyToArray" | "decompose" | "extractBasis" | "getPosition" | "getMaxScaleOnAxis" | "decompose2D">>


copy()

copy(m): Matrix4

Copies the elements of matrix m into this matrix.

Parameters

m

Matrix4

Returns

Matrix4


copyPosition()

copyPosition(m): Matrix4

Copies the translation component of the supplied matrix m into this matrix’s translation component.

Parameters

m

Matrix4

Returns

Matrix4


extractBasis()

extractBasis(xAxis, yAxis, zAxis): Matrix4

Extracts the basis of this matrix into the three axis vectors provided. If this matrix is:

a, b, c, d,
e, f, g, h,
i, j, k, l,
m, n, o, p

then the xAxis, yAxis, zAxis will be set to:

xAxis = (a, e, i)
yAxis = (b, f, j)
zAxis = (c, g, k)

Parameters

xAxis

Vector3

yAxis

Vector3

zAxis

Vector3

Returns

Matrix4


makeBasis()

makeBasis(xAxis, yAxis, zAxis): Matrix4

Set this to the basis matrix consisting of the three provided basis vectors:

xAxis.x, yAxis.x, zAxis.x, 0,
xAxis.y, yAxis.y, zAxis.y, 0,
xAxis.z, yAxis.z, zAxis.z, 0,
0,       0,       0,       1

Parameters

xAxis

Vector3

yAxis

Vector3

zAxis

Vector3

Returns

Matrix4


extractRotation()

extractRotation(m): Matrix4

Extracts the rotation component of the supplied matrix m into this matrix’s rotation component.

Parameters

m

Matrix4

Returns

Matrix4


makeRotationFromEuler()

makeRotationFromEuler(euler): Matrix4

Sets the rotation component (the upper left 3x3 matrix) of this matrix to the rotation specified by the given euler. The rest of the matrix is set to the identity. Depending on the order of the euler, there are six possible outcomes.

Parameters

euler

Euler

Returns

Matrix4

Remarks

See this page for a complete list.


makeRotationFromQuaternion()

makeRotationFromQuaternion(q): Matrix4

Sets the rotation component of this matrix to the rotation specified by q, as outlined here. The rest of the matrix is set to the identity. So, given q = w + xi + yj + zk, the resulting matrix will be:

1-2y²-2z²    2xy-2zw    2xz+2yw    0
2xy+2zw      1-2x²-2z²  2yz-2xw    0
2xz-2yw      2yz+2xw    1-2x²-2y²  0
0            0          0          1

Parameters

q

Quaternion

Returns

Matrix4


lookAt()

lookAt(eye, target, up): Matrix4

Constructs a rotation matrix, looking from eye towards center oriented by the up vector.

Parameters

eye

Vector3

target

Vector3

up

Vector3

Returns

Matrix4


multiply()

multiply(m): Matrix4

Post-multiplies this matrix by m.

Parameters

m

Matrix4

Returns

Matrix4


premultiply()

premultiply(m): Matrix4

Pre-multiplies this matrix by m.

Parameters

m

Matrix4

Returns

Matrix4


multiplyMatrices()

multiplyMatrices(a, b): Matrix4

Sets this matrix to a x b.

Parameters

a

Matrix4

b

Matrix4

Returns

Matrix4


multiplyScalar()

multiplyScalar(s): Matrix4

Multiplies every component of the matrix by a scalar value s.

Parameters

s

number

Returns

Matrix4


applyToBufferAttribute()

applyToBufferAttribute(attribute, __forceJSImpl?): BufferAttribute

Apply this matrix to given attribute buffer.

Parameters

attribute

BufferAttribute

__forceJSImpl?

boolean

Returns

BufferAttribute


applyToArray()

applyToArray(array): Float32Array

Apply this matrix on given array. Each vector item of array should hold three elements.

Parameters

array

Float32Array

Returns

Float32Array


determinant()

determinant(): number

Computes and returns the determinant of this matrix. Based on the method outlined here.

Returns

number


transpose()

transpose(): Matrix4

Transposes this matrix.

Returns

Matrix4


setPosition()

setPosition(v): Matrix4

Sets the position component for this matrix from vector v, without affecting the rest of the matrix - i.e. if the matrix is currently:

a, b, c, d,
e, f, g, h,
i, j, k, l,
m, n, o, p

This becomes:

a, b, c, v.x,
e, f, g, v.y,
i, j, k, v.z,
m, n, o, p

Parameters

v

Vector3

Returns

Matrix4


getPosition()

getPosition(v): Vector3

Return the first three elements of last column.

Parameters

v

Vector3

Returns

Vector3


getInverse()

getInverse(m, throwOnDegenerate?): Matrix4

Change this matrix to inverse.

Parameters

m

Matrix4

throwOnDegenerate?

boolean

Returns

Matrix4


scale()

scale(v): Matrix4

Multiplies the columns of this matrix by vector v.

Parameters

v

Vector3

Returns

Matrix4


getScale()

getScale(v): Vector3

Return the scales of three dimension.

Parameters

v

Vector3

Returns

Vector3


translate()

translate(tx, ty, tz): Matrix4

Apply a translation to this matrix.

Parameters

tx

number

translate first row by tx.

ty

number

translate second row by ty.

tz

number

Returns

Matrix4


getMaxScaleOnAxis()

getMaxScaleOnAxis(): number

Gets the maximum scale value of the 3 axes.

Returns

number


makeTranslation()

makeTranslation(x, y, z): Matrix4

Sets this matrix as a translation transform:

1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1

Parameters

x

number

the amount to translate in the X axis.

y

number

the amount to translate in the Y axis.

z

number

the amount to translate in the Z axis.

Returns

Matrix4


makeRotationX()

makeRotationX(theta): Matrix4

Sets this matrix as a rotational transformation around the X axis by Float| theta (θ) radians. The resulting matrix will be:

1      0             0        0
0 cos(θ) -sin(θ)  0
0 sin(θ) cos(θ)   0
0      0             0        1

Parameters

theta

number

Rotation angle in radians.

Returns

Matrix4


makeRotationY()

makeRotationY(theta): Matrix4

Sets this matrix as a rotational transformation around the Y axis by Float| theta (θ) radians. The resulting matrix will be:

cos(θ)  0 sin(θ) 0
     0        1      0       0
-sin(θ) 0 cos(θ) 0
     0        0      0       1

Parameters

theta

number

Rotation angle in radians.

Returns

Matrix4


makeRotationZ()

makeRotationZ(theta): Matrix4

Sets this matrix as a rotational transformation around the Z axis by Float| theta (θ) radians. The resulting matrix will be:

cos(θ) -sin(θ) 0 0
sin(θ) cos(θ)  0 0
      0            0       1 0
      0            0       0 1

Parameters

theta

number

Rotation angle in radians.

Returns

Matrix4


makeRotationAxis()

makeRotationAxis(axis, angle): Matrix4

Sets this matrix as rotation transform around axis by Float| theta radians.
This is a somewhat controversial but mathematically sound alternative to rotating via Quaternions| Quaternions.

Parameters

axis

Vector3

Rotation axis, should be normalized.

angle

number

Returns

Matrix4

Remarks

See the discussion here.


makeScale()

makeScale(x, y, z): Matrix4

Parameters

x

number

the amount to scale in the X axis.

y

number

the amount to scale in the Y axis.

z

number

the amount to scale in the Z axis. Sets this matrix as scale transform:

x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1

Returns

Matrix4


makeShear()

makeShear(x, y, z): Matrix4

Parameters

x

number

the amount to shear in the X axis.

y

number

the amount to shear in the Y axis.

z

number

the amount to shear in the Z axis. Sets this matrix as a shear transform:

1, y, z, 0,
x, 1, z, 0,
x, y, 1, 0,
0, 0, 0, 1

Returns

Matrix4


compose()

compose(position, quaternion, scale): Matrix4

Sets this matrix to the transformation composed of position, quaternion and scale.

Parameters

position

Vector3

quaternion

Quaternion

scale

Vector3

Returns

Matrix4


decompose()

decompose(position, quaternion, scale): Matrix4

Decomposes this matrix into it’s position, quaternion and scale components.

Parameters

position

Vector3

quaternion

Quaternion

scale

Vector3

Returns

Matrix4

Note

Not all matrices are decomposable in this way. For example, if an object has a non-uniformly scaled parent, then the object’s world matrix may not be decomposable, and this method may not be appropriate.


compose2D()

compose2D(x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY): this

Sets the matrix based on all the available properties.

Parameters

x

number

Position on the x axis.

y

number

Position on the y axis.

pivotX

number

Pivot on the x axis.

pivotY

number

Pivot on the y axis.

scaleX

number

Scale on the x axis.

scaleY

number

Scale on the y axis.

rotation

number

Rotation in radians.

skewX

number

Skew on the x axis.

skewY

number

Skew on the y axis.

Returns

this

This matrix. Good for chaining method calls.


decompose2D()

decompose2D(): object

Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform.

Returns

object

The transform with the newly applied properties.

x

x: number

y

y: number

scaleX

scaleX: number

scaleY

scaleY: number

rotation

rotation: number

skewX

skewX: number

skewY

skewY: number


makePerspective()

makePerspective(left, right, top, bottom, near, far): Matrix4

Creates a perspective projection matrix. This is used internally by PerspectiveCamera.updateProjectionMatrix| PerspectiveCamera.updateProjectionMatrix()

Parameters

left

number

number

top

number

bottom

number

near

number

far

number

Returns

Matrix4


makeOrthographic()

makeOrthographic(left, right, top, bottom, near, far): Matrix4

Creates an orthographic projection matrix. This is used internally by OrthographicCamera.updateProjectionMatrix| OrthographicCamera.updateProjectionMatrix().

Parameters

left

number

right

number

top

number

bottom

number

near

number

far

number

Returns

Matrix4


transformVector2()

transformVector2(vIn, vOut?): Vector2

Apply this matrix to a 2D vector, z and w will set to 1 and 0.

Parameters

vIn
x

number

y

number

vOut?

Vector2

Returns

Vector2


equals()

equals(matrix): boolean

Return true if this matrix and matrix are equal.

Parameters

matrix

Matrix4

Returns

boolean


fromArray()

fromArray(array, offset?): Matrix4

Sets the elements of this matrix based on an array in column-major format.

Parameters

array

ArrayLike<number>

the array to read the elements from.

offset?

number

( optional ) offset into the array.

Returns

Matrix4

Default Value

0.


getNumberCount()

getNumberCount(): number

There are 16 elements in this matrix.

Returns

number


toArray()

toArray(array?, offset?): number[]

Writes the elements of this matrix to an array in column-major format.

Parameters

array?

number[]

(optional) array to store the resulting vector in.

offset?

number

(optional) offset in the array at which to put the result.

Returns

number[]