1
Fork 0
mirror of https://github.com/RGBCube/Site synced 2025-07-30 20:47:46 +00:00

cube: scrolling movement

This commit is contained in:
RGBCube 2025-06-02 02:56:14 +03:00
parent 3dbeaf579f
commit ad30320a8e
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M

View file

@ -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) => {