Index: branches/bsp_model/src/lib/collision_reaction/cr_physics_ground_walk.cc
===================================================================
--- branches/bsp_model/src/lib/collision_reaction/cr_physics_ground_walk.cc	(revision 8699)
+++ branches/bsp_model/src/lib/collision_reaction/cr_physics_ground_walk.cc	(revision 8714)
@@ -1,12 +1,12 @@
 /*
    orxonox - the future of 3D-vertical-scrollers
-
+ 
    Copyright (C) 2004 orx
-
+ 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2, or (at your option)
    any later version.
-
+ 
    ### File Specific:
    main-programmer: Patrick Boenzli
@@ -24,8 +24,4 @@
 #include "cr_physics_ground_walk.h"
 
-#include "aabb.h"
-
-#include "debug.h"
-
 #include <vector>
 
@@ -37,5 +33,5 @@
  */
 CRPhysicsGroundWalk::CRPhysicsGroundWalk ()
-  : CollisionReaction()
+    : CollisionReaction()
 {
   this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk");
@@ -47,6 +43,5 @@
  */
 CRPhysicsGroundWalk::~CRPhysicsGroundWalk ()
-{
-}
+{}
 
 
@@ -59,36 +54,62 @@
   CollisionEvent* ce = collision->getCollisionEvents().front();
   Vector normal = ce->getGroundNormal();
+  // normal.normalize();
 
-  AABB* box = ce->getEntityB()->getModelAABB();
+  // put it back
+  //   PRINTF(0)("putting it back to lastPos: \n");
+  //   this->lastPositions[0].debug();
+  //   PRINTF(0)("current pos:\n");
+  //   collision->getEntityB()->getAbsCoor().debug();
 
-  Vector center = ce->getEntityB()->getAbsCoor() /*+ box->center*/;
-  Vector collisionPos = ce->getCollisionPosition() - center;
 
-  float objSize = box->halfLength[1];
+  Vector height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor();
 
-  if( normal.len() <= 0.1f)
-  {
+  if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
     collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
     return;
   }
-
-  if( collisionPos.y <= -(objSize + 0.1f))
-  {
+  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.03 * downspeed, 0.0));
-  }
-  else
-  {
-    if( collisionPos.y > -objSize  &&
-        collisionPos.y < (objSize + 0.4))
-    {
-      //if(downspeed <= 0) downspeed =1;
-      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() +
-                                          Vector(0.0, collisionPos.y + objSize + 0.1, 0.0));
-    }
-      downspeed = 0;
+    collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
+    return;
   }
 
 
+  if(height.y < -3.510001 + 10.0) // Above ground
+  {
+    if(height.y > -15.6) // Snap in
+    {
+      downspeed = 0;
+      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,height.y+3.500005 + 10.0,0.0));
+    } else
+    {
+      downspeed++;
+      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
+    }
+
+  }
+  else {
+    if(height.y > -3.50000 + 10.0  && height.y <    9.9+ 10.0) // below ground
+    {
+      //if(downspeed <= 0) downspeed =1;
+      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, 0.00001 /*height.y+3.500005 + 10.0*/,0.0));
+      //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0));
+      downspeed = 0;
+    }
+
+  }
+
+
+  /*
+  PRINTF(0)("Collision with Ground: \n");
+  collision->getEntityB()->getAbsCoor().debug();
+  collision->getEntityB()->setVelocity(Vector());
+  collision->getEntityB()->setAbsCoor(this->lastPositions[1]);
+
+  */
 }
 
@@ -103,5 +124,5 @@
   for( int i = 9; i > 0; i--) {
     this->lastPositions[i] = this->lastPositions[i-1];
-//     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
+    //     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
   }
   this->lastPositions[0] = owner->getAbsCoor();
Index: branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 8699)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 8714)
@@ -41,6 +41,4 @@
 #include "world_entity.h"
 
-#include "aabb.h"
-
 #include "util/loading/load_param.h"
 #include "util/loading/factory.h"
@@ -842,5 +840,6 @@
         this->checkBrushRayN(&curBrush);
       if(curBrush.n_brushsides <=0) this->outputAllSolid = true;
-    }
+    } 
+    
     return;
   }
@@ -909,4 +908,15 @@
 
 }
+
+float BspManager::checkPatchAltitude(BspTreeNode* node)
+{
+  leaf& curLeaf = this->bspFile->leaves[node->leafIndex];
+  for(int i = 0; i < curLeaf.n_leaffaces ; i++)
+  {
+   
+  }
+  return 10.0f;
+}
+
 void BspManager::checkCollisionBox(void)
 {
@@ -944,44 +954,23 @@
   this->outputFraction = 1.0f;
 
-  AABB* box = worldEntity->getModelAABB();
-
-
-  Vector forwardDir;
-  Vector upDir;
+
+
+
+  Vector forwardDir = worldEntity->getAbsDirX();
+
+
+  Vector upDir = worldEntity->getAbsDirY();
+  upDir.x = 0.0;
+  upDir.y = 1.0;
+  upDir.z = 0.0;
   Vector dest;
-  Vector position;
-  Vector out;
-  float height;
-
-  if( box != NULL)
-  {
-    forwardDir = worldEntity->getAbsDirX();
-    forwardDir = forwardDir * box->halfLength[0];
-
-    upDir = Vector(0,1,0) * box->halfLength[1];
-
-    position = worldEntity->getAbsCoor() + box->center + box->axis[1] * box->halfLength[1];
-    dest     = worldEntity->getAbsCoor() + box->center - box->axis[1] * box->halfLength[1];
-    out      = dest;
-
-    height = box->halfLength[1];
-  }
-  else
-  {
-    forwardDir = worldEntity->getAbsDirX();
-    forwardDir = forwardDir * 8.0f;
-
-    upDir = worldEntity->getAbsDirY();
-    upDir.x = 0.0;
-    upDir.y = 1.0;
-    upDir.z = 0.0;
-    dest;
-
-    position = worldEntity->getAbsCoor() + upDir*5.0f;
-    dest = worldEntity->getAbsCoor() - upDir*40.0f; //
-    out = dest;
-
-    height = 40;
-  }
+  /*
+  dest.x  += forwardDir.x;
+  dest.y  += forwardDir.y;
+  dest.z  += forwardDir.z;
+  */
+  Vector position = worldEntity->getAbsCoor() + upDir*10.0f ;
+  dest = worldEntity->getAbsCoor() - upDir*40.0f; //
+  Vector out = dest;
 
 
@@ -989,22 +978,25 @@
 
   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 position1 = position; // + Vector(0.0,0.6,0.0);
+  Vector position2 = position + Vector(0.0,1.0,0.0);
+  Vector dest1 = position + forwardDir*4.0f;
   Vector dest2 = position2 + forwardDir;
-//   dest = position - Vector(0.0, 40.0,0.0);
+  dest = position - Vector(0.0, 40.0,0.0);
   Vector out1;
   Vector out2;
 
 
-
+  float height = 40;
 
   this->inputStart =  position;
   this->inputEnd =   dest;
   this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
+  
+
 
 //   PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction);
 //   PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z);
 //   PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z);
+
 //   position1.debug();
 
@@ -1052,10 +1044,29 @@
 
   }
+  
+  plane* testPlane = this->collPlane;
+  
+  this->outputStartsOut = true;
+  this->outputAllSolid = false;
+  this->outputFraction = 1.0f;
+  this->inputStart =  position;
+  this->inputEnd =   dest1;
+  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest1 );
+  out.x = this->outputFraction;
+  out.z = this->outputFraction;
+  
+  /*
+  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) {
     PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction);
-    worldEntity->registerCollision(this->parent, worldEntity, Vector(this->collPlane->x, this->collPlane->y, this->collPlane->z), out);
-  }
-  else  worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 1.0, 0.0), dest);
+    worldEntity->registerCollision(this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out);
+  }
+  else  worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest);
 
 }
Index: branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_manager.h	(revision 8699)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_manager.h	(revision 8714)
@@ -73,9 +73,10 @@
   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  TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
   void  checkCollisionBox(void);
   void  checkBrushRay(brush* curBrush);
   void  checkBrushRayN(brush* curBrush);
-  void   checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
+  void  checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
+  float  checkPatchAltitude(BspTreeNode* node); //! To be implemented...
 
   void drawDebugCube(Vector* cam);
