import * as mc from "@minecraft/server";
function toRadians(degrees) {
    return degrees * (Math.PI / 180);
}
export function getOffsetRelativeToEntityRotation(player, offset) {
    const yawRadians = toRadians(player.getRotation().y);
    const pitchRadians = toRadians(player.getRotation().x);
    const sinYaw = Math.sin(yawRadians);
    const cosYaw = Math.cos(yawRadians);
    const sinPitch = Math.sin(pitchRadians);
    const cosPitch = Math.cos(pitchRadians);
    const deltaX = cosYaw * offset.x - sinYaw * offset.z;
    const deltaZ = sinYaw * offset.x + cosYaw * offset.z;
    const deltaY = cosPitch * offset.y + sinPitch * Math.sqrt(offset.x * offset.x + offset.z * offset.z);
    return {
        x: player.location.x + cosPitch * deltaX,
        y: player.location.y + deltaY,
        z: player.location.z + cosPitch * deltaZ,
    };
}
export function thirdPersonRelative(player, offset) {
    const rotation = player.getRotation();
    rotation.x = Math.min(90, Math.max(-90, rotation.x));
    player.camera.setCamera("minecraft:free", {
        rotation: rotation,
        location: getOffsetRelativeToEntityRotation(player, offset),
        easeOptions: {
            easeTime: 0.2,
            easeType: mc.EasingType.Linear,
        },
    });
}
