use cgmath::*;
pub enum LightType {
Point {
position: Vector3<f32>, color: Vector3<f32>, intensity: f32, },
Directional {
direction: Vector3<f32>, color: Vector3<f32>, intensity: f32, },
Spot {
position: Vector3<f32>, direction: Vector3<f32>, color: Vector3<f32>, intensity: f32, angle: Deg<f32>, },
}
pub struct Light {
pub light_type: LightType,
}
impl Light {
pub fn new(light_type: LightType) -> Self {
Self { light_type }
}
pub fn to_shader_data(&self) -> LightShaderData {
match &self.light_type {
LightType::Point {
position,
color,
intensity,
} => LightShaderData {
position: *position,
direction: Vector3::new(0.0, 0.0, 0.0), color: *color,
intensity: *intensity,
angle: 0.0, },
LightType::Directional {
direction,
color,
intensity,
} => LightShaderData {
position: Vector3::new(0.0, 0.0, 0.0), direction: *direction,
color: *color,
intensity: *intensity,
angle: 0.0, },
LightType::Spot {
position,
direction,
color,
intensity,
angle,
} => LightShaderData {
position: *position,
direction: *direction,
color: *color,
intensity: *intensity,
angle: angle.0.to_radians(),
},
}
}
pub fn set_color(&mut self, color: Vector3<f32>) {
match &mut self.light_type {
LightType::Point { color: c, .. } => *c = color,
LightType::Directional { color: c, .. } => *c = color,
LightType::Spot { color: c, .. } => *c = color,
}
}
pub fn set_intensity(&mut self, intensity: f32) {
match &mut self.light_type {
LightType::Point { intensity: i, .. } => *i = intensity,
LightType::Directional { intensity: i, .. } => *i = intensity,
LightType::Spot { intensity: i, .. } => *i = intensity,
}
}
}
#[derive(Clone, Copy)]
pub struct LightShaderData {
pub position: Vector3<f32>,
pub direction: Vector3<f32>,
pub color: Vector3<f32>,
pub intensity: f32,
pub angle: f32,
}