]> git.tdb.fi Git - libs/gl.git/blob - source/materials/pointlight.cpp
4bbf4135dae9a7eabe6a24ba2c8a90cf62999781
[libs/gl.git] / source / materials / pointlight.cpp
1 #include "pointlight.h"
2 #include "programdata.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GL {
8
9 PointLight::PointLight():
10         position(0.0f, 0.0f, 0.0f),
11         attenuation{1.0f, 0.0f, 0.1f}
12 { }
13
14 void PointLight::update_matrix()
15 {
16         matrix = Matrix::translation(position);
17 }
18
19 void PointLight::set_matrix(const Matrix &m)
20 {
21         Placeable::set_matrix(m);
22         position = matrix.column(3).slice<3>(0);
23         update_matrix();
24         ++generation;
25 }
26
27 void PointLight::set_position(const Vector3 &p)
28 {
29         position = p;
30         update_matrix();
31         ++generation;
32 }
33
34 void PointLight::set_attenuation(float c, float l, float q)
35 {
36         attenuation[0] = c;
37         attenuation[1] = l;
38         attenuation[2] = q;
39         ++generation;
40 }
41
42 void PointLight::update_shader_data(ProgramData &shdata, const string &base) const
43 {
44         shdata.uniform(base+".type", 2);
45         shdata.uniform(base+".position", position.x, position.y, position.z, 1.0f);
46         shdata.uniform(base+".color", color.r, color.g, color.b);
47 }
48
49
50 DataFile::Loader::ActionMap PointLight::Loader::shared_actions;
51
52 PointLight::Loader::Loader(PointLight &l):
53         DerivedObjectLoader<PointLight, Light::Loader>(l)
54 {
55         set_actions(shared_actions);
56 }
57
58 void PointLight::Loader::init_actions()
59 {
60         Light::Loader::init_actions();
61         add("attenuation", &Loader::attenuation);
62         add("position", &Loader::position);
63 }
64
65 void PointLight::Loader::attenuation(float c, float l, float q)
66 {
67         obj.set_attenuation(c, l, q);
68 }
69
70 void PointLight::Loader::position(float x, float y, float z)
71 {
72         obj.set_position(Vector3(x, y, z));
73 }
74
75 } // namespace GL
76 } // namespace Msp