-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight.h
51 lines (42 loc) · 1.38 KB
/
Light.h
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
//
//
//
#ifndef RAY_TRACER_LIGHT_H
#define RAY_TRACER_LIGHT_H
#include <sstream>
class Light {
public:
enum class Type {
Directional,
Point
};
Vector3 direction; // Normalized direction of the light (for directional)
Vector3 position; // Position of the light (for point)
Vector3 color; // Color intensity
Type type;
Light(Type type, const Vector3& directionOrPosition, const Vector3& color)
: color(color), type(type) {
if (type == Type::Directional) {
direction = directionOrPosition.normalize();
} else {
position = directionOrPosition;
}
}
std::string toString() const {
std::ostringstream oss;
if (type == Type::Directional) {
oss << "Directional Light with direction (" << direction.x << ", " << direction.y << ", " << direction.z << ")";
} else {
oss << "Point Light with position (" << position.x << ", " << position.y << ", " << position.z << ")";
}
oss << " and color intensity (" << color.x << ", " << color.y << ", " << color.z << ")";
return oss.str();
}
};
bool operator==(const Light& lhs, const Light& rhs) {
return lhs.type == rhs.type &&
lhs.direction == rhs.direction &&
lhs.position == rhs.position &&
lhs.color == rhs.color;
}
#endif //RAY_TRACER_LIGHT_H