cube tests

This commit is contained in:
biglyderv 2025-03-04 22:32:32 -05:00
parent 7caf01a4ae
commit 6be7f85b93
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
3 changed files with 66 additions and 35 deletions

View file

@ -1,5 +1,4 @@
'use strict';
var nothingness = 1, nGain = 0.01; //todo: outsource into another file
var canvas, gl, positionAttributeLocation, positionBuffer, matBuffer, vpBuffer, sizeBuffer, distBuffer, fgBuffer;
@ -102,9 +101,9 @@ function renderThing() {
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);
gl.uniformMatrix4fv(vpBuffer, false, new Float32Array([
256, 0, 0, 0,
0, 256, 0, 0,
0, 0, 256 / 4, 0,
1024, 0, 0, 0,
0, 1024, 0, 0,
0, 0, 1024 / 4, 0,
0, 0, 0, 1
]));
@ -121,41 +120,23 @@ function renderThing() {
var count = 6;
gl.drawArrays(primitiveType, offset, count);
positions = MDN.createCubeData(1, 1, 1);
positions = MDN.createCubeData(10,10,10);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);
let vp = MDN.rotateYMatrix(nothingness);
vp = MDN.multiplyMatrices(MDN.translateMatrix(0, 0, -3), vp)
for (let cubie of cubePos) {
let vp = MDN.rotateYMatrix(Math.log(nothingness+1) * cubie[2] / 10);
vp = MDN.multiplyMatrices(MDN.translateMatrix(cubie[0], cubie[1], cubie[2]), vp)
gl.uniformMatrix4fv(vpBuffer, false, new Float32Array(vp));
gl.uniformMatrix4fv(vpBuffer, false, new Float32Array(vp));
gl.uniform1i(fgBuffer, true);
count = positions.length / 3;
gl.drawArrays(primitiveType, offset, count);
gl.uniform1i(fgBuffer, true);
count = positions.length / 3;
gl.drawArrays(primitiveType, offset, count);
}
requestAnimationFrame(renderThing);
}
let hud = document.querySelector('.hud');
main();
requestAnimationFrame(renderThing)
let clicking = false;
setInterval(function () {
nothingness += nGain;
}, 1000 / 60)
document.body.onclick = async function () {
if (clicking) return;
clicking = true;
let oldNGain = nGain;
nGain += 0.05;
while (nGain > oldNGain) {
nGain -= 0.005;
await new Promise((res) => setTimeout(res, 1000 / 60))
}
nGain = oldNGain;
clicking = false;
}
requestAnimationFrame(renderThing)