mirror of
https://github.com/RGBCube/Site
synced 2025-08-01 13:37:49 +00:00
cube: scrolling movement
This commit is contained in:
parent
3dbeaf579f
commit
ad30320a8e
1 changed files with 19 additions and 5 deletions
|
@ -118,7 +118,8 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
const friction = 3;
|
const friction = 3;
|
||||||
const sensitivity = 0.01;
|
const sensitivityMouse = 0.01;
|
||||||
|
const sensitivityWheel = 0.005;
|
||||||
|
|
||||||
// One minute.
|
// One minute.
|
||||||
const screensaverTimeoutMs = 1 * 60 * 1000;
|
const screensaverTimeoutMs = 1 * 60 * 1000;
|
||||||
|
@ -172,9 +173,7 @@
|
||||||
|
|
||||||
const newMouse = Vec(event.clientX, event.clientY, 0);
|
const newMouse = Vec(event.clientX, event.clientY, 0);
|
||||||
|
|
||||||
const timeDelta = (globalThis.performance.now() - mouse.lastMove) / 1000;
|
if (globalThis.performance.now() - mouse.lastMove > 100) {
|
||||||
|
|
||||||
if (timeDelta > 0.1) {
|
|
||||||
// This is a fresh scroll.
|
// This is a fresh scroll.
|
||||||
mouse.previous = newMouse;
|
mouse.previous = newMouse;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +185,8 @@
|
||||||
|
|
||||||
const axis = Vec(-delta.y, delta.x, 0)
|
const axis = Vec(-delta.y, delta.x, 0)
|
||||||
.normalize()
|
.normalize()
|
||||||
.scale(delta.length() * sensitivity);
|
.scale(delta.length())
|
||||||
|
.scale(sensitivityMouse);
|
||||||
|
|
||||||
impulseThisFrame = Vec.sum(impulseThisFrame, axis);
|
impulseThisFrame = Vec.sum(impulseThisFrame, axis);
|
||||||
|
|
||||||
|
@ -205,6 +205,20 @@
|
||||||
handleMove(event);
|
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;
|
let lastUpdate = 0;
|
||||||
|
|
||||||
const updateFrame = (timestamp) => {
|
const updateFrame = (timestamp) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue