Index: branches/ODE/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- branches/ODE/src/lib/graphics/importer/bsp_manager.cc	(revision 9904)
+++ branches/ODE/src/lib/graphics/importer/bsp_manager.cc	(revision 9919)
@@ -48,4 +48,6 @@
 #include "cr_defs.h"
 
+#include<ode/ode.h>
+
 
 //CREATE_FACTORY( BspManager, CL_BSP_MODEL);
@@ -88,4 +90,18 @@
 {
   // open a BSP file
+  this->world =  dWorldCreate();
+  space = dSimpleSpaceCreate(0);
+ 
+   //!fixme
+  for (int i=0; i<30; i++) {
+    contact[i].surface.mode = dContactBounce | dContactSoftCFM;
+    contact[i].surface.mu = dInfinity;
+    contact[i].surface.mu2 = 0;
+    contact[i].surface.bounce = 0.1;
+    contact[i].surface.bounce_vel = 0.1;
+    contact[i].surface.soft_cfm = 0.01;
+  }
+
+
 
 
@@ -101,4 +117,14 @@
   this->outputFraction = 1.0f;
 
+  contactgroup = dJointGroupCreate (0);
+  dWorldSetGravity (world,0,0,-0.5);
+  dWorldSetCFM (world,1e-5);
+ this->ODE_Geom_IDs = new dGeomID[this->bspFile->numPatches* 7 *7];
+
+  for( int i = 0 ; i < (this->bspFile->numPatches ); i++ )
+	{ 
+    		this->ODE_Geom_IDs[i] = dCreateTriMesh(space,(this->bspFile->getODE_Geometry())[i],0 , 0, 0);
+
+	}
   return 0;
 }
@@ -970,179 +996,133 @@
 
 
-#if 0
-  // Retrieve Bounding box
-  AABB* box = worldEntity->getModelAABB();
-
-
-  Vector forwardDir = Vector(0.0,0.0,1.0);
-  Vector upDir = Vector(0.0,1.0,0.0);
-  Vector position = worldEntity->getAbsCoor();
-
-  bool SolidFlag = false;
-  bool collision = false;
-  Vector position1 = position;
-  Vector position2 = position + Vector(0.0,1.0,0.0);
-  Vector position3 = position;
-  Vector position4 = position + Vector(0.0,1.0,0.0);
-  Vector dest = worldEntity->getAbsCoor() - upDir*40.0f; //
-  Vector dest1 = position + forwardDir*4.0f;
-  Vector dest2 = position2 + forwardDir*4.0;
-  Vector dest3 = position + forwardDir*4.0f;
-  Vector dest4 = position2 + forwardDir*4.0;
-  dest = position - Vector(0.0, 40.0,0.0);
-  Vector out = dest;
-  Vector out1;
-  Vector out2;
-
-
-  plane* testPlane;
-
-  bool xCollision = false;
-  bool zCollision = false;
-
-
-  float height = 40;
-
-
-  if( box != NULL) {
-    position = worldEntity->getAbsCoor() +  box->center; // + Vector(0.0, 1.0, 0.0) * box->halfLength[1] * 1.0f;
-    dest     = worldEntity->getAbsCoor() +  box->center - Vector(0.0, 1.0, 0.0) * (box->halfLength[1] + BSP_Y_OFFSET) *   100;
-
-    Vector dirX =  worldEntity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize();
-
-    //position1 = worldEntity->getAbsCoor() +  box->center - dirX * (box->halfLength[0]  + BSP_X_OFFSET);
-    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);
-    dest3     = worldEntity->getAbsCoor() +  box->center + dirZ * (box->halfLength[2]  + BSP_Z_OFFSET);
-    dest4     = worldEntity->getAbsCoor() -  box->center + dirZ * (box->halfLength[2]  + BSP_Z_OFFSET);
-  } else {
-    // Init positions and destinations to anything useful!
-
-  }
-
-
-
-  // 1st Ray: Y RAY
-  this->inputStart =  position;
-  this->inputEnd =   dest;
-  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
-
-
-  //
-  if(!this->outputStartsOut ) {
-    this->collPlane = new plane;
-    this->collPlane->x = 0.0f;
-    this->collPlane->y = 0.0f;
-    this->collPlane->z = 0.0f;
-    collision = 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;
-        collision = true;
-        SolidFlag = true;
-      } else
-        collision = false;
-
-
-      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;
-
-      Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z);
-      this->out = out;
-    }
-  }
-    testPlane = this->collPlane;
-
-
-  bool xCollisionNeg = false;
-  bool zCollisionNeg = false;
-
-
-
-    // 2nd Collision Detection X-RAY
-    this->outputStartsOut = true;
-    this->outputAllSolid = false;
-    this->outputFraction = 1.0f;
-    this->inputStart =  position1;
-    this->inputEnd =   dest1;
-    this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 );
-
-    if(this->outputFraction < 1.0f) {
-      out.x = dest1.x + (dest1.x -position1.x) * this->outputFraction;
-      dest1 = position1 + (dest1 -position1) * this->outputFraction;
-      xCollision = 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;
-      xCollision = true;
-    }
-    //out.z = this->outputFraction;
-
-
-
-      // 3rd Collision Detection Z-RAY
-      this->outputStartsOut = true;
-      this->outputAllSolid = false;
-      this->outputFraction = 1.0f;
-      this->inputStart =  position2;
-      this->inputEnd =   dest2;
-
-      this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 );
-      //out.x = this->outputFraction;
-
-      if(this->outputFraction < 1.0f ) {
-        out.z = out.z = dest2.z + (dest2.z -position2.z) * this->outputFraction;
-        dest2 = position2 + (dest2 -position2) * this->outputFraction;
-        zCollision = 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;
-        zCollision = true;
-      }
-
-
-  // Return the normal here: Normal's stored in this->collPlane;
-  if( collision) {
-    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);
-  }
-#endif
-
-}
-
+
+
+// Create the World-Entities BBOX
+   AABB* box = worldEntity->getModelAABB();
+   dReal  aabbox [6];
+
+if(  box != NULL)
+{
+	
+	dGeomID RayX =    dCreateRay(space,box->halfLength[0] *2.0f);
+	dGeomRaySet (RayX, worldEntity->getAbsCoor().x  - box->halfLength[0]  ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z,
+                  1.0f, 0.0f, 0.0f); 
+	dGeomID RayY =    dCreateRay(space,box->halfLength[1] *2.0f);
+	dGeomRaySet (RayY, worldEntity->getAbsCoor().x    ,worldEntity->getAbsCoor().y - box->halfLength[1], worldEntity->getAbsCoor().z,
+                  0.0f, 1.0f, 0.0f); 
+	dGeomID RayZ =    dCreateRay(space,box->halfLength[2] *2.0f);
+	dGeomRaySet (RayZ, worldEntity->getAbsCoor().x    ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z - box->halfLength[2],
+                  0.0f, 0.0f, 1.0f); 
+
+	dGeomID RayXPos =    dCreateRay(space,box->halfLength[0]);
+	dGeomRaySet (RayX, worldEntity->getAbsCoor().x    ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z,
+                  1.0f, 0.0f, 0.0f); 
+	dGeomID RayYPos =    dCreateRay(space,box->halfLength[1] );
+	dGeomRaySet (RayY, worldEntity->getAbsCoor().x    ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z,
+                  0.0f, 1.0f, 0.0f); 
+	dGeomID RayZPos =    dCreateRay(space,box->halfLength[2] );
+	dGeomRaySet (RayZ, worldEntity->getAbsCoor().x    ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z,
+                  0.0f, 0.0f, 1.0f); 
+
+	dGeomID RayXNeg =    dCreateRay(space,box->halfLength[0] * 40.0f );
+	dGeomRaySet (RayX, worldEntity->getAbsCoor().x    ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z,
+                  -1.0f, 0.0f, 0.0f); 
+	dGeomID RayYNeg =    dCreateRay(space,box->halfLength[1] );
+	dGeomRaySet (RayY, worldEntity->getAbsCoor().x    ,worldEntity->getAbsCoor().y , worldEntity->getAbsCoor().z,
+                  0.0f, -1.0f, 0.0f); 
+	dGeomID RayZNeg =    dCreateRay(space,box->halfLength[2] );
+	dGeomRaySet (RayZ, worldEntity->getAbsCoor().x    ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z ,
+                  0.0f, 0.0f, -1.0f); 
+
+ 
+    	dGeomID BBOX = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*40.0f + BSP_Y_OFFSET*30.0f ,2.0f* box->halfLength[2]);
+    	dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x  ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z);
+   	dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z);
+
+
+dGeomID BBOX2 ;
+ 
+   int g;
+   bool collision = false;
+
+   for( int i = 0 ; i < this->bspFile->numPatches /* * 7 */; i++ )
+	{  
+			// dGeomGetAABB (this->bspFile->ODE_Geom_IDs[i],aabbox );
+			// BBOX2 = dCreateBox (space, aabbox[1]-aabbox[0], aabbox[3]-aabbox[2], aabbox[5]-aabbox[4]);
+			//  dGeomSetPosition (BBOX2,(aabbox[1]+ aabbox[0])/2, (aabbox[3]+ aabbox[2])/2, (aabbox[4]+ aabbox[5])/2);
+			// dGeomDestroy(BBOX2);
+			 g = 0;
+			 if(dCollide(this->ODE_Geom_IDs[i],BBOX, 1, &contact[0].geom, sizeof(dContact)) ) {
+					
+					if(dCollide(this->ODE_Geom_IDs[i],RayX, 1, &contact[0].geom, sizeof(dContact)))  {
+						if(dCollide(this->ODE_Geom_IDs[i],RayXPos, 1, &contact[0].geom, sizeof(dContact)))  {
+						          worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(1.0f, 0.0f, 0.0f),
+                                                          Vector((float)contact[0].geom.pos[0],(float)contact[0].geom.pos[1],contact[0].geom.pos[2]), false);	
+							
+						}//if		
+						if(dCollide(this->ODE_Geom_IDs[i],RayXNeg, 1, &contact[0].geom, sizeof(dContact)))  {
+							  worldEntity->registerCollision(COLLISION_TYPE_AXIS_X_NEG , this->parent, worldEntity, Vector(1.0f, 0.0f, 0.0f),
+                                                          Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false);
+							 
+						}//if
+					}//if
+				
+					
+					if(dCollide(this->ODE_Geom_IDs[i],RayY, 1, &contact[0].geom, sizeof(dContact)))  {
+						
+						// worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f),
+                                                //          Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false);
+
+						//PRINTF(0)("Ground \n");
+						if(dCollide(this->ODE_Geom_IDs[i],RayYPos, 1, &contact[0].geom, sizeof(dContact)))  {
+							  worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f),
+                                                          Vector(contact[0].geom.pos[0],contact[0].geom.pos[1] ,contact[0].geom.pos[2]), false);
+							
+						}//if
+						else if(dCollide(this->ODE_Geom_IDs[i],RayYNeg, 1, &contact[0].geom, sizeof(dContact)))  {
+							  worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f),
+                                                          Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false);
+							
+						}//if
+						else {
+
+						worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f),
+                                                          Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false);
+
+						}
+
+					}//if
+				
+					if(dCollide(this->ODE_Geom_IDs[i],RayZ, 1, &contact[0].geom, sizeof(dContact)))  {
+						if(dCollide(this->ODE_Geom_IDs[i],RayZPos, 1, &contact[0].geom, sizeof(dContact)))  {
+							  worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(0.0f, 0.0f, 1.0f),
+                                                         Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false);
+							
+						}//if
+						if(dCollide(this->ODE_Geom_IDs[i],RayZNeg, 1, &contact[0].geom, sizeof(dContact)))  {
+							  worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this->parent, worldEntity, Vector(0.0f, 0.0f, 1.0f),
+                                                          Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false);
+							
+						}//if
+
+
+					}//if
+			
+			} //if
+		} //for
+			
+      dGeomDestroy(RayX);
+      dGeomDestroy(RayY);
+      dGeomDestroy(RayZ);
+      dGeomDestroy(RayXPos);
+      dGeomDestroy(RayYPos);
+      dGeomDestroy(RayZPos);
+      dGeomDestroy(RayXNeg);
+      dGeomDestroy(RayYNeg);
+      dGeomDestroy(RayZNeg);
+	
+     dGeomDestroy(BBOX);
+} // if(bbox != 0)
+}
 
 
