-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlights.h
56 lines (48 loc) · 1.48 KB
/
lights.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
#ifndef LIGHTS_H_
#define LIGHTS_H_
#include "vec3d.h"
#include "color.h"
using namespace color;
using namespace v3d;
namespace lights
{
class ambientLight
{
rgbColor color_;
F64 intensity;
rgbColor background_;
public:
ambientLight(rgbColor col, rgbColor back, F64 intens) : color_(col), intensity(intens), background_(back) {};
ambientLight() : color_(rgbColor(0,0,0,true)), intensity(0), background_(color_) {};
rgbColor color() { return color_*intensity; };
rgbColor background(F64 x, F64 y) { return background_; };
};
class light
{
protected:
rgbColor color_;
F64 intensity;
light(rgbColor col, F64 intens) : color_(col), intensity(intens) {};
public:
virtual ~light() = default;
virtual vec3d getDirection(point to) = 0; //vestigial perameter "to" needed for point lights
rgbColor color() const { return color_; };
};
class pointLight : public light
{
point source;
public:
pointLight(point _source, rgbColor col, F64 intens) : light(col, intens), source(_source) {};
virtual ~pointLight() override = default;
virtual vec3d getDirection(point to) override { return (1/(vec3d(source, to).dot(vec3d(source, to))))*vec3d(source, to); };
};
class directionalLight : public light
{
vec3d direction;
public:
directionalLight(vec3d dir, rgbColor col, F64 intens) : light(col, intens), direction(dir.unit()) {};
virtual ~directionalLight() override = default;
virtual vec3d getDirection(point to) override { return -1*direction; };
};
}
#endif