1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
use crate::color::Color;
use crate::vector::Vec3;
#[derive(Debug, Clone)]
pub struct LightSource
{
position: Vec3<f32>,
ambient: Color<f32>,
diffuse: Color<f32>,
specular: Color<f32>,
}
impl LightSource
{
#[must_use]
pub fn position(&self) -> &Vec3<f32>
{
&self.position
}
#[must_use]
pub fn ambient(&self) -> &Color<f32>
{
&self.ambient
}
#[must_use]
pub fn diffuse(&self) -> &Color<f32>
{
&self.diffuse
}
#[must_use]
pub fn specular(&self) -> &Color<f32>
{
&self.specular
}
pub fn translate(&mut self, translation: Vec3<f32>)
{
self.position += translation;
}
}
#[derive(Debug, Clone, Default)]
pub struct LightSourceBuilder
{
position: Vec3<f32>,
ambient: Color<f32>,
diffuse: Color<f32>,
specular: Color<f32>,
}
impl LightSourceBuilder
{
#[must_use]
pub fn new() -> Self
{
Self {
position: Vec3::default(),
ambient: Color::WHITE_F32,
diffuse: Color::WHITE_F32,
specular: Color::WHITE_F32,
}
}
#[must_use]
pub fn position(mut self, position: Vec3<f32>) -> Self
{
self.position = position;
self
}
#[must_use]
pub fn ambient(mut self, ambient: Color<f32>) -> Self
{
self.ambient = ambient;
self
}
#[must_use]
pub fn diffuse(mut self, diffuse: Color<f32>) -> Self
{
self.diffuse = diffuse;
self
}
#[must_use]
pub fn specular(mut self, specular: Color<f32>) -> Self
{
self.specular = specular;
self
}
#[must_use]
pub fn build(&self) -> LightSource
{
LightSource {
position: self.position.clone(),
ambient: self.ambient.clone(),
diffuse: self.diffuse.clone(),
specular: self.specular.clone(),
}
}
}
|