MCPcopy Index your code
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / transformVertices

Function transformVertices

assets/js/block_ninja.js:466–496  ·  view source on GitHub ↗
(vertices, target, tX, tY, tZ, rX, rY, rZ, sX, sY, sZ)

Source from the content-addressed store, hash-verified

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.
466function 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.

Callers 3

transformMethod · 0.85
block_ninja.jsFile · 0.85
tickFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected