Matrix4.set()
方法用于设置 4x4 矩阵的值并返回该矩阵自身。该方法会用指定的数值依次填充矩阵的元素,矩阵的行和列分别以 x、y、z 和 w 来表示。
matrix.set(n11, n12, n13, n14,
n21, n22, n23, n24,
n31, n32, n33, n34,
n41, n42, n43, n44);
n11
~n44
: 数值类型,指定要设置的矩阵元素的值。import * as THREE from 'three';
const matrix = new THREE.Matrix4();
matrix.set(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
Matrix4
是 three.js 中用于处理 3D 空间变换的对象,它保存了一个 4x4 的矩阵,其中前三列分别表示空间坐标系中 X、Y、Z 轴方向的向量,第四列为原点的坐标。Matrix4
支持多种基本变换操作,如旋转、平移、缩放等,也可以用作多个变换的组合。
需要注意的是,在实际应用中往往使用其他三.js 对象(如 Vector3
)进行变换,并使用 Matrix4
的 make*()
方法将这些变换指令转换为矩阵操作,例如:
import * as THREE from 'three';
const vector = new THREE.Vector3(1, 2, 3);
const matrix = new THREE.Matrix4();
// 平移 1, 2, 3
matrix.makeTranslation(1, 2, 3);
// 应用变换
vector.applyMatrix4(matrix);