First commit

This commit is contained in:
Daniel Ledda
2020-06-23 23:45:44 +02:00
commit 2381f43d38
28 changed files with 8385 additions and 0 deletions

21
src/utils.ts Normal file
View File

@@ -0,0 +1,21 @@
import Matrix4 from "./Matrix4";
export function identityMatrix(size: number): Float32Array {
const mat = Array<number>(size*size).fill(0);
return new Float32Array(
mat.map((_, index) =>
index % 5 === 0 ? 1 : 0
));
}
export function perspMat(fovDeg: number, aspect: number, near: number, far: number): Matrix4 {
const f = Math.tan(Math.PI * 0.5 - 0.5 * fovDeg);
const rangeInv = 1.0 / (near - far);
return new Matrix4([
f / aspect, 0, 0, 0,
0, f, 0, 0,
0, 0, (near + far) * rangeInv, -1,
0, 0, near * far * rangeInv * 2, 0
]);
}