Index: orxonox/trunk/src/lib/graphics/light.cc
===================================================================
--- orxonox/trunk/src/lib/graphics/light.cc	(revision 4735)
+++ orxonox/trunk/src/lib/graphics/light.cc	(revision 4736)
@@ -45,46 +45,42 @@
 
 /**
-   \param lightNumber the Light Number to initiate
-*/
-Light::Light(int lightNumber)
-{
-  this->init(lightNumber);
-}
-
-/**
  * \param root The XML-element to load the Light from
  */
  Light::Light(const TiXmlElement* root)
 {
-  this->init(1);
-  this->loadParams(root);
-}
-
-/**
-   \brief destroys a Light
-*/
-Light::~Light(void)
-{
-  glDisable(lightsV[this->lightNumber]);
-}
-
-/**
- * \brief initializes a Light
- */
-void Light::init(int lightNumber)
-{
+  this->lightNumber = LightManager::getInstance()->registerLight(this);
+
   this->setClassID(CL_LIGHT, "Light");
   char tmpName[10];
-  sprintf(tmpName, "Light[%d]", lightNumber);
+  sprintf(tmpName, "Light[%d]", this->lightNumber);
   this->setName(tmpName);
 
-  PRINTF(4)("initializing Light number %d.\n", lightNumber);
+  PRINTF(4)("initializing Light number %d.\n", this->lightNumber);
   // enable The light
-  glEnable(lightsV[lightNumber]); // postSpawn
+  glEnable(lightsV[this->lightNumber]); // postSpawn
 
   // set values (defaults)
-  this->lightNumber = lightNumber;
   this->setDiffuseColor(1.0, 1.0, 1.0);
   this->setSpecularColor(1.0, 1.0, 1.0);
+
+  this->loadParams(root);
+
+}
+
+/**
+   \brief destroys a Light
+*/
+Light::~Light(void)
+{
+  glDisable(lightsV[this->lightNumber]);
+
+  LightManager::getInstance()->unregisterLight(this);
+}
+
+/**
+ * \brief initializes a Light
+ */
+void Light::init()
+{
 }
 
@@ -187,5 +183,5 @@
    \brief draws this Light. Being a World-entity the possibility to do this lies at hand.
 */
-void Light::draw()
+void Light::draw() const
 {
   float pos[4] = {this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z, 1.0};
@@ -245,5 +241,5 @@
   glDisable(GL_LIGHTING);
 
-  // this will be done either by worldEntity, or by pNode as each light is one of them
+  // this will be done either by PNode-tree as each light is one of them
   //  for (int i = 0; i < NUMBEROFLIGHTS; i++)
   //    this->deleteLight(i);
@@ -252,17 +248,8 @@
 }
 
-
 /**
    \brief singleton-Reference to the Light-class
 */
 LightManager* LightManager::singletonRef = NULL;
-
-/**
-   \brief initializes a new Light with default values, and enables GL_LIGHTING
-*/
-void LightManager::initLight(int lightNumber)
-{
-  lights[lightNumber] = new Light(lightNumber);
-}
 
 /**
@@ -292,98 +279,4 @@
   }
 }
-
-/**
-   \brief Adds a new Light, by selecting the First free slot.
-
-   if no slot is free error
-*/
-int LightManager::addLight(void)
-{
-  for (int i = 0; i < NUMBEROFLIGHTS; i++)
-    if (!this->lights[i])
-      return addLight(i);
-  PRINTF(1)("no more light slots availiable. All %d already taken\n", NUMBEROFLIGHTS);
-  return -1;
-}
-
-
-/**
-   \brief Adds a new Light
-   \param lightNumber The number of the light to add.
-
-   if the Number is not free: warn, automatically choose another slot.
-*/
-int LightManager::addLight(int lightNumber)
-{
-  if (this->lights[lightNumber])
-    {
-      PRINTF(2)("Lightslot %d is allready taken, trying another one\n", lightNumber);
-      return this->addLight();
-    }
-  this->initLight(lightNumber);
-  this->currentLight = this->lights[lightNumber];
-  return lightNumber;
-}
-
-
-/**
-   \brief select the light to work with
-   \param lightNumber the light to work with
-*/
-void LightManager::editLightNumber(int lightNumber)
-{
-  if (!this->currentLight)
-    {
-      PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n");
-      return;
-    }
-  this->currentLight = lights[lightNumber];
-}
-
-
-/**
-   \brief Delete the current Light
-*/
-void LightManager::deleteLight(void)
-{
-  if (!this->currentLight)
-    {
-      PRINTF(1)("no Light defined yet. So you cannot delete any Light right now.\n");
-      return;
-    }
-
-  this->deleteLight(this->currentLight->getLightNumber());
-}
-
-
-/**
-   \brief delete light.
-   \param lightNumber the number of the light to delete
-*/
-void LightManager::deleteLight(int lightNumber)
-{
-  if (this->lights[lightNumber])
-    {
-      PRINTF(4)("deleting Light number %d\n", lightNumber);
-      delete this->lights[lightNumber];
-      this->lights[lightNumber] = NULL;
-    }
-}
-
-
-/**
-   \brief draws all the Lights in their appropriate position
-*/
-void LightManager::draw()
-{
-  glMatrixMode(GL_MODELVIEW);
-  glLoadIdentity();
-  PRINTF(4)("Drawing the Lights\n");
-  for (int i = 0; i < NUMBEROFLIGHTS; i++)
-    if (this->lights[i])
-      lights[i]->draw();
-}
-
-
 
 // set Attributes
@@ -404,93 +297,41 @@
 }
 
-/**
-   \brief sets an emitting Diffuse color of the currently selected Light
-   \param r red
-   \param g green
-   \param b blue
-*/
-void LightManager::setDiffuseColor(GLfloat r, GLfloat g, GLfloat b)
-{
-  if (!this->currentLight)
+int LightManager::registerLight(Light* light)
+{
+  for (int i = 0; i < NUMBEROFLIGHTS; i++)
+    if (!this->lights[i])
+  {
+    this->lights[i]=light;
+    return i;
+  }
+  PRINTF(1)("no more light slots availiable. All %d already taken\n", NUMBEROFLIGHTS);
+  return -1;
+}
+
+void LightManager::unregisterLight(Light* light)
+{
+  for (int i = 0; i < NUMBEROFLIGHTS; i++)
+  {
+    if (this->lights[i] == light)
     {
-      PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n");
-      return;
+      this->lights[i] == NULL;
     }
-  this->currentLight->setDiffuseColor(r,g,b);
-}
-
-
-/**
-   \brief sets an emitting Specular color of the currently selected Light
-   \param r red
-   \param g green
-   \param b blue
-*/
-void LightManager::setSpecularColor(GLfloat r, GLfloat g, GLfloat b)
-{
-  if (!this->currentLight)
-    {
-      PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n");
-      return;
-    }
-  this->currentLight->setSpecularColor(r, g, b);
-}
-
-
-/**
-   \brief Sets the AttenuationType of th currently selecte LightSource Light Source
-   \param constantAttenuation The Constant Attenuation of the Light
-   \param linearAttenuation The Linear Attenuation of the Light
-   \param quadraticAttenuation The Quadratic Attenuation of the Light
-*/
-void LightManager::setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation)
-{
-  if (!this->currentLight)
-    {
-      PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n");
-      return;
-    }
-  this->currentLight->setAttenuation(constantAttenuation, linearAttenuation, quadraticAttenuation);
-}
-
-
-/**
-   \brief stets the direction of the Spot Light.
-   \param direction The direction of the Spot Light.
-*/
-void LightManager::setSpotDirection(Vector direction)
-{
-  if (!this->currentLight)
-    {
-      PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n");
-      return;
-    }
-  this->currentLight->setSpotDirection(direction);
-}
-
-
-/**
-   \brief sets the cutoff angle of the Light.
-   \param cutoff The cutoff angle.
-*/
-void LightManager::setSpotCutoff(GLfloat cutoff)
-{
-  if (!this->currentLight)
-    {
-      PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n");
-      return;
-    }
-  this->currentLight->setSpotCutoff(cutoff);
-}
-
-/**
-   \returns a pointer to a Light
-   \param lightNumber The light to request the pointer from
-*/
-Light* LightManager::getLight(int lightNumber) const
-{
-  return this->lights[lightNumber];
-}
-
+  }
+  PRINTF(2)("Light %p could not be unloaded (this should not heappen\n)");
+  return;
+}
+
+/**
+   \brief draws all the Lights in their appropriate position
+ */
+void LightManager::draw() const
+{
+  glMatrixMode(GL_MODELVIEW);
+  glLoadIdentity();
+  PRINTF(4)("Drawing the Lights\n");
+  for (int i = 0; i < NUMBEROFLIGHTS; i++)
+    if (this->lights[i])
+      lights[i]->draw();
+}
 
 /**
Index: orxonox/trunk/src/lib/graphics/light.h
===================================================================
--- orxonox/trunk/src/lib/graphics/light.h	(revision 4735)
+++ orxonox/trunk/src/lib/graphics/light.h	(revision 4736)
@@ -26,9 +26,8 @@
 {
  public:
-  Light(int lightNumber);
-  Light(const TiXmlElement* root);
+  Light(const TiXmlElement* root = NULL);
   virtual ~Light(void);
 
-  void init(int lightNumber);
+  void init();
   void loadParams(const TiXmlElement* root);
 
@@ -43,5 +42,5 @@
   int getLightNumber(void) const {return this->lightNumber;}
 
-  virtual void draw();
+  virtual void draw() const;
 
   void debug(void) const;
@@ -66,13 +65,10 @@
 
    <b>Usage:</b>\n
-   First you have to get the Light Manager up and running by using LightManager::getInstance.
+   First you have to get the Light Manager up and running by using LightManager::getInstance().
    This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n
    Then you will create a new light using:
-   \li int addLight(void);
-   \li int addLight(int lightNumber);
+   \li new Light();
 
    now you can operate on the light as follows:
-   \li void setPosition(Vector position);
-   \li void setPosition(GLfloat x, GLfloat y, GLfloat z);
    \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
    \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
@@ -80,13 +76,8 @@
    \li void setSpotDirection(Vector direction);
    \li void setSpotCutoff(GLfloat cutoff);
-
-   These functions are preatty selv-explaining, but you can read about them below.\n
-   If you want to fetch info, or the a Light use:
-   \li Vector getPosition(void) const;
-   \li Vector getPosition(int lightNumber) const;
-   \li Light* getLight(int LightNumber) const;
+   \li all PNode stuff also works
 
    To redraw the light use
-   \li void draw();
+   \li void draw() const;
 
    and to delete one just use
@@ -97,5 +88,5 @@
 
    You can also operate on the single Lights themselves, by first retreaving them with
-   \li Light* getLight(int LightNumber);
+   \li Light* getLight(int LightNumber) const;
    \n
    and then using the same functions on this to change settings.
@@ -103,4 +94,5 @@
 class LightManager : public BaseObject
 {
+  friend class Light;
 
  public:
@@ -112,36 +104,18 @@
   void loadLights(const TiXmlElement* root);
 
-  // set Attributes
-  int addLight(void);
-  int addLight(int lightNumber);
-  void editLightNumber(int lightNumber);
-  void deleteLight(void);
-  void deleteLight(int lightNumber);
-
   void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
 
-  void draw();
+  Light* getLight(int lightNumber) const;
+  inline Light* getLight() const { return this->currentLight; };
 
-  //set Attributes
-  void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
-  void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
-  void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
-  void setSpotDirection(Vector direction);
-  void setSpotCutoff(GLfloat cutoff);
-
-  // get Attributes
-  Vector getPosition(void) const;
-  Vector getPosition(int lightNumber) const;
-
-  Light* getLight(int lightNumber) const;
-  Light* getLight() const { return this->currentLight; };
+  void draw() const;
 
   void debug(void) const;
 
-
  private:
   LightManager(void);
-  void initLight(int LightNumber);
 
+  int  registerLight(Light* light);
+  void unregisterLight(Light* light);
 
  private:
