From ed43c9ea5c6972e6e525862ba82f47df6f016720 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Fri, 17 Dec 2021 06:14:16 -0800 Subject: [PATCH] Clamp camera rotx and fix motion --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 91352d4..feff417 100644 --- a/index.js +++ b/index.js @@ -103,8 +103,7 @@ const stuff = { function handleKeys(params) { const move = (forward, right) => { const dir = [right, 0, -forward, 1.0]; - const camori = params.camera.orientation; - const ori = se3.rotxyz(...camori); + const ori = se3.roty(params.camera.orientation[1]); const tf = se3.apply(ori, dir); if (params.flying) { @@ -439,6 +438,10 @@ async function main() { const moveListener = e => { params.camera.orientation[1] -= e.movementX / 500; params.camera.orientation[0] -= e.movementY / 500; + + params.camera.orientation[0] = Math.min(Math.max( + params.camera.orientation[0], -Math.PI / 2 + ), Math.PI / 2); }; const changeListener = () => { if (document.pointerLockElement === canvas) {