mirror of
https://github.com/RGBCube/rgbcube.github.io
synced 2025-05-31 05:08:12 +00:00
Touch support
This commit is contained in:
parent
87d9c0361d
commit
d42b67f25e
1 changed files with 21 additions and 6 deletions
27
cube.js
27
cube.js
|
@ -97,12 +97,14 @@ const orientation = {
|
||||||
previous: null,
|
previous: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleUp = () => {
|
||||||
document.addEventListener("mouseup", () => {
|
|
||||||
mouse.down = false;
|
mouse.down = false;
|
||||||
});
|
};
|
||||||
|
|
||||||
document.addEventListener("mousemove", (event) => {
|
document.addEventListener("mouseup", handleUp);
|
||||||
|
document.addEventListener("touchend", handleUp);
|
||||||
|
|
||||||
|
const handleMove = (event) => {
|
||||||
if (!mouse.down) return;
|
if (!mouse.down) return;
|
||||||
|
|
||||||
const newMouse = new Vec3(event.clientX, event.clientY, 0);
|
const newMouse = new Vec3(event.clientX, event.clientY, 0);
|
||||||
|
@ -121,18 +123,31 @@ const orientation = {
|
||||||
const rotation = Quat.fromAngleAxis(delta.length() * sensitivity, axis);
|
const rotation = Quat.fromAngleAxis(delta.length() * sensitivity, axis);
|
||||||
|
|
||||||
orientation.set(Quat.mul(rotation, orientation.get()));
|
orientation.set(Quat.mul(rotation, orientation.get()));
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("mousemove", handleMove);
|
||||||
|
document.addEventListener("touchmove", (event) => {
|
||||||
|
const delta = event.changedTouches[0];
|
||||||
|
|
||||||
|
event.clientX = delta.clientX;
|
||||||
|
event.clientY = delta.clientY;
|
||||||
|
|
||||||
|
handleMove(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
let angularMomentum = new Vec3(0, 0, 0);
|
let angularMomentum = new Vec3(0, 0, 0);
|
||||||
|
|
||||||
document.addEventListener("mousedown", (event) => {
|
const handleDown = (event) => {
|
||||||
// Disables link dragging that occurs when spinning.
|
// Disables link dragging that occurs when spinning.
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
mouse.down = true;
|
mouse.down = true;
|
||||||
|
|
||||||
angularMomentum = new Vec3(0, 0, 0);
|
angularMomentum = new Vec3(0, 0, 0);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
document.addEventListener("mousedown", handleDown);
|
||||||
|
document.addEventListener("touchstart", handleDown);
|
||||||
|
|
||||||
let lastUpdate = 0;
|
let lastUpdate = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue