Skip to main content

scenevm/
light.rs

1use vek::Vec3;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum LightType {
5    Point,
6}
7
8#[derive(Debug, Clone)]
9pub struct Light {
10    pub light_type: LightType,
11    pub position: Vec3<f32>,
12    pub color: Vec3<f32>,
13    pub intensity: f32,
14    pub radius: f32,
15    pub emitting: bool,
16    pub start_distance: f32,
17    pub end_distance: f32,
18    pub flicker: f32,
19}
20
21impl Light {
22    pub fn new_pointlight(position: Vec3<f32>) -> Self {
23        Light {
24            light_type: LightType::Point,
25            position,
26            color: Vec3::new(1.0, 1.0, 1.0),
27            intensity: 100.0,
28            radius: 10.0,
29            emitting: true,
30            start_distance: 0.0,
31            end_distance: 10.0,
32            flicker: 0.0,
33        }
34    }
35
36    pub fn with_position(mut self, position: Vec3<f32>) -> Self {
37        self.position = position;
38        self
39    }
40    pub fn with_color(mut self, color: Vec3<f32>) -> Self {
41        self.color = color;
42        self
43    }
44    pub fn with_intensity(mut self, intensity: f32) -> Self {
45        self.intensity = intensity;
46        self
47    }
48    pub fn with_radius(mut self, radius: f32) -> Self {
49        self.radius = radius;
50        self
51    }
52    pub fn with_emitting(mut self, emitting: bool) -> Self {
53        self.emitting = emitting;
54        self
55    }
56    pub fn with_start_distance(mut self, start_distance: f32) -> Self {
57        self.start_distance = start_distance;
58        self
59    }
60    pub fn with_end_distance(mut self, end_distance: f32) -> Self {
61        self.end_distance = end_distance;
62        self
63    }
64    pub fn with_flicker(mut self, flicker: f32) -> Self {
65        self.flicker = flicker;
66        self
67    }
68}