Index: branches/ODE/src/lib/graphics/importer/bsp/bsp_file.cc
===================================================================
--- trunk/src/lib/graphics/importer/bsp/bsp_file.cc	(revision 10161)
+++ branches/ODE/src/lib/graphics/importer/bsp/bsp_file.cc	(revision 10355)
@@ -40,4 +40,7 @@
 #include <vector>
 
+#ifdef WITH_ODE
+#include <ode/ode.h>
+#endif
 
 
@@ -330,4 +333,7 @@
     this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)];
  // this->patchRowIndexes = new int*[7*4*this->numPatches]; Not needed?
+    #ifdef WITH_ODE
+    this->ODE_Geometry = new dTriMeshDataID[this->numPatches*7*7];
+    #endif
     this->patchTrianglesPerRow = new char[7*4*this->numPatches];
     this->VertexArrayModels  = new VertexArrayModel*[this->numPatches];
@@ -728,5 +734,13 @@
  * @todo cleanup this function, let the user choose the level of tesselation
  */
-
+#ifdef WITH_ODE
+uint  Ind [] = {8,0,9,     0,1,9,     9,1,10,   1,2,10,    10,2,11,  2,3,11,   11,3,12,  3,4,12,    12,4,13,  4,5,13,   13,5,14,   5,6,14,   14,6,15,  6,7,15,  
+		16,8,17,   8,9,17,    17,9,18,  9,10,18,   18,10,19, 10,11,19, 19,11,20, 11,12,20,  20,12,21, 12,13,21, 21,13,22, 13,14,22,  22,14,23, 14,15,23, 
+		24,16,25,  16,17,25,  25,17,26, 17,18,26,  26,18,27, 18,19,27, 27,19,28, 19,20,28,  28,20,29, 20,21,29, 29,21,30, 21,22,30,  30,22,31, 22,23,31, 
+		32,24,33,  24,25,33,  33,25,34, 25,26,34,  34,26,35, 26,27,35, 35,27,36, 27,28,36,  36,28,37, 28,29,37 ,37,29,38, 29,30,38,  38,30,39, 30,31,39, 
+		40,32,41,  32,33,41,  41,33,42, 33,34,42,  42,34,43, 34,35,43, 43,35,44, 35,36,44,  44,36,45, 36,37,45, 45,37,46, 37,38,46,  46,38,47, 38,39,47, 
+		48,40,49,  40,41,49,  49,41,50, 41,42,50,  50,42,51, 42,43,51, 51,43,52, 43,44,52,  52,44,53, 44,45,53, 53,45,54, 45,46,54,  54,46,55, 46,47,55, 
+		56,48,57,  48,49,57,  57,49,58, 49,50,58,  58,50,59, 50,51,59, 59,51,60, 51,52,60,  60,52,61, 52,53,61, 61,53,62, 52,54,62,  62,54,63, 54,55,63, 0 };
+#endif
 
 void BspFile::tesselate(int iface)
@@ -888,4 +902,10 @@
         }
       }
+
+	#ifdef WITH_ODE
+	this->ODE_Geometry[this->patchOffset] = dGeomTriMeshDataCreate();
+     // Create ODE Triangle Mesh Geometry
+	dGeomTriMeshDataBuildSingle(this->ODE_Geometry[this->patchOffset], &((((BspVertex*)(this->patchVertice))[level1*level1*this->patchOffset ]).position[0]), sizeof(BspVertex), level1*level1, &(Ind[0]) ,7*14*3, 3* sizeof(uint) );
+	#endif
 
 
Index: branches/ODE/src/lib/graphics/importer/bsp/bsp_file.h
===================================================================
--- trunk/src/lib/graphics/importer/bsp/bsp_file.h	(revision 10161)
+++ branches/ODE/src/lib/graphics/importer/bsp/bsp_file.h	(revision 10355)
@@ -17,4 +17,9 @@
   Quake 3 Collision Detection by Nathan Ostgard        http://www.devmaster.net/articles/quake3collision/
 */
+
+#define WITH_ODE
+#ifdef WITH_ODE
+#include <ode/ode.h>
+#endif
 
 #include <vector>
@@ -159,4 +164,8 @@
   AMat loadMat( char* mat );
   AMat loadAVI(char * mat);
+
+  #ifdef WITH_ODE
+	dTriMeshDataID*    getODE_Geometry(void) {return this->ODE_Geometry;}
+  #endif
  
 
@@ -215,4 +224,10 @@
  
   ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials
+
+  #ifdef WITH_ODE
+	  dTriMeshDataID*   ODE_Geometry; //!< ODE Geometry Data for patches
+ 	  dGeomID*          ODE_Geom_IDs; //!< IDs of ODE Geometry Data
+  #endif
+
 };
 
Index: branches/ODE/src/lib/graphics/importer/bsp/bsp_manager.cc
===================================================================
--- trunk/src/lib/graphics/importer/bsp/bsp_manager.cc	(revision 10161)
+++ branches/ODE/src/lib/graphics/importer/bsp/bsp_manager.cc	(revision 10355)
@@ -49,4 +49,7 @@
 #include "collision_tube.h"
 
+#ifdef WITH_ODE
+	#include<ode/ode.h>
+#endif
 
 //CREATE_FACTORY( BspManager, CL_BSP_MODEL);
@@ -88,5 +91,20 @@
 int BspManager::load(const char* fileName, float scale)
 {
+#ifdef WITH_ODE
+  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;
+  }
+#endif
   // open a BSP file
+
 
 
@@ -101,4 +119,21 @@
 
   this->outputFraction = 1.0f;
+
+
+#ifdef WITH_ODE
+	
+  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);
+
+	}
+
+#endif
+
 
   return 0;
@@ -124,5 +159,5 @@
 {
 
-  if(!this->bspFile->MovieMaterials.empty()) {
+  if(unlikely(!this->bspFile->MovieMaterials.empty())) {
     ::std::vector<MoviePlayer *>::iterator it = this->bspFile->MovieMaterials.begin() ;
     while(it != this->bspFile->MovieMaterials.end()) {
@@ -138,4 +173,12 @@
 const void BspManager::draw()
 {
+
+// Remove lines below
+//glShadeModel( GL_SMOOTH );							// Enable Smooth Shading
+	//glColor( 0.0f, 0.0f, 0.0f, 0.5f );		// Black Background
+	//glClearDepth( 1.0f );								// Depth Buffer Setup
+	//glClearStencil( 0 );									// Stencil Buffer Setup
+	//glEnable( GL_DEPTH_TEST );							// Enables Depth Testing
+	//glDepthFunc( GL_LEQUAL );
 
   /*
@@ -171,5 +214,5 @@
   this->lastTex = -1;
   // erase alreadyVisible
-  for(int i = 0; i < this->bspFile->numFaces; i++) this->alreadyVisible[i] = false;
+ // for(int i = 0; i < this->bspFile->numFaces; i++) this->alreadyVisible[i] = false;
   float tmp = 0;
   //this->opal.clear();
@@ -184,6 +227,6 @@
 
 
-  this->viewDir=    State::getCamera()->getAbsDirX();
-  float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z);
+ // this->viewDir=    State::getCamera()->getAbsDirX();
+ // float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z);
 
   BspTreeNode*  ActLeaf = this->getLeaf(this->bspFile->root, &ship);
@@ -197,12 +240,10 @@
 
 
-  this->outputStartsOut = true;
-  this->outputAllSolid = false;
-  this->outputFraction = 1.0f;
-
-  if ( viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
-  {
-
-
+  //this->outputStartsOut = true;
+  //this->outputAllSolid = false;
+  //this->outputFraction = 1.0f;
+
+  if (unlikely( viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0) )  //!< if (sizeof(Visdata) == 0)
+  {
 
     // Iterate through all Leafs
@@ -258,9 +299,9 @@
 
       if(cluster < 0) continue;
-      v = ((viscluster *  ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8));
+      v = ((viscluster *  ( ((int *)this->bspFile->visData)[1]) ) + (cluster >> 3));
       visSet =((char*) (this->bspFile->visData))[v + 8];
 
       // gets bit of visSet
-      if( ((visSet) & (1 << (cluster &  7))) != 0 ) {
+      if( ((visSet) & (1 << (cluster &  7))) /* != 0 */) {
 
         // Frustum culling
@@ -275,5 +316,5 @@
         const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist;
 
-        if(dMins < -70.0 && dMaxs < -70.0) {
+        if(dMins < -0.0 && dMaxs < -0.0) {
           continue;
         }
@@ -299,9 +340,13 @@
 
   while(!this->opal.empty()) {
+
+    
     this->draw_face(this->opal.front());
+    this->alreadyVisible[(int)(this->opal.front())] = false;
     this->opal.pop_front();
   }
   while(!this->trasparent.empty()) {
     this->draw_face(this->trasparent.back());
+    this->alreadyVisible[(int)(this->trasparent.back())] = false;
     this->trasparent.pop_back();
   }
@@ -319,8 +364,9 @@
 {
   face& curFace =  (this->bspFile->faces)[curface];
+  if (unlikely(curFace.effect != -1)) return;
   const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
-  int stride = sizeof(BspVertex);  // sizeof(Vertex)
+  const int stride = sizeof(BspVertex);  // sizeof(Vertex)
   int offset    = curFace.vertex;
-  if (curFace.effect != -1) return;
+ 
   // PRINTF(0)("BSP Manager: ");
   // PRINTF(0)("BSP Manager: type: %i  \n", curFace.texture);
@@ -353,5 +399,5 @@
   }
 
-  if(curFace.lm_index < 0) {
+  if(unlikely(curFace.lm_index < 0)) {
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     glActiveTextureARB(GL_TEXTURE1_ARB);
@@ -375,4 +421,13 @@
   glEnableClientState(GL_NORMAL_ARRAY );
   //  glEnableClientState(GL_COLOR_ARRAY);
+
+ //TUTU
+//glShadeModel( GL_SMOOTH );							// Enable Smooth Shading
+//	glClearColor( 0.0f, 0.0f, 0.0f, 0.5f );		// Black Background
+//	glClearDepth( 1.0f );								// Depth Buffer Setup
+//	glClearStencil( 0 );									// Stencil Buffer Setup
+//	glEnable( GL_DEPTH_TEST );							// Enables Depth Testing
+//	glDepthFunc( GL_LEQUAL );
+ //TUTU
 
 
@@ -449,12 +504,13 @@
 void BspManager::draw_patch(face* Face)
 {
+  if (Face->effect != -1) return;
   if(this->lastTex != Face->texture) {
     this->bspFile->Materials[Face->texture].mat->select();
     this->lastTex = Face->texture;
   }
-  if (Face->effect != -1) return;
-
-
-  if(Face->lm_index < 0) {
+  
+
+
+  if(unlikely(Face->lm_index < 0)) {
     glActiveTextureARB(GL_TEXTURE1_ARB);
     glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap);
@@ -960,4 +1016,5 @@
 {
 
+
   // Init  Collision Detection
   this->outputStartsOut = true;
@@ -969,4 +1026,138 @@
   this->checkCollisionY(worldEntity);
   this->checkCollisionZ(worldEntity);
+
+
+#ifdef WITH_ODE
+	// Create the World-Entities BBOX
+   AABB* box = worldEntity->getModelAABB();
+   dReal  aabbox [6];
+
+
+	if(  box != NULL)
+{
+	
+	
+	//PRINTF(0)(" BOX NOT NULL ........... \n");
+
+	dGeomID RayX =    dCreateRay(this->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] * 1.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  ; 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(true || dCollide(this->ODE_Geom_IDs[i],BBOX, 1, &contact[0].geom, sizeof(dContact)) ) {
+					
+					if( true || 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)))  {
+						          CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_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]), true);	
+							
+						}//if		
+						if(dCollide(this->ODE_Geom_IDs[i],RayXNeg, 1, &contact[0].geom, sizeof(dContact)))  {
+							  CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_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]), true);
+							 
+						}//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)))  {
+							  CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_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)))  {
+							  CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_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 {
+
+						CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_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(true || 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)))  {
+							 CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_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]), true);
+							
+						}//if
+						if(dCollide(this->ODE_Geom_IDs[i],RayZNeg, 1, &contact[0].geom, sizeof(dContact)))  {
+							  CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_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]), true);
+							
+						}//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)
+#endif
 
 
Index: branches/ODE/src/lib/graphics/importer/bsp/bsp_manager.h
===================================================================
--- trunk/src/lib/graphics/importer/bsp/bsp_manager.h	(revision 10161)
+++ branches/ODE/src/lib/graphics/importer/bsp/bsp_manager.h	(revision 10355)
@@ -31,4 +31,10 @@
 #define BSP_Y_OFFSET 40.0f
 #define BSP_Z_OFFSET 20.0f
+
+#define WITH_ODE
+
+#ifdef WITH_ODE 
+	#include <ode/ode.h>
+#endif
 
 
@@ -136,4 +142,13 @@
 
   int tgl;
+
+
+  #ifdef WITH_ODE
+   dWorldID world;
+   dSpaceID space;
+   dJointGroupID contactgroup;
+   dContact contact[300];
+   dGeomID*          ODE_Geom_IDs; //!< IDs of ODE Geometry Data
+  #endif
 };
 
