Index: orxonox/branches/shadows/src/shadow.cc
===================================================================
--- orxonox/branches/shadows/src/shadow.cc	(revision 3680)
+++ orxonox/branches/shadows/src/shadow.cc	(revision 3706)
@@ -39,7 +39,8 @@
 */
 
-Shadow::Shadow(Model* player,float* groundVertexes)
+Shadow::Shadow(OBJModel* player,Player* playerangle,float groundVertexes[])
 {
     this->player=player;
+    this->playerangle=playerangle;
 }
 
@@ -88,5 +89,5 @@
     glNewList(this->player_id,GL_COMPILE);
     
-    //blabla
+    this->player->draw();
     
     glEndList();    
@@ -94,9 +95,5 @@
     this->image=(unsigned char*)malloc(SIZE*SIZE*4);
     
-    //this->player_id=newList {glNormalefv;glVertex3fv}
-    //this->ground_id=newList {glTexCoord2fv;glNormal3fv;glVertex3fv}
-    
-    
-    //lightPos[] blabla
+
 }
 
@@ -117,8 +114,11 @@
     glLoadIdentity();
     
-    //gluLookAt(light0,light1,light2,player0,player1,player2,0,0,1);
+    gluLookAt(this->lightPos[0],this->lightPos[1],this->lightPos[2],this->playerPos[0],this->playerPos[1],this->playerPos[2],0,0,1);
     
     glColor3f(.4,.4,.4);
-    //glTranslatef(player0,player1,player2);
+    glTranslatef(this->playerPos[0],this->playerPos[1],this->playerPos[2]);
+    glRotatef(this->playerangle->angle,1.0,0.0,0.0);
+    
+    
     glCallList(this->player_id);
     glColor3f(1,1,1);
@@ -134,8 +134,37 @@
 }
 
+
+/** 
+    brief updatePosition is used in the same kind as for skysphere, because
+    the light has got a static orientation(parallel light), we have to always 
+    add the same relative coordinates being 0,10,19 to the players position
+    in order to receive the lightPosition. This is needed to calculate the Shadow!!
+
+*/
+
+void Shadow::updatePosition(float x,float y,float z)
+{
+    this->playerPos[0]=x;
+    this->playerPos[1]=y;
+    this->playerPos[2]=z;
+    
+    this->lightPos[0]=this->playerPos[0];
+    this->lightPos[1]=this->playerPos[1]+10;
+    this->lightPos[2]=this->playerPos[2]+19;
+
+    
+}
+/**
+
+    brief m_inverse simply inverses the *m matrix and stores the result back
+    to *out. This is needed further down in the draw() method
+
+
+*/
+
 void Shadow::m_inverse(const float *m,float *out)
 {
     float det;
-    det=m[0]*m[5]*m[10];
+    det=  m[0]*m[5]*m[10];
     det+= m[4]*m[9]*m[2];
     det+= m[8]*m[1]*m[6];
@@ -143,6 +172,30 @@
     det-= m[4]*m[1]*m[10];
     det-= m[0]*m[9]*m[6];
-}
-
+    
+    if(det!= 0.0)
+	det=1.0/det;
+    out[0]=  (m[5]*m[10]-m[9]*m[6])*det;
+    out[1]= -(m[1]*m[10]-m[9]*m[2])*det;
+    out[2]=  (m[1]*m[6]-m[5]*m[2])*det;
+    out[3]= 0.0;
+    out[4]= -(m[4]*m[10]-m[8]*m[6])*det;
+    out[5]=  (m[0]*m[10]-m[8]*m[2])*det;
+    out[6]= -(m[0]*m[6]-m[4]*m[2])*det;
+    out[7]= 0.0;
+    out[8]=  (m[4]*m[9]-m[8]*m[5])*det;
+    out[9]= -(m[0]*m[9]-m[8]*m[1])*det;
+    out[10]= (m[0]*m[5]-m[4]*m[1])*det;
+    out[11]= 0.0;
+    out[12]=- (m[12]*out[0]+m[13]*out[4]+m[14]*out[8]);
+    out[13]=- (m[12]*out[1]+m[13]*out[5]+m[14]*out[9]);
+    out[14]=- (m[12]*out[2]+m[13]*out[6]+m[14]*out[10]);
+    out[15]= 1.0;
+
+
+}
+
+/**
+    brief Method draw() is called after each tick() from the world.cc class
+*/
 
 void Shadow::draw()
@@ -151,5 +204,5 @@
     createShadow();
     
-    glClearColor(0,0,0,0);
+    /*glClearColor(0,0,0,0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glMatrixMode(GL_PROJECTION);
@@ -159,6 +212,6 @@
     glLoadIdentity();
     
-    //gluLookAt(camera0,camera1,camera2,player0,player1,player2,0,0,1);
-    
+    gluLookAt(this->cameraPos[0],this->cameraPos[1],this->cameraPos[2],this->playerPos[0],this->playerPos[1],this->playerPos[2],0,0,1);
+    */
     glEnable(GL_TEXTURE_GEN_S);
     glEnable(GL_TEXTURE_GEN_T);
@@ -166,4 +219,28 @@
     glEnable(GL_TEXTURE_GEN_Q);
     glGetFloatv(GL_MODELVIEW_MATRIX,m);
+    m_inverse(m,im);
+    glMatrixMode(GL_TEXTURE);
+    glLoadIdentity();
+    glTranslatef(0.5,0.5,1.0);
+    glOrtho(-1,1,-1,1,-1,1);
+    
+    gluLookAt(this->lightPos[0],this->lightPos[1],this->lightPos[2],this->playerPos[0],this->playerPos[1],this->playerPos[2],0,0,1);
+    
+    glMultMatrixf(im);
+    glEnable(GL_TEXTURE_2D),
+    glBindTexture(GL_TEXTURE_2D,this->shadow_id);
+    glEnable(GL_BLEND);
+    glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
+    glCallList(ground_id);
+    glDisable(GL_BLEND);
+    
+    glLoadIdentity();
+    glMatrixMode(GL_MODELVIEW);
+    glDisable(GL_TEXTURE_GEN_S);
+    glDisable(GL_TEXTURE_GEN_T);
+    glDisable(GL_TEXTURE_GEN_R);
+    glDisable(GL_TEXTURE_GEN_Q);
+    
+    
     
 }
