import * as THREE from 'three';
import * as CONSTANTS from '../../../types/world/worldConstants';

export default async function switchToFirstPerson(
    controls: any,
    camera: any
) {
    if (!controls) return;

    const cameraDirection = new THREE.Vector3();
    camera.getWorldDirection(cameraDirection);
    cameraDirection.normalize();

    await controls.setPosition(camera.position.x, 2, camera.position.z, true);
    controls.setTarget(camera.position.x, 2, camera.position.z, true);
    controls.mouseButtons.left = CONSTANTS.firstPersonControls.leftMouse;
    controls.lockPointer();

    controls.azimuthRotateSpeed = CONSTANTS.firstPersonControls.azimuthRotateSpeed;
    controls.polarRotateSpeed = CONSTANTS.firstPersonControls.polarRotateSpeed;
    controls.truckSpeed = CONSTANTS.firstPersonControls.truckSpeed;
    controls.minDistance = CONSTANTS.firstPersonControls.minDistance;
    controls.maxDistance = CONSTANTS.firstPersonControls.maxDistance;
    controls.maxPolarAngle = CONSTANTS.firstPersonControls.maxPolarAngle;
}