@@ -83,7 +83,7 @@ export class Matrix extends MatrixInterface {
83
83
* const matrix2 = new p5.Matrix([4, 5, 6]);
84
84
* matrix1.add(matrix2); // matrix1 is now [5, 7, 9]
85
85
*
86
- * // p5.js script example
86
+ *
87
87
* <div class="norender"><code>
88
88
* function setup() {
89
89
*
@@ -148,7 +148,7 @@ export class Matrix extends MatrixInterface {
148
148
* // Assuming matrix is an instance of Matrix with initial values [1, 2, 3, 4] matrix.setElement(2, 99);
149
149
* // Now the matrix values are [1, 2, 99, 4]
150
150
*
151
- * // p5.js script example
151
+ *
152
152
* <div class="norender"><code>
153
153
* function setup() {
154
154
*
@@ -182,7 +182,7 @@ export class Matrix extends MatrixInterface {
182
182
* matrix.reset(); // Reset to identity matrix
183
183
* console.log(matrix.matrix); // Output: Identity matrix
184
184
*
185
- * // p5.js script example
185
+ *
186
186
* <div class="norender"><code>
187
187
* function setup() {
188
188
*
@@ -234,7 +234,7 @@ export class Matrix extends MatrixInterface {
234
234
* matrix.set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
235
235
* console.log(matrix.matrix); // Output: [1, 2, 3, ..., 16]
236
236
*
237
- * // p5.js script example
237
+ *
238
238
* <div class="norender"><code>
239
239
* function setup() {
240
240
*
@@ -277,7 +277,7 @@ export class Matrix extends MatrixInterface {
277
277
* same values as the original matrix.
278
278
*
279
279
* @example
280
- * // p5.js script example
280
+ *
281
281
* <div class="norender"><code>
282
282
* function setup() {
283
283
*
@@ -309,7 +309,7 @@ export class Matrix extends MatrixInterface {
309
309
* @return {p5.Matrix } The result matrix.
310
310
*
311
311
* @example
312
- * // p5.js script example
312
+ *
313
313
* <div class="norender"><code>
314
314
* function setup() {
315
315
*
@@ -337,7 +337,7 @@ export class Matrix extends MatrixInterface {
337
337
* @returns {Matrix } A new matrix instance that is a copy of the current matrix.
338
338
*
339
339
* @example
340
- * // p5.js script example
340
+ *
341
341
* <div class="norender"><code>
342
342
* function setup() {
343
343
*
@@ -384,7 +384,7 @@ export class Matrix extends MatrixInterface {
384
384
* const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
385
385
* const diagonal = matrix.diagonal(); // [1, 5, 9]
386
386
*
387
- * // p5.js script example
387
+ *
388
388
* <div class="norender"><code>
389
389
* function setup() {
390
390
*
@@ -419,7 +419,7 @@ export class Matrix extends MatrixInterface {
419
419
* const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
420
420
* const rowVector = matrix.row(1); // Returns a vector [2, 5, 8]
421
421
*
422
- * // p5.js script example
422
+ *
423
423
* <div class="norender"><code>
424
424
* function setup() {
425
425
*
@@ -454,7 +454,7 @@ export class Matrix extends MatrixInterface {
454
454
* const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
455
455
* const columnVector = matrix.column(1); // Returns a vector [4, 5, 6]
456
456
*
457
- * // p5.js script example
457
+ *
458
458
* <div class="norender"><code>
459
459
* function setup() {
460
460
*
@@ -497,7 +497,7 @@ export class Matrix extends MatrixInterface {
497
497
* matrix4x4.transpose();
498
498
* console.log(matrix4x4.matrix); // Output: Transposed 4x4 identity matrix
499
499
*
500
- * // p5.js script example
500
+ *
501
501
* <div class="norender"><code>
502
502
* function setup() {
503
503
*
@@ -548,7 +548,7 @@ export class Matrix extends MatrixInterface {
548
548
* matrix4x4_1.mult(matrix4x4_2);
549
549
* console.log(matrix4x4_1.matrix); // Output: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1]
550
550
*
551
- * // p5.js script example
551
+ *
552
552
* <div class="norender"><code>
553
553
* function setup() {
554
554
*
@@ -601,7 +601,7 @@ export class Matrix extends MatrixInterface {
601
601
* const result = matrix.multiplyVec(vector);
602
602
* console.log(result.toString()); // Output: Transformed vector
603
603
*
604
- * // p5.js script example
604
+ *
605
605
* <div class="norender"><code>
606
606
* function setup() {
607
607
*
@@ -650,7 +650,7 @@ export class Matrix extends MatrixInterface {
650
650
* const invertedMatrix4x4 = matrix4x4.invert();
651
651
* console.log(invertedMatrix4x4.matrix); // Output: Inverted 4x4 matrix
652
652
*
653
- * // p5.js script example
653
+ *
654
654
* <div class="norender"><code>
655
655
* function setup() {
656
656
*
@@ -699,7 +699,7 @@ export class Matrix extends MatrixInterface {
699
699
* console.log("Original 4x4 Matrix:", matrix4x4.matrix);
700
700
* console.log("Extracted 3x3 Submatrix:", subMatrix3x3.matrix);
701
701
*
702
- * // p5.js script example
702
+ *
703
703
* <div class="norender"><code>
704
704
* function setup() {
705
705
*
@@ -751,7 +751,7 @@ export class Matrix extends MatrixInterface {
751
751
* mat3.inverseTranspose4x4(mat4);
752
752
* console.log("Converted 3×3 Matrix:", mat3.matrix);
753
753
*
754
- * // p5.js script example
754
+ *
755
755
* <div class="norender"><code>
756
756
* function setup() {
757
757
*
@@ -933,7 +933,7 @@ export class Matrix extends MatrixInterface {
933
933
* matrix.scale(scaleArray);
934
934
* console.log(matrix.matrix);
935
935
*
936
- * // p5.js script example
936
+ *
937
937
* <div class="norender"><code>
938
938
* function setup() {
939
939
*
@@ -1011,6 +1011,24 @@ export class Matrix extends MatrixInterface {
1011
1011
* - [0, 0, 1] rotates around the z-axis. *
1012
1012
* @chainable
1013
1013
* inspired by Toji's gl-matrix lib, mat4 rotation
1014
+ *
1015
+ * @example
1016
+ *
1017
+ * <div class="norender"><code>
1018
+ * function setup() {
1019
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
1020
+ * console.log("Original Matrix:", matrix.matrix);
1021
+ *
1022
+ * // Rotate the matrix 90 degrees (PI/2 radians) around the Y-axis
1023
+ * matrix.rotate4x4(Math.PI / 2, [0, 1, 0]);
1024
+ * console.log("After Rotation (Y-axis, 90 degrees):", matrix.matrix);
1025
+ *
1026
+ * // Rotate the matrix 45 degrees (PI/4 radians) around a custom axis
1027
+ * const axis = new p5.Vector(1, 1, 0); // Custom axis
1028
+ * matrix.rotate4x4(Math.PI / 4, axis);
1029
+ * console.log("After Rotation (Custom Axis, 45 degrees):", matrix.matrix);
1030
+ * }
1031
+ * </code></div>
1014
1032
*/
1015
1033
rotate4x4 ( a , x , y , z ) {
1016
1034
if ( x instanceof Vector ) {
@@ -1097,7 +1115,7 @@ export class Matrix extends MatrixInterface {
1097
1115
* matrix.translate([5, 15]); // Translate by 5 units along x and 15 along y
1098
1116
* console.log(matrix.matrix);
1099
1117
*
1100
- * // p5.js script example
1118
+ *
1101
1119
* <div class="norender"><code>
1102
1120
* function setup() {
1103
1121
*
@@ -1147,7 +1165,7 @@ export class Matrix extends MatrixInterface {
1147
1165
* matrix.rotateX(Math.PI / 4); // Rotate 45 degrees around the X-axis
1148
1166
* console.log(matrix.matrix);
1149
1167
*
1150
- * // p5.js script example
1168
+ *
1151
1169
* <div class="norender"><code>
1152
1170
* function setup() {
1153
1171
*
@@ -1184,7 +1202,7 @@ export class Matrix extends MatrixInterface {
1184
1202
* matrix.rotateY(Math.PI / 4); // Rotate 45 degrees around the Y-axis
1185
1203
* console.log(matrix.matrix);
1186
1204
*
1187
- * // p5.js script example
1205
+ *
1188
1206
* <div class="norender"><code>
1189
1207
* function setup() {
1190
1208
*
@@ -1223,7 +1241,7 @@ export class Matrix extends MatrixInterface {
1223
1241
* matrix.rotateZ(Math.PI / 4); // Rotate 45 degrees around the Z-axis
1224
1242
* console.log(matrix.matrix);
1225
1243
*
1226
- * // p5.js script example
1244
+ *
1227
1245
* <div class="norender"><code>
1228
1246
* function setup() {
1229
1247
*
@@ -1264,7 +1282,7 @@ export class Matrix extends MatrixInterface {
1264
1282
* matrix.perspective(Math.PI / 4, 1.5, 0.1, 100); // Set perspective projection
1265
1283
* console.log(matrix.matrix);
1266
1284
*
1267
- * // p5.js script example
1285
+ *
1268
1286
* <div class="norender"><code>
1269
1287
* function setup() {
1270
1288
*
@@ -1380,7 +1398,7 @@ export class Matrix extends MatrixInterface {
1380
1398
* const result = matrix.multiplyVec4(1, 2, 3, 1); // Transform the vector [1, 2, 3, 1]
1381
1399
* console.log(result); // Output: [1, 2, 3, 1] (unchanged for identity matrix)
1382
1400
*
1383
- * // p5.js script example
1401
+ *
1384
1402
* <div class="norender"><code>
1385
1403
* function setup() {
1386
1404
*
@@ -1436,7 +1454,7 @@ export class Matrix extends MatrixInterface {
1436
1454
* const transformedPoint = matrix.multiplyPoint(point);
1437
1455
* console.log(transformedPoint.toString()); // Output: [1, 2, 3] (unchanged for identity matrix)
1438
1456
*
1439
- * // p5.js script example
1457
+ *
1440
1458
* <div class="norender"><code>
1441
1459
* function setup() {
1442
1460
*
@@ -1489,7 +1507,7 @@ export class Matrix extends MatrixInterface {
1489
1507
* const transformedPoint = matrix.multiplyAndNormalizePoint(point);
1490
1508
* console.log(transformedPoint.toString()); // Output: [1, 2, 3] (unchanged for identity matrix)
1491
1509
*
1492
- * // p5.js script example
1510
+ *
1493
1511
* <div class="norender"><code>
1494
1512
* function setup() {
1495
1513
*
@@ -1544,7 +1562,7 @@ export class Matrix extends MatrixInterface {
1544
1562
* const transformedDirection = matrix.multiplyDirection(direction);
1545
1563
* console.log(transformedDirection.toString()); // Output: [1, 0, 0] (unchanged for identity matrix)
1546
1564
*
1547
- * // p5.js script example
1565
+ *
1548
1566
* <div class="norender"><code>
1549
1567
* function setup() {
1550
1568
*
@@ -1597,7 +1615,7 @@ export class Matrix extends MatrixInterface {
1597
1615
* const result = matrix.multiplyVec3(vector);
1598
1616
* console.log(result.toString()); // Output: Transformed vector
1599
1617
*
1600
- * // p5.js script example
1618
+ *
1601
1619
* <div class="norender"><code>
1602
1620
* function setup() {
1603
1621
*
0 commit comments