# Class: Matrix4

## Table of contents

### Constructors

- constructor

### Accessors

- IDENTITY

### Methods

- axisRotate
- clone
- decomposeTransRotMatScale
- getColumn
- getRow
- getValue
- inverse
- multiply
- print
- rotateByQuaternion
- scale
- set
- setArray
- setColumn
- setRow
- setValue
- toArray
- transformDirection
- transformPoint
- transformVector
- translate
- transpose
- xRotate
- yRotate
- zRotate
- composeFromRST3
- composeTQS
- composeTRS
- createFromArray
- createFromTypedArray
- createRotationAxis
- createRotationX
- createRotationY
- createRotationZ
- fromQuaternion
- lookAt
- orthographic
- perspective

## Constructors

### constructor

• **new Matrix4**(`raw?`, `offset?`)

#### Parameters

| Name | Type |
| :------ | :------ |
| `raw?` | `Float32Array` |
| `offset?` | `number` |

## Accessors

### IDENTITY

• `Static` `get` **IDENTITY**(): [`Matrix4`](Matrix4)

单位矩阵

**`readonly`**

**`static`**

**`memberof`** Matrix4

#### Returns

[`Matrix4`](Matrix4)

单位矩阵，每次返回都会创建新的对象

## Methods

### axisRotate

▸ **axisRotate**(`axis`, `angleInRadians`, `dst?`): [`Matrix4`](Matrix4)

将该矩阵绕指定轴旋转

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `axis` | [`Vector3`](Vector3) | 轴向量 |
| `angleInRadians` | `number` | 旋转幅度，用弧度表示 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### clone

▸ **clone**(): [`Matrix4`](Matrix4)

拷贝该矩阵

**`memberof`** Matrix4

#### Returns

[`Matrix4`](Matrix4)

拷贝出来的对象

___

### decomposeTransRotMatScale

▸ **decomposeTransRotMatScale**(`dstTranslation`, `dstRotationMatrix`, `dstScale`): `boolean`

分解RTS矩阵为位移、旋转、缩放向量，返回是否成功

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `dstTranslation` | [`Vector3`](Vector3) | 目标位移向量 |
| `dstRotationMatrix` | [`Matrix4`](Matrix4) | 目标旋转矩阵 |
| `dstScale` | [`Vector3`](Vector3) | 目标缩放分量 |

#### Returns

`boolean`

分解是否成功，如不成功，可能是缩放分量为0

___

### getColumn

▸ **getColumn**(`column`, `dst?`): [`Vector4`](Vector4)

获取矩阵某列

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `column` | `number` | 列数 |
| `dst?` | [`Vector4`](Vector4) | - |

#### Returns

[`Vector4`](Vector4)

该列数据

___

### getRow

▸ **getRow**(`row`, `dst?`): [`Vector4`](Vector4)

获取矩阵某行

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `row` | `number` | 行数 |
| `dst?` | [`Vector4`](Vector4) | - |

#### Returns

[`Vector4`](Vector4)

该行数据

___

### getValue

▸ **getValue**(`column`, `row`): `number`

获取矩阵某行某列的值

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `column` | `number` | 列数 |
| `row` | `number` | 行数 |

#### Returns

`number`

自身

___

### inverse

▸ **inverse**(`dst?`): [`Matrix4`](Matrix4)

求该矩阵的逆

**`memberof`** Matrix4

#### Parameters

| Name | Type |
| :------ | :------ |
| `dst?` | [`Matrix4`](Matrix4) |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### multiply

▸ **multiply**(`m`, `dst?`): [`Matrix4`](Matrix4)

将该矩阵与另一个矩阵相乘

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `m` | [`Matrix4`](Matrix4) | 右乘矩阵 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### print

▸ **print**(): `void`

#### Returns

`void`

___

### rotateByQuaternion

▸ **rotateByQuaternion**(`quaternion`, `dst?`): [`Matrix4`](Matrix4)

将该矩阵使用指定四元数旋转

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `quaternion` | [`Quaternion`](Quaternion) | 四元数 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### scale

▸ **scale**(`sx`, `sy`, `sz`, `dst?`): [`Matrix4`](Matrix4)

将该矩阵进行缩放变换

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `sx` | `number` | x轴缩放 |
| `sy` | `number` | y轴缩放 |
| `sz` | `number` | z轴缩放 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### set

▸ **set**(`val`): [`Matrix4`](Matrix4)

拷贝目标矩阵的值到该矩阵

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `val` | [`Matrix4`](Matrix4) | 目标 |

#### Returns

[`Matrix4`](Matrix4)

自身

___

### setArray

▸ **setArray**(`value`, `offset?`): [`Matrix4`](Matrix4)

#### Parameters

| Name | Type |
| :------ | :------ |
| `value` | `ArrayLike` |
| `offset?` | `number` |

#### Returns

[`Matrix4`](Matrix4)

___

### setColumn

▸ **setColumn**(`vec`, `column`): [`Matrix4`](Matrix4)

设置矩阵某列

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `vec` | [`Vector4`](Vector4) | 列向量 |
| `column` | `number` | 列数 |

#### Returns

[`Matrix4`](Matrix4)

自身

___

### setRow

▸ **setRow**(`vec`, `row`): [`Matrix4`](Matrix4)

设置矩阵某行

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `vec` | [`Vector4`](Vector4) | 行向量 |
| `row` | `number` | 行数 |

#### Returns

[`Matrix4`](Matrix4)

自身

___

### setValue

▸ **setValue**(`value`, `column`, `row`): [`Matrix4`](Matrix4)

设置该矩阵某行某列的值

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value` | `number` | 值 |
| `column` | `number` | 列数 |
| `row` | `number` | 行数 |

#### Returns

[`Matrix4`](Matrix4)

自身

___

### toArray

▸ **toArray**(): `number`[]

返回矩阵数据

**`memberof`** Matrix4

#### Returns

`number`[]

矩阵数据，以JSArray返回

___

### transformDirection

▸ **transformDirection**(`dir`, `dst?`): [`Vector3`](Vector3)

矩阵变换作用于方向

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `dir` | [`Vector3`](Vector3) | 方向 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### transformPoint

▸ **transformPoint**(`p`, `dst?`): [`Vector3`](Vector3)

矩阵变换作用于点

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `p` | [`Vector3`](Vector3) | 点 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### transformVector

▸ **transformVector**(`v`, `dst?`): [`Vector4`](Vector4)

矩阵变换作用于向量

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v` | [`Vector4`](Vector4) | 向量 |
| `dst?` | [`Vector4`](Vector4) | - |

#### Returns

[`Vector4`](Vector4)

计算结果

___

### translate

▸ **translate**(`tx`, `ty`, `tz`, `dst?`): [`Matrix4`](Matrix4)

将该矩阵进行位移变换

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `tx` | `number` | x轴位移 |
| `ty` | `number` | y轴位移 |
| `tz` | `number` | z轴位移 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### transpose

▸ **transpose**(`dst?`): [`Matrix4`](Matrix4)

求该矩阵的转置

**`memberof`** Matrix4

#### Parameters

| Name | Type |
| :------ | :------ |
| `dst?` | [`Matrix4`](Matrix4) |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### xRotate

▸ **xRotate**(`rx`, `dst?`): [`Matrix4`](Matrix4)

将该矩阵绕x轴旋转

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `rx` | `number` | 旋转幅度，用弧度表示 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### yRotate

▸ **yRotate**(`ry`, `dst?`): [`Matrix4`](Matrix4)

将该矩阵绕y轴旋转

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `ry` | `number` | 旋转幅度，用弧度表示 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### zRotate

▸ **zRotate**(`rz`, `dst?`): [`Matrix4`](Matrix4)

将该矩阵绕z轴旋转

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `rz` | `number` | 旋转幅度，用弧度表示 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### composeFromRST3

▸ `Static` **composeFromRST3**(`m3`, `dst?`): [`Matrix4`](Matrix4)

从二维RST矩阵扩展到三维RST矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `m3` | [`Matrix3`](Matrix3) | 二维RST矩阵 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### composeTQS

▸ `Static` **composeTQS**(`translation`, `rotation`, `scale`, `dst?`): [`Matrix4`](Matrix4)

将位移旋转缩放合成一个RST矩阵，旋转用四元数表示

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `translation` | [`Vector3`](Vector3) | 位移向量 |
| `rotation` | [`Quaternion`](Quaternion) | 旋转四元数 |
| `scale` | [`Vector3`](Vector3) | 缩放向量 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### composeTRS

▸ `Static` **composeTRS**(`translation`, `rotation`, `scale`, `dst?`): [`Matrix4`](Matrix4)

将位移旋转缩放合成一个RST矩阵，旋转用矩阵表示

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `translation` | [`Vector3`](Vector3) | 位移向量 |
| `rotation` | [`Matrix4`](Matrix4) | 旋转矩阵 |
| `scale` | [`Vector3`](Vector3) | 缩放向量 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### createFromArray

▸ `Static` **createFromArray**(`array`): [`Matrix4`](Matrix4)

使用一个数组创建
此操作会拷贝一份数组

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `array` | `number`[] | 数据源，长度必须为16，否则会抛出异常 |

#### Returns

[`Matrix4`](Matrix4)

创建出来的矩阵

___

### createFromTypedArray

▸ `Static` **createFromTypedArray**(`array`, `offset?`): [`Matrix4`](Matrix4)

使用某个已有的typedArray创建
此操作不会拷贝数据，而是在原来的内存区域上操作

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `array` | `Float32Array` | `undefined` | 数据源 |
| `offset` | `number` | `0` | - |

#### Returns

[`Matrix4`](Matrix4)

创建出来的矩阵

___

### createRotationAxis

▸ `Static` **createRotationAxis**(`axis`, `angleInRadians`, `dst?`): [`Matrix4`](Matrix4)

创建绕指定轴旋转的矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `axis` | [`Vector3`](Vector3) | 旋转轴 |
| `angleInRadians` | `number` | 旋转幅度，用弧度表示 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### createRotationX

▸ `Static` **createRotationX**(`rad`, `dst?`): [`Matrix4`](Matrix4)

创建绕X轴旋转的矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `rad` | `number` | 旋转幅度，用弧度表示 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### createRotationY

▸ `Static` **createRotationY**(`rad`, `dst?`): [`Matrix4`](Matrix4)

创建绕Y轴旋转的矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `rad` | `number` | 旋转幅度，用弧度表示 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### createRotationZ

▸ `Static` **createRotationZ**(`rad`, `dst?`): [`Matrix4`](Matrix4)

创建绕Z轴旋转的矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `rad` | `number` | 旋转轴 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### fromQuaternion

▸ `Static` **fromQuaternion**(`quat`, `dst?`): [`Matrix4`](Matrix4)

将四元数转换为旋转矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `quat` | [`Quaternion`](Quaternion) | 四元数 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### lookAt

▸ `Static` **lookAt**(`position`, `target`, `up`, `dst?`): [`Matrix4`](Matrix4)

构造相机矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `position` | [`Vector3`](Vector3) | 相机位置 |
| `target` | [`Vector3`](Vector3) | 相机目标位置 |
| `up` | [`Vector3`](Vector3) | 上方向 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### orthographic

▸ `Static` **orthographic**(`left`, `right`, `bottom`, `top`, `near`, `far`, `dst?`): [`Matrix4`](Matrix4)

构造正交投影矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `left` | `number` | 左平面 |
| `right` | `number` | 右平面 |
| `bottom` | `number` | 上平面 |
| `top` | `number` | 下平面 |
| `near` | `number` | 近平面 |
| `far` | `number` | 远平面 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果

___

### perspective

▸ `Static` **perspective**(`fieldOfViewRadians`, `aspect`, `near`, `far`, `dst?`): [`Matrix4`](Matrix4)

构造透视投影矩阵

**`static`**

**`memberof`** Matrix4

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `fieldOfViewRadians` | `number` | 视野大小，用弧度表示 |
| `aspect` | `number` | 宽高比 |
| `near` | `number` | 近平面 |
| `far` | `number` | 远平面 |
| `dst?` | [`Matrix4`](Matrix4) | - |

#### Returns

[`Matrix4`](Matrix4)

计算结果
