webgl/public/gl/math/Mat4.js
Tyler Murphy f70007d58b changes
2023-01-19 14:32:58 -05:00

47 lines
No EOL
1 KiB
JavaScript

const PI = Math.PI
const PI2 = PI * 2
const PIH = PI * 0.5
const cosFromSin = (sin, angle) => {
const pih = PI / 2;
const pi2 = PI * 2
const cos = Math.sqrt(1.0 - sin * sin);
const a = angle + PIH;
const b = a - parseInt(a / PI2) * PI2;
if (b < 0.0)
b = PIH + b;
if (b >= PI)
return -cos;
return cos;
}
export class Mat4 {
constructor() {
this.data = [
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
]
}
set(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
const d = this.data
d[0] = m00; d[4] = m01; d[8] = m02; d[12] = m03;
d[1] = m10; d[5] = m11; d[9] = m12; d[13] = m13;
d[2] = m20; d[6] = m21; d[10] = m22; d[14] = m23;
d[3] = m30; d[7] = m31; d[11] = m32; d[15] = m33;
return this
}
identity() {
this.set(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
)
return this
}
}