#include <stdexcept>
#include <cmath>
+#include <msp/core/algorithm.h>
#include "error.h"
#include "light.h"
#include "lighting.h"
set_fog_density(-log(pow(0.5, 1.0/d)));
}
-void Lighting::attach(unsigned i, const Light &l)
+void Lighting::attach(const Light &l)
{
- if(i>=lights.size())
- lights.resize(i+1);
+ if(find(lights, &l)==lights.end())
+ lights.push_back(&l);
+}
- lights[i] = &l;
+void Lighting::detach(const Light &l)
+{
+ vector<const Light *>::iterator i = find(lights, &l);
+ if(i!=lights.end())
+ lights.erase(i);
}
void Lighting::detach(unsigned i)
if(i>=lights.size())
return;
- lights[i] = 0;
+ detach(*lights[i]);
}
const Light *Lighting::get_attached_light(unsigned i) const
{
shdata.uniform("ambient_color", ambient);
shdata.uniform("sky_color", sky_color);
- shdata.uniform("eye_zenith_dir", view_matrix.block<3, 3>(0, 0)*zenith_direction);
+ shdata.uniform("world_zenith_dir", zenith_direction);
shdata.uniform("horizon_limit", horizon_angle.radians());
shdata.uniform("fog_color", fog_color);
shdata.uniform("fog_density", fog_density);
- // For backwards compatibility
- shdata.uniform("eye_sky_dir", view_matrix.block<3, 3>(0, 0)*zenith_direction);
-
for(unsigned i=0; i<lights.size(); ++i)
if(lights[i])
lights[i]->update_shader_data(shdata, view_matrix, i);
DataFile::Loader::ActionMap Lighting::Loader::shared_actions;
Lighting::Loader::Loader(Lighting &l):
- DataFile::ObjectLoader<Lighting>(l)
+ CollectionObjectLoader<Lighting>(l, 0)
+{
+ set_actions(shared_actions);
+}
+
+Lighting::Loader::Loader(Lighting &l, Collection &c):
+ CollectionObjectLoader<Lighting>(l, &c)
{
set_actions(shared_actions);
}
add("fog_half_distance", &Loader::fog_half_distance);
add("horizon_angle", &Loader::horizon_angle);
add("light", &Loader::light);
+ add("light", &Loader::light_inline);
add("sky_color", &Loader::sky_color);
add("zenith_direction", &Loader::zenith_direction);
+
+ // Deprecated
+ add("light", &Loader::light_inline_index);
}
void Lighting::Loader::ambient(float r, float g, float b)
obj.set_horizon_angle(Geometry::Angle<float>::from_degrees(a));
}
-void Lighting::Loader::light(unsigned i)
+void Lighting::Loader::light(const string &name)
+{
+ obj.attach(get_collection().get<Light>(name));
+}
+
+void Lighting::Loader::light_inline()
{
RefPtr<Light> lgt = new Light;
load_sub(*lgt);
- obj.attach(i, *lgt);
+ obj.attach(*lgt);
obj.owned_data.push_back(lgt.release());
}
+void Lighting::Loader::light_inline_index(unsigned)
+{
+ light_inline();
+}
+
void Lighting::Loader::sky_color(float r, float g, float b)
{
obj.set_sky_color(Color(r, g, b));