From ad30320a8e1bce1a887e3e5a8027e1347f165eb2 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Mon, 2 Jun 2025 02:56:14 +0300 Subject: [PATCH] cube: scrolling movement --- site/_includes/cube.vto | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/site/_includes/cube.vto b/site/_includes/cube.vto index ef25f8b..8c7e4d9 100644 --- a/site/_includes/cube.vto +++ b/site/_includes/cube.vto @@ -118,7 +118,8 @@ ); const friction = 3; - const sensitivity = 0.01; + const sensitivityMouse = 0.01; + const sensitivityWheel = 0.005; // One minute. const screensaverTimeoutMs = 1 * 60 * 1000; @@ -172,9 +173,7 @@ const newMouse = Vec(event.clientX, event.clientY, 0); - const timeDelta = (globalThis.performance.now() - mouse.lastMove) / 1000; - - if (timeDelta > 0.1) { + if (globalThis.performance.now() - mouse.lastMove > 100) { // This is a fresh scroll. mouse.previous = newMouse; } @@ -186,7 +185,8 @@ const axis = Vec(-delta.y, delta.x, 0) .normalize() - .scale(delta.length() * sensitivity); + .scale(delta.length()) + .scale(sensitivityMouse); impulseThisFrame = Vec.sum(impulseThisFrame, axis); @@ -205,6 +205,20 @@ handleMove(event); }); + const handleWheel = (event) => { + mouse.lastMove = globalThis.performance.now(); + + const axis = Vec(event.deltaY, -event.deltaX, 0) + .scale(sensitivityWheel); + + impulseThisFrame = Vec.sum(impulseThisFrame, axis); + + const rotation = Quat.fromAxis(axis); + orient.set(Quat.mul(rotation, orient.get())); + }; + + document.addEventListener("wheel", handleWheel, { passive: false }); + let lastUpdate = 0; const updateFrame = (timestamp) => {