Matrix3.copy()
用于复制一个矩阵。
matrix3.copy(sourceMatrix3);
sourceMatrix3
:源矩阵。必须是 Matrix3
类型。const matrix1 = new THREE.Matrix3().set(
1, 2, 3,
4, 5, 6,
7, 8, 9
);
const matrix2 = new THREE.Matrix3();
matrix2.copy(matrix1);
console.log(matrix2.elements); // 输出:[1, 2, 3, 4, 5, 6, 7, 8, 9]
Matrix3.copy()
方法将一个 Matrix3
类型的矩阵对象赋值给另一个矩阵对象。源矩阵中的所有元素将被复制并覆盖目标矩阵中的元素。由于此方法会改变目标矩阵的状态,因此应注意保存目标矩阵中原本的值。
Matrix3.prototype.copy = function ( m ) {
this.set(
m.elements[ 0 ], m.elements[ 3 ], m.elements[ 6 ],
m.elements[ 1 ], m.elements[ 4 ], m.elements[ 7 ],
m.elements[ 2 ], m.elements[ 5 ], m.elements[ 8 ]
);
return this;
};
源码中的 copy()
方法将源矩阵中的元素按行优先存储的方式赋值给目标矩阵。对于每个元素,都需要从源矩阵中取出对应位置的值,并将其赋值给目标矩阵中对应位置的元素。