#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
add("light", &Loader::light);
add("sky_color", &Loader::sky_color);
add("zenith_direction", &Loader::zenith_direction);
+
+ // Deprecated
+ add("light", &Loader::light_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()
{
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_index(unsigned)
+{
+ light_inline();
+}
+
void Lighting::Loader::sky_color(float r, float g, float b)
{
obj.set_sky_color(Color(r, g, b));
void fog_density(float);
void fog_half_distance(float);
void horizon_angle(float);
- void light(unsigned);
+ void light();
+ void light_index(unsigned);
void sky_color(float, float, float);
void zenith_direction(float, float, float);
};
distance is 50%. */
void set_fog_half_distance(float);
- /** Attaches a light source. */
- void attach(unsigned, const Light &);
+ /** Attaches a light source. If the light was already attached, does
+ nothing. */
+ void attach(const Light &);
- /** Detaches a light source. */
- void detach(unsigned);
+ /** Detaches a light source. If the light was not attached, does nothing. */
+ void detach(const Light &);
+
+ DEPRECATED void attach(unsigned, const Light &l) { attach(l); }
+ DEPRECATED void detach(unsigned);
/** Returns an attached light. If no light is attached at that index, null
is returned. */
- const Light *get_attached_light(unsigned) const;
+ DEPRECATED const Light *get_attached_light(unsigned) const;
+
+ const std::vector<const Light *> &get_attached_lights() const { return lights; }
/** Updates a ProgramData object with the uniforms for the Lighting,
including all attached light sources. A view matrix must be passed in. */
mouse.signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Viewer::axis_motion), false));
light.set_position(GL::Vector4(0, 0, 1, 0));
- lighting.attach(0, light);
+ lighting.attach(light);
camera.set_up_direction(GL::Vector3(0, 0, 1));
update_camera();