// Copyright © 2025 The µcad authors <info@ucad.xyz>
// SPDX-License-Identifier: AGPL-3.0-or-later

pub mod camera_controller;

use bevy::prelude::*;

use crate::State;

pub fn setup_camera(mut commands: Commands, state: Res<State>) {
    let radius = state.scene.radius;

    // Place the camera on the +X, +Y, +Z diagonal of the sphere
    let direction = bevy::prelude::Vec3::new(1.0, -1.0, 1.0).normalize() * radius;

    // camera
    commands.spawn((
        Camera3d::default(),
        camera_controller::CameraController::default(),
        Projection::from(OrthographicProjection {
            scaling_mode: bevy::render::camera::ScalingMode::FixedVertical {
                viewport_height: radius,
            },
            ..OrthographicProjection::default_3d()
        }),
        Transform::from_translation(direction)
            .looking_at(bevy::prelude::Vec3::ZERO, bevy::prelude::Vec3::Z),
    ));
}
