Class: Matrix4

Matrix4

new Matrix4()

4x4 矩阵

Members Show Inherited

Name Type Default Description
className String Matrix4

类名

isMatrix4 Boolean true
elements Float32Array

数据

Methods Show Inherited

Copy the values from one mat4 to this

Name Type Description
m Matrix4

the source matrix

Returns:
Type Description
Matrix4 this

Creates a new mat4 initialized with values from this matrix

Returns:
Type Description
Matrix4 a new Matrix4

toArray(array, offset){Array}

转换到数组

Name Type Default Description
array Array [] optional

数组

offset Number 0 optional

数组偏移值

Returns:
Type Description
Array

fromArray(array, offset){Matrix4}

从数组赋值

Name Type Default Description
array Array

数组

offset Number 0 optional

数组偏移值

Returns:
Type Description
Matrix4 this

set(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33){Matrix4}

Set the components of a mat3 to the given values

Name Type Description
m00 Number
m01 Number
m02 Number
m03 Number
m10 Number
m11 Number
m12 Number
m13 Number
m20 Number
m21 Number
m22 Number
m23 Number
m30 Number
m31 Number
m32 Number
m33 Number
Returns:
Type Description
Matrix4 this

Set this to the identity matrix

Returns:
Type Description
Matrix4 this

Transpose the values of this

Returns:
Type Description
Matrix4 this

invert a matrix

Name Type Default Description
m Matrix4 this optional
Returns:
Type Description
Matrix4 this

Calculates the adjugate of a mat4

Name Type Default Description
m Matrix4 this optional
Returns:
Type Description
Matrix4 this

determinant(){Matrix4}

Calculates the determinant of this

Returns:
Type Description
Matrix4 this

multiply(a, b){Matrix4}

Multiplies two matrix4's

Name Type Description
a Matrix4
b Matrix4 optional

如果不传,计算 this 和 a 的乘积

Returns:
Type Description
Matrix4 this

premultiply(m){Matrix4}

左乘

Name Type Description
m Matrix4
Returns:
Type Description
Matrix4 this

Translate this by the given vector

Name Type Description
v Vector3

vector to translate by

Returns:
Type Description
Matrix4 this

Scales the mat3 by the dimensions in the given vec2

Name Type Description
v Vector3

the vec3 to scale the matrix by

Returns:
Type Description
Matrix4 this

rotate(rad, axis){Matrix4}

Rotates this by the given angle

Name Type Description
rad Number

the angle to rotate the matrix by

axis Vector3

the axis to rotate around

Returns:
Type Description
Matrix4 this

Rotates this by the given angle around the X axis

Name Type Description
rad Number

the angle to rotate the matrix by

Returns:
Type Description
Matrix4 this

Rotates this by the given angle around the Y axis

Name Type Description
rad Number

the angle to rotate the matrix by

Returns:
Type Description
Matrix4 this

Rotates this by the given angle around the Z axis

Name Type Description
rad Number

the angle to rotate the matrix by

Returns:
Type Description
Matrix4 this

fromTranslation(transition){Matrix4}

Creates a matrix from a vector translation

Name Type Description
transition Vector3

Translation vector

Returns:
Type Description
Matrix4 this

fromScaling(v){Matrix4}

Creates a matrix from a vector scaling

Name Type Description
v Vector3

Scaling vector

Returns:
Type Description
Matrix4 this

fromRotation(rad, axis){Matrix4}

Creates a matrix from a given angle around a given axis

Name Type Description
rad Number

the angle to rotate the matrix by

axis Vector3

the axis to rotate around

Returns:
Type Description
Matrix4 this

fromXRotation(rad){Matrix4}

Creates a matrix from the given angle around the X axis

Name Type Description
rad Number

the angle to rotate the matrix by

Returns:
Type Description
Matrix4 this

fromYRotation(rad){Matrix4}

Creates a matrix from the given angle around the Y axis

Name Type Description
rad Number

the angle to rotate the matrix by

Returns:
Type Description
Matrix4 this

fromZRotation(rad){Matrix4}

Creates a matrix from the given angle around the Z axis

Name Type Description
rad Number

the angle to rotate the matrix by

Returns:
Type Description
Matrix4 this

fromRotationTranslation(q, v){Matrix4}

Creates a matrix from a quaternion rotation and vector translation

Name Type Description
q Quaternion

Rotation quaternion

v Vector3

Translation vector

Returns:
Type Description
Matrix4 this

getTranslation(out){Vector3}

Returns the translation vector component of a transformation matrix. If a matrix is built with fromRotationTranslation, the returned vector will be the same as the translation vector originally supplied.

Name Type Default Description
out Vector3 new Vector3 optional

Vector to receive translation component

Returns:
Type Description
Vector3 out

getScaling(out){Vector3}

Returns the scaling factor component of a transformation matrix. If a matrix is built with fromRotationTranslationScale with a normalized Quaternion paramter, the returned vector will be the same as the scaling vector originally supplied.

Name Type Default Description
out Vector3 new Vector3 optional

Vector to receive scaling factor component

Returns:
Type Description
Vector3 out

getRotation(out){Quaternion}

Returns a quaternion representing the rotational component of a transformation matrix. If a matrix is built with fromRotationTranslation, the returned quaternion will be the same as the quaternion originally supplied.

Name Type Description
out Quaternion

Quaternion to receive the rotation component

Returns:
Type Description
Quaternion out

fromRotationTranslationScale(q, v, s){Matrix4}

Creates a matrix from a quaternion rotation, vector translation and vector scale

Name Type Description
q Quaternion

Rotation quaternion

v Vector3

Translation vector

s Vector3

Scaling vector

Returns:
Type Description
Matrix4 this

fromRotationTranslationScaleOrigin(q, v, s, o){Matrix4}

Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin

Name Type Description
q Quaternion

Rotation quaternion

v Vector3

Translation vector

s Vector3

Scaling vector

o Vector3

The origin vector around which to scale and rotate

Returns:
Type Description
Matrix4 this

Calculates a 4x4 matrix from the given quaternion

Name Type Description
q Quaternion

Quaternion to create matrix from

Returns:
Type Description
Matrix4 this

frustum(left, right, bottom, top, near, far){Matrix4}

Generates a frustum matrix with the given bounds

Name Type Description
left Number

Left bound of the frustum

right Number

Right bound of the frustum

bottom Number

Bottom bound of the frustum

top Number

Top bound of the frustum

near Number

Near bound of the frustum

far Number

Far bound of the frustum

Returns:
Type Description
Matrix4 this

perspective(fovy, aspect, near, far){Matrix4}

Generates a perspective projection matrix with the given bounds

Name Type Description
fovy Number

Vertical field of view in radians

aspect Number

Aspect ratio. typically viewport width/height

near Number

Near bound of the frustum

far Number

Far bound of the frustum

Returns:
Type Description
Matrix4 this

perspectiveFromFieldOfView(fov, Near, far){Matrix4}

Generates a perspective projection matrix with the given field of view.

Name Type Description
fov Object

Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees

Near Number

bound of the frustum

far Number

Far bound of the frustum

Returns:
Type Description
Matrix4 this

ortho(left, right, bottom, top, near, far){Matrix4}

Generates a orthogonal projection matrix with the given bounds

Name Type Description
left Number

Left bound of the frustum

right Number

Right bound of the frustum

bottom Number

Bottom bound of the frustum

top Number

Top bound of the frustum

near Number

Near bound of the frustum

far Number

Far bound of the frustum

Returns:
Type Description
Matrix4 this

lookAt(eye, center, up){Matrix4}

Generates a look-at matrix with the given eye position, focal point, and up axis

Name Type Description
eye XYZObject

Position of the viewer

center XYZObject

Point the viewer is looking at

up Vector3

pointing up

Returns:
Type Description
Matrix4 this

targetTo(eye, Point, up){Matrix4}

Generates a matrix that makes something look at something else.

Name Type Description
eye XYZObject

Position of the viewer

Point XYZObject

the viewer is looking at

up Vector3

pointing up

Returns:
Type Description
Matrix4 this

frob(){Number}

Returns Frobenius norm of a mat4

Returns:
Type Description
Number Frobenius norm

add(a, b){Marix4}

Adds two mat4's

Name Type Description
a Matrix4
b Matrix4 optional

如果不传,计算 this 和 a 的和

Returns:
Type Description
Marix4 this

subtract(a, b){Marix4}

Subtracts matrix b from matrix a

Name Type Description
a Matrix4
b Matrix4 optional

如果不传,计算 this 和 a 的差

Returns:
Type Description
Marix4 this

exactEquals(a, b){Boolean}

Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)

Name Type Description
a Matrix4
b Matrix4 optional

如果不传,比较 this 和 a 是否相等

Returns:
Type Description
Boolean

equals(a, b){Boolean}

Returns whether or not the matrices have approximately the same elements in the same position.

Name Type Description
a Matrix4
b Matrix4 optional

如果不传,比较 this 和 a 是否近似相等

Returns:
Type Description
Boolean

compose(q, v, s, p){Matrix4}

compose

Name Type Description
q Quaternion

quaternion

v Vector3

position

s Vector3

scale

p Vector3

[pivot]

Returns:
Type Description
Matrix4 this

decompose(q, v, s, p){Matrix4}

decompose

Name Type Description
q Quaternion

quaternion

v Vector3

position

s Vector3

scale

p Vector3

[pivot]

Returns:
Type Description
Matrix4 this

Alias for Matrix4#subtract

Alias for Matrix4#multiply