Skip to content

Commit 2813196

Browse files
authored
Matrix4: Make makeTranslation() accept Vector3. (#26044)
* make Matrix4.makeTranslation accept Vector3 (fixes #26038) * make Matrix4.makeTranslation accept Vector3 (docs)
1 parent 05201f9 commit 2813196

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

docs/api/en/math/Matrix4.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,12 @@ <h3>
396396
0, 0, 0, 1 </code>
397397
</p>
398398

399+
<h3>[method:this makeTranslation]( [param:Vector3 v] )</h3>
399400
<h3>
400-
[method:this makeTranslation]( [param:Float x], [param:Float y], [param:Float z] )
401+
[method:this makeTranslation]( [param:Float x], [param:Float y], [param:Float z] ) // optional API
401402
</h3>
402403
<p>
403-
[page:Float x] - the amount to translate in the X axis.<br />
404-
[page:Float y] - the amount to translate in the Y axis.<br />
405-
[page:Float z] - the amount to translate in the Z axis.<br /><br />
406-
407-
Sets this matrix as a translation transform:
404+
Sets this matrix as a translation transform from vector [page:Vector3 v], or numbers [page:Float x], [page:Float y] and [page:Float z]:
408405
<code>
409406
1, 0, 0, x,
410407
0, 1, 0, y,

docs/api/it/math/Matrix4.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,12 @@ <h3>[method:this makeShear]( [param:Float xy], [param:Float xz], [param:Float yx
342342
</code>
343343
</p>
344344

345-
<h3>[method:this makeTranslation]( [param:Float x], [param:Float y], [param:Float z] )</h3>
345+
<h3>[method:this makeTranslation]( [param:Vector3 v] )</h3>
346+
<h3>
347+
[method:this makeTranslation]( [param:Float x], [param:Float y], [param:Float z] ) // optional API
348+
</h3>
346349
<p>
347-
[page:Float x] - la quantità da translare sull'asse X.<br />
348-
[page:Float y] - la quantità da translare sull'asse Y.<br />
349-
[page:Float z] - la quantità da translare sull'asse Z.<br /><br />
350-
351-
Imposta questa matrice come una trasformata di traslazione:
350+
Imposta questa matrice come una trasformata di traslazione dal vettore [page:Vector3 v]:
352351
<code>
353352
1, 0, 0, x,
354353
0, 1, 0, y,

docs/api/zh/math/Matrix4.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,12 @@ <h3>[method:this makeShear]( [param:Float x], [param:Float y], [param:Float z] )
320320
</code>
321321
</p>
322322

323-
<h3>[method:this makeTranslation]( [param:Float x], [param:Float y], [param:Float z] )</h3>
323+
<h3>[method:this makeTranslation]( [param:Vector3 v] )</h3>
324+
<h3>
325+
[method:this makeTranslation]( [param:Float x], [param:Float y], [param:Float z] ) // optional API
326+
</h3>
324327
<p>
325-
[page:Float x] - 在X轴上的平移量。<br />
326-
[page:Float y] - 在Y轴上的平移量。<br />
327-
[page:Float z] - 在Z轴上的平移量。<br /><br />
328-
329-
设置该矩阵为平移变换:
328+
取传入参数[param:Vector3 v]中值设设置该矩阵为平移变换:
330329
<code>
331330
1, 0, 0, x,
332331
0, 1, 0, y,

src/math/Matrix4.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,29 @@ class Matrix4 {
560560

561561
makeTranslation( x, y, z ) {
562562

563-
this.set(
563+
if ( x.isVector3 ) {
564564

565-
1, 0, 0, x,
566-
0, 1, 0, y,
567-
0, 0, 1, z,
568-
0, 0, 0, 1
565+
this.set(
569566

570-
);
567+
1, 0, 0, x.x,
568+
0, 1, 0, x.y,
569+
0, 0, 1, x.z,
570+
0, 0, 0, 1
571+
572+
);
573+
574+
} else {
575+
576+
this.set(
577+
578+
1, 0, 0, x,
579+
0, 1, 0, y,
580+
0, 0, 1, z,
581+
0, 0, 0, 1
582+
583+
);
584+
585+
}
571586

572587
return this;
573588

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ export default QUnit.module( 'Maths', () => {
588588
a.makeTranslation( b.x, b.y, b.z );
589589
assert.ok( matrixEquals4( a, c ), 'Passed!' );
590590

591+
a.makeTranslation( b );
592+
assert.ok( matrixEquals4( a, c ), 'Passed!' );
593+
591594
} );
592595

593596
QUnit.test( 'makeRotationX', ( assert ) => {

0 commit comments

Comments
 (0)