use nalgebra::RealField;
use serde::{Deserialize, Serialize};
use crate::{error::Result, scene::Projection, traits::FallibleNumeric};
const DEGREES_TO_RADIANS: f64 = std::f64::consts::PI / 180.0;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SerializedProjection<T: RealField + Copy> {
Perspective(T),
Orthographic(T),
}
impl<T: RealField + Copy> SerializedProjection<T> {
pub fn build(self) -> Result<Projection<T>> {
Ok(match self {
Self::Perspective(fov) => {
let to_rad = T::try_from_f64(DEGREES_TO_RADIANS)?;
Projection::Perspective(fov * to_rad)
}
Self::Orthographic(width) => Projection::Orthographic(width),
})
}
}