Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonyyu-1 authored Jul 15, 2024
1 parent bbfa179 commit a68e1a8
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1141,45 +1141,56 @@ async function main() {
startY = 0;
});


let startTouches = [];
function initializeTouchPoints(touches) {
startTouches = Array.from(touches).map(touch => ({
id: touch.identifier,
startX: touch.clientX,
startY: touch.clientY
}));
}

function getTouchDeltas(touches) {
let deltas = Array.from(touches).map(touch => {
let startTouch = startTouches.find(t => t.id === touch.identifier);
if (startTouch) {
return {
dx: (5 * (touch.clientX - startTouch.startX)) / innerWidth,
dy: (5 * (touch.clientY - startTouch.startY)) / innerHeight
};
}
return { dx: 0, dy: 0 };
});
return deltas;
}

function updateViewMatrix(deltas) {
let inv = invert4(viewMatrix);
deltas.forEach(delta => {
inv = rotate4(inv, delta.dx, 0, 1, 0);
//inv = rotate4(inv, -delta.dy, 1, 0, 0);

//if (lastY !== null) {
const deltaY = (5 * delta.dy) / innerHeight;
if((totalVerticalDistance < -0.6 && deltaY > 0 )||(totalVerticalDistance > 0.6 && deltaY < 0)||(totalVerticalDistance>=-0.6 && totalVerticalDistance <= 0.6)){
totalVerticalDistance += deltaY;
}
//}

});
viewMatrix = invert4(inv);
}

canvas.addEventListener("touchstart", (e) => {
carousel = false;
e.preventDefault();
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;

down = 1
initializeTouchPoints(e.touches);
});

canvas.addEventListener("touchmove", (e) => {
canvas.addEventListener("touchend", (e) => {
e.preventDefault();
if (down == 1) {
let inv = invert4(viewMatrix);
let inv2 = invert4(viewMatrix);
let dx = (5 * (e.touches[0].clientX - startX)) / innerWidth;
mousemove_y = (5 * (e.touches[0].clientY - startY)) / innerHeight;
let d = 4;

//inv = translate4(inv, 0, 0, d);
inv = rotate4(inv, dx, 0, 1, 0);
//inv = rotate4(inv, -dy, 1, 0, 0);
//inv = translate4(inv, 0, 0, -d);
// let postAngle = Math.atan2(inv[0], inv[10])
// inv = rotate4(inv, postAngle - preAngle, 0, 0, 1)
// console.log(postAngle)
viewMatrix = invert4(inv);
//viewMatrix = ensureXZPlaneAlignment(invert4(inv));
if (1) { // Check if the left mouse button is pressed
if (lastY !== null) {
const deltaY = (5 * (e.touches[0].clientY - startY)) / innerHeight;
totalVerticalDistance += deltaY;
}
lastY = e.touches[0].clientY;
} else {
lastY = null; // Reset lastY when the mouse button is not pressed
}
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;
}
initializeTouchPoints(e.touches); // 更新触控点位置
});


Expand Down

0 comments on commit a68e1a8

Please sign in to comment.