Index: trunk/src/lib/collision_detection/cd_engine.cc
===================================================================
--- trunk/src/lib/collision_detection/cd_engine.cc	(revision 9062)
+++ trunk/src/lib/collision_detection/cd_engine.cc	(revision 9110)
@@ -45,4 +45,6 @@
 
   this->bAbordOnFirstCollision = false;
+  
+  this->terrain = NULL;
 }
 
Index: trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc
===================================================================
--- trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc	(revision 9062)
+++ trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc	(revision 9110)
@@ -70,12 +70,13 @@
 
 
-  float CR_MAX_WALK_HEIGHT = 2.0f;
+  float CR_MAX_WALK_HEIGHT = 15.0f;
   float CR_THRESHOLD = 0.2f;
 
-  float height = 0;
-  float front = 0;
-  float side = 0;
-
-  //PRINTF(0)("collision raction======================================\n");
+  float height = 0.0f;
+  float front = 0.0f;
+  float back = 0.0f;
+  float right = 0.0f;
+  float left = 0.0f;
+
 
   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
@@ -93,53 +94,55 @@
     switch( ce->getType())
     {
-        // collision in the x-axis
+        /* collision in the X-AXIS */
       case COLLISION_TYPE_AXIS_X:
-        front = collPos.len() - box->halfLength[0]; // should be [0]
+        front = collPos.len() - box->halfLength[0];
 
         // object is beneath the plane (ground)
         if( front <= 0.0f )
         {
-          Vector dirX = entity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize();
+          Vector dirX = entity->getAbsDirX();
+          dirX.y = 0.0f;
+          dirX.normalize();
           Vector backoff = dirX * front;
-          
-          entity->setAbsCoor(entity->getLastAbsCoor());
-         // entity->shiftCoor(backoff);
-        }
-        // object is already in the wall
-        else if( ce->isInWall())
-        {
-              entity->setAbsCoor(entity->getLastAbsCoor());
-        }
-        break;
-        
+
+          entity->shiftCoor(backoff);
+        }
+        else if( ce->isInWall())
+        {
+          // object is already in the wall
+          entity->setAbsCoor(entity->getLastAbsCoor());
+        }
+        break;
+
       case COLLISION_TYPE_AXIS_X_NEG:
-        front = collPos.len() - box->halfLength[0]; // should be [0]
-
-        // object is beneath the plane (ground)
-        if( front <= 0.0f )
-        {
-          Vector dirX = entity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize();
-          Vector backoff = dirX * front * -1.0f;
-          
-          entity->setAbsCoor(entity->getLastAbsCoor());
-         // entity->shiftCoor(backoff);
-        }
-        // object is already in the wall
-        else if( ce->isInWall())
-        {
-          entity->setAbsCoor(entity->getLastAbsCoor());
-        }
-        break;
-
-
-        // collision in the y-axis
+        back = collPos.len() - box->halfLength[0];
+
+        // object is beneath the plane (ground)
+        if( back <= 0.0f)
+        {
+          Vector dirX = entity->getAbsDirX();
+          dirX.y = 0.0f;
+          dirX.normalize();
+          Vector backoff = dirX * back * -1.0f;
+
+          entity->shiftCoor(backoff);
+        }
+        else if( ce->isInWall())
+        {
+          // object is already in the wall
+          entity->setAbsCoor(entity->getLastAbsCoor());
+        }
+        break;
+
+
+        /* collision in the Y-AXIS */
       case COLLISION_TYPE_AXIS_Y_NEG:
         // calulate the height above ground
-        height = collPos.y - box->halfLength[1];
-
-
-        // object is beneath the plane (ground)
-        if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
-        else if( height < 0.0f )
+        height = collPos.len() - box->halfLength[1];
+
+
+        // object is beneath the plane (ground)
+        //         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
+        if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)
         {
           entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
@@ -160,36 +163,38 @@
 
 
+        /* collision in the Z-AXIS */
+      case COLLISION_TYPE_AXIS_Z:
+
+        right = collPos.len()  - box->halfLength[2];
+
+        // object is beneath the plane (ground)
+        if( right <= 0.0f )
+        {
+          Vector dirZ = entity->getAbsDirZ();
+          dirZ.y = 0.0f;
+          dirZ.normalize();
+          Vector backoff = dirZ * right;
+          entity->shiftCoor(backoff);
+        }
+        else if( ce->isInWall())
+        {
+          // object is already in the wall
+          entity->setAbsCoor(entity->getLastAbsCoor());
+        }
+        break;
+
+
         // collision in the z-axis
-      case COLLISION_TYPE_AXIS_Z:
-
-        side = collPos.len()  - box->halfLength[2]; // should be [2]
-
-        // object is beneath the plane (ground)
-        if( side <= 0.0f )
-        {
-          entity->setAbsCoor(entity->getAbsCoor());
-          Vector dirZ = entity->getAbsDirZ(); dirZ.y = 0.0f; dirZ.normalize();
-          Vector backoff = dirZ * side;
-          entity->shiftCoor(backoff);
-        }
-        // object is already in the wall
-        else if( ce->isInWall())
-        {
-          entity->setAbsCoor(entity->getLastAbsCoor());
-        }
-        break;
-        
-        
-         // collision in the z-axis
       case COLLISION_TYPE_AXIS_Z_NEG:
 
-        side = collPos.len()  - box->halfLength[2]; // should be [2]
-
-        // object is beneath the plane (ground)
-        if( side <= 0.0f )
-        {
-         
-          Vector dirZ = entity->getAbsDirZ(); dirZ.y = 0.0f; dirZ.normalize();
-          Vector backoff = dirZ * side*-1.0f;
+        left = collPos.len()  - box->halfLength[2];
+
+        // object is beneath the plane (ground)
+        if( left <= 0.0f )
+        {
+          Vector dirZ = entity->getAbsDirZ();
+          dirZ.y = 0.0f;
+          dirZ.normalize();
+          Vector backoff = dirZ * left*-1.0f;
           entity->shiftCoor(backoff);
         }
@@ -209,75 +214,4 @@
 
 
-#if 0
-  if( box != NULL)
-    height = ( ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() )*(-1.0f) ;
-  else
-    height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() ;
-
-
-  if( box != NULL)
-  {
-
-
-    if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f)
-    {
-      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
-      return;
-    }
-    if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f)
-    {
-      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
-      return;
-    }
-
-    if(ce->getGroundNormal().len() <= 0.1f)
-    {
-      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
-      return;
-    }
-
-
-    if(ce->getGroundNormal().len() >= 1.4f)
-    {
-      downspeed++;
-      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
-      return;
-    }
-
-
-    if(height.y > box->halfLength[1] + 0.0f ) // Above ground
-    {
-      if(height.y < box->halfLength[1] + 2.3f) // Snap in
-      {
-        downspeed = 0;
-        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() - Vector(0.0,height.y  - box->halfLength[1] - 0.0f,0.0));
-      } else
-      {
-        downspeed++;
-        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
-      }
-
-    }
-    else
-    {
-      if(height.y <  box->halfLength[1] + 0.0f   /* && height.y  >  - 55.0f*/) // below ground
-      {
-        //if(downspeed <= 0) downspeed =1;
-        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -height.y  +  box->halfLength[1] + 2.0f,0.0));
-        //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0));
-        downspeed = 0;
-      }
-
-    }
-
-  }// if(box!= NULL)
-#endif
-  /*
-  PRINTF(0)("Collision with Ground: \n");
-  collision->getEntityB()->getAbsCoor().debug();
-  collision->getEntityB()->setVelocity(Vector());
-  collision->getEntityB()->setAbsCoor(this->lastPositions[1]);
-
-  */
 
 }
Index: trunk/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- trunk/src/lib/graphics/importer/bsp_manager.cc	(revision 9062)
+++ trunk/src/lib/graphics/importer/bsp_manager.cc	(revision 9110)
@@ -960,4 +960,11 @@
   this->outputFraction = 1.0f;
 
+
+  this->checkCollisionX(worldEntity);
+  this->checkCollisionY(worldEntity);
+  this->checkCollisionZ(worldEntity);
+
+
+#if 0
   // Retrieve Bounding box
   AABB* box = worldEntity->getModelAABB();
@@ -985,4 +992,9 @@
 
 
+  plane* testPlane;
+
+  bool xCollision = false;
+  bool zCollision = false;
+
 
   float height = 40;
@@ -998,5 +1010,5 @@
     dest1     = worldEntity->getAbsCoor() +  box->center + dirX * (box->halfLength[0]  + BSP_X_OFFSET);
     dest2     = worldEntity->getAbsCoor() -  box->center + dirX * (box->halfLength[0]  + BSP_X_OFFSET);
-    
+
     Vector dirZ =  worldEntity->getAbsDirZ(); dirX.y = 0.0f; dirZ.normalize();
     //position2 = worldEntity->getAbsCoor() +  box->center - dirZ * (box->halfLength[2]  + BSP_Z_OFFSET);
@@ -1009,10 +1021,6 @@
 
 
-//   PRINTF(0)("x and v\n");
-//   worldEntity->getAbsDirX().debug();
-//   worldEntity->getAbsDirV().debug();
-
-
-  // 1st Ray
+
+  // 1st Ray: Y RAY
   this->inputStart =  position;
   this->inputEnd =   dest;
@@ -1052,18 +1060,14 @@
       this->out = out;
     }
-
-
-  }
-
-  plane* testPlane = this->collPlane;
-
-  bool xCollision = false;
-  bool zCollision = false;
+  }
+    testPlane = this->collPlane;
+
+
   bool xCollisionNeg = false;
   bool zCollisionNeg = false;
-  
-
-
-    // 2nd Collision Detection
+
+
+
+    // 2nd Collision Detection X-RAY
     this->outputStartsOut = true;
     this->outputAllSolid = false;
@@ -1093,5 +1097,5 @@
 
 
-      // 3rd Collision Detection
+      // 3rd Collision Detection Z-RAY
       this->outputStartsOut = true;
       this->outputAllSolid = false;
@@ -1121,28 +1125,408 @@
       }
 
-  //end if
-  /*
-  This is how you would calculate the Coordinates where worldEntity Collided with the BSP world.
-  out.x = position1.x + (dest.x -position1.x) * this->outputFraction;
-  out.z = position1.z + (dest.z -position1.z) * this->outputFraction;
-  */
-
 
   // Return the normal here: Normal's stored in this->collPlane;
   if( collision) {
-    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
+    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
 }
   if(xCollision) {
     worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z),dest1 , SolidFlag);
   }
-  
+
   if(zCollision) {
     worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), dest2 , SolidFlag);
   }
-
-
-  //else  worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y, this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest, false);
-
-}
+#endif
+
+}
+
+
+
+/**
+ * check the collision in the x direction (forward, backward)
+ */
+void BspManager::checkCollisionX(WorldEntity* entity)
+{
+  // Retrieve Bounding box
+  AABB* box = entity->getModelAABB();
+
+
+  plane*            testPlane          = NULL;  //!< the collision test plane
+
+  Vector            forward;                    //!< left collision ray
+  Vector            backward;                   //!< right collision ray
+  Vector            collPos;                    //!< the collision position
+
+  bool              xCollisionForward  = false; //!< flag true if right collision
+  bool              xCollisionBackward = false; //!< flag true if left collision
+  bool              SolidFlag          = false; //!< flag set true if solid
+
+  Vector            position;                   //!< current position of the entity
+  Vector            dirX;                       //!< direction x
+
+  position = entity->getAbsCoor();
+  dirX =  entity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize();
+
+  // calculate the rays
+  if( box != NULL)
+  {
+    forward  = entity->getAbsCoor() +  box->center + dirX * (box->halfLength[0]  + BSP_X_OFFSET);
+    backward = entity->getAbsCoor() +  box->center - dirX * (box->halfLength[0]  + BSP_X_OFFSET);
+  }
+  else
+  {
+    forward  = position + dirX * 4.0f;
+    backward = position + Vector(0.0, 1.0, 0.0) + dirX * 4.0;
+  }
+
+
+  /*   X Ray forward  */
+  // init some member variables before collision check
+  this->outputStartsOut = true;
+  this->outputAllSolid = false;
+  this->outputFraction = 1.0f;
+  this->inputStart =  position;
+  this->inputEnd =   forward;
+  this->checkCollisionRayN(this->root, 0.0f, 1.0f, &position, &forward );
+
+  // collision occured
+  if( this->outputFraction < 1.0f)
+  {
+    collPos = position + (forward - position) * this->outputFraction;
+    xCollisionForward = true;
+    testPlane = this->collPlane;
+  }
+  if(this->outputAllSolid )
+  {
+    this->collPlane = new plane;
+    this->collPlane->x = 0.0f;
+    this->collPlane->y = 0.0f;
+    this->collPlane->z = 0.0f;
+    testPlane = this->collPlane;
+    SolidFlag = true;
+    xCollisionForward = true;
+  }
+
+  // collision registration
+  if( xCollisionForward)
+  {
+    entity->registerCollision(COLLISION_TYPE_AXIS_X ,
+                              this->parent, entity,
+                              Vector(testPlane->x, testPlane->y, testPlane->z),
+                              collPos,
+                              SolidFlag);
+  }
+
+
+
+  /*   X Ray backward  */
+  // init some member variables before collision check
+  this->outputStartsOut = true;
+  this->outputAllSolid = false;
+  this->outputFraction = 1.0f;
+  this->inputStart =  position;
+  this->inputEnd =   backward;
+  this->checkCollisionRayN(this->root, 0.0f, 1.0f, &position, &backward );
+
+  // collision occured
+  if( this->outputFraction < 1.0f)
+  {
+    collPos = position + (backward - position) * this->outputFraction;
+    xCollisionBackward = true;
+    testPlane = this->collPlane;
+  }
+  if( this->outputAllSolid)
+  {
+    this->collPlane = new plane;
+    this->collPlane->x = 0.0f;
+    this->collPlane->y = 0.0f;
+    this->collPlane->z = 0.0f;
+    testPlane = this->collPlane;
+    SolidFlag = true;
+    xCollisionBackward = true;
+  }
+
+  // collision registration
+  if( xCollisionBackward)
+  {
+    entity->registerCollision(COLLISION_TYPE_AXIS_X_NEG ,
+                              this->parent, entity,
+                              Vector(testPlane->x, testPlane->y, testPlane->z),
+                              collPos,
+                              SolidFlag);
+  }
+}
+
+
+/**
+ * check the collision in the z direction (up, down)
+ */
+void BspManager::checkCollisionY(WorldEntity* entity)
+{
+
+  // Retrieve Bounding box
+  AABB* box = entity->getModelAABB();
+
+
+  plane*            testPlane          = NULL;  //!< the collision test plane
+
+  Vector            up;                         //!< up collision ray
+  Vector            down;                       //!< down collision ray
+  Vector            collPos;                    //!< the collision position
+
+  bool              yCollisionUp       = false; //!< flag true if right collision
+  bool              yCollisionDown     = false; //!< flag true if left collision
+  bool              SolidFlag          = false; //!< flag set true if solid
+
+  Vector            position;                   //!< current position of the entity
+  Vector            dirY;                       //!< direction x
+
+  position = entity->getAbsCoor();
+  collPos = position;
+  dirY =  Vector(0.0, 1.0, 0.0);
+
+  // calculate the rays
+  if( box != NULL)
+  {
+    up   = position +  box->center + dirY * (box->halfLength[1]/*  + BSP_Y_OFFSET*/);
+    down = position +  box->center - dirY * (box->halfLength[1]  + BSP_Y_OFFSET);
+  }
+  else
+  {
+    up   = position + dirY * 4.0f;
+    down = position + Vector(0.0, 1.0, 0.0) + dirY * 4.0;
+  }
+
+
+
+
+  /*   Y Ray up */
+  // init some member variables before collision check
+  this->inputStart = position;
+  this->inputEnd   = up;
+  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &up );
+
+  if( !this->outputStartsOut )
+  {
+    this->collPlane = new plane;
+    this->collPlane->x = 0.0f;
+    this->collPlane->y = 0.0f;
+    this->collPlane->z = 0.0f;
+    yCollisionUp = true;
+  }
+  else
+  {
+    if( this->outputFraction == 1.0f)
+    {
+      if( this->outputAllSolid )
+      {
+        this->collPlane = new plane;
+        this->collPlane->x = 0.0f;
+        this->collPlane->y = 0.0f;
+        this->collPlane->z = 0.0f;
+        yCollisionUp = true;
+        SolidFlag = true;
+      }
+      else
+      {
+        yCollisionUp = false;
+        collPos = up;
+      }
+    }
+    else
+    {
+      yCollisionUp = true;
+      collPos = position + (up - position) * this->outputFraction;
+      this->out = collPos;        // why this????
+    }
+  }
+  testPlane = this->collPlane;
+
+  // collision registration
+  if( yCollisionUp)
+  {
+    entity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent,
+                              entity,
+                              Vector(testPlane->x, testPlane->y, testPlane->z),
+                              collPos, SolidFlag);
+  }
+
+
+
+
+  /*   Y Ray down */
+  // init some member variables before collision check
+  this->inputStart = position;
+  this->inputEnd   = down;
+  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &down );
+
+  if( !this->outputStartsOut )
+  {
+    this->collPlane = new plane;
+    this->collPlane->x = 0.0f;
+    this->collPlane->y = 0.0f;
+    this->collPlane->z = 0.0f;
+    yCollisionDown = true;
+  }
+  else
+  {
+    if( this->outputFraction == 1.0f)
+    {
+      if( this->outputAllSolid )
+      {
+        this->collPlane = new plane;
+        this->collPlane->x = 0.0f;
+        this->collPlane->y = 0.0f;
+        this->collPlane->z = 0.0f;
+        yCollisionDown = true;
+        SolidFlag = true;
+      }
+      else
+      {
+        yCollisionDown = false;
+        collPos = down;
+      }
+    }
+    else
+    {
+      yCollisionDown = true;
+      collPos = position + (down - position) * this->outputFraction;
+      this->out = collPos;        // why this????
+    }
+  }
+  testPlane = this->collPlane;
+
+  // collision registration
+  if( yCollisionDown)
+  {
+    entity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent,
+                              entity,
+                              Vector(testPlane->x, testPlane->y, testPlane->z),
+                              collPos, SolidFlag);
+  }
+
+
+}
+
+
+
+
+/**
+ * check the collision in the z direction (left, right)
+ */
+void BspManager::checkCollisionZ(WorldEntity* entity)
+{
+  // Retrieve Bounding box
+  AABB* box = entity->getModelAABB();
+
+
+  plane*            testPlane          = NULL;  //!< the collision test plane
+
+  Vector            right;                      //!< right collision ray
+  Vector            left;                       //!< left collision ray
+  Vector            collPos;                    //!< the collision position
+
+  bool              zCollisionRight    = false; //!< flag true if right collision
+  bool              zCollisionLeft     = false; //!< flag true if left collision
+  bool              SolidFlag          = false; //!< flag set true if solid
+
+  Vector            position;                   //!< current position of the entity
+  Vector            dirZ;                       //!< direction x
+
+  position = entity->getAbsCoor();
+  dirZ =  entity->getAbsDirZ(); dirZ.y = 0.0f; dirZ.normalize();
+
+  // calculate the rays
+  if( box != NULL)
+  {
+    right = entity->getAbsCoor() +  box->center + dirZ * (box->halfLength[2]  + BSP_Z_OFFSET);
+    left  = entity->getAbsCoor() +  box->center - dirZ * (box->halfLength[2]  + BSP_Z_OFFSET);
+  }
+  else
+  {
+    right = position + dirZ * 4.0f;
+    left  = position + Vector(0.0, 1.0, 0.0) + dirZ * 4.0;
+  }
+
+
+  /*   Z Ray right */
+  // init some member variables before collision check
+  this->outputStartsOut = true;
+  this->outputAllSolid = false;
+  this->outputFraction = 1.0f;
+  this->inputStart =  position;
+  this->inputEnd =   right;
+  this->checkCollisionRayN(this->root, 0.0f, 1.0f, &position, &right );
+
+
+  // collision occured
+  if( this->outputFraction < 1.0f )
+  {
+    collPos = position + (right - position) * this->outputFraction;
+    zCollisionRight = true;
+    testPlane = this->collPlane;
+  }
+  if(this->outputAllSolid )
+  {
+    this->collPlane = new plane;
+    this->collPlane->x = 0.0f;
+    this->collPlane->y = 0.0f;
+    this->collPlane->z = 0.0f;
+    testPlane = this->collPlane;
+
+    SolidFlag = true;
+    zCollisionRight = true;
+  }
+
+
+  if( zCollisionRight) {
+    entity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent,
+                              entity,
+                              Vector(testPlane->x, testPlane->y, testPlane->z),
+                              collPos , SolidFlag);
+  }
+
+
+
+  /*   Z Ray left */
+  // init some member variables before collision check
+  this->outputStartsOut = true;
+  this->outputAllSolid = false;
+  this->outputFraction = 1.0f;
+  this->inputStart =  position;
+  this->inputEnd =    left;
+  this->checkCollisionRayN(this->root, 0.0f, 1.0f, &position, &left);
+
+
+  // collision occured
+  if( this->outputFraction < 1.0f )
+  {
+    collPos = position + (left - position) * this->outputFraction;
+    zCollisionLeft = true;
+    testPlane = this->collPlane;
+  }
+  if(this->outputAllSolid )
+  {
+    this->collPlane = new plane;
+    this->collPlane->x = 0.0f;
+    this->collPlane->y = 0.0f;
+    this->collPlane->z = 0.0f;
+    testPlane = this->collPlane;
+
+    SolidFlag = true;
+    zCollisionLeft = true;
+  }
+
+
+  if( zCollisionLeft) {
+    entity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this->parent,
+                              entity,
+                              Vector(testPlane->x, testPlane->y, testPlane->z),
+                              collPos , SolidFlag);
+  }
+
+}
+
+
 
 
Index: trunk/src/lib/graphics/importer/bsp_manager.h
===================================================================
--- trunk/src/lib/graphics/importer/bsp_manager.h	(revision 9062)
+++ trunk/src/lib/graphics/importer/bsp_manager.h	(revision 9110)
@@ -28,7 +28,7 @@
 
 
-#define BSP_X_OFFSET 40.0f
+#define BSP_X_OFFSET 20.0f
 #define BSP_Y_OFFSET 40.0f
-#define BSP_Z_OFFSET 40.0f
+#define BSP_Z_OFFSET 20.0f
 
 
@@ -79,16 +79,24 @@
 
 private:
-  // Functions
+  // collision functions
   BspTreeNode* getLeaf(BspTreeNode*  node,   Vector* cam) ;  //!< Traverses the tree
   void  checkCollision(BspTreeNode* node, Vector* cam); //!< Obsolete. Use this function for debugging only!
   void  checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
   void  checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
-  void  TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
+
+  void checkCollisionX(WorldEntity* entity);
+  void checkCollisionY(WorldEntity* entity);
+  void checkCollisionZ(WorldEntity* entity);
+
   void  checkCollisionBox(void);
   void  checkBrushRay(brush* curBrush);
   void  checkBrushRayN(brush* curBrush);
   void  checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
-  float  checkPatchAltitude(BspTreeNode* node); //! To be implemented...
+  float checkPatchAltitude(BspTreeNode* node); //! To be implemented...
 
+  void  TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
+
+
+  // visibility functions
   void drawDebugCube(Vector* cam);
   bool isAlreadyVisible(int Face);
Index: trunk/src/lib/graphics/importer/md3/md3_model.cc
===================================================================
--- trunk/src/lib/graphics/importer/md3/md3_model.cc	(revision 9062)
+++ trunk/src/lib/graphics/importer/md3/md3_model.cc	(revision 9110)
@@ -525,6 +525,7 @@
     float  interpolatedMatrix[4][4];
 
-    Quaternion currQuat(currFrameTag->matrix); currQuat.matrix(currRot);
-    Quaternion nextQuat(nextFrameTag->matrix); nextQuat.matrix(nextRot);
+    /// TODO CHANGED BY BENSCH TO MATCH NEW QUATERNION FUNCTIONALITY
+    Quaternion currQuat; currQuat.from3x3(currFrameTag->matrix); currQuat.matrix(currRot);
+    Quaternion nextQuat; nextQuat.from3x3(nextFrameTag->matrix); nextQuat.matrix(nextRot);
 
     Quaternion interpolatedQuat = Quaternion::quatSlerp(currQuat, nextQuat, frac); interpolatedQuat.matrix(interpolatedMatrix);
Index: trunk/src/lib/graphics/importer/primitive_model.cc
===================================================================
--- trunk/src/lib/graphics/importer/primitive_model.cc	(revision 9062)
+++ trunk/src/lib/graphics/importer/primitive_model.cc	(revision 9110)
@@ -18,5 +18,4 @@
 #include "primitive_model.h"
 
-#include <math.h>
 #include "vector.h"
 #include "debug.h"
Index: trunk/src/lib/graphics/spatial_separation/quadtree.cc
===================================================================
--- trunk/src/lib/graphics/spatial_separation/quadtree.cc	(revision 9062)
+++ trunk/src/lib/graphics/spatial_separation/quadtree.cc	(revision 9110)
@@ -52,7 +52,7 @@
 
   /* make an array with access to the leafs of the Quad-Tree */
-  this->nodes = new QuadtreeNode*[(int)pow(4, treeDepth)];
+  this->nodes = new QuadtreeNode*[(int)pow(4.0, treeDepth)];
   int index = 0; //new int; *index = 0; // !!changed by bensch!!
-  for(int i = 0; i < (int)pow(2, treeDepth); ++i)
+  for(int i = 0; i < (int)pow(2.0, treeDepth); ++i)
   {
     this->rootNode->buildHashTable(this->nodes, &index);
@@ -70,5 +70,5 @@
   this->offset->x = xOff;
   this->offset->z = yOff;
-  this->maxIndex = (int)pow(2, this->treeDepth);
+  this->maxIndex = (int)pow(2.0, this->treeDepth);
 }
 
@@ -103,5 +103,5 @@
 void Quadtree::revertHashTable(QuadtreeNode** nodes)
 {
-  int                  len         = (int)pow(2, this->treeDepth);          //!< the length of a quadtree side
+  int                  len         = (int)pow(2.0, this->treeDepth);          //!< the length of a quadtree side
   int                  iterator    = 0;                                     //!< iterator used for mapping
   QuadtreeNode*        tmpNode     = NULL;                                  //!< temp saving place
@@ -132,5 +132,5 @@
 void Quadtree::sortHashTable(QuadtreeNode** nodes)
 {
-  int                  len         = (int)pow(2, this->treeDepth);          //!< the length of a quadtree side
+  int                  len         = (int)pow(2.0, this->treeDepth);          //!< the length of a quadtree side
   float                a;                                                   //!< temp place for float a
   float                b;                                                   //!< temp place for float b
@@ -207,5 +207,5 @@
 {
   //this->rootNode->drawTree();
-  for(int i = 0; i < (int)pow(4, this->treeDepth); ++i)
+  for(int i = 0; i < (int)pow(4.0, this->treeDepth); ++i)
   {
     this->nodes[i]->draw();
Index: trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
===================================================================
--- trunk/src/lib/graphics/spatial_separation/quadtree_node.cc	(revision 9062)
+++ trunk/src/lib/graphics/spatial_separation/quadtree_node.cc	(revision 9110)
@@ -164,5 +164,5 @@
 
   /*              offset              #of elements in a row            #of rows in a quadtree          */
-  int threshold = this->nodeIter + (int)pow(2, this->maxDepth) * (int)pow(2, maxDepth - treeDepth - 1);
+  int threshold = this->nodeIter + (int)pow(2.0, this->maxDepth) * (int)pow(2.0, maxDepth - treeDepth - 1);
   int loopLimit = (*index < threshold)?2:4;
 
Index: trunk/src/lib/gui/gl/glgui_box.cc
===================================================================
--- trunk/src/lib/gui/gl/glgui_box.cc	(revision 9062)
+++ trunk/src/lib/gui/gl/glgui_box.cc	(revision 9110)
@@ -59,5 +59,5 @@
   void GLGuiBox::unpack(GLGuiWidget* widget)
   {
-    assert(widget == NULL);
+    assert(widget != NULL);
 
     std::vector<GLGuiWidget*>::iterator delWidget = std::find(this->children.begin(), this->children.end(), widget);
Index: trunk/src/lib/gui/gtk/gui_gtk.cc
===================================================================
--- trunk/src/lib/gui/gtk/gui_gtk.cc	(revision 9062)
+++ trunk/src/lib/gui/gtk/gui_gtk.cc	(revision 9110)
@@ -30,5 +30,5 @@
 #include <string.h>
 #include <stdlib.h>
-#include <math.h>
+#include <cmath>
 
 using namespace std;
Index: trunk/src/lib/math/curve.cc
===================================================================
--- trunk/src/lib/math/curve.cc	(revision 9062)
+++ trunk/src/lib/math/curve.cc	(revision 9110)
@@ -29,5 +29,5 @@
 #include "debug.h"
 
-#include <math.h>
+#include <cmath>
 #include <stdio.h>
 
Index: trunk/src/lib/math/line.h
===================================================================
--- trunk/src/lib/math/line.h	(revision 9062)
+++ trunk/src/lib/math/line.h	(revision 9110)
@@ -24,5 +24,4 @@
 #define __LINE_H_
 
-#include <math.h>
 #include "compiler.h"
 #include "vector.h"
Index: trunk/src/lib/math/matrix.cc
===================================================================
--- trunk/src/lib/math/matrix.cc	(revision 9062)
+++ trunk/src/lib/math/matrix.cc	(revision 9110)
@@ -14,5 +14,5 @@
 */
 #include "matrix.h"
-#include <math.h>
+#include <cmath>
 
 #ifdef DEBUG
Index: trunk/src/lib/math/matrix.h
===================================================================
--- trunk/src/lib/math/matrix.h	(revision 9062)
+++ trunk/src/lib/math/matrix.h	(revision 9110)
@@ -4,5 +4,4 @@
  */
 
-#include <math.h>
 #include "vector.h"
 
Index: trunk/src/lib/math/plane.h
===================================================================
--- trunk/src/lib/math/plane.h	(revision 9062)
+++ trunk/src/lib/math/plane.h	(revision 9110)
@@ -24,5 +24,4 @@
 #define __PLANE_H_
 
-#include <math.h>
 #include "compiler.h"
 #include "vector.h"
Index: trunk/src/lib/math/quaternion.cc
===================================================================
--- trunk/src/lib/math/quaternion.cc	(revision 9062)
+++ trunk/src/lib/math/quaternion.cc	(revision 9110)
@@ -28,6 +28,4 @@
   #define PRINT(x) printf
 #endif
-
-using namespace std;
 
 /////////////////
@@ -58,19 +56,19 @@
   m[0][1] = x.y;
   m[0][2] = x.z;
-  m[0][3] = 0;
+  m[0][3] = 0.0;
   m[1][0] = y.x;
   m[1][1] = y.y;
   m[1][2] = y.z;
-  m[1][3] = 0;
+  m[1][3] = 0.0;
   m[2][0] = z.x;
   m[2][1] = z.y;
   m[2][2] = z.z;
-  m[2][3] = 0;
-  m[3][0] = 0;
-  m[3][1] = 0;
-  m[3][2] = 0;
-  m[3][3] = 1;
-
-  *this = Quaternion (m);
+  m[2][3] = 0.0;
+  m[3][0] = 0.0;
+  m[3][1] = 0.0;
+  m[3][2] = 0.0;
+  m[3][3] = 1.0;
+
+  this->from4x4(m);
 }
 
@@ -279,5 +277,5 @@
  * @param m: a 4x4 matrix in glMatrix order
  */
-Quaternion::Quaternion (float m[4][4])
+void Quaternion::from4x4(float m[4][4])
 {
 
@@ -285,5 +283,5 @@
   int    i, j, k;
 
-  int nxt[3] = {1, 2, 0};
+  static int nxt[3] = {1, 2, 0};
 
   tr = m[0][0] + m[1][1] + m[2][2];
@@ -327,9 +325,9 @@
 
 /**
- * Creates a quaternion from a 3x3 rotation matrix.
+ * applies a quaternion from a 3x3 rotation matrix.
  * @param mat The 3x3 source rotation matrix.
  * @return The equivalent 4 float quaternion.
  */
-Quaternion::Quaternion(float mat[3][3])
+void Quaternion::from3x3(float mat[3][3])
 {
   int   NXT[] = {1, 2, 0};
Index: trunk/src/lib/math/quaternion.h
===================================================================
--- trunk/src/lib/math/quaternion.h	(revision 9062)
+++ trunk/src/lib/math/quaternion.h	(revision 9110)
@@ -24,8 +24,5 @@
 #define __QUATERNION_H_
 
-#include <math.h>
 #include "compiler.h"
-//! PI the circle-constant
-#define PI 3.14159265359f
 #include "vector.h"
 
@@ -39,12 +36,16 @@
   /** creates a Default quaternion (multiplicational identity Quaternion)*/
   inline Quaternion () { w = 1; v = Vector(0,0,0); }
+  /** Copy constructor @param q the Quaternion to copy. */
+  inline Quaternion (const Quaternion& q) { w = q.w; v = q.v; };
   /** creates a Quaternion looking into the direction v @param v: the direction @param f: the value */
   inline Quaternion (const Vector& v, float f) { this->w = f; this->v = v; }
-  Quaternion (float m[4][4]);
-  Quaternion (float m[3][3]);
   /** turns a rotation along an axis into a Quaternion @param angle: the amount of radians to rotate @param axis: the axis to rotate around */
   inline Quaternion (float angle, const Vector& axis) { w = cos(angle/2.0); v = axis * sin(angle/2.0); }
   Quaternion (const Vector& dir, const Vector& up);
   Quaternion (float roll, float pitch, float yaw);
+
+  void from3x3(float m[3][3]);
+  void from4x4(float m[4][4]);
+
 
   /** @param q: the Quaternion to compare with this one. @returns true if the Quaternions are the same, false otherwise */
Index: trunk/src/lib/math/vector.cc
===================================================================
--- trunk/src/lib/math/vector.cc	(revision 9062)
+++ trunk/src/lib/math/vector.cc	(revision 9110)
@@ -29,5 +29,4 @@
 #endif
 
-using namespace std;
 
 /////////////
@@ -40,9 +39,9 @@
 Vector Vector::getNormalized() const
 {
-  float l = this->len();
-  if(unlikely(l == 1.0 || l == 0.0))
+  float length = this->len();
+  if (unlikely(length == 0.0))
     return *this;
   else
-    return (*this / l);
+    return (*this / length);
 }
 
Index: trunk/src/lib/math/vector.h
===================================================================
--- trunk/src/lib/math/vector.h	(revision 9062)
+++ trunk/src/lib/math/vector.h	(revision 9110)
@@ -24,5 +24,5 @@
 #define __VECTOR_H_
 
-#include <math.h>
+#include <cmath>
 #include "compiler.h"
 //! PI the circle-constant
@@ -42,5 +42,4 @@
   Vector (float x, float y, float z) : x(x), y(y), z(z) {}  //!< assignment constructor
   Vector () : x(0), y(0), z(0) {}
-  ~Vector () {}
 
   /** @param v: the Vecor to compare with this one @returns true, if the Vecors are the same, false otherwise */
@@ -90,5 +89,5 @@
   void scale(const Vector& v) {   x *= v.x;  y *= v.y; z *= v.z; };
   /** @returns the length of the vector */
-  inline float len() const { return sqrt (x*x+y*y+z*z); }
+  inline float len() const { return sqrt (x*x + y*y + z*z); }
   /** normalizes the vector */
   inline void normalize() { float l = len(); if( unlikely(l == 0.0))return; this->x=this->x/l; this->y=this->y/l; this->z=this->z/l; };
Index: trunk/src/lib/network/network_game_manager.cc
===================================================================
--- trunk/src/lib/network/network_game_manager.cc	(revision 9062)
+++ trunk/src/lib/network/network_game_manager.cc	(revision 9110)
@@ -98,4 +98,5 @@
   ClassID playableClassId = rules.getPlayableClassId( userId, team );
   std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId );
+  std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId );
   
   BaseObject * bo = Factory::fabricate( playableClassId );
@@ -106,5 +107,7 @@
   Playable & playable = *(dynamic_cast<Playable*>(bo));
   
-  if (  playableModel != "" )
+  if ( playableTexture != "" )
+    playable.loadMD2Texture( playableTexture );
+  if ( playableModel != "" )
     playable.loadModel( playableModel );
   playable.setOwner( userId );
Index: trunk/src/lib/network/player_stats.cc
===================================================================
--- trunk/src/lib/network/player_stats.cc	(revision 9062)
+++ trunk/src/lib/network/player_stats.cc	(revision 9110)
@@ -238,2 +238,35 @@
 }
 
+
+
+ScoreList PlayerStats::getScoreList( )
+{
+  ScoreList result;
+  
+  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
+  
+  if ( !list )
+  {
+    return result;
+  }
+  
+  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
+  {
+    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
+    
+    TeamScoreList::iterator it = result[stats.getTeamId()].begin();
+    
+    while (  it != result[stats.getTeamId()].end() && stats.score > it->score )
+    {
+      it++;
+    }
+    
+    PlayerScore score;
+    score.name = stats.getNickName();
+    score.score = stats.getScore();
+    
+    result[stats.getTeamId()].insert(it, score);
+  }
+  
+  return result;
+}
Index: trunk/src/lib/network/player_stats.h
===================================================================
--- trunk/src/lib/network/player_stats.h	(revision 9062)
+++ trunk/src/lib/network/player_stats.h	(revision 9110)
@@ -20,4 +20,12 @@
   TEAM_SPECTATOR = -1
 };
+
+struct PlayerScore
+{
+  std::string name;
+  int score;
+};
+typedef std::list<PlayerScore> TeamScoreList;
+typedef std::map<int,TeamScoreList> ScoreList;
 
 //! A class for storing player information
@@ -62,4 +70,6 @@
     
     static void deleteAllPlayerStats();
+    
+    static ScoreList getScoreList();
 
   private:
Index: trunk/src/lib/network/shared_network_data.cc
===================================================================
--- trunk/src/lib/network/shared_network_data.cc	(revision 9062)
+++ trunk/src/lib/network/shared_network_data.cc	(revision 9110)
@@ -44,3 +44,5 @@
  */
 SharedNetworkData::~SharedNetworkData()
-{}
+{
+  SharedNetworkData::singletonRef = NULL;
+}
Index: trunk/src/lib/network/synchronizeable.cc
===================================================================
--- trunk/src/lib/network/synchronizeable.cc	(revision 9062)
+++ trunk/src/lib/network/synchronizeable.cc	(revision 9110)
@@ -67,8 +67,10 @@
 {
   if ( this->networkStream )
+  {
     this->networkStream->disconnectSynchronizeable(*this);
   
-  if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) )
-    NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
+    if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) )
+      NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
+  }
     
   for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
Index: trunk/src/lib/shell/shell_buffer.cc
===================================================================
--- trunk/src/lib/shell/shell_buffer.cc	(revision 9062)
+++ trunk/src/lib/shell/shell_buffer.cc	(revision 9110)
@@ -41,5 +41,5 @@
   ShellBuffer* ShellBuffer::singletonRef = NULL;
   std::list<std::string> ShellBuffer::buffer;
-  char ShellBuffer::bufferArray[SHELL_BUFFER_SIZE];
+  char ShellBuffer::bufferArray[SHELL_BUFFER_SIZE] = "";
 
 
Index: trunk/src/lib/util/loading/game_loader.cc
===================================================================
--- trunk/src/lib/util/loading/game_loader.cc	(revision 9062)
+++ trunk/src/lib/util/loading/game_loader.cc	(revision 9110)
@@ -57,4 +57,6 @@
     delete this->currentCampaign;
   this->currentCampaign = NULL;
+  
+  GameLoader::singletonRef = NULL;
 }
 
