@@ -521,7 +521,7 @@ export class Matrix extends MatrixInterface {
521521 * const matrix1 = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
522522 * const matrix2 = new p5.Matrix([9, 8, 7, 6, 5, 4, 3, 2, 1]);
523523 * matrix1.mult(matrix2);
524- * console.log(matrix1.matrix); // Output: [30, 24, 18, 84 , 69, 54, 138, 114, 90 ]
524+ * console.log(matrix1.matrix); // Output: [90, 114, 138, 54 , 69, 84, 18, 24, 30 ]
525525 *
526526 * // Multiplying a 4x4 matrix with another 4x4 matrix
527527 * const matrix4x4_1 = new p5.Matrix(4); // Identity matrix
@@ -536,7 +536,7 @@ export class Matrix extends MatrixInterface {
536536 * const matrix2 = new p5.Matrix([9, 8, 7, 6, 5, 4, 3, 2, 1]);
537537 * console.log("Before multiplication:", matrix1.matrix);
538538 * matrix1.mult(matrix2);
539- * console.log("After multiplication:", matrix1.matrix); // Output: [30, 24, 18, 84 , 69, 54, 138, 114, 90 ]
539+ * console.log("After multiplication:", matrix1.matrix); // Output: [90, 114, 138, 54 , 69, 84, 18, 24, 30 ]
540540 * }
541541 */
542542 mult ( multMatrix ) {
@@ -1718,8 +1718,8 @@ export class Matrix extends MatrixInterface {
17181718 for ( let j = 0 ; j < this . #sqDimention; j ++ ) {
17191719 for ( let k = 0 ; k < this . #sqDimention; k ++ ) {
17201720 result [ i * this . #sqDimention + j ] +=
1721- this . matrix [ i * this . #sqDimention + k ] *
1722- multMatrix [ k * this . #sqDimention + j ] ;
1721+ multMatrix [ i * this . #sqDimention + k ] *
1722+ this . matrix [ k * this . #sqDimention + j ] ;
17231723 }
17241724 }
17251725 }
@@ -1730,7 +1730,7 @@ export class Matrix extends MatrixInterface {
17301730 /**
17311731 * This function is only for 3x3 matrices.
17321732 * multiply two mat3s. It is an operation to multiply the 3x3 matrix of
1733- * the argument from the right . Arguments can be a 3x3 p5.Matrix,
1733+ * the argument from the left . Arguments can be a 3x3 p5.Matrix,
17341734 * a Float32Array of length 9, or a javascript array of length 9.
17351735 * In addition, it can also be done by enumerating 9 numbers.
17361736 *
@@ -1740,27 +1740,19 @@ export class Matrix extends MatrixInterface {
17401740 * @chainable
17411741 */
17421742 #mult3x3( _src ) {
1743- // each row is used for the multiplier
1744- let b0 = this . mat3 [ 0 ] ;
1745- let b1 = this . mat3 [ 1 ] ;
1746- let b2 = this . mat3 [ 2 ] ;
1747- this . mat3 [ 0 ] = b0 * _src [ 0 ] + b1 * _src [ 3 ] + b2 * _src [ 6 ] ;
1748- this . mat3 [ 1 ] = b0 * _src [ 1 ] + b1 * _src [ 4 ] + b2 * _src [ 7 ] ;
1749- this . mat3 [ 2 ] = b0 * _src [ 2 ] + b1 * _src [ 5 ] + b2 * _src [ 8 ] ;
1750-
1751- b0 = this . mat3 [ 3 ] ;
1752- b1 = this . mat3 [ 4 ] ;
1753- b2 = this . mat3 [ 5 ] ;
1754- this . mat3 [ 3 ] = b0 * _src [ 0 ] + b1 * _src [ 3 ] + b2 * _src [ 6 ] ;
1755- this . mat3 [ 4 ] = b0 * _src [ 1 ] + b1 * _src [ 4 ] + b2 * _src [ 7 ] ;
1756- this . mat3 [ 5 ] = b0 * _src [ 2 ] + b1 * _src [ 5 ] + b2 * _src [ 8 ] ;
1757-
1758- b0 = this . mat3 [ 6 ] ;
1759- b1 = this . mat3 [ 7 ] ;
1760- b2 = this . mat3 [ 8 ] ;
1761- this . mat3 [ 6 ] = b0 * _src [ 0 ] + b1 * _src [ 3 ] + b2 * _src [ 6 ] ;
1762- this . mat3 [ 7 ] = b0 * _src [ 1 ] + b1 * _src [ 4 ] + b2 * _src [ 7 ] ;
1763- this . mat3 [ 8 ] = b0 * _src [ 2 ] + b1 * _src [ 5 ] + b2 * _src [ 8 ] ;
1743+ const a0 = this . mat3 [ 0 ] , a1 = this . mat3 [ 1 ] , a2 = this . mat3 [ 2 ] ;
1744+ const a3 = this . mat3 [ 3 ] , a4 = this . mat3 [ 4 ] , a5 = this . mat3 [ 5 ] ;
1745+ const a6 = this . mat3 [ 6 ] , a7 = this . mat3 [ 7 ] , a8 = this . mat3 [ 8 ] ;
1746+
1747+ this . mat3 [ 0 ] = _src [ 0 ] * a0 + _src [ 1 ] * a3 + _src [ 2 ] * a6 ;
1748+ this . mat3 [ 1 ] = _src [ 0 ] * a1 + _src [ 1 ] * a4 + _src [ 2 ] * a7 ;
1749+ this . mat3 [ 2 ] = _src [ 0 ] * a2 + _src [ 1 ] * a5 + _src [ 2 ] * a8 ;
1750+ this . mat3 [ 3 ] = _src [ 3 ] * a0 + _src [ 4 ] * a3 + _src [ 5 ] * a6 ;
1751+ this . mat3 [ 4 ] = _src [ 3 ] * a1 + _src [ 4 ] * a4 + _src [ 5 ] * a7 ;
1752+ this . mat3 [ 5 ] = _src [ 3 ] * a2 + _src [ 4 ] * a5 + _src [ 5 ] * a8 ;
1753+ this . mat3 [ 6 ] = _src [ 6 ] * a0 + _src [ 7 ] * a3 + _src [ 8 ] * a6 ;
1754+ this . mat3 [ 7 ] = _src [ 6 ] * a1 + _src [ 7 ] * a4 + _src [ 8 ] * a7 ;
1755+ this . mat3 [ 8 ] = _src [ 6 ] * a2 + _src [ 7 ] * a5 + _src [ 8 ] * a8 ;
17641756
17651757 return this ;
17661758 }
0 commit comments