-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexperimentalControls.js
More file actions
83 lines (70 loc) · 2.71 KB
/
experimentalControls.js
File metadata and controls
83 lines (70 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import * as THREE from 'three';
import { PointerLockControls } from 'three/examples/jsm/controls/PointerLockControls.js';
export function setupExperimentalControls(camera, renderer) {
const controls = new PointerLockControls(camera, renderer.domElement);
const velocity = new THREE.Vector3();
const speed = 5;
const altitudeSpeed = 3;
// Movement state
const movement = {
forward: 0,
right: 0,
up: 0
};
// Initialize mobile controls
createMobileControls();
// Lock controls on tap
renderer.domElement.addEventListener('click', () => {
if (controls.isLocked) return;
controls.lock().catch(e => {
console.log("Pointer lock failed:", e);
});
});
function update(delta) {
velocity.set(
movement.right * speed * delta,
movement.up * altitudeSpeed * delta,
movement.forward * speed * delta
);
controls.moveRight(velocity.x);
controls.moveForward(velocity.z);
camera.position.y = Math.max(0.5, camera.position.y + velocity.y);
}
return { controls, update };
function createMobileControls() {
// Create container for mobile controls
const container = document.createElement('div');
container.style.position = 'fixed';
container.style.bottom = '20px';
container.style.left = '0';
container.style.right = '0';
container.style.display = 'flex';
container.style.justifyContent = 'space-between';
container.style.padding = '0 20px';
container.style.zIndex = '1000';
document.body.appendChild(container);
// Movement joystick
const joystick = createJoystick(
(x, y) => {
movement.forward = -y;
movement.right = x;
},
() => {
movement.forward = 0;
movement.right = 0;
}
);
container.appendChild(joystick);
// Altitude buttons
const altitudeContainer = document.createElement('div');
altitudeContainer.style.display = 'flex';
altitudeContainer.style.flexDirection = 'column';
altitudeContainer.style.gap = '10px';
const upBtn = createButton('↑', () => movement.up = 1, () => movement.up = 0);
const downBtn = createButton('↓', () => movement.up = -1, () => movement.up = 0);
altitudeContainer.appendChild(upBtn);
altitudeContainer.appendChild(downBtn);
container.appendChild(altitudeContainer);
}
// ... (include createJoystick and createButton functions from your original code) ...
}