diff --git a/main.mjs b/main.mjs index ab1f019..50e225c 100644 --- a/main.mjs +++ b/main.mjs @@ -10,23 +10,25 @@ let mouse_pos = [0, 0]; // Update the Camera position function updateCamera(gl, program) { - if (keymap.get("w")) { - camera_pos[2] += 0.1; - } - if (keymap.get("a")) { - camera_pos[0] += -0.1; - } - if (keymap.get("s")) { - camera_pos[2] += -0.1; - } - if (keymap.get("d")) { - camera_pos[0] += 0.1; - } - if (keymap.get("e")) { - camera_pos[1] += 0.1; - } - if (keymap.get("q")) { - camera_pos[1] += -0.1; + if (document.pointerLockElement) { + if (keymap.get("w")) { + camera_pos[2] += 0.1; + } + if (keymap.get("a")) { + camera_pos[0] += -0.1; + } + if (keymap.get("s")) { + camera_pos[2] += -0.1; + } + if (keymap.get("d")) { + camera_pos[0] += 0.1; + } + if (keymap.get("e")) { + camera_pos[1] += 0.1; + } + if (keymap.get("q")) { + camera_pos[1] += -0.1; + } } // Position @@ -51,15 +53,15 @@ function draw(gl, program) { TIME += 1 / 60; gl.uniform1f(loc, TIME); - if (document.pointerLockElement) { - updateCamera(gl, program); - } + updateCamera(gl, program); // Draw the frame recursively on next frame gl.drawArrays(gl.TRIANGLES, 0, 6); requestAnimationFrame(() => draw(gl, program)); } +//** MAIN PROGRAM **// + // Initialize the shader const [gl, program, canvas] = await initShader(CANVAS_WIDTH, CANVAS_HEIGHT); @@ -85,5 +87,4 @@ canvas.addEventListener("click", async () => { }); // Update loop -updateCamera(gl, program); draw(gl, program);