Skip to content

Home > @esengine/ecs-framework-monorepo > Matrix3

Matrix3 class

3x3变换矩阵类

用于2D变换(平移、旋转、缩放)的3x3矩阵 矩阵布局: [m00, m01, m02] [scaleX * cos, -scaleY * sin, translateX] [m10, m11, m12] = [scaleX * sin, scaleY * cos, translateY] [m20, m21, m22] [0, 0, 1]

Signature:

typescript
export declare class Matrix3

Constructors

Constructor

Modifiers

Description

(constructor)(elements)

创建3x3矩阵

Properties

Property

Modifiers

Type

Description

elements

Float32Array

矩阵元素,按行优先存储

IDENTITY

static

readonly

Matrix3

单位矩阵

m00

number

m01

number

m02

number

m10

number

m11

number

m12

number

m20

number

m21

number

m22

number

ZERO

static

readonly

Matrix3

零矩阵

Methods

Method

Modifiers

Description

add(other)

矩阵加法

clone()

克隆当前矩阵

copy(other)

复制另一个矩阵的值

decompose()

分解变换矩阵为平移、旋转、缩放分量

determinant()

计算矩阵行列式

equals(other, epsilon)

检查两个矩阵是否相等

exactEquals(other)

检查两个矩阵是否完全相等

fromArray(elements)

从数组设置矩阵元素

get(row, col)

获取矩阵元素

getRotation()

获取旋转角度

getScale()

获取缩放分量

getTranslation()

获取平移分量

identity()

设置矩阵为单位矩阵

invert()

矩阵求逆

isIdentity(epsilon)

检查是否为单位矩阵

makeRotation(angle)

设置为旋转矩阵

makeScale(scaleX, scaleY)

设置为缩放矩阵

makeTranslation(x, y)

设置为平移矩阵

multiply(other)

矩阵乘法

multiply(a, b)

static

矩阵乘法(静态方法)

multiplyScalar(scalar)

矩阵标量乘法

premultiply(other)

左乘另一个矩阵(other * this)

rotate(angle)

复合旋转

rotation(angle)

static

创建旋转矩阵(静态方法)

scale(scaleX, scaleY)

复合缩放

scale(scaleX, scaleY)

static

创建缩放矩阵(静态方法)

set(row, col, value)

设置矩阵元素

subtract(other)

矩阵减法

toArray()

转换为数组

toCSSTransform()

转换为CSS transform字符串

toString()

转换为字符串

transformDirection(vector)

变换向量(仅应用旋转和缩放,忽略平移)

transformVector(vector)

变换向量(应用完整的3x3变换)

transformVectors(vectors)

批量变换向量数组

translate(x, y)

复合平移

translation(x, y)

static

创建平移矩阵(静态方法)

transpose()

矩阵转置

TRS(translation, rotation, scale)

static

创建TRS(平移-旋转-缩放)变换矩阵

zero()

设置矩阵为零矩阵

基于 MIT 许可证发布