Index: trunk/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- trunk/src/lib/graphics/importer/bsp_manager.cc	(revision 9061)
+++ 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 9061)
+++ 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 9061)
+++ 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 9061)
+++ 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"
