-
Notifications
You must be signed in to change notification settings - Fork 0
/
light.h
64 lines (48 loc) · 1.2 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
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <cfloat>
#include "fcolor.h"
#include "vec.h"
struct Lighting {
float distance; // 光源までの距離
FColor intensity; // 強度
Vec direction; // 方向
};
class LightSource {
public:
FColor intensity;
LightSource() {}
LightSource(FColor i):
intensity(i)
{}
virtual Lighting lightingAt(Vec pos) = 0;
};
class PointLightSource : public LightSource {
public:
Vec position;
PointLightSource() {}
PointLightSource(FColor i, Vec p):
LightSource(i), position(p)
{}
Lighting lightingAt(Vec pos) override {
Lighting light;
light.intensity = intensity;
light.distance = (pos - position).magSg();
light.direction = (pos - position).normalize();
return light;
}
};
class DirectionalLightSource : public LightSource {
public:
Vec direction;
DirectionalLightSource() {}
DirectionalLightSource(FColor i, Vec d):
LightSource(i), direction(d)
{}
Lighting lightingAt(Vec pos) override {
Lighting light;
light.intensity = intensity;
light.distance = FLT_MAX;
light.direction = direction.normalize();
return light;
}
};