MCPcopy Index your code
hub / github.com/processing/p5.js / rotate4x4

Method rotate4x4

src/math/Matrices/Matrix.js:1000–1061  ·  view source on GitHub ↗

* Rotate the Matrix around a specified axis by a given angle. * * This method applies a rotation transformation to the matrix, modifying its orientation * in 3D space. The rotation is performed around the provided axis, which can be defined * as a `p5.Vector` or an array of numbers repre

(a, x, y, z)

Source from the content-addressed store, hash-verified

998 * }
999 */
1000 rotate4x4(a, x, y, z) {
1001 if (x instanceof Vector) {
1002 // x is a vector, extract the components from it.
1003 y = x.y;
1004 z = x.z;
1005 x = x.x; //must be last
1006 } else if (x instanceof Array) {
1007 // x is an array, extract the components from it.
1008 y = x[1];
1009 z = x[2];
1010 x = x[0]; //must be last
1011 }
1012
1013 const len = Math.sqrt(x * x + y * y + z * z);
1014 x *= 1 / len;
1015 y *= 1 / len;
1016 z *= 1 / len;
1017
1018 const a00 = this.matrix[0];
1019 const a01 = this.matrix[1];
1020 const a02 = this.matrix[2];
1021 const a03 = this.matrix[3];
1022 const a10 = this.matrix[4];
1023 const a11 = this.matrix[5];
1024 const a12 = this.matrix[6];
1025 const a13 = this.matrix[7];
1026 const a20 = this.matrix[8];
1027 const a21 = this.matrix[9];
1028 const a22 = this.matrix[10];
1029 const a23 = this.matrix[11];
1030
1031 //sin,cos, and tan of respective angle
1032 const sA = Math.sin(a);
1033 const cA = Math.cos(a);
1034 const tA = 1 - cA;
1035 // Construct the elements of the rotation matrix
1036 const b00 = x * x * tA + cA;
1037 const b01 = y * x * tA + z * sA;
1038 const b02 = z * x * tA - y * sA;
1039 const b10 = x * y * tA - z * sA;
1040 const b11 = y * y * tA + cA;
1041 const b12 = z * y * tA + x * sA;
1042 const b20 = x * z * tA + y * sA;
1043 const b21 = y * z * tA - x * sA;
1044 const b22 = z * z * tA + cA;
1045
1046 // rotation-specific matrix multiplication
1047 this.matrix[0] = a00 * b00 + a10 * b01 + a20 * b02;
1048 this.matrix[1] = a01 * b00 + a11 * b01 + a21 * b02;
1049 this.matrix[2] = a02 * b00 + a12 * b01 + a22 * b02;
1050 this.matrix[3] = a03 * b00 + a13 * b01 + a23 * b02;
1051 this.matrix[4] = a00 * b10 + a10 * b11 + a20 * b12;
1052 this.matrix[5] = a01 * b10 + a11 * b11 + a21 * b12;
1053 this.matrix[6] = a02 * b10 + a12 * b11 + a22 * b12;
1054 this.matrix[7] = a03 * b10 + a13 * b11 + a23 * b12;
1055 this.matrix[8] = a00 * b20 + a10 * b21 + a20 * b22;
1056 this.matrix[9] = a01 * b20 + a11 * b21 + a21 * b22;
1057 this.matrix[10] = a02 * b20 + a12 * b21 + a22 * b22;

Callers 5

_rotateViewMethod · 0.95
rotateXMethod · 0.95
rotateYMethod · 0.95
rotateZMethod · 0.95
p5.Matrix.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected