UNPKG

4.37 kBTypeScriptView Raw
1// https://threejs.org/docs/#api/en/math/Matrix3
2
3import { Matrix4 } from "./Matrix4.js";
4import { Vector2 } from "./Vector2.js";
5import { Vector3 } from "./Vector3.js";
6
7export type Matrix3Tuple = [
8 n11: number,
9 n12: number,
10 n13: number,
11 n21: number,
12 n22: number,
13 n23: number,
14 n31: number,
15 n32: number,
16 n33: number,
17];
18
19export class Matrix3 {
20 readonly isMatrix3: true;
21
22 /**
23 * Array with matrix values.
24 * @default [1, 0, 0, 0, 1, 0, 0, 0, 1]
25 */
26 elements: Matrix3Tuple;
27
28 /**
29 * Creates an identity matrix.
30 */
31 constructor();
32 /**
33 * Creates a 3x3 matrix with the given arguments in row-major order.
34 */
35 constructor(
36 n11: number,
37 n12: number,
38 n13: number,
39 n21: number,
40 n22: number,
41 n23: number,
42 n31: number,
43 n32: number,
44 n33: number,
45 );
46
47 set(
48 n11: number,
49 n12: number,
50 n13: number,
51 n21: number,
52 n22: number,
53 n23: number,
54 n31: number,
55 n32: number,
56 n33: number,
57 ): Matrix3;
58
59 identity(): this;
60
61 copy(m: Matrix3): this;
62
63 extractBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): this;
64
65 setFromMatrix4(m: Matrix4): Matrix3;
66
67 /**
68 * Multiplies this matrix by m.
69 */
70 multiply(m: Matrix3): this;
71
72 premultiply(m: Matrix3): this;
73
74 /**
75 * Sets this matrix to a x b.
76 */
77 multiplyMatrices(a: Matrix3, b: Matrix3): this;
78
79 multiplyScalar(s: number): this;
80
81 determinant(): number;
82
83 /**
84 * Inverts this matrix in place.
85 */
86 invert(): this;
87
88 /**
89 * Transposes this matrix in place.
90 */
91 transpose(): this;
92
93 getNormalMatrix(matrix4: Matrix4): this;
94
95 /**
96 * Transposes this matrix into the supplied array r, and returns itself.
97 */
98 transposeIntoArray(r: number[]): this;
99
100 setUvTransform(tx: number, ty: number, sx: number, sy: number, rotation: number, cx: number, cy: number): this;
101
102 scale(sx: number, sy: number): this;
103
104 rotate(theta: number): this;
105
106 translate(tx: number, ty: number): this;
107
108 /**
109 * Sets this matrix as a 2D translation transform:
110 *
111 * ```
112 * 1, 0, x,
113 * 0, 1, y,
114 * 0, 0, 1
115 * ```
116 *
117 * @param v the amount to translate.
118 */
119 makeTranslation(v: Vector2): this;
120 /**
121 * Sets this matrix as a 2D translation transform:
122 *
123 * ```
124 * 1, 0, x,
125 * 0, 1, y,
126 * 0, 0, 1
127 * ```
128 *
129 * @param x the amount to translate in the X axis.
130 * @param y the amount to translate in the Y axis.
131 */
132 makeTranslation(x: number, y: number): this;
133
134 /**
135 * Sets this matrix as a 2D rotational transformation by theta radians. The resulting matrix will be:
136 *
137 * ```
138 * cos(θ) -sin(θ) 0
139 * sin(θ) cos(θ) 0
140 * 0 0 1
141 * ```
142 *
143 * @param theta Rotation angle in radians. Positive values rotate counterclockwise.
144 */
145 makeRotation(theta: number): this;
146
147 /**
148 * Sets this matrix as a 2D scale transform:
149 *
150 * ```
151 * x, 0, 0,
152 * 0, y, 0,
153 * 0, 0, 1
154 * ```
155 *
156 * @param x the amount to scale in the X axis.
157 * @param y the amount to scale in the Y axis.
158 */
159 makeScale(x: number, y: number): this;
160
161 equals(matrix: Matrix3): boolean;
162
163 /**
164 * Sets the values of this matrix from the provided array or array-like.
165 * @param array the source array or array-like.
166 * @param offset (optional) offset into the array-like. Default is 0.
167 */
168 fromArray(array: ArrayLike<number>, offset?: number): this;
169
170 /**
171 * Writes the elements of this matrix to an array in
172 * {@link https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major} format.
173 */
174 toArray(): Matrix3Tuple;
175 /**
176 * Writes the elements of this matrix to an array in
177 * {@link https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major} format.
178 * @param array array to store the resulting vector in. If not given a new array will be created.
179 * @param offset (optional) offset in the array at which to put the result.
180 */
181 toArray<TArray extends ArrayLike<number>>(array: TArray, offset?: number): TArray;
182
183 clone(): this;
184}