diff --git a/main.mjs b/main.mjs index 3177ed0..ab1f019 100644 --- a/main.mjs +++ b/main.mjs @@ -51,7 +51,9 @@ function draw(gl, program) { TIME += 1 / 60; gl.uniform1f(loc, TIME); + if (document.pointerLockElement) { updateCamera(gl, program); + } // Draw the frame recursively on next frame gl.drawArrays(gl.TRIANGLES, 0, 6); @@ -71,8 +73,10 @@ document.addEventListener("keyup", function (event) { }); // Mouse movement document.addEventListener("mousemove", function (event) { + if (document.pointerLockElement) { mouse_pos[0] += event.movementX / 800; mouse_pos[1] += event.movementY / 800; + } }); // Request pointer Lock