Matrix4x4f
Type | Name | Interface Description |
---|---|---|
Functions | constructor() | • Function: Creates a default 4x4 matrix with all elements initialized to 0. |
Functions | constructor(m0: number,...,m15: number) | • Function: Create a 4x4 matrix with specified element values. |
Functions | set(row: number, column: number, value: number): void | • Function: Sets the specified element of the matrix. |
Functions | get(row: number, column: number): number | • Function: Get the specified element of the matrix. |
Functions | add(other:Matrix4x4f): this | • Function: Adds another matrix to the current matrix. |
Functions | clone(): Matrix4x4f | • Function: Clone the current matrix. |
Functions | divide(other:Matrix4x4f): this | • Function: Divide the current matrix by another matrix. |
Functions | equals(other:Matrix4x4f): boolean | • Function: Checks whether the current matrix is equal to another matrix. |
Examples
constructor()
let mat = new Matrix4x4f();
constructor(m01: number,...,m15: number)
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
set(row: number, column: number, value: number): void
let mat = new Matrix4x4f();
mat.set(0, 0, 1);
get(row: number, column: number): number
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let value = mat.get(0, 0);
console.log(value);
add(other:Matrix4x4f): this
let mat1 = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let mat2 = new Matrix4x4f(
16, 15, 14, 13,
12, 11, 10, 9,
8, 7, 6, 5,
4, 3, 2, 1
);
mat1.add(mat2);
clone(): Matrix4x4
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let cloneMat = mat.clone();
divide(other: Matrix4x4f): this
let mat1 = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let mat2 = new Matrix4x4f(
16, 15, 14, 13,
12, 11, 10, 9,
8, 7, 6, 5,
4, 3, 2, 1
);
equals(other:Matrix4x4f): boolean
let mat1 = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let mat2 = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
console.log(mat1.equals(mat2)); // true
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
let mat1 = new Matrix4x4f();
mat.set(0, 0, 1);
let mat2 = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
mat2.get(0,0);
//add
mat1.add(mat2);
//devide
mat1.divide(mat2);
//clone
const clonedMat = mat1.clone();
//equals
console.log(mat1.equals(clonedMat));
}
onUpdate(deltaTime: number) {
}
}
Type | Name | Interface Description |
---|---|---|
Functions | getEulerAngles(): Vector3f | • Function: Obtain the Euler angles represented by the matrix. |
Functions | inverse(): this | • Function: Find the inverse matrix of the current matrix. |
Functions | multiply(other:Matrix4x4f): this | • Function: Multiply the current matrix by another matrix. |
Functions | multiplyDirection(dir: Vector3f): Vector3f | • Function: Multiply the current matrix by a direction vector. |
Functions | multiplyPoint(point: Vector3f): Vector3f | • Function: Multiply the current matrix by a point vector. |
Functions | multiplyScalar(scale: number): this | • Function: Multiply the current matrix by a scalar. |
Functions | multiplyVector(vec: Vector4f): Vector4f | • Function: Multiply the current matrix by a four-dimensional vector. |
Functions | subtract(other:Matrix4x4f): this | • Function: Subtract another matrix from the current matrix. |
Functions | toString(): string | • Function: Returns the string representation of the current matrix. |
Examples
getEulerAngles():Vector3f
let mat = new Matrix4x4f(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
let eulerAngles = mat.getEulerAngles();
inverse(): this
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
mat.inverse();
multiply(other:Matrix4x4f): this
let mat1 = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let mat2 = new Matrix4x4f(
16, 15, 14, 13,
12, 11, 10, 9,
8, 7, 6, 5,
4, 3, 2, 1
);
mat1.multiply(mat2);
multiplyDirection(dir: Vector3f): Vector3f
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let dir = new Vector3f(1, 0, 0);
let resultDir = mat.multiplyDirection(dir);
multiplyPoint(point: Vector3f): Vector3f
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let point = new Vector3f(1, 2, 3);
let resultPoint = mat.multiplyPoint(point);
multiplyScalar(scale: number): this
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
mat.multiplyScalar(2);
multiplyVector(vec: Vector4f): Vector4f
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let vec = new Vector4f(1, 2, 3, 4);
let resultVec = mat.multiplyVector(vec);
subtract(other:Matrix4x4f): this
let mat1 = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let mat2 = new Matrix4x4f(
16, 15, 14, 13,
12, 11, 10, 9,
8, 7, 6, 5,
4, 3, 2, 1
);
mat1.subtract(mat2);
toString(): string
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
console.log(mat.toString()); // "Matrix4x4f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)"
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
let mat = new Matrix3x3f();
mat.set(0, 0, 1);
let mat2 = new Matrix3x3f(1, 2, 3, 4, 5, 6, 7, 8, 9);
//getEulerAngles
let eulerAngles = mat1.getEulerAngles();
//inverse
mat1.inverse();
//multiply
mat1.multiply(mat2);
//multiplyDirection
let dir = new Vector3f(1, 0, 0);
let resultDir = mat1.multiplyDirection(dir);
//multiplyPoint
let point = new Vector3f(1, 2, 3);
let resultPoint = mat1.multiplyPoint(point);
//multiplyScalar
mat1.multiplyScalar(2);
//multiplyVector
let vec = new Vector4f(1, 2, 3, 4);
let resultVec = mat1.multiplyVector(vec);
//subtract
mat1.subtract(mat2);
//transpose
mat1.transpose();
//toString
console.log(mat1.toString())
}
onUpdate(deltaTime: number) {
}
}
Type | Name | Interface Description |
---|---|---|
Static Functions | compose(translation:Vector3f, rotation: Quaternionf, scale: Vector3f): this | • Function: Create a matrix based on translation, rotation and scaling. |
Static Functions | getDecompose(translation: Vector3f, rotation: Quaternionf, scale: Vector3f): void | • Function: Decompose the matrix into translation, rotation, and scaling. |
Static Functions | setFromToRotation(from: Vector3f, to: Vector3f): this | • Function: Create a matrix representing rotation from two vectors. |
Static Functions | setTranslate(v: Vector3f): this | • Function: Set the translation part of the matrix. |
Static Functions | translate(vec: Vector3f): this | • Function: Apply translation to matrices. |
Static Functions | setScale(v: Vector3f): this | • Function: Sets the scaling part of the matrix. |
Static Functions | scale(vec: Vector3f): this | • Function: Apply scaling to the matrix. |
Static Functions | transpose(): this | • Function: Transpose the current matrix. |
Static Functions | compareApproximately(mat1: Matrix4x4f, mat2: Matrix4x4f, dist:number): boolean | • Function: Check if two matrices are approximately equal within a specified distance. |
Examples
compose(translation:Vector3f, rotation: Quaternionf, scale: Vector3f):this
let translation = new Vector3f(1, 2, 3);
let rotation = new Quaternionf(1, 0, 0, 0);
let scale = new Vector3f(1, 1, 1);
let mat = new Matrix4x4f();
mat.compose(translation, rotation, scale);
getDecompose(translation: Vector3f, rotation: Quaternionf, scale: Vector3f): void
let mat = new Matrix4x4f(
1, 0, 0, 1,
0, 1, 0, 2,
0, 0, 1, 3,
0, 0, 0, 1
);
let translation = new Vector3f();
let rotation = new Quaternionf();
let scale = new Vector3f();
mat.getDecompose(translation, rotation, scale);
setFromToRotation(from: Vector3f, to: Vector3f): this
let from = new Vector3f(1, 0, 0);
let to = new Vector3f(0, 1, 0);
let mat = new Matrix4x4f();
mat.setFromToRotation(from, to);
setTranslate(v: Vector3f): this
let mat = new Matrix4x4f();
let vec = new Vector3f(1, 2, 3);
mat.setTranslate(vec);
translate(vec: Vector3f): this
let mat = new Matrix4x4f();
let vec = new Vector3f(1, 2, 3);
mat.translate(vec);
setScale(v: Vector3f): this
let mat = new Matrix4x4f();
let vec = new Vector3f(2, 2, 2);
mat.setScale(vec);
scale(vec: Vector3f): this
let mat = new Matrix4x4f();
let vec = new Vector3f(2, 2, 2);
mat.scale(vec);
transpose(): this
let mat = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
mat.transpose();
compareApproximately(mat1: Matrix4x4f, mat2:Matrix4x4f, dist:number):boolean
let mat1 = new Matrix4x4f(
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
);
let mat2 = new Matrix4x4f(
1.1, 2.1, 3.1, 4.1,
5.1, 6.1, 7.1, 8.1,
9.1, 10.1, 11.1, 12.1,
13.1, 14.1, 15.1, 16.1
);
console.log(Matrix4x4f.compareApproximately(mat1, mat2, 0.2)); // true
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
//compose
let translation = new Vector3f(1, 2, 3);
let rotation = new Quaternionf(1, 0, 0, 0);
let scale = new Vector3f(1, 1, 1);
let mat = new Matrix4x4f();
mat.compose(translation, rotation, scale);
//getDecompose
mat.getDecompose(translation, rotation, scale);
//setFromToRotation
let from = new Vector3f(1, 0, 0);
let to = new Vector3f(0, 1, 0);
mat = new Matrix4x4f();
mat.setFromToRotation(from, to);
//inverse
ma.inverse();
//multiply
mat.multiply(mat2);
//multiplyDirection
let dir = new Vector3f(1, 0, 0);
let resultDir = mat1.multiplyDirection(dir);
//setTranslate
let vec = new Vector3f(1, 2, 3);
mat.setTranslate(vec);
//translate
mat.translate(new Vector3f(1, 2, 3));
//setScale
mat.setScale(new Vector3f(2, 2, 2));
//scale
mat.scale(new Vector3f(2, 2, 2));
//transpose
mat.transpose();
//compareApproximately
console.log(Matrix4x4f.compareApproximately(mat, mat.clone(), 0.01)); // true
}
onUpdate(deltaTime: number) {
}
}
Type | Name | Interface Description |
---|---|---|
Static Functions | lookAt(eye:Vector3f, center:Vector3f, up:Vector3f): Matrix4x4f | • Function: Creates a view matrix based on the observation point, target point, and up direction. |
Static Functions | makeFromEulerAngles(euler: Vector3f): Matrix4x4f | • Function: Create a rotation matrix based on Euler angles. |
Static Functions | makeFromRotation(rotation: Quaternionf): Matrix4x4f | • Function: Create a rotation matrix based on a quaternion. |
Static Functions | makeFromScale(scale: Vector3f): Matrix4x4f | • Function: Create a scaling matrix based on the scaling vector. |
Static Functions | makeFromTranslation(translation: Vector3f): Matrix4x4f | • Function: Create a translation matrix based on the translation vector. |
Static Functions | orthographic(left: number, right: number, bottom: number, top: number, zNear: number, zFar: number): Matrix4x4f | • Function: Creates an orthogonal projection matrix. |
Static Functions | perspective(fovY: number, aspect: number, zNear: number, zFar: number): Matrix4x4f | • Function: Creates a perspective projection matrix. |
Examples
lookAt(eye:Vector3f, center:Vector3f, up:Vector3f):Matrix4x4f
let eye = new Vector3f(0, 0, 5);
let center = new Vector3f(0, 0, 0);
let up = new Vector3f(0, 1, 0);
let viewMatrix = Matrix4x4f.lookAt(eye, center, up);
makeFromEulerAngles(euler: Vector3f): Matrix4x4f
let euler = new Vector3f(Math.PI / 2, 0, 0);
let rotMatrix = Matrix4x4f.makeFromEulerAngles(euler);
makeFromRotation(rotation: Quaternionf): Matrix4x4f
let quat = new Quaternionf(1, 0, 0, 0);
let rotMatrix = Matrix4x4f.makeFromRotation(quat);
makeFromScale(scale: Vector3f): Matrix4x4f
let scale = new Vector3f(2, 2, 2);
let scaleMatrix = Matrix4x4f.makeFromScale(scale);
makeFromTranslation(translation: Vector3f): Matrix4x4f
let translation = new Vector3f(1, 2, 3);
let translationMatrix = Matrix4x4f.makeFromTranslation(translation);
orthographic(left: number, right: number, bottom: number, top: number, zNear: number, zFar: number): Matrix4x4f
let orthoMatrix = Matrix4x4f.orthographic(-1, 1, -1, 1, 0.1, 100);
perspective(fovY: number, aspect: number, zNear: number, zFar: number): Matrix4x4f
let perspectiveMatrix = Matrix4x4f.perspective(45, 1.33, 0.1, 100);
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
//lookAt
let eye = new Vector3f(0, 0, 5);
let center = new Vector3f(0, 0, 0);
let up = new Vector3f(0, 1, 0);
let viewMatrix = Matrix4x4f.lookAt(eye, center, up);
//makeFromEulerAngles
let euler = new Vector3f(Math.PI / 2, 0, 0);
let rotMatrix = Matrix4x4f.makeFromEulerAngles(euler);
//makeFromRotation
let quat = new Quaternionf(1, 0, 0, 0);
let rotMatrix = Matrix4x4f.makeFromRotation(quat);
//makeFromScale
let scale = new Vector3f(2, 2, 2);
let scaleMatrix = Matrix4x4f.makeFromScale(scale);
//makeFromTranslation
let translation = new Vector3f(1, 2, 3);
let translationMatrix = Matrix4x4f.makeFromTranslation(translation);
//orthographic
let orthoMatrix = Matrix4x4f.orthographic(-1, 1, -1, 1, 0.1, 100);
//perspective
let perspectiveMatrix = Matrix4x4f.perspective(45, 1.33, 0.1, 100);
}
onUpdate(deltaTime: number) {
}
}