-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightSource.cpp
More file actions
122 lines (100 loc) · 2.74 KB
/
Copy pathlightSource.cpp
File metadata and controls
122 lines (100 loc) · 2.74 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "lightSource.h"
#include "math.h"
#include "util.h"
LightSource::LightSource()
{
this->intensity = 0;
this->color = { 0, 0, 0 };
}
LightSource::LightSource(float intensity)
{
this->intensity = intensity;
this->color = { 0, 0, 0 };
}
LightSource::LightSource(float intensity, Util::Color color)
{
this->intensity = intensity;
this->color = color;
}
float LightSource::getIntensity() const
{
return this->intensity;
}
void LightSource::setIntensity(float intensity)
{
this->intensity = intensity;
}
UnidirectionalLightSource::UnidirectionalLightSource()
{
this->direction = { 0, 0, -1 };
}
UnidirectionalLightSource::UnidirectionalLightSource(Math::Vector3 direction)
{
this->direction = direction;
}
UnidirectionalLightSource::UnidirectionalLightSource(Math::Vector3 direction, float intensity)
: LightSource::LightSource(intensity)
{
this->direction = direction;
}
UnidirectionalLightSource::UnidirectionalLightSource(Math::Vector3 direction, float intensity, Util::Color color)
: LightSource::LightSource(intensity, color)
{
this->direction = direction;
}
Math::Vector3 UnidirectionalLightSource::getDirection() const
{
return this->direction;
}
void UnidirectionalLightSource::setDirection(Math::Vector3 direction)
{
this->direction = direction;
}
void UnidirectionalLightSource::setMaxRenderDistance(float maxRenderDistance)
{
this->maxRenderDistance = maxRenderDistance;
}
float UnidirectionalLightSource::timeToLightSource(Math::Ray ray) const
{
return maxRenderDistance;
}
Math::Vector3 UnidirectionalLightSource::getLightDirectionToSurfacePoint(Math::Vector3 surfacePoint) const
{
return this->direction / this->direction.norm();
}
PointLightSource::PointLightSource()
{
this->point = { 0, 0, -1 };
}
PointLightSource::PointLightSource(Math::Vector3 point)
{
this->point = point;
}
PointLightSource::PointLightSource(Math::Vector3 point, float intensity)
: LightSource::LightSource(intensity)
{
this->point = point;
}
PointLightSource::PointLightSource(Math::Vector3 point, float intensity, Util::Color color)
: LightSource::LightSource(intensity, color)
{
this->point = point;
}
Math::Vector3 PointLightSource::getPoint() const
{
return this->point;
}
void PointLightSource::setPoint(Math::Vector3 point)
{
this->point = point;
}
float PointLightSource::timeToLightSource(Math::Ray ray) const
{
float raySpeed = ray.direction.norm();
return std::abs(this->point.getX() - ray.origin.getX()) / raySpeed;
}
Math::Vector3 PointLightSource::getLightDirectionToSurfacePoint(Math::Vector3 surfacePoint) const
{
const Math::Vector3 unnormalizedDirection = surfacePoint - this->point;
return unnormalizedDirection / unnormalizedDirection.norm();
}