import { clamp } from "./ControlTypes.js";
export class EditorFlyControls {
    camera;
    enabled = true;
    yaw = 0;
    pitch = 0;
    baseSpeed;
    fastMultiplier;
    lookSpeed;
    constructor(camera, options = {}) {
        this.camera = camera;
        this.baseSpeed = options.baseSpeed ?? 3;
        this.fastMultiplier = options.fastMultiplier ?? 4;
        this.lookSpeed = options.lookSpeed ?? 0.0025;
        this.pitch = clamp(camera.rotation?.x ?? 0, -Math.PI / 2 + 0.001, Math.PI / 2 - 0.001);
        this.yaw = camera.rotation?.y ?? 0;
    }
    update(snapshot, deltaSeconds) {
        if (!this.enabled)
            return;
        if (snapshot.button(1).down || snapshot.button(2).down) {
            this.yaw -= snapshot.pointer.deltaX * this.lookSpeed;
            this.pitch = clamp(this.pitch - snapshot.pointer.deltaY * this.lookSpeed, -Math.PI / 2 + 0.001, Math.PI / 2 - 0.001);
            if (this.camera.rotation) {
                this.camera.rotation.x = this.pitch;
                this.camera.rotation.y = this.yaw;
            }
        }
        const speed = this.baseSpeed * (snapshot.key("ShiftLeft").down || snapshot.key("ShiftRight").down ? this.fastMultiplier : 1);
        const forward = (snapshot.key("KeyW").down ? 1 : 0) - (snapshot.key("KeyS").down ? 1 : 0);
        const strafe = (snapshot.key("KeyD").down ? 1 : 0) - (snapshot.key("KeyA").down ? 1 : 0);
        const lift = (snapshot.key("KeyE").down ? 1 : 0) - (snapshot.key("KeyQ").down ? 1 : 0);
        const step = speed * deltaSeconds;
        const sin = Math.sin(this.yaw);
        const cos = Math.cos(this.yaw);
        this.camera.position.x += (strafe * cos + forward * sin) * step;
        this.camera.position.z += (forward * cos - strafe * sin) * step;
        this.camera.position.y += lift * step;
    }
    dispose() {
        this.enabled = false;
    }
}
//# sourceMappingURL=EditorFlyControls.js.map