Text archives Help
- From: "James Bigler" <bigler@cs.utah.edu>
- To: manta@sci.utah.edu
- Subject: [Manta] r2105 - trunk/Interface
- Date: Thu, 21 Feb 2008 09:45:49 -0700 (MST)
Author: bigler
Date: Thu Feb 21 09:45:48 2008
New Revision: 2105
Modified:
trunk/Interface/LightSet.cc
trunk/Interface/LightSet.h
Log:
Interface/LightSet.cc
Interface/LightSet.h
Added remove function. Use with caution with respect to changing the global
light set, as it doesn't handle cases where materials have a local light
sets.
Changed integral accessor to size_t from int. This is consistent with the
vector interface.
Made all private member variables start with underscore ('_').
Modified: trunk/Interface/LightSet.cc
==============================================================================
--- trunk/Interface/LightSet.cc (original)
+++ trunk/Interface/LightSet.cc Thu Feb 21 09:45:48 2008
@@ -9,21 +9,29 @@
#include <iostream>
#include <sstream>
+#include <algorithm>
using namespace Manta;
using namespace std;
+void LightSet::remove(Light* light)
+{
+ vector<Light*>::iterator iter = find(_lights.begin(), _lights.end(),
light);
+ if (iter != _lights.end())
+ _lights.erase(iter);
+}
+
LightSet* LightSet::merge(LightSet* l1, LightSet* l2)
{
LightSet* r = new LightSet();
// L1 takes precedence for ambient lights
- if(l1->ambientLight)
- r->ambientLight = l1->ambientLight;
+ if(l1->_ambientLight)
+ r->_ambientLight = l1->_ambientLight;
else
- r->ambientLight = l2->ambientLight;
- for(int i=0;i<l1->numLights();i++)
+ r->_ambientLight = l2->_ambientLight;
+ for(size_t i = 0; i < l1->numLights(); i++)
r->add(l1->getLight(i));
- for(int i=0;i<l2->numLights();i++)
+ for(size_t i = 0; i < l2->numLights(); i++)
r->add(l2->getLight(i));
return r;
}
@@ -32,28 +40,28 @@
{
// This won't work in many of the shadow algorithms
// Call preprocess on ambient light.
- ambientLight->preprocess(context);
-
+ _ambientLight->preprocess(context);
+
// Call preprocess on each light.
- for(unsigned int i=0;i<lights.size();++i){
- lights[i]->preprocess(context);
+ for(size_t i = 0; i < _lights.size(); ++i) {
+ _lights[i]->preprocess(context);
}
}
string LightSet::toString() const {
ostringstream out;
- out << "ambientLight = "<<ambientLight<<"\n";
- if (ambientLight)
- out << ambientLight->toString();
- out << "Num lights = "<<lights.size()<<"\n";
- for(int i = 0; i < static_cast<int>(lights.size()); i++) {
- out << "lights["<<i<<"] = "<<lights[i]<<"\n";
+ out << "ambientLight = "<<_ambientLight<<"\n";
+ if (_ambientLight)
+ out << _ambientLight->toString();
+ out << "Num lights = "<<_lights.size()<<"\n";
+ for(size_t i = 0; i < _lights.size(); ++i) {
+ out << "lights["<<i<<"] = "<<_lights[i]<<"\n";
}
return out.str();
}
void LightSet::readwrite(ArchiveElement* archive)
{
- archive->readwrite("lights", lights);
- archive->readwrite("ambientLight", ambientLight);
+ archive->readwrite("lights", _lights);
+ archive->readwrite("ambientLight", _ambientLight);
}
Modified: trunk/Interface/LightSet.h
==============================================================================
--- trunk/Interface/LightSet.h (original)
+++ trunk/Interface/LightSet.h Thu Feb 21 09:45:48 2008
@@ -14,24 +14,31 @@
class LightSet {
public:
- LightSet() : ambientLight(0) { }
- LightSet( int size_ ) : lights( size_ ), ambientLight(0) { }
+ LightSet() : _ambientLight(0) { }
+ LightSet( size_t size ) : _lights( size ), _ambientLight(0) { }
~LightSet() { }
// Get and set the ambient light for the scene.
- const AmbientLight* getAmbientLight() const { return ambientLight; }
- void setAmbientLight(AmbientLight* newamb) { ambientLight = newamb; }
-
+ const AmbientLight* getAmbientLight() const { return _ambientLight; }
+ void setAmbientLight(AmbientLight* newamb) { _ambientLight = newamb; }
+
// Determine the size of the light set.
- int numLights() const { return static_cast<int>(lights.size()); }
+ size_t numLights() const { return _lights.size(); }
+
+ // Append a light to the light set. Note that if the renderer has
already
+ // started preprocess will not be called on new lights.
+ void add(Light* light) { _lights.push_back(light); }
+
+ // Remove the light from the list. This can have rerecusions if local
+ // LightSet objects are being used in a material, as we can't track this
+ // light to them. It is up to the external entity managing the scene to
+ // make sure consistency is observed. USE WITH EXTREME CAUTION.
+ void remove(Light* light);
- // Append a light to the light set.
- void add(Light* light) { lights.push_back(light); }
-
// Accessors.
- const Light* getLight(int which) const { return lights[which]; }
- Light* getLight(int which) { return lights[which]; }
-
+ const Light* getLight(size_t which) const { return _lights[which]; }
+ Light* getLight(size_t which) { return _lights[which]; }
+
// Combine two light sets.
static LightSet* merge(LightSet* l1, LightSet* l2);
@@ -45,8 +52,8 @@
LightSet(const LightSet&);
LightSet& operator=(const LightSet&);
- vector<Light*> lights;
- AmbientLight* ambientLight;
+ vector<Light*> _lights;
+ AmbientLight* _ambientLight;
};
}
- [Manta] r2105 - trunk/Interface, James Bigler, 02/21/2008
Archive powered by MHonArc 2.6.16.