Index: orxonox/trunk/src/light.cc
===================================================================
--- orxonox/trunk/src/light.cc	(revision 3436)
+++ orxonox/trunk/src/light.cc	(revision 3437)
@@ -23,4 +23,7 @@
 using namespace std;
 
+//! Definition of the Lights
+int lightsV[] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7};
+
 
 /**
@@ -29,11 +32,11 @@
 Light::Light () 
 {
-  this->init();
-}
-
-Light::Light(Vector position)
-{
-  this->init();
-  this->setPosition(position);
+  this->setClassName ("Light");
+
+  glEnable (GL_LIGHTING);
+  this->lights = new LightValue*[NUMBEROFLIGHTS];
+  for (int i = 0; i < NUMBEROFLIGHTS; i++)
+    lights[i] = NULL;
+  this->currentLight = new LightValue;
 }
 
@@ -46,5 +49,22 @@
 {
   glDisable(GL_LIGHTING);
-  glDisable(GL_LIGHT0);
+  
+  for (int i = 0; i < NUMBEROFLIGHTS; i++)
+    this->deleteLight(i);
+  delete lights;
+  Light::singletonRef = NULL;
+}
+
+Light* Light::singletonRef = NULL;
+
+/**
+   \returns The Instance of the Lights
+*/
+Light* Light::getInstance(void)
+{
+  if (singletonRef)
+    return singletonRef;
+  else
+    return Light::singletonRef = new Light();
 }
 
@@ -52,16 +72,84 @@
    \brief initializes a new Light with default values, and enables GL_LIGHTING
 */
-void Light::init()
-{
-  this->setClassName ("Light");
-  glEnable (GL_LIGHTING);
-  glEnable (GL_LIGHT0);
+void Light::init(int lightNumber)
+{
+  PRINTF(3)("initializing Light number %d.\n", lightNumber);
+  // enable The light
+  glEnable(lightsV[lightNumber]);
+  this->currentLight = lights[lightNumber] = new LightValue;
   
+  // set default values
+  this->currentLight->lightNumber = lightNumber;
   this->setPosition(Vector(0.0, 0.0, 0.0));
   this->setDiffuseColor(1.0, 1.0, 1.0);
   this->setSpecularColor(1.0, 1.0, 1.0);
   //  lmodelAmbient[] = {.1, .1, .1, 1.0};
-  
-}
+}
+
+/**
+   \brief Adds a new Light, by selecting the First free slot.
+
+   if no slot is free error
+*/
+int Light::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 Light::addLight(int lightNumber)
+{
+  if (this->lights[lightNumber])
+    {
+      PRINTF(2)("Lightslot %d is allready taken, trying another one\n", lightNumber);
+      return this->addLight();
+    }
+  this->init(lightNumber);
+  this->currentLight = this->lights[lightNumber];
+  return lightNumber;
+}
+
+/**
+   \brief select the light to work with
+   \param lightNumber the light to work with
+*/
+void Light::editLightNumber(int lightNumber)
+{
+  this->currentLight = lights[lightNumber];
+}
+
+/**
+   \brief Delete the current Light
+*/
+void Light::deleteLight(void)
+{
+  this->deleteLight(this->currentLight->lightNumber);
+}
+
+/**
+   \brief delete light.
+   \param lightnumber the number of the light to delete
+*/
+void Light::deleteLight(int lightNumber)
+{
+  if (this->lights[lightNumber])
+    {
+      PRINTF(3)("deleting Light number %d\n", lightNumber);
+      delete this->lights[lightNumber];
+      glDisable(lightsV[lightNumber]);
+      this->lights[lightNumber] = NULL;
+    }
+}
+
+
 
 // set Attributes
@@ -73,11 +161,20 @@
 void Light::setPosition(Vector position)
 {
-  this->lightPosition[0] = position.x;
-  this->lightPosition[1] = position.y;
-  this->lightPosition[2] = position.z;
-  this->lightPosition[3] = 0.0;
-
-  glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
-
+  this->currentLight->lightPosition[0] = position.x;
+  this->currentLight->lightPosition[1] = position.y;
+  this->currentLight->lightPosition[2] = position.z;
+  this->currentLight->lightPosition[3] = 0.0;
+
+  glLightfv (GL_LIGHT0, GL_POSITION, this->currentLight->lightPosition);
+}
+
+void Light::setPosition(GLfloat x, GLfloat y, GLfloat z)
+{
+  this->currentLight->lightPosition[0] = x;
+  this->currentLight->lightPosition[1] = y;
+  this->currentLight->lightPosition[2] = z;
+  this->currentLight->lightPosition[3] = 0.0;
+
+  glLightfv (GL_LIGHT0, GL_POSITION, this->currentLight->lightPosition);
 }
 
@@ -90,10 +187,10 @@
 void Light::setDiffuseColor(GLfloat r, GLfloat g, GLfloat b)
 {
-  this->diffuseColor[0] = r;
-  this->diffuseColor[1] = g;
-  this->diffuseColor[2] = b;
-  this->diffuseColor[3] = 1.0;
-
-  glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuseColor);
+  this->currentLight->diffuseColor[0] = r;
+  this->currentLight->diffuseColor[1] = g;
+  this->currentLight->diffuseColor[2] = b;
+  this->currentLight->diffuseColor[3] = 1.0;
+
+  glLightfv (GL_LIGHT0, GL_DIFFUSE, this->currentLight->diffuseColor);
 }
 
@@ -107,10 +204,10 @@
 void Light::setSpecularColor(GLfloat r, GLfloat g, GLfloat b)
 {
-  this->specularColor[0] = r;
-  this->specularColor[1] = g;
-  this->specularColor[2] = b;
-  this->specularColor[3] = 1.0;
-
-  glLightfv (GL_LIGHT0, GL_SPECULAR, specularColor);
+  this->currentLight->specularColor[0] = r;
+  this->currentLight->specularColor[1] = g;
+  this->currentLight->specularColor[2] = b;
+  this->currentLight->specularColor[3] = 1.0;
+
+  glLightfv (GL_LIGHT0, GL_SPECULAR, this->currentLight->specularColor);
 }
 
@@ -122,5 +219,5 @@
 Vector Light::getPosition(void)
 {
-  Vector tmpPosition(lightPosition[0], lightPosition[1], lightPosition[2]);
+  Vector tmpPosition(this->currentLight->lightPosition[0], this->currentLight->lightPosition[1], this->currentLight->lightPosition[2]);
   return tmpPosition;
 }
