Index: branches/bsp_model/src/lib/collision_detection/cd_engine.cc
===================================================================
--- branches/bsp_model/src/lib/collision_detection/cd_engine.cc	(revision 7805)
+++ branches/bsp_model/src/lib/collision_detection/cd_engine.cc	(revision 7833)
@@ -29,5 +29,5 @@
 #include "quadtree_node.h"
 
-
+#include "bsp_manager.h"
 
 using namespace std;
@@ -137,13 +137,24 @@
  *  this checks the collisions with the ground
  */
-void CDEngine::checkCollisionGround()
+void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
 {
   if( likely( this->terrain != NULL))
   {
     Quadtree* q = dynamic_cast<Terrain*>(this->terrain)->ssp->getQuadtree();
-
 //    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
   }
-  //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor());
+  
+  if( likely( this->bspManager != NULL))
+  {
+    std::list<WorldEntity*>::iterator iterator;
+    PRINTF(3)("checking for collisions\n");
+
+    iterator = list1.begin();
+    while (iterator != list1.end())
+    {
+      bspManager->checkCollision(*iterator);
+      iterator++;
+    }
+  }
 }
 
Index: branches/bsp_model/src/lib/collision_detection/cd_engine.h
===================================================================
--- branches/bsp_model/src/lib/collision_detection/cd_engine.h	(revision 7805)
+++ branches/bsp_model/src/lib/collision_detection/cd_engine.h	(revision 7833)
@@ -17,4 +17,5 @@
 class OBBTree;
 class Terrain;
+class BspManager;
 //class Player;
 
@@ -50,4 +51,5 @@
 
   inline void setTerrain(Terrain* terrain) { this->terrain = terrain; }
+  inline void setBSPModel(BspManager* bspManager) { this->bspManager = bspManager; }
   //  inline void setPlayer(Player* player) { this->player = player; } /* only for debug purposes \todo: delete*/
 
@@ -56,5 +58,6 @@
 //  void checkCollisions();
   void checkCollisions(std::list<WorldEntity*>& list1, std::list<WorldEntity*>& list2);
-
+  void checkCollisionGround(std::list<WorldEntity*>& list1);
+  
   void drawBV(const std::list<WorldEntity*>& drawList ) const;
   void debug();
@@ -68,5 +71,5 @@
 
   void checkCollisionObjects();
-  void checkCollisionGround();
+
 
   void debugSpawnTree(int depth, sVec3D* vertices, int numVertices);
@@ -79,4 +82,5 @@
 
   Terrain*                terrain;                          //!< this it a ref to the terrain, serving as a ground for all WE
+  BspManager*             bspManager;
 //  Player*                 player;
 };
Index: branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 7805)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 7833)
@@ -32,6 +32,7 @@
 #include "movie_player.h"
 
-
-
+#include "cd_engine.h"
+
+#include "world_entity.h"
 
 BspManager::BspManager()
@@ -43,4 +44,6 @@
   this->root  = this->bspFile->get_root();
   this->alreadyVisible = new bool [this->bspFile->numFaces];
+
+  CDEngine::getInstance()->setBSPModel(this);
 }
 
@@ -77,6 +80,6 @@
 
 
- 
- // this->viewDir=    State::getCameraTarget()->getAbsCoor() -  State::getCamera()->getAbsCoor() ;
+
+  // this->viewDir=    State::getCameraTarget()->getAbsCoor() -  State::getCamera()->getAbsCoor() ;
   float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z);
 
@@ -88,18 +91,18 @@
 
   this->cam = State::getCameraTargetNode()->getAbsCoor();
- // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
+  // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
   this->outputStartsOut = true;
   this->outputAllSolid = false;
   this->outputFraction = 1.0f;
-  
+
   this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam);
-  
+
   if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam);
 
   if ( viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
   {
-   
-    
-    
+
+
+
     // Iterate through all Leafspublic final double readLEDouble()
     for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )
@@ -108,28 +111,26 @@
       leaf& curLeaf = (this->bspFile->leaves)[i];
       if(curLeaf.cluster<0) continue;
-     
-      
+
+
       /** Do Frustum culling and draw 'em all **/
       bool inFrustum = true;
 
       Vector dir;
-      dir.x = this->cam.x - State::getCameraTargetNode()->getLastAbsCoor().x;
-      dir.y = this->cam.y - State::getCameraTargetNode()->getLastAbsCoor().y;
-      dir.z = this->cam.z - State::getCameraTargetNode()->getLastAbsCoor().z;
+      dir.x = State::getCameraNode()->getAbsDirZ().x;
+      dir.y =  State::getCameraNode()->getAbsDirZ().y;
+      dir.z =  State::getCameraNode()->getAbsDirZ().z;
       float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
       //if(dist < 0) dist = -dist;
       const float dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] - dist ;
       const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist ;
-     
-      if(dMins < -30.0 && dMaxs < -30.0)
-      {    
-       //continue; 
+
+      if(dMins < -1.0 && dMaxs < -1.0) {
+        //continue;
       }
-      if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 3000  && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 3000)
-      {
-        //continue; 
+      if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 3000  && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 3000) {
+        //continue;
       }
-    
-       
+
+
       // Iterate through all faces
       for (int j = 0; j < curLeaf.n_leaffaces ; ++j) {
@@ -138,5 +139,5 @@
         if (f >=0 && !this->isAlreadyVisible(f)) {
           this->alreadyVisible[f] = true;
-          	
+
           addFace(f); // "visibleFaces.append(f)"
         }
@@ -147,8 +148,7 @@
 
     } //for
-  } 
-  else {
-
- 
+  } else {
+
+
     unsigned int v;
     unsigned char  visSet;
@@ -165,24 +165,23 @@
       visSet =((char*) (this->bspFile->visData))[v + 8];
 
-      // gets bit of visSet 
+      // gets bit of visSet
       if( ((visSet) & (1 << (cluster &  7))) != 0 ) {
-        
+
         // Frustum culling
-    
+
         Vector dir;
-        dir.x = this->cam.x - State::getCameraTargetNode()->getLastAbsCoor().x;
-        dir.y = this->cam.y - State::getCameraTargetNode()->getLastAbsCoor().y;
-        dir.z = this->cam.z - State::getCameraTargetNode()->getLastAbsCoor().z;
+        dir.x = State::getCameraNode()->getAbsDirX().x;
+        dir.y =  State::getCameraNode()->getAbsDirX().y;
+        dir.z =  State::getCameraNode()->getAbsDirX().z;
         const float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
-      //if(dist < 0) dist = -dist;
+        //if(dist < 0) dist = -dist;
         const float dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] - dist;
         const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist;
-     
-        if(dMins < -150.0 && dMaxs < -150.0)
-        {    
-        continue; 
+
+        if(dMins < -30.0 && dMaxs < -30.0) {
+          continue;
         }
-        
-        
+
+
         // Iterate through all faces
         for (int j = 0; j < curLeaf.n_leaffaces ; ++j) {
@@ -238,6 +237,5 @@
 
   if(this->lastTex != curFace.texture) {
-    if(this->bspFile->Materials[curFace.texture].animated)
-    {
+    if(this->bspFile->Materials[curFace.texture].animated) {
       glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
       glEnable(GL_BLEND);
@@ -248,9 +246,7 @@
       glBindTexture(GL_TEXTURE_2D, n );
       glDisable(GL_BLEND);
-    }
-    else
-    {
-    this->bspFile->Materials[curFace.texture].mat->select();
-    this->lastTex = curFace.texture;
+    } else {
+      this->bspFile->Materials[curFace.texture].mat->select();
+      this->lastTex = curFace.texture;
     }
   }
@@ -267,6 +263,6 @@
 
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-  
- // glColor4f(3.0,3.0,3.0,1.0);
+
+  // glColor4f(3.0,3.0,3.0,1.0);
   glEnableClientState(GL_VERTEX_ARRAY );
   glEnableClientState(GL_TEXTURE_COORD_ARRAY );
@@ -370,5 +366,5 @@
   glEnableClientState(GL_TEXTURE_COORD_ARRAY );
   for(int i = Face->n_meshverts -1; i >=0   ; i--) {
-   //glFrontFace(GL_CW);
+    //glFrontFace(GL_CW);
     //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);
 
@@ -382,5 +378,5 @@
     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
-  
+
 
 
@@ -390,5 +386,5 @@
 
 
-  //  glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
+    //  glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
 
 
@@ -436,20 +432,19 @@
   float startDistance;
   float endDistance;
-  
+
   float startFraction = -1.0f;
   float endFraction = 1.0f;
   bool startsOut = false;
   bool endsOut = false;
-  
+
   Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
   Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
 
-  for (int i = 0; i < curBrush->n_brushsides; i++)
-  {
+  for (int i = 0; i < curBrush->n_brushsides; i++) {
     brushside& curBrushSide =   this->bspFile->brushSides[curBrush->brushside + i]   ;
     plane& curPlane  =   this->bspFile->planes[curBrushSide.plane] ;
 
-       startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d;
-     endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d;
+    startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d;
+    endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d;
 
     if (startDistance > 0)
@@ -458,41 +453,33 @@
       endsOut = true;
 
-        // make sure the trace isn't completely on one side of the brush
-    if (startDistance > 0 && endDistance > 0)
-    {   // both are in front of the plane, its outside of this brush
+    // make sure the trace isn't completely on one side of the brush
+    if (startDistance > 0 && endDistance > 0) {   // both are in front of the plane, its outside of this brush
       return;
     }
-    if (startDistance <= 0 && endDistance <= 0)
-    {   // both are behind this plane, it will get clipped by another one
+    if (startDistance <= 0 && endDistance <= 0) {   // both are behind this plane, it will get clipped by another one
       continue;
     }
 
-        // MMM... BEEFY
-    if (startDistance > endDistance)
-    {   // line is entering into the brush
+    // MMM... BEEFY
+    if (startDistance > endDistance) {   // line is entering into the brush
       float fraction = (startDistance - EPSILON) / (startDistance - endDistance);  // *
       if (fraction > startFraction)
         startFraction = fraction;
-    }
-    else
-    {   // line is leaving the brush
+    } else {   // line is leaving the brush
       float fraction = (startDistance + EPSILON) / (startDistance - endDistance);  // *
       if (fraction < endFraction)
         endFraction = fraction;
     }
-    
-  }
-   if (startsOut == false)
-    {
-      this->outputStartsOut = false;
-      if (endsOut == false)
-        this->outputAllSolid = true;
-      return;
-    }
-
-  if (startFraction < endFraction)
-  {
-    if (startFraction > -1.0f && startFraction < outputFraction)
-    {
+
+  }
+  if (startsOut == false) {
+    this->outputStartsOut = false;
+    if (endsOut == false)
+      this->outputAllSolid = true;
+    return;
+  }
+
+  if (startFraction < endFraction) {
+    if (startFraction > -1.0f && startFraction < outputFraction) {
       if (startFraction < 0)
         startFraction = 0;
@@ -500,5 +487,5 @@
     }
   }
-  
+
 }
 
@@ -518,7 +505,7 @@
       //object *brush = &BSP.brushes[BSP.leafBrushes[leaf->firstLeafBrush + i]];
       if (curBrush.n_brushsides > 0   &&
-        ((((BspTexture*)(this->bspFile->textures))[curBrush.texture]).contents & 1)) 
-      // CheckBrush( brush );
-      this->checkBrushRay(&curBrush);
+          ((((BspTexture*)(this->bspFile->textures))[curBrush.texture]).contents & 1))
+        // CheckBrush( brush );
+        this->checkBrushRay(&curBrush);
       if(curBrush.n_brushsides <=0) this->outputAllSolid = true;
     }
@@ -548,5 +535,5 @@
       fraction2 = (startDistance + EPSILON) * inverseDistance;
     } else if (endDistance < startDistance) {
-      side = 0; // front(start)->x * (node->plane.x)+ 
+      side = 0; // front(start)->x * (node->plane.x)+
       float inverseDistance = 1.0f / (startDistance - endDistance);
       fraction1 = (startDistance + EPSILON) * inverseDistance;
@@ -596,4 +583,73 @@
 
 }
+
+
+void BspManager::checkCollision(WorldEntity* worldEntity)
+{
+
+  Vector position = worldEntity->getAbsCoor();
+
+
+  Vector forwardDir = worldEntity->getAbsDirX();
+  forwardDir.x =10*forwardDir.x;
+  forwardDir.y =10*forwardDir.y;
+  forwardDir.z =10*forwardDir.z;
+  
+  Vector upDir = worldEntity->getAbsDirY();
+  Vector dest = position;
+  dest.x  += forwardDir.x;
+  dest.y  += forwardDir.y;
+  dest.z  += forwardDir.z;
+  Vector out = Vector(-1875.0,-1875.0,-1875.0);
+  if(!worldEntity->isA(CL_PLAYABLE)) {
+  }
+  else {
+    bool collision = false;
+    Vector position1 = position + Vector(0.0,0.1,0.0);
+    Vector position2 = position + Vector(0.0,0.2,0.0);
+    Vector dest1 = position1 + forwardDir;
+    Vector dest2 = position2 + forwardDir;
+    dest = position - upDir;
+    Vector out1;
+    Vector out2;
+
+    this->checkCollisionRay(this->root,0.0f,1.0f, &position1, &dest1 );
+    if(this->outputFraction == 1.0f)  out1 = dest;
+    else {
+      collision = true;
+      out1.x = position1.x + (dest1.x -position1.x) * this->outputFraction;
+      out1.y = position1.y + (dest1.y -position1.y) * this->outputFraction;
+      out1.z = position1.z + (dest1.z - position1.z) * this->outputFraction;
+
+    }
+
+    this->checkCollisionRay(this->root,0.0f,1.0f, &position2, &dest2 );
+    if(this->outputFraction == 1.0f) out2= dest;
+    else
+    {
+      collision = true;
+    out2.x = position2.x + (dest2.x -position2.x) * this->outputFraction;
+    out2.y = position2.y + (dest2.y -position2.y) * this->outputFraction;
+    out2.z = position2.z + (dest2.z - position2.z) * this->outputFraction;
+
+    }
+    
+    this->checkCollisionRay(this->root,0.0f,1.0f, &position, &dest );
+    if(this->outputFraction == 1.0f) out = dest;
+    else
+    {
+    collision = true;
+    out.x = position.x + (dest.x -position.x) * this->outputFraction;
+    out.y = position.y + (dest.y -position.y) * this->outputFraction;
+    out.z = position.z + (dest.z -position.z) * this->outputFraction;
+  
+    }
+   
+    if(collision) worldEntity->collidesWithGround(out,out1,out2);
+  
+  }
+
+}
+
 void  BspManager::checkCollision(BspTreeNode* node, Vector* cam)
 {
@@ -625,9 +681,9 @@
 
     if (camLeaf.cluster < 0) {
-                              this->drawDebugCube(&this->cam); 
-                              this->drawDebugCube(&next);
-                              State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
-                              State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
-                              }
+      this->drawDebugCube(&this->cam);
+      this->drawDebugCube(&next);
+      State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
+      State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
+    }
 
 
Index: branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_manager.h	(revision 7805)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_manager.h	(revision 7833)
@@ -25,4 +25,5 @@
 struct face;
 struct brush;
+class WorldEntity;
 
 class BspManager
@@ -38,4 +39,5 @@
   void draw_patch(face* Face);
 
+  void checkCollision(WorldEntity* worldEntity);
 
 private:
