Skip to content

Commit cbb33f0

Browse files
authored
Matrix3/4: Constructor has now parameters. (#26021)
1 parent 0a754b1 commit cbb33f0

File tree

10 files changed

+84
-22
lines changed

10 files changed

+84
-22
lines changed

docs/api/en/math/Matrix3.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h2>Code Example</h2>
2121

2222
<h2>A Note on Row-Major and Column-Major Ordering</h2>
2323
<p>
24-
The [page:set]() method takes arguments in
24+
The constructor and [page:set]() method take arguments in
2525
[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order row-major]
2626
order, while internally they are stored in the [page:.elements elements]
2727
array in column-major order.<br /><br />
@@ -49,10 +49,12 @@ <h2>A Note on Row-Major and Column-Major Ordering</h2>
4949

5050
<h2>Constructor</h2>
5151

52-
<h3>[name]()</h3>
52+
<h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13],
53+
[param:Number n21], [param:Number n22], [param:Number n22],
54+
[param:Number n31], [param:Number n32], [param:Number n33] )</h3>
5355
<p>
54-
Creates and initializes the [name] to the 3x3
55-
[link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
56+
Creates a 3x3 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
57+
the [name] to the 3x3 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
5658
</p>
5759

5860
<h2>Properties</h2>

docs/api/en/math/Matrix4.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h1>[name]</h1>
6262

6363
<h2>A Note on Row-Major and Column-Major Ordering</h2>
6464
<p>
65-
The [page:set]() method takes arguments in
65+
The constructor and [page:set]() method take arguments in
6666
[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order row-major]
6767
order, while internally they are stored in the [page:.elements elements] array in column-major order.<br /><br />
6868

@@ -117,11 +117,14 @@ <h2>Extracting position, rotation and scale</h2>
117117

118118
<h2>Constructor</h2>
119119

120-
<h3>[name]()</h3>
120+
<h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13], [param:Number n14],
121+
[param:Number n21], [param:Number n22], [param:Number n23], [param:Number n24],
122+
[param:Number n31], [param:Number n32], [param:Number n33], [param:Number n34],
123+
[param:Number n41], [param:Number n42], [param:Number n43], [param:Number n44] )</h3>
121124

122125
<p>
123-
Creates and initializes the [name] to the 4x4
124-
[link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
126+
Creates a 4x4 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
127+
the [name] to the 4x4 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
125128
</p>
126129

127130
<h2>Properties</h2>

docs/api/it/math/Matrix3.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ <h2>Una nota sull'ordine delle Row-Major (righe principali) e delle Column-Major
4646
<h2>Costruttore</h2>
4747

4848

49-
<h3>[name]()</h3>
49+
<h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13],
50+
[param:Number n21], [param:Number n22], [param:Number n22],
51+
[param:Number n31], [param:Number n32], [param:Number n33] )</h3>
5052
<p>
51-
Crea e inizializza [name] nella
52-
[link:https://en.wikipedia.org/wiki/Identity_matrix matrice] identità 3x3.
53+
Creates a 3x3 matrix with the given arguments in row-major. If no arguments are provided, the constructor initializes
54+
the [name] to the 3x3 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
5355
</p>
5456

5557
<h2>Proprietà</h2>

docs/api/it/math/Matrix4.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,15 @@ <h2>Estrazione della posizione, della rotazione e del ridimensionamento</h2>
105105
<h2>Costruttore</h2>
106106

107107

108-
<h3>[name]()</h3>
108+
<h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13], [param:Number n14],
109+
[param:Number n21], [param:Number n22], [param:Number n23], [param:Number n24],
110+
[param:Number n31], [param:Number n32], [param:Number n33], [param:Number n34],
111+
[param:Number n41], [param:Number n42], [param:Number n43], [param:Number n44] )</h3>
109112

110113
<p>
111-
Crea e inizializza [name] nella [link:https://en.wikipedia.org/wiki/Identity_matrix matrice] identità 4x4.
112-
</p>
114+
Creates a 4x4 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
115+
the [name] to the 4x4 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
116+
</p>
113117

114118
<h2>Proprietà</h2>
115119

docs/api/zh/math/Matrix3.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ <h2>注意行优先列优先的顺序。</h2>
4343
<h2>Constructor</h2>
4444

4545

46-
<h3>[name]()</h3>
46+
<h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13],
47+
[param:Number n21], [param:Number n22], [param:Number n22],
48+
[param:Number n31], [param:Number n32], [param:Number n33] )</h3>
4749
<p>
48-
创建并初始化一个3X3的单位矩阵[link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
50+
Creates a 3x3 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
51+
the [name] to the 3x3 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
4952
</p>
5053

5154

52-
5355
<h2>属性(Properties)</h2>
5456

5557
<h3>[property:Array elements]</h3>

docs/api/zh/math/Matrix4.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ <h2>提取位置(平移)、旋转和缩放</h2>
9595
<h2>构造器(Constructor)</h2>
9696

9797

98-
<h3>[name]()</h3>
98+
<h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13], [param:Number n14],
99+
[param:Number n21], [param:Number n22], [param:Number n23], [param:Number n24],
100+
[param:Number n31], [param:Number n32], [param:Number n33], [param:Number n34],
101+
[param:Number n41], [param:Number n42], [param:Number n43], [param:Number n44] )</h3>
99102

100103
<p>
101-
创建并初始化一个4X4的单位矩阵[link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
102-
</p>
104+
Creates a 4x4 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
105+
the [name] to the 4x4 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
106+
</p>
103107

104108
<h2>属性(Properties)</h2>
105109

src/math/Matrix3.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Matrix3 {
22

3-
constructor() {
3+
constructor( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
44

55
Matrix3.prototype.isMatrix3 = true;
66

@@ -12,6 +12,12 @@ class Matrix3 {
1212

1313
];
1414

15+
if ( n11 !== undefined ) {
16+
17+
this.set( n11, n12, n13, n21, n22, n23, n31, n32, n33 );
18+
19+
}
20+
1521
}
1622

1723
set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {

src/math/Matrix4.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Vector3 } from './Vector3.js';
22

33
class Matrix4 {
44

5-
constructor() {
5+
constructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
66

77
Matrix4.prototype.isMatrix4 = true;
88

@@ -15,6 +15,12 @@ class Matrix4 {
1515

1616
];
1717

18+
if ( n11 !== undefined ) {
19+
20+
this.set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 );
21+
22+
}
23+
1824
}
1925

2026
set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {

test/unit/src/math/Matrix3.tests.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ export default QUnit.module( 'Maths', () => {
6969

7070
assert.ok( ! matrixEquals3( a, b ), 'Passed!' );
7171

72+
const c = new Matrix3( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
73+
assert.ok( c.elements[ 0 ] == 0 );
74+
assert.ok( c.elements[ 1 ] == 3 );
75+
assert.ok( c.elements[ 2 ] == 6 );
76+
assert.ok( c.elements[ 3 ] == 1 );
77+
assert.ok( c.elements[ 4 ] == 4 );
78+
assert.ok( c.elements[ 5 ] == 7 );
79+
assert.ok( c.elements[ 6 ] == 2 );
80+
assert.ok( c.elements[ 7 ] == 5 );
81+
assert.ok( c.elements[ 8 ] == 8 );
82+
83+
assert.ok( ! matrixEquals3( a, c ), 'Passed!' );
84+
7285
} );
7386

7487
// PUBLIC STUFF

test/unit/src/math/Matrix4.tests.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ export default QUnit.module( 'Maths', () => {
7272

7373
assert.ok( ! matrixEquals4( a, b ), 'Passed!' );
7474

75+
const c = new Matrix4( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
76+
assert.ok( c.elements[ 0 ] == 0 );
77+
assert.ok( c.elements[ 1 ] == 4 );
78+
assert.ok( c.elements[ 2 ] == 8 );
79+
assert.ok( c.elements[ 3 ] == 12 );
80+
assert.ok( c.elements[ 4 ] == 1 );
81+
assert.ok( c.elements[ 5 ] == 5 );
82+
assert.ok( c.elements[ 6 ] == 9 );
83+
assert.ok( c.elements[ 7 ] == 13 );
84+
assert.ok( c.elements[ 8 ] == 2 );
85+
assert.ok( c.elements[ 9 ] == 6 );
86+
assert.ok( c.elements[ 10 ] == 10 );
87+
assert.ok( c.elements[ 11 ] == 14 );
88+
assert.ok( c.elements[ 12 ] == 3 );
89+
assert.ok( c.elements[ 13 ] == 7 );
90+
assert.ok( c.elements[ 14 ] == 11 );
91+
assert.ok( c.elements[ 15 ] == 15 );
92+
93+
assert.ok( ! matrixEquals4( a, c ), 'Passed!' );
94+
7595
} );
7696

7797
// PUBLIC STUFF

0 commit comments

Comments
 (0)