00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SG_DIRECTIONAL_LIGHT_BIN_HXX
00023 #define SG_DIRECTIONAL_LIGHT_BIN_HXX
00024
00025 class SGDirectionalLightBin {
00026 public:
00027 struct Light {
00028 Light(const SGVec3f& p, const SGVec3f& n, const SGVec4f& c) :
00029 position(p), normal(n), color(c)
00030 { }
00031 SGVec3f position;
00032 SGVec3f normal;
00033 SGVec4f color;
00034 };
00035 typedef std::vector<Light> LightList;
00036
00037 void insert(const Light& light)
00038 { _lights.push_back(light); }
00039 void insert(const SGVec3f& p, const SGVec3f& n, const SGVec4f& c)
00040 { insert(Light(p, n, c)); }
00041
00042 unsigned getNumLights() const
00043 { return _lights.size(); }
00044 const Light& getLight(unsigned i) const
00045 { return _lights[i]; }
00046
00047
00048 struct DirectionLess {
00049 DirectionLess(const SGVec3f& direction) :
00050 _direction(direction)
00051 { }
00052 inline bool operator() (const Light& l, const Light& r) const
00053 { return dot(_direction, l.position) < dot(_direction, r.position); }
00054 private:
00055 SGVec3f _direction;
00056 };
00057 typedef std::multiset<Light,DirectionLess> LightSet;
00058
00059 LightList getSortedLights(const SGVec3f& sortDirection) const
00060 {
00061 LightSet lightSet = LightSet(DirectionLess(sortDirection));
00062 for (unsigned i = 0; i < _lights.size(); ++i)
00063 lightSet.insert(_lights[i]);
00064
00065 LightList sortedLights;
00066 sortedLights.reserve(_lights.size());
00067 for (LightSet::const_iterator i = lightSet.begin(); i != lightSet.end(); ++i)
00068 sortedLights.push_back(*i);
00069
00070 return sortedLights;
00071 }
00072
00073 private:
00074 LightList _lights;
00075 };
00076
00077 #endif