move.gl
Version:
move.gl is a ...
39 lines (36 loc) • 1.49 kB
text/typescript
/**
* @title Spatial Navigation Handler
* @notice Provides navigation controls for moving through a 3D space or virtual environments.
* @dev Supports both keyboard and other input methods for movement and rotation in a 3D space.
*/
class SpatialNavigationHandler {
private position: { x: number; y: number; z: number } = { x: 0, y: 0, z: 0 };
private rotation: { yaw: number; pitch: number; roll: number } = { yaw: 0, pitch: 0, roll: 0 };
constructor() {
document.addEventListener('keydown', this.handleKeyInput);
}
private handleKeyInput = (event: KeyboardEvent) => {
switch(event.key) {
case 'ArrowUp':
this.position.y += 1; // Move up
break;
case 'ArrowDown':
this.position.y -= 1; // Move down
break;
case 'ArrowLeft':
this.rotation.yaw -= 5; // Turn left
break;
case 'ArrowRight':
this.rotation.yaw += 5; // Turn right
break;
case 'w':
this.position.z += 1; // Move forward
break;
case 's':
this.position.z -= 1; // Move backward
break;
// Add more controls as needed
}
console.log(`Position: (${this.position.x}, ${this.position.y}, ${this.position.z}), Rotation: (${this.rotation.yaw}, ${this.rotation.pitch}, ${this.rotation.roll})`);
};
}