Skip to content

Commit

Permalink
Update main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonyyu-1 authored Jul 9, 2024
1 parent f5953d7 commit 0fd246d
Showing 1 changed file with 1 addition and 98 deletions.
99 changes: 1 addition & 98 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1138,104 +1138,7 @@ async function main() {
startY = 0;
});

let altX = 0,
altY = 0;
canvas.addEventListener(
"touchstart",
(e) => {
e.preventDefault();
if (e.touches.length === 1) {
carousel = false;
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;
down = 1;
} else if (e.touches.length === 2) {
// console.log('beep')
carousel = false;
startX = e.touches[0].clientX;
altX = e.touches[1].clientX;
startY = e.touches[0].clientY;
altY = e.touches[1].clientY;
down = 1;
}
},
{ passive: false },
);
canvas.addEventListener(
"touchmove",
(e) => {
e.preventDefault();
if (e.touches.length === 1 && down) {
let inv = invert4(viewMatrix);
let dx = (4 * (e.touches[0].clientX - startX)) / innerWidth;
let dy = (4 * (e.touches[0].clientY - startY)) / innerHeight;

let d = 4;
inv = translate4(inv, 0, 0, d);
// inv = translate4(inv, -x, -y, -z);
// inv = translate4(inv, x, y, z);
inv = rotate4(inv, dx, 0, 1, 0);
inv = rotate4(inv, -dy, 1, 0, 0);
inv = translate4(inv, 0, 0, -d);

viewMatrix = invert4(inv);
actualViewMatrix = invert4(inv);
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;
} else if (e.touches.length === 2) {
// alert('beep')
const dtheta =
Math.atan2(startY - altY, startX - altX) -
Math.atan2(
e.touches[0].clientY - e.touches[1].clientY,
e.touches[0].clientX - e.touches[1].clientX,
);
const dscale =
Math.hypot(startX - altX, startY - altY) /
Math.hypot(
e.touches[0].clientX - e.touches[1].clientX,
e.touches[0].clientY - e.touches[1].clientY,
);
const dx =
(e.touches[0].clientX +
e.touches[1].clientX -
(startX + altX)) /
2;
const dy =
(e.touches[0].clientY +
e.touches[1].clientY -
(startY + altY)) /
2;
let inv = invert4(viewMatrix);
// inv = translate4(inv, 0, 0, d);
inv = rotate4(inv, dtheta, 0, 0, 1);

inv = translate4(inv, -dx / innerWidth, -dy / innerHeight, 0);

// let preY = inv[13];
inv = translate4(inv, 0, 0, 3 * (1 - dscale));
// inv[13] = preY;

viewMatrix = invert4(inv);

startX = e.touches[0].clientX;
altX = e.touches[1].clientX;
startY = e.touches[0].clientY;
altY = e.touches[1].clientY;
}
},
{ passive: false },
);
canvas.addEventListener(
"touchend",
(e) => {
e.preventDefault();
down = false;
startX = 0;
startY = 0;
},
{ passive: false },
);


let jumpDelta = 0;
let vertexCount = 0;
Expand Down

0 comments on commit 0fd246d

Please sign in to comment.