diff --git a/js/app.mjs b/js/app.mjs index 29fab70..5c8586d 100644 --- a/js/app.mjs +++ b/js/app.mjs @@ -1,6 +1,10 @@ +import { testCullingFrustrum } from "./renderer/culling-frustrum.mjs"; import startHelloWebGL from "./renderer/renderer.mjs"; import { mat4 } from "./util/glMatrix_util.mjs"; window.addEventListener("load", (_) => { + + testCullingFrustrum(); + startHelloWebGL(); }); \ No newline at end of file diff --git a/js/renderer/culling-frustrum.mjs b/js/renderer/culling-frustrum.mjs index f5afe0f..c30a4f6 100644 --- a/js/renderer/culling-frustrum.mjs +++ b/js/renderer/culling-frustrum.mjs @@ -38,11 +38,13 @@ export function testCullingFrustrum() { var cam = new Camera(0.1, 5, 45, 16.0 / 9.0); var maze = generateMaze(20, 20, 0.1); maze.print(); - cam.setRotation([0.0, 60.0, 0.0]); - // cam.setPosition([5.0, 0.0, 5.0]); - cam.setPosition(maze.startPosition); + // cam.setRotation([0.0, 60.0, 0.0]); + cam.setPosition([5.0, 0.0, 5.0]); + // cam.setPosition(maze.startPosition); var cullFrus = new CullingFrustrum(cam); + cam.getFrustrumPlanes().forEach(x => x.printEquation()); + var layout = maze.getArrayLayout(); function layoutToCoord(x, z) { diff --git a/js/renderer/renderer.mjs b/js/renderer/renderer.mjs index 23efd00..b4c763d 100644 --- a/js/renderer/renderer.mjs +++ b/js/renderer/renderer.mjs @@ -228,8 +228,6 @@ function drawScene() { testCubeMaterial.camera.setRotation([xRot, yRot, 0.0]); - console.log(testCubeMaterial.camera.up.map(x => x.toFixed(2))); - var f = (keys['w'] ? 1.0 : 0.0) + (keys['s'] ? -1.0 : 0.0); var r = (keys['a'] ? 1.0 : 0.0) + (keys['d'] ? -1.0 : 0.0); cameraPosition = addVector(cameraPosition, multVector(testCubeMaterial.camera.forward, f * 0.2)); @@ -237,6 +235,17 @@ function drawScene() { testCubeMaterial.camera.setPosition(cameraPosition); + batchMesh.geometry.batchInstances = mazeWalls.filter(x => { + const mat = mat4.create(testCubeMaterial.mvMatrix); + const pos = new Float32Array(3); + pos[0] = x.position[0]; + pos[1] = x.position[1]; + pos[2] = x.position[2]; + const matRes = mat4.create(); + const instancePos = mat4.multiplyVec3(mat, pos, matRes); + return cullingFrustrum.testBoundingSphere(instancePos, Math.sqrt(3)); + }); + setCameraPositionUI(testCubeMaterial.camera.position); batchMesh.draw(gl); }