X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Fpointlight.cpp;fp=source%2Fmaterials%2Fpointlight.cpp;h=4bbf4135dae9a7eabe6a24ba2c8a90cf62999781;hb=adc26a2e141a2853b6c5025130c46a46cece4b84;hp=0000000000000000000000000000000000000000;hpb=e6e6f0fe81a2f92985e65ae0de708974194d81a3;p=libs%2Fgl.git diff --git a/source/materials/pointlight.cpp b/source/materials/pointlight.cpp new file mode 100644 index 00000000..4bbf4135 --- /dev/null +++ b/source/materials/pointlight.cpp @@ -0,0 +1,76 @@ +#include "pointlight.h" +#include "programdata.h" + +using namespace std; + +namespace Msp { +namespace GL { + +PointLight::PointLight(): + position(0.0f, 0.0f, 0.0f), + attenuation{1.0f, 0.0f, 0.1f} +{ } + +void PointLight::update_matrix() +{ + matrix = Matrix::translation(position); +} + +void PointLight::set_matrix(const Matrix &m) +{ + Placeable::set_matrix(m); + position = matrix.column(3).slice<3>(0); + update_matrix(); + ++generation; +} + +void PointLight::set_position(const Vector3 &p) +{ + position = p; + update_matrix(); + ++generation; +} + +void PointLight::set_attenuation(float c, float l, float q) +{ + attenuation[0] = c; + attenuation[1] = l; + attenuation[2] = q; + ++generation; +} + +void PointLight::update_shader_data(ProgramData &shdata, const string &base) const +{ + shdata.uniform(base+".type", 2); + shdata.uniform(base+".position", position.x, position.y, position.z, 1.0f); + shdata.uniform(base+".color", color.r, color.g, color.b); +} + + +DataFile::Loader::ActionMap PointLight::Loader::shared_actions; + +PointLight::Loader::Loader(PointLight &l): + DerivedObjectLoader(l) +{ + set_actions(shared_actions); +} + +void PointLight::Loader::init_actions() +{ + Light::Loader::init_actions(); + add("attenuation", &Loader::attenuation); + add("position", &Loader::position); +} + +void PointLight::Loader::attenuation(float c, float l, float q) +{ + obj.set_attenuation(c, l, q); +} + +void PointLight::Loader::position(float x, float y, float z) +{ + obj.set_position(Vector3(x, y, z)); +} + +} // namespace GL +} // namespace Msp