small changes

This commit is contained in:
Tyler Murphy 2023-01-18 23:44:45 -05:00
parent 30cf48cd70
commit 19ac1aee5d
4 changed files with 18 additions and 58 deletions

View file

@ -15,6 +15,9 @@ export class Entity {
}
tran() {
this.rotation.x %= 360;
this.rotation.y %= 360;
this.rotation.z %= 360;
return new Mat4()
.identity()
.pos(this.position)

View file

@ -32,6 +32,10 @@ export class Renderer {
canvas.height = window.innerHeight
gl.viewport(0, 0, canvas.width, canvas.height)
}
this.FOV = 90
this.FAR = 1000
this.NEAR = .1
}
draw(scene, camera) {
@ -57,17 +61,14 @@ export class Renderer {
}
proj() {
const fov = 90
const far = 100
const near = 0.1
const aspect = canvas.width / canvas.height
const f = 1.0 / Math.tan((fov * (Math.PI/180)) / 2)
const f = 1.0 / Math.tan((this.FOV * (Math.PI/180)) / 2)
const fa = f / aspect
const nf = 1.0 / (near - far)
const nf = 1.0 / (this.NEAR - this.FAR)
const c1 = (near + far) * nf
const c2 = near * far * nf * 2
const c1 = (this.NEAR + this.FAR) * nf
const c2 = this.NEAR * this.FAR * nf * 2
return new Mat4().set(
fa, 0, 0, 0,

View file

@ -49,52 +49,6 @@ export class Mat4 {
return this
}
mult(v) {
return this.multmat(this.clone(), v)
}
premult(v) {
return this.multmat(v, this.clone())
}
multmat(ma, mb) {
const a = ma.data;
const b = mb.data
const d = this.data;
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
const b00 = b[0], b01 = b[1], b02 = b[2], b03 = a[3];
const b10 = b[4], b11 = b[5], b12 = b[6], b13 = a[7];
const b20 = b[8], b21 = b[9], b22 = b[10], b23 = a[11];
const b30 = b[12], b31 = b[13], b32 = b[14], b33 = a[15];
d[0] = a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30;
d[1] = a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31;
d[2] = a00 * b02 + a01 * b12 + a02 * b22 + a03 * b32;
d[3] = a00 * b03 + a01 * b13 + a02 * b23 + a03 * b33;
d[4] = a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30;
d[5] = a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31;
d[6] = a10 * b02 + a11 * b12 + a12 * b22 + a13 * b32;
d[7] = a10 * b03 + a11 * b13 + a12 * b23 + a13 * b33;
d[8] = a20 * b00 + a21 * b10 + a22 * b20 + a23 * b30;
d[9] = a20 * b01 + a21 * b11 + a22 * b21 + a23 * b31;
d[10] = a20 * b02 + a21 * b12 + a22 * b22 + a23 * b32;
d[11] = a20 * b03 + a21 * b13 + a22 * b23 + a23 * b33;
d[12] = a30 * b00 + a31 * b10 + a32 * b20 + a33 * b30;
d[13] = a30 * b01 + a31 * b11 + a32 * b21 + a33 * b31;
d[14] = a30 * b02 + a31 * b12 + a32 * b22 + a33 * b32;
d[15] = a30 * b03 + a31 * b13 + a32 * b23 + a33 * b33;
return this;
}
pos(v) {
const d = this.data
@ -134,7 +88,7 @@ export class Mat4 {
return this
}
scale( v ) {
scale(v) {
const d = this.data;
d[0] *= v.x; d[1] *= v.y; d[2] *= v.z;
@ -147,11 +101,11 @@ export class Mat4 {
get() {
const d = this.data
return [
return new Float32Array([
d[0], d[4], d[8], d[12],
d[1], d[5], d[9], d[13],
d[2], d[6], d[10], d[14],
d[3], d[7], d[11], d[15]
]
])
}
}

View file

@ -21,16 +21,18 @@ async function main() {
.finish()
var Cube = new GL.Entity(Mesh)
Cube.position.z = -4;
Cube.position.z = -5;
Scene.add(Material, Cube)
const a = new GL.Vec3(1,1,1)
Renderer.FOV = 70
GL.Loop(() => {
Renderer.draw(Scene, Camera)
Cube.rotation.add(a)
});
});
}
main()