(vertices, target, tX, tY, tZ, rX, rY, rZ, sX, sY, sZ)
| 464 | // If `vertices` and `target` are different arrays, `vertices` will not be touched, instead the |
| 465 | // transformed values from `vertices` will be written to `target` array. |
| 466 | function transformVertices(vertices, target, tX, tY, tZ, rX, rY, rZ, sX, sY, sZ) { |
| 467 | // Matrix multiplcation constants only need calculated once for all vertices. |
| 468 | const sinX = Math.sin(rX); |
| 469 | const cosX = Math.cos(rX); |
| 470 | const sinY = Math.sin(rY); |
| 471 | const cosY = Math.cos(rY); |
| 472 | const sinZ = Math.sin(rZ); |
| 473 | const cosZ = Math.cos(rZ); |
| 474 | |
| 475 | // Using forEach() like map(), but with a (recycled) target array. |
| 476 | vertices.forEach((v, i) => { |
| 477 | const targetVertex = target[i]; |
| 478 | // X axis rotation |
| 479 | const x1 = v.x; |
| 480 | const y1 = v.z*sinX + v.y*cosX; |
| 481 | const z1 = v.z*cosX - v.y*sinX; |
| 482 | // Y axis rotation |
| 483 | const x2 = x1*cosY - z1*sinY; |
| 484 | const y2 = y1; |
| 485 | const z2 = x1*sinY + z1*cosY; |
| 486 | // Z axis rotation |
| 487 | const x3 = x2*cosZ - y2*sinZ; |
| 488 | const y3 = x2*sinZ + y2*cosZ; |
| 489 | const z3 = z2; |
| 490 | |
| 491 | // Scale, Translate, and set the transform. |
| 492 | targetVertex.x = x3 * sX + tX; |
| 493 | targetVertex.y = y3 * sY + tY; |
| 494 | targetVertex.z = z3 * sZ + tZ; |
| 495 | }); |
| 496 | } |
| 497 | |
| 498 | // 3D projection on a single vertex. |
| 499 | // Directly mutates the vertex. |
no outgoing calls
no test coverage detected