2023-01-19 18:39:40 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-01-19 03:43:02 +00:00
|
|
|
export class Mat4 {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.data = [
|
2023-01-19 18:39:40 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0
|
2023-01-19 03:43:02 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
set(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
|
|
const d = this.data
|
2023-01-19 19:32:58 +00:00
|
|
|
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;
|
2023-01-19 03:43:02 +00:00
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
identity() {
|
|
|
|
this.set(
|
|
|
|
1, 0, 0, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 0, 0, 1
|
|
|
|
)
|
|
|
|
return this
|
|
|
|
}
|
2023-01-19 19:32:58 +00:00
|
|
|
|
2023-01-19 03:43:02 +00:00
|
|
|
}
|