use crate::prelude::*;
#[cfg(feature = "serde")]
use serde::{de::DeserializeOwned, Deserialize, Serialize};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(bound = "T: Serialize + DeserializeOwned"))]
pub enum LightSource<T = f64, const N: usize = 3> {
Ambient,
Point(Point<T, N>),
Direction(Vector<T, N>),
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(bound = "T: Serialize + DeserializeOwned"))]
pub struct Light<T = f64, const N: usize = 3> {
pub source: LightSource<T, N>,
pub intensity: T,
}
impl<T, const N: usize> Light<T, N> {
pub const fn new(source: LightSource<T, N>, intensity: T) -> Self {
Self { source, intensity }
}
pub const fn ambient(intensity: T) -> Self {
Self::new(LightSource::Ambient, intensity)
}
pub fn point<P>(intensity: T, position: P) -> Self
where
P: Into<Point<T, N>>,
{
Self::new(LightSource::Point(position.into()), intensity)
}
pub fn direction<V>(intensity: T, direction: V) -> Self
where
V: Into<Vector<T, N>>,
{
Self::new(LightSource::Direction(direction.into()), intensity)
}
}
impl<T, const N: usize> Default for Light<T, N>
where
T: Default,
{
fn default() -> Self {
Self::new(LightSource::Ambient, T::default())
}
}