Update index.html
Browse files- index.html +32 -0
index.html
CHANGED
|
@@ -121,6 +121,38 @@
|
|
| 121 |
zoom = Math.max(1, Math.min(20, zoom));
|
| 122 |
});
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
function animate() {
|
| 125 |
requestAnimationFrame(animate);
|
| 126 |
|
|
|
|
| 121 |
zoom = Math.max(1, Math.min(20, zoom));
|
| 122 |
});
|
| 123 |
|
| 124 |
+
// Touch pinch to zoom
|
| 125 |
+
let lastDistance = 0;
|
| 126 |
+
renderer.domElement.addEventListener('touchmove', (e) => {
|
| 127 |
+
if (e.touches.length === 2) {
|
| 128 |
+
e.preventDefault();
|
| 129 |
+
const touch1 = e.touches[0];
|
| 130 |
+
const touch2 = e.touches[1];
|
| 131 |
+
const dx = touch1.clientX - touch2.clientX;
|
| 132 |
+
const dy = touch1.clientY - touch2.clientY;
|
| 133 |
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 134 |
+
|
| 135 |
+
if (lastDistance > 0) {
|
| 136 |
+
const delta = distance - lastDistance;
|
| 137 |
+
zoom -= delta * 0.02;
|
| 138 |
+
zoom = Math.max(1, Math.min(20, zoom));
|
| 139 |
+
}
|
| 140 |
+
lastDistance = distance;
|
| 141 |
+
} else if (e.touches.length === 1) {
|
| 142 |
+
// Single finger drag
|
| 143 |
+
const touch = e.touches[0];
|
| 144 |
+
const deltaX = touch.clientX - previousMousePosition.x;
|
| 145 |
+
const deltaY = touch.clientY - previousMousePosition.y;
|
| 146 |
+
rotation.y += deltaX * 0.01;
|
| 147 |
+
rotation.x += deltaY * 0.01;
|
| 148 |
+
previousMousePosition = { x: touch.clientX, y: touch.clientY };
|
| 149 |
+
}
|
| 150 |
+
}, false);
|
| 151 |
+
|
| 152 |
+
renderer.domElement.addEventListener('touchend', () => {
|
| 153 |
+
lastDistance = 0;
|
| 154 |
+
});
|
| 155 |
+
|
| 156 |
function animate() {
|
| 157 |
requestAnimationFrame(animate);
|
| 158 |
|