Index: /trunk/src/defs/class_id.h
===================================================================
--- /trunk/src/defs/class_id.h	(revision 8185)
+++ /trunk/src/defs/class_id.h	(revision 8186)
@@ -182,4 +182,5 @@
   CL_BUILDING                   =    0x00000310,
   CL_MAPPED_WATER               =    0x00000311,
+  CL_BSP_ENTITY                 =    0x00000312,
 
   // Playables
@@ -259,4 +260,5 @@
   CL_OBB                        =    0x00720000,
   CL_BOUNDING_SPHERE            =    0x00740000,
+  
 
 
@@ -285,5 +287,6 @@
   CL_HEIGHT_MAP                 =    0x0000090a,
   CL_GRID                       =    0x0000090b,
-
+  CL_BSP_MODEL                  =    0x0000090c, //!FIXME 
+  
   CL_MATERIAL                   =    0x00000810,
   CL_SHADER                     =    0x00000811,
Index: /trunk/src/lib/collision_detection/cd_engine.cc
===================================================================
--- /trunk/src/lib/collision_detection/cd_engine.cc	(revision 8185)
+++ /trunk/src/lib/collision_detection/cd_engine.cc	(revision 8186)
@@ -29,5 +29,5 @@
 #include "quadtree_node.h"
 
-
+#include "bsp_manager.h"
 
 using namespace std;
@@ -95,13 +95,24 @@
  *  this checks the collisions with the ground
  */
-void CDEngine::checkCollisionGround()
+void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
 {
   if( likely( this->terrain != NULL))
   {
     Quadtree* q = dynamic_cast<Terrain*>(this->terrain)->ssp->getQuadtree();
-
 //    QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
   }
-  //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor());
+  
+  if( likely( this->bspManager != NULL))
+  {
+    std::list<WorldEntity*>::iterator iterator;
+    PRINTF(3)("checking for collisions\n");
+
+    iterator = list1.begin();
+    while (iterator != list1.end())
+    {
+      bspManager->checkCollision(*iterator);
+      iterator++;
+    }
+  }
 }
 
Index: /trunk/src/lib/collision_detection/cd_engine.h
===================================================================
--- /trunk/src/lib/collision_detection/cd_engine.h	(revision 8185)
+++ /trunk/src/lib/collision_detection/cd_engine.h	(revision 8186)
@@ -17,4 +17,5 @@
 class OBBTree;
 class Terrain;
+class BspManager;
 //class Player;
 
@@ -50,6 +51,8 @@
 
   inline void setTerrain(Terrain* terrain) { this->terrain = terrain; }
+  inline void setBSPModel(BspManager* bspManager) { this->bspManager = bspManager; }
 
   void checkCollisions(std::list<WorldEntity*>& list1, std::list<WorldEntity*>& list2);
+  void checkCollisionGround(std::list<WorldEntity*>& list1);
 
   void drawBV(const std::list<WorldEntity*>& drawList, int level) const;
@@ -69,5 +72,5 @@
 
   void checkCollisionObjects();
-  void checkCollisionGround();
+
 
   void debugSpawnTree(int depth, sVec3D* vertices, int numVertices);
@@ -81,4 +84,5 @@
 
   Terrain*                terrain;                          //!< this it a ref to the terrain, serving as a ground for all WE
+  BspManager*             bspManager;
 };
 
Index: /trunk/src/lib/coord/p_node.h
===================================================================
--- /trunk/src/lib/coord/p_node.h	(revision 8185)
+++ /trunk/src/lib/coord/p_node.h	(revision 8186)
@@ -191,7 +191,8 @@
   /** tells the child that the parent's Direction has changed */
   inline void parentDirChanged () { this->bRelDirChanged = true; }
+ public:
   /** @returns the last calculated coordinate */
   inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
-
+ private:
   static PNode* createNullParent();
   void reparent();
Index: /trunk/src/lib/graphics/importer/Makefile.am
===================================================================
--- /trunk/src/lib/graphics/importer/Makefile.am	(revision 8185)
+++ /trunk/src/lib/graphics/importer/Makefile.am	(revision 8186)
@@ -16,23 +16,36 @@
                            height_map.cc \
                            media_container.cc \
-                           movie_player.cc
+                           movie_player.cc \
+                           \
+                           bsp_manager.cc \
+                           bsp_file.cc \
+                           bsp_tree_node.cc \
+                           bsp_tree_leaf.cc
+
+
 
 libtc_a_SOURCES  = tc.cc
 
 
-noinst_HEADERS = model.h \
-		 tc.h \
-                 vertex_array_model.h \
-                 grid.h \
-                 static_model.h \
-                 objModel.h \
-                 primitive_model.h \
-                 md2Model.h \
-                 material.h \
-                 texture.h \
-                 texture_sequence.h \
-                 height_map.h \
-                 anorms.h \
-                 anormtab.h \
-                 media_container.h \
-                 movie_player.h
+noinst_HEADERS = \
+		model.h \
+		tc.h \
+		vertex_array_model.h \
+		grid.h \
+		static_model.h \
+		objModel.h \
+		primitive_model.h \
+		md2Model.h \
+		material.h \
+		texture.h \
+		texture_sequence.h \
+		height_map.h \
+		anorms.h \
+		anormtab.h \
+		media_container.h \
+		movie_player.h\
+		\
+		bsp_manager.h \
+		bsp_file.h \
+		bsp_tree_node.h \
+		bsp_tree_leaf.h
Index: /trunk/src/lib/graphics/importer/bsp_file.cc
===================================================================
--- /trunk/src/lib/graphics/importer/bsp_file.cc	(revision 8186)
+++ /trunk/src/lib/graphics/importer/bsp_file.cc	(revision 8186)
@@ -0,0 +1,1052 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2006 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: bottac@ee.ethz.ch
+
+   Inspired by:
+   Rendering Q3 Maps by Morgan McGuire                  http://graphics.cs.brown.edu/games/quake/quake3.html
+   Unofficial Quake 3 Map Specs by Kekoa Proudfoot      http://graphics.stanford.edu/~kekoa/q3/
+   Quake 3 Collision Detection by Nathan Ostgard        http://www.devmaster.net/articles/quake3collision/
+*/
+
+
+#include "bsp_file.h"
+#include "bsp_tree_node.h"
+#include <fstream>
+#include "file.h"
+#include <sys/stat.h>
+#include <string.h>
+#include "debug.h"
+#include "material.h"
+#include "vertex_array_model.h"
+// Necessary ?
+#include "base_object.h"
+#include "vector.h"
+#include "util/loading/resource_manager.h"
+#include "movie_player.h"
+
+#include <SDL/SDL_endian.h>
+#include <SDL/SDL_image.h>
+
+using namespace std;
+
+
+// Constructor
+BspFile::BspFile()
+{}
+
+/**
+ *  Loads a quake3 level (*.bsp)
+ * @param name the Name of the *.bsp file
+ */
+int BspFile::read(const char* name)
+{
+  //this->scale = 0.4;
+  int offset;
+  int size;
+  struct stat results;
+
+
+  if (stat( name , &results) == 0) {
+    PRINTF(0)("BSP FILE: Datei %s gefunden. \n", name);
+    ifstream bspFile (name, ios::in | ios::binary);
+    bspFile.read(this->header, 260);
+    PRINTF(0)("BSP FILE: BSPVersion: %i. \n", ((int *)(header) )[1]);
+    if(SDL_SwapLE32(((int *)(header) )[1]) == 46)    PRINTF(0)("BSP FILE: This is the good one! :-)  \n");
+    else  PRINTF(0)("BSP FILE: Wrong BSPVersion.\n");   //!< now, we should do some error handling
+
+    // Get the Nodes
+    offset = SDL_SwapLE32(((int *)(header) )[8]);
+    size    = SDL_SwapLE32(((int *)(header))[9]);
+    PRINTF(4)("BSP FILE: NodeSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumNodes: %i. \n", size / sizeof(node));
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(node));
+    PRINTF(4)("BSP FILE: NodeOffset: %i. \n", offset);
+    this->numNodes = size/sizeof(node);
+    this->nodes = new node [this->numNodes];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->nodes, size);
+
+    // and their Planes
+    offset = SDL_SwapLE32(((int *)(header) )[6]);
+    size    = SDL_SwapLE32(((int *)(header))[7]);
+    PRINTF(4)("BSP FILE: PlanesSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumPlanes: %i. \n", size / sizeof(plane));
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", sizeof(plane));
+    PRINTF(4)("BSP FILE: PlanesOffset: %i. \n", offset);
+    this->numPlanes = size/sizeof(plane);
+    this->planes = new plane [this->numPlanes];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->planes, size);
+
+    // Get the Leafs
+    offset = SDL_SwapLE32(((int *)(header) )[10]);
+    size    = SDL_SwapLE32(((int *)(header))[11]);
+    PRINTF(4)("BSP FILE: LeaveSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumLeaves: %i. \n", size / sizeof(leaf));
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(leaf));
+    PRINTF(4)("BSP FILE: LeaveOffset: %i. \n", offset);
+    this->numLeafs = size/sizeof(leaf);
+    this->leaves = new leaf [this->numLeafs];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->leaves, size);
+
+    // Get the Models
+    offset = SDL_SwapLE32(((int *)(header))[16]);
+    size    = SDL_SwapLE32(((int *)(header))[17]);
+    PRINTF(4)("BSP FILE: ModelsSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumModels: %i. \n", size / sizeof(model));
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(model));
+    PRINTF(4)("BSP FILE: ModelsOffset: %i. \n", offset);
+    this->numBspModels = size/sizeof(model);
+    this->bspModels = new model [this->numBspModels];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->bspModels, size);
+
+    // Get the leafFaces
+    offset = SDL_SwapLE32(((int *)(header))[12]);
+    size    = SDL_SwapLE32(((int *)(header))[13]);
+    PRINTF(4)("BSP FILE: leafFacesSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumleafFaces: %i. \n", size / 4);
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4);
+    PRINTF(4)("BSP FILE: leafFacesOffset: %i. \n", offset);
+    this->numLeafFaces = size/4;
+    this->leafFaces = new char [size];
+    bspFile.seekg(offset);
+    bspFile.read(this->leafFaces, size);
+
+    // Get the leafBrushes
+    offset = SDL_SwapLE32(((int *)(header))[14]);
+    size    = SDL_SwapLE32(((int *)(header))[15]);
+    PRINTF(4)("BSP FILE: leafBrushesSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumleafBrushes: %i. \n", size / 4);
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4);
+    PRINTF(4)("BSP FILE: leafBrushesOffset: %i. \n", offset);
+    this->numLeafBrushes = size/4;
+    this->leafBrushes = new char [size];
+    bspFile.seekg(offset);
+    bspFile.read(this->leafBrushes, size);
+
+    // Get the brushes
+    offset = SDL_SwapLE32(((int *)(header))[18]);
+    size    = SDL_SwapLE32(((int *)(header))[19]);
+    PRINTF(4)("BSP FILE: BrushesSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumBrushes: %i. \n", size / sizeof(brush));
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(brush));
+    PRINTF(4)("BSP FILE: BrushesOffset: %i. \n", offset);
+    this->brushes = new brush [size/sizeof(brush)];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->brushes, size);
+
+    // Get the brushSides
+    offset =   SDL_SwapLE32(((int *)(header))[20]);
+    size    = SDL_SwapLE32(((int *)(header))[21]);
+    PRINTF(4)("BSP FILE: BrushSidesSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumBrushSides: %i. \n", size / 8);
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 8);
+    PRINTF(4)("BSP FILE: BrushSidesOffset: %i. \n", offset);
+    this->numBrushSides = size/sizeof(brushside);
+    this->brushSides = new brushside [this->numBrushSides];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->brushSides, size);
+
+    // Get the Vertice
+    offset = SDL_SwapLE32(((int *)(header))[22]);
+    size    = SDL_SwapLE32(((int *)(header))[23]);
+    PRINTF(4)("BSP FILE: VerticeSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumVertice: %i. \n", size / 44);
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 44);
+    PRINTF(4)("BSP FILE: VerticeOffset: %i. \n", offset);
+    this->numVertex = size/44;
+    this->vertice = new char [size];
+    bspFile.seekg(offset);
+    bspFile.read(this->vertice, size);
+
+    // Get the MeshVerts
+    offset = SDL_SwapLE32(((int *)(header))[24]);
+    size    = SDL_SwapLE32(((int *)(header))[25]);
+    PRINTF(4)("BSP FILE: MeshVertsSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumMeshVerts: %i. \n", size / sizeof(meshvert));
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(meshvert));
+    PRINTF(4)("BSP FILE: MeshVertsOffset: %i. \n", offset);
+    this->meshverts = new meshvert [size / sizeof(meshvert)];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->meshverts, size);
+
+    // Get the Faces
+    offset = SDL_SwapLE32(((int *)(header))[28]);
+    size    = SDL_SwapLE32(((int *)(header))[29]);
+    PRINTF(4)("BSP FILE: FacesSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumFaces: %i. \n", size / sizeof(face));
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(face));
+    PRINTF(4)("BSP FILE: FacesOffset: %i. \n", offset);
+    this->numFaces = size/sizeof(face);
+    this->faces = new face [this->numFaces];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->faces, size);
+
+    //Get the lightmaps
+    offset = SDL_SwapLE32(((int *)(header))[30]);
+    size    = SDL_SwapLE32(((int *)(header))[31]);
+    this->numLightMaps = size/ sizeof(lightmap);
+    this->lightMaps = new lightmap [this->numLightMaps];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->lightMaps, size);
+
+
+    // Get the Visdata
+    offset = SDL_SwapLE32(((int *)(header))[34]);
+    size    = SDL_SwapLE32(((int *)(header))[35]);
+
+    this->visData = new char [size];
+    bspFile.seekg(offset);
+    bspFile.read(this->visData, size);
+
+    PRINTF(4)("BSP FILE: VisDataSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumVisData: %i. \n", size /1 - 8);
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 1);
+    PRINTF(4)("BSP FILE: VisDataOffset: %i. \n", offset);
+
+    // Get the Textures
+    offset = SDL_SwapLE32(((int *)(header))[4]);
+    size    = SDL_SwapLE32(((int *)(header))[5]);
+
+    this->textures= new char [size];
+    bspFile.seekg(offset);
+    bspFile.read(this->textures, size);
+
+    PRINTF(4)("BSP FILE: TextureSize: %i Bytes. \n", size);
+    PRINTF(4)("BSP FILE: NumTextures: %i. \n", size /72);
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 72);
+    PRINTF(4)("BSP FILE: TextureOffset: %i. \n", offset);
+    this->numTextures = size/72;
+
+    bspFile.close();
+
+    for(int i = 0 ; i < this->numTextures; i++)
+      PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]);
+    this->load_textures();
+
+    // Load the lightMaps
+    this->glLightMapTextures = new GLuint[this->numLightMaps];
+    for(int i = 0; i < this->numLightMaps; i++)
+      this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]);
+
+    //Create white texture for if no lightmap specified
+    glGenTextures(1, &this->whiteLightMap);
+    glBindTexture(GL_TEXTURE_2D, this->whiteLightMap);
+        //Create texture
+    this->whiteTexture[0]=255;
+    this->whiteTexture[1]=255;
+    this->whiteTexture[2]=255;
+
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2);
+
+
+
+    /* control the mipmap levels */
+    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
+    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
+
+    /* build the Texture  OpenGL V >= 1.1 */
+    glTexImage2D(GL_TEXTURE_2D,
+                 0,
+                 GL_RGBA8,
+                 1,
+                 1,
+                 0,
+                 GL_RGB,
+                 GL_UNSIGNED_BYTE,
+                 (const GLvoid *)&(this->whiteTexture));
+
+   gluBuild2DMipmaps(   GL_TEXTURE_2D, GL_RGBA8, 1, 1,
+                      GL_RGB, GL_UNSIGNED_BYTE,(const GLvoid *) &(this->whiteTexture));
+
+
+
+    // Get the number of patches
+    this->numPatches = 0;
+    this->patchOffset   = 0;
+
+    for( int i = 0; i < this->numFaces; i++) {
+      face& cFace = ((face *)(this->faces))[i];
+      if (SDL_SwapLE32(cFace.type) == 2)
+        this->numPatches += (SDL_SwapLE32(cFace.size[0]) -1 ) / 2  * (SDL_SwapLE32(cFace.size[1]) -1) / 2;
+    }
+
+    // Allocate Memory
+    this->patchVertice = new char[8*8*44*(this->numPatches+10)];
+    this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)];
+    this->patchRowIndexes = new int*[7*4*this->numPatches];
+    this->patchTrianglesPerRow = new char[7*4*this->numPatches];
+    this->VertexArrayModels  = new VertexArrayModel*[this->numPatches];
+
+    PRINTF(0)("BSP FILE:NumberOfPatches: %i . \n", numPatches);
+
+    this->swapAllBspCoordinates();
+
+    // Do tesselation for all Faces of type 2
+    for( int i = 0; i < this->numFaces; i++) {
+      if (SDL_SwapLE32((this->faces)[i].type) == 2)
+        this->tesselate(i);
+    }
+
+    PRINTF(0)("BSP FILE:PatchOffset: %i . \n", this->patchOffset);
+
+    return  1;
+  } else {
+    PRINTF(0)("BSP FILE: Datei nicht gefunden. \n");
+    return -1;
+  }
+
+
+
+}
+
+void BspFile::build_tree()
+{
+
+  PRINTF(0)("BSP FILE:\n");
+  PRINTF(0)("BSP FILE: Building Tree...\n");
+  root = this->build_tree_rec(0);
+  PRINTF(0)("BSP FILE: ...done. \n");
+  PRINTF(0)("BSP FILE:  \n");
+  PRINTF(0)("BSP FILE: Node #0: \n");
+  PRINTF(0)("BSP FILE:  x: %f \n",root->plane.x);
+  PRINTF(0)("BSP FILE:  y: %f\n",root->plane.y);
+  PRINTF(0)("BSP FILE:  z: %f\n",root->plane.z);
+}
+
+/**
+ *  Called by BspFile::build_tree() only.
+ */
+BspTreeNode*   BspFile::build_tree_rec(int i)
+{
+  // PRINTF(0)("BSP FILE: Node #%i\n", i);
+  BspTreeNode* thisNode = new BspTreeNode();
+  int left =(((node *) nodes) [i]).left;
+  int right =(((node *) nodes) [i]).right;
+  int planeIndex = (((node *) nodes) [i]).plane;
+  float x1 =(((plane *) this->planes) [planeIndex]).x;
+  float y1 =(((plane *) this->planes) [planeIndex]).y;
+  float z1 =(((plane *) this->planes) [planeIndex]).z;
+  thisNode->leafIndex = 0;
+  thisNode->d          = (((plane *) this->planes) [planeIndex]).d;
+
+  thisNode->plane = Vector(x1,y1,z1);
+  thisNode->isLeaf = false;
+
+  if(left >= 0) {
+    thisNode->left = this->build_tree_rec(left);
+  } else {
+    //BspTreeLeaf tmp =  BspTreeLeaf();
+    //tmp.isLeaf = true;
+    //tmp.leafIndex = -left -1;
+    //thisNode->left = (BspTreeNode*) (&tmp);
+    thisNode->left  = new BspTreeNode();
+    thisNode->left->isLeaf = true;
+    thisNode->left->leafIndex = - (left +1);
+    //PRINTF(0)("BSP FILE:  LeafIndex: %i\n",-left);
+  } // assign leav
+  if(right >= 0) {
+    thisNode->right =  this->build_tree_rec(right);
+  } else {
+    //BspTreeLeaf tmp =  BspTreeLeaf();
+    //tmp.isLeaf = true;
+    //tmp.leafIndex = -right -1;
+    //thisNode->right = (BspTreeNode*) (&tmp);
+    thisNode->right = new BspTreeNode();
+    thisNode->right->isLeaf = true;
+    thisNode->right->leafIndex = -(right +1);
+    //PRINTF(0)("BSP FILE:  LeafIndex: %i\n",-right);
+  } // assign leaf
+  return thisNode;
+}
+
+/**
+ *  returns the root node of the bsp-tree
+ */
+BspTreeNode* BspFile::get_root()
+{
+  return root;
+}
+
+void BspFile::load_textures()
+{
+  ::std::string absFileName;
+  char fileName [228];
+  char ext [100];
+  struct stat results;
+
+
+  this->Materials = new AMat[this->numTextures];
+  for(int i = 0 ; i < this->numTextures; i++) {
+    PRINTF(0)("BSP FILE: Texture : %s. \n", &this->textures[8+ 72*i]);
+
+
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    if(strlen(fileName) == 0)
+    {
+     //         Default Material
+      this->Materials[i].mat = new Material();
+    this->Materials[i].mat->setDiffuse(0.1,0.1,1.0);
+    this->Materials[i].mat->setAmbient(0.1,0.1,1.0 );
+    this->Materials[i].mat->setSpecular(0.4,0.4,1.0);
+    //this->Materials[i]->setShininess(100.0);
+   // this->Materials[i].mat->setTransparency(1.0);
+    this->Materials[i].mat->setDiffuseMap("pictures/ground.tga");
+    this->Materials[i].mat->setAmbientMap("pictures/ground.tga");
+    this->Materials[i].mat->setSpecularMap("pictures/ground.tga");
+    this->Materials[i].alpha = false;
+    this->Materials[i].animated = false;
+     continue;
+    }
+
+      // Check for mov
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".mov");
+    strncat (fileName, ext, strlen(fileName));
+
+    absFileName = ResourceManager::getFullName(fileName);
+
+    if(File(absFileName).exists()) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] = this->loadAVI(fileName);
+      continue;
+    }
+
+    // Check for avi
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".avi");
+    strncat (fileName, ext, strlen(fileName));
+
+    absFileName = ResourceManager::getFullName(fileName);
+
+    if(File(absFileName).exists()) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] = this->loadAVI(fileName);
+      continue;
+    }
+
+       // Check for mpg
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".mpg");
+    strncat (fileName, ext, strlen(fileName));
+
+    absFileName = ResourceManager::getFullName(fileName);
+
+    if(File(absFileName).exists()) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] = this->loadAVI(fileName);
+      continue;
+    }
+
+    // Check for tga
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".tga");
+    strncat (fileName, ext, strlen(fileName));
+
+    absFileName = ResourceManager::getFullName(fileName);
+
+    if(File(absFileName).exists()) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] = this->loadMat(fileName);
+      continue;
+    }
+    // Check for TGA
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".TGA");
+    strncat (fileName, ext, strlen(fileName));
+    absFileName = ResourceManager::getFullName(fileName);
+
+    if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] = this->loadMat(fileName);
+      continue;
+    }
+    // Check for jpg
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".jpg");
+    strncat (fileName, ext, strlen(fileName));
+    absFileName = ResourceManager::getFullName(fileName);
+    if(File(absFileName).exists()) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] =this->loadMat(fileName);
+      continue;
+    }
+
+
+    // Check for JPG
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".JPG");
+    strncat (fileName, ext, strlen(fileName));
+    absFileName = ResourceManager::getFullName(fileName);
+    if(File(absFileName).exists()) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] =this->loadMat(fileName);
+      continue;
+    }
+
+
+
+    // Check for bmp
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".bmp");
+    strncat (fileName, ext, strlen(fileName));
+    absFileName = ResourceManager::getFullName(fileName);
+
+    if(File(absFileName).exists()) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] =this->loadMat(fileName);
+      continue;
+    }
+
+    // Check for BMP
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy(ext, ".BMP");
+    strncat (fileName, ext, strlen(fileName));
+    absFileName = ResourceManager::getFullName(fileName);
+
+    if(File(absFileName).exists()) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] = this->loadMat(fileName);
+      continue;
+    }
+
+
+    //  Default Material
+    this->Materials[i].mat = new Material();
+    this->Materials[i].mat->setDiffuse(0.1,0.1,0.1);
+    this->Materials[i].mat->setAmbient(0.1,0.1,0.1 );
+    this->Materials[i].mat->setSpecular(0.4,0.4,0.4);
+    //this->Materials[i]->setShininess(100.0);
+    //this->Materials[i].mat->setTransparency(1.0);
+    this->Materials[i].mat->setDiffuseMap("pictures/error_texture.png");
+    this->Materials[i].mat->setAmbientMap("pictures/error_texture.png");
+    this->Materials[i].mat->setSpecularMap("pictures/error_texture.png");
+    this->Materials[i].alpha = true;
+    this->Materials[i].animated = false;
+
+  }
+}
+
+
+AMat BspFile::loadMat(char* mat)
+{
+  AMat tmpAMat;
+  this->testSurf = NULL;
+
+  this->testSurf = IMG_Load(ResourceManager::getFullName(mat).c_str());
+  if(this->testSurf != NULL) {
+    if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true;
+    else                                       tmpAMat.alpha = false;
+  } else   tmpAMat.alpha = false;
+
+  Material* tmp = new Material();
+   tmp->setDiffuse(1.0,1.0,1.0);
+   tmp->setAmbient(1.0,1.0,1.0 );
+  tmp->setSpecular(1.0,1.0,1.0);
+  //    tmp->setShininess(.5);
+  //    tmp->setTransparency(0.0);
+
+  tmp->setDiffuseMap(mat);
+
+  tmpAMat.mat = tmp;
+  tmpAMat.animated = false;
+  return tmpAMat;
+}
+
+AMat BspFile::loadAVI(char* mat)
+{
+  AMat tmpAMat;
+
+
+  MoviePlayer * testMC = new MoviePlayer(mat);
+  testMC->start(0);
+
+  //Material* tmp = new Material();
+ // tmp->setDiffuse(1.0,1.0,1.0);
+  //tmp->setAmbient(1.0,1.0,1.0 );
+  //tmp->setSpecular(1.0,1.0,1.0);
+  //    tmp->setShininess(.5);tmpAMat
+  //    tmp->setTransparency(0.0);
+
+  //tmp->setDiffuseMap(mat);
+
+  tmpAMat.aviMat = testMC;
+  tmpAMat.animated = true;
+  tmpAMat.alpha = true;
+  return tmpAMat;
+}
+
+unsigned int BspFile::loadLightMapToGL(lightmap& lightMapTexture)
+{
+  int      errorCode = 0;           //!< the error code for the texture loading functions
+  unsigned int   lightMap;          //!< the OpenGL texture handle
+  int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
+  int      mipmapWidth = 0;         //!< the width of the mipmap
+  int      mipmapHight = 0;         //!< the height of the mipmap3
+  float sc, scale, temp;
+  for(int i = 0; i < 128*128*3 ; i++)
+  {
+  sc =  ((unsigned char *)(&lightMapTexture))[i];
+  sc *= 1/255.0;
+  scale = 2.0;
+  if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp;
+  scale*=255.0;
+  sc*=scale;
+  if(false)
+    ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc + 75;
+  else
+    ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc ;
+  }
+
+  glGenTextures(1, &lightMap);
+  glBindTexture(GL_TEXTURE_2D,  lightMap);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2);
+
+
+  /* control the mipmap levels */
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
+
+  /* build the Texture  OpenGL V >= 1.1 */
+   glTexImage2D(GL_TEXTURE_2D,
+                   0,
+                   GL_RGBA8,
+                   128,
+                   128,
+                   0,
+                   GL_RGB,
+                   GL_UNSIGNED_BYTE,
+                   (const GLvoid *)&lightMapTexture);
+
+
+   // build the MipMaps automaticaly
+   errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D,
+GL_RGBA8,
+                                 128,
+                                 128,
+                                 GL_RGB,
+                                 GL_UNSIGNED_BYTE,
+                                 (const GLvoid *)&lightMapTexture
+                                );
+
+
+
+
+  return lightMap;
+
+}
+
+/**
+ * Generates a vertex-array, a indice-array and a texture-coordinates-array for iface.
+ * @param iface integer index of face
+ * @todo cleanup this function, let the user choose the level of tesselation
+ */
+
+
+void BspFile::tesselate(int iface)
+{
+  face*  Face =  &((this->faces)[iface]);
+  BspVertex *  BspVrtx = (BspVertex*)this->vertice;
+  int level = 7;
+  int level1 = 8;
+  int size0 = (Face->size[0]);
+  int size1 = (Face->size[1]);
+  // For each patch...
+  for(int i = 0; i <  ( size0 - 1)    ; i+=2) {
+    for(int j = 0; j < ( size1 -1)    ; j+=2) {
+
+
+      // Make a patch...
+      // Get controls[9];
+      BspVec controls[9];
+      BspVec controlsTmp[9];
+      BspVertex VControls[9];
+      for(int k = 0; k < 3; k++) {
+        for(int l = 0; l < 3; l++) {
+          controls[k +3*l]. position[0] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[0]);
+          controls[k +3*l]. position[1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
+          controls[k +3*l]. position[2] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/
+
+          controlsTmp[2-k +6-3*l]. position[0] =   (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]);
+          controlsTmp[2-k +6-3*l]. position[1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
+          controlsTmp[2-k +6-3*l]. position[2] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/
+
+          VControls[k +3*l]. position[0] =   (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]);
+          VControls[k +3*l]. position[1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]);
+          VControls[k +3*l]. position[2] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]);
+
+          VControls[k +3*l]. normal[0] =   (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].normal[0]);
+          VControls[k +3*l]. normal[1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].normal[1]);
+          VControls[k +3*l]. normal[2] =   (    BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].normal[2]);
+
+          VControls[k +3*l]. texcoord[0][0]=    (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[0][0]);
+          VControls[k +3*l]. texcoord[0][1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[0][1]);
+          VControls[k +3*l]. texcoord[1][0] =   (    BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[1][0]);
+          VControls[k +3*l]. texcoord[1][1] =   (    BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[1][1]);
+
+
+        }
+      }
+      //***********************************************************************************************************************
+      // Compute the vertice
+      //***********************************************************************************************************************
+      float px, py;
+      BspVertex temp[3];
+      BspVertex* Vertice = &(((BspVertex*)this->patchVertice)[level1*level1*this->patchOffset]);
+
+      for(int v=0; v<=level; ++v) {
+        px=(float)v/level;
+
+        Vertice[v].position[0]=VControls[0].position[0]*((1.0f-px)*(1.0f-px))+VControls[3].position[0]*((1.0f-px)*px*2)+VControls[6].position[0]*(px*px);
+        Vertice[v].position[1]=VControls[0].position[1]*((1.0f-px)*(1.0f-px))+VControls[3].position[1]*((1.0f-px)*px*2)+VControls[6].position[1]*(px*px);
+        Vertice[v].position[2]=VControls[0].position[2]*((1.0f-px)*(1.0f-px))+VControls[3].position[2]*((1.0f-px)*px*2)+VControls[6].position[2]*(px*px);
+
+        Vertice[v].normal[0]=VControls[0].normal[0]*((1.0f-px)*(1.0f-px))+VControls[3].normal[0]*((1.0f-px)*px*2)+VControls[6].normal[0]*(px*px);
+        Vertice[v].normal[1]=VControls[0].normal[1]*((1.0f-px)*(1.0f-px))+VControls[3].normal[1]*((1.0f-px)*px*2)+VControls[6].normal[1]*(px*px);
+        Vertice[v].normal[2]=VControls[0].normal[2]*((1.0f-px)*(1.0f-px))+VControls[3].normal[2]*((1.0f-px)*px*2)+VControls[6].normal[2]*(px*px);
+
+        Vertice[v].texcoord[0][0]=VControls[0].texcoord[0][0]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[0][0]*((1.0f-px)*px*2)+VControls[6].texcoord[0][0]*(px*px);
+        Vertice[v].texcoord[0][1]=VControls[0].texcoord[0][1]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[0][1]*((1.0f-px)*px*2)+VControls[6].texcoord[0][1]*(px*px);
+        Vertice[v].texcoord[1][0]=VControls[0].texcoord[1][0]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[1][0]*((1.0f-px)*px*2)+VControls[6].texcoord[1][0]*(px*px);
+        Vertice[v].texcoord[1][1]=VControls[0].texcoord[1][1]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[1][1]*((1.0f-px)*px*2)+VControls[6].texcoord[1][1]*(px*px);
+
+      }
+
+
+      for(int u=1; u<=level; ++u) {
+        py=(float)u/level;
+
+        // temp[0]=controlPoints[0]*((1.0f-py)*(1.0f-py))+ controlPoints[1]*((1.0f-py)*py*2)+ controlPoints[2]*(py*py);
+        temp[0].position[0]=VControls[0].position[0]*((1.0f-py)*(1.0f-py))+VControls[1].position[0]*((1.0f-py)*py*2)+VControls[2].position[0]*(py*py);
+        temp[0].position[1]=VControls[0].position[1]*((1.0f-py)*(1.0f-py))+VControls[1].position[1]*((1.0f-py)*py*2)+VControls[2].position[1]*(py*py);
+        temp[0].position[2]=VControls[0].position[2]*((1.0f-py)*(1.0f-py))+VControls[1].position[2]*((1.0f-py)*py*2)+VControls[2].position[2]*(py*py);
+
+        temp[0].normal[0]=VControls[0].normal[0]*((1.0f-py)*(1.0f-py))+VControls[1].normal[0]*((1.0f-py)*py*2)+VControls[2].normal[0]*(py*py);
+        temp[0].normal[1]=VControls[0].normal[1]*((1.0f-py)*(1.0f-py))+VControls[1].normal[1]*((1.0f-py)*py*2)+VControls[2].normal[1]*(py*py);
+        temp[0].normal[2]=VControls[0].normal[2]*((1.0f-py)*(1.0f-py))+VControls[1].normal[2]*((1.0f-py)*py*2)+VControls[2].normal[2]*(py*py);
+
+        temp[0].texcoord[0][0]=VControls[0].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[0][0]*((1.0f-py)*py*2)+VControls[2].texcoord[0][0]*(py*py);
+        temp[0].texcoord[0][1]=VControls[0].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[0][1]*((1.0f-py)*py*2)+VControls[2].texcoord[0][1]*(py*py);
+        temp[0].texcoord[1][0]=VControls[0].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[1][0]*((1.0f-py)*py*2)+VControls[2].texcoord[1][0]*(py*py);
+        temp[0].texcoord[1][1]=VControls[0].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[1][1]*((1.0f-py)*py*2)+VControls[2].texcoord[1][1]*(py*py);
+
+
+
+        // temp[1]=controlPoints[3]*((1.0f-py)*(1.0f-py))+ controlPoints[4]*((1.0f-py)*py*2)+ controlPoints[5]*(py*py);
+        temp[1].position[0]=VControls[3].position[0]*((1.0f-py)*(1.0f-py))+VControls[4].position[0]*((1.0f-py)*py*2)+VControls[5].position[0]*(py*py);
+        temp[1].position[1]=VControls[3].position[1]*((1.0f-py)*(1.0f-py))+VControls[4].position[1]*((1.0f-py)*py*2)+VControls[5].position[1]*(py*py);
+        temp[1].position[2]=VControls[3].position[2]*((1.0f-py)*(1.0f-py))+VControls[4].position[2]*((1.0f-py)*py*2)+VControls[5].position[2]*(py*py);
+
+        temp[1].normal[0]=VControls[3].normal[0]*((1.0f-py)*(1.0f-py))+VControls[4].normal[0]*((1.0f-py)*py*2)+VControls[5].normal[0]*(py*py);
+        temp[1].normal[1]=VControls[3].normal[1]*((1.0f-py)*(1.0f-py))+VControls[4].normal[1]*((1.0f-py)*py*2)+VControls[5].normal[1]*(py*py);
+        temp[1].normal[2]=VControls[3].normal[2]*((1.0f-py)*(1.0f-py))+VControls[4].normal[2]*((1.0f-py)*py*2)+VControls[5].normal[2]*(py*py);
+
+        temp[1].texcoord[0][0]=VControls[3].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[0][0]*((1.0f-py)*py*2)+VControls[5].texcoord[0][0]*(py*py);
+        temp[1].texcoord[0][1]=VControls[3].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[0][1]*((1.0f-py)*py*2)+VControls[5].texcoord[0][1]*(py*py);
+        temp[1].texcoord[1][0]=VControls[3].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[1][0]*((1.0f-py)*py*2)+VControls[5].texcoord[1][0]*(py*py);
+        temp[1].texcoord[1][1]=VControls[3].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[1][1]*((1.0f-py)*py*2)+VControls[5].texcoord[1][1]*(py*py);
+
+
+        // temp[2]=controlPoints[6]*((1.0f-py)*(1.0f-py))+controlPoints[7]*((1.0f-py)*py*2)+controlPoints[8]*(py*py);
+        temp[2].position[0]=VControls[6].position[0]*((1.0f-py)*(1.0f-py))+VControls[7].position[0]*((1.0f-py)*py*2)+VControls[8].position[0]*(py*py);
+        temp[2].position[1]=VControls[6].position[1]*((1.0f-py)*(1.0f-py))+VControls[7].position[1]*((1.0f-py)*py*2)+VControls[8].position[1]*(py*py);
+        temp[2].position[2]=VControls[6].position[2]*((1.0f-py)*(1.0f-py))+VControls[7].position[2]*((1.0f-py)*py*2)+VControls[8].position[2]*(py*py);
+
+        temp[2].normal[0]=VControls[6].normal[0]*((1.0f-py)*(1.0f-py))+VControls[7].normal[0]*((1.0f-py)*py*2)+VControls[8].normal[0]*(py*py);
+        temp[2].normal[1]=VControls[6].normal[1]*((1.0f-py)*(1.0f-py))+VControls[7].normal[1]*((1.0f-py)*py*2)+VControls[8].normal[1]*(py*py);
+        temp[2].normal[2]=VControls[6].normal[2]*((1.0f-py)*(1.0f-py))+VControls[7].normal[2]*((1.0f-py)*py*2)+VControls[8].normal[2]*(py*py);
+
+        temp[2].texcoord[0][0]=VControls[6].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[0][0]*((1.0f-py)*py*2)+VControls[8].texcoord[0][0]*(py*py);
+        temp[2].texcoord[0][1]=VControls[6].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[0][1]*((1.0f-py)*py*2)+VControls[8].texcoord[0][1]*(py*py);
+        temp[2].texcoord[1][0]=VControls[6].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[1][0]*((1.0f-py)*py*2)+VControls[8].texcoord[1][0]*(py*py);
+        temp[2].texcoord[1][1]=VControls[6].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[1][1]*((1.0f-py)*py*2)+VControls[8].texcoord[1][1]*(py*py);
+
+
+
+
+        for(int v=0; v<=level; ++v) {
+          px=(float)v/level;
+
+
+
+
+
+          //Vertice[u*(tesselation+1)+v]=       temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px);
+          Vertice[u*(level1)+v].position[0]=temp[0].position[0]*((1.0f-px)*(1.0f-px))+temp[1].position[0]*((1.0f-px)*px*2)+temp[2].position[0]*(px*px);
+          Vertice[u*(level1)+v].position[1]=temp[0].position[1]*((1.0f-px)*(1.0f-px))+temp[1].position[1]*((1.0f-px)*px*2)+temp[2].position[1]*(px*px);
+          Vertice[u*(level1)+v].position[2]=temp[0].position[2]*((1.0f-px)*(1.0f-px))+temp[1].position[2]*((1.0f-px)*px*2)+temp[2].position[2]*(px*px);
+
+          Vertice[u*(level1)+v].normal[0]=temp[0].normal[0]*((1.0f-px)*(1.0f-px))+temp[1].normal[0]*((1.0f-px)*px*2)+temp[2].normal[0]*(px*px);
+          Vertice[u*(level1)+v].normal[1]=temp[0].normal[1]*((1.0f-px)*(1.0f-px))+temp[1].normal[1]*((1.0f-px)*px*2)+temp[2].normal[1]*(px*px);
+          Vertice[u*(level1)+v].normal[2]=temp[0].normal[2]*((1.0f-px)*(1.0f-px))+temp[1].normal[2]*((1.0f-px)*px*2)+temp[2].normal[2]*(px*px);
+
+          Vertice[u*(level1)+v].texcoord[0][0]=temp[0].texcoord[0][0]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[0][0]*((1.0f-px)*px*2)+temp[2].texcoord[0][0]*(px*px);
+          Vertice[u*(level1)+v].texcoord[0][1]=temp[0].texcoord[0][1]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[0][1]*((1.0f-px)*px*2)+temp[2].texcoord[0][1]*(px*px);
+          Vertice[u*(level1)+v].texcoord[1][0]=temp[0].texcoord[1][0]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[1][0]*((1.0f-px)*px*2)+temp[2].texcoord[1][0]*(px*px);
+          Vertice[u*(level1)+v].texcoord[1][1]=temp[0].texcoord[1][1]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[1][1]*((1.0f-px)*px*2)+temp[2].texcoord[1][1]*(px*px);
+
+
+
+        }
+      }
+
+      //Create indices
+      GLuint* indices= & ((GLuint*)(this->patchIndexes))[level*level1*2*this->patchOffset];
+
+      for(int row=0; row<level; ++row) {
+        for(int point=0; point<=level; ++point) {
+          //calculate indices
+          //reverse them to reverse winding
+          indices[(row*(level1)+point)*2+1]=row*(level1)+point;
+          indices[(row*(level1)+point)*2]=(row+1)*(level1)+point;
+        }
+      }
+
+
+      //***********************************************************************************************************************
+      // Debug Model
+      //***********************************************************************************************************************
+
+      this->VertexArrayModels[this->patchOffset] = new VertexArrayModel();
+      VertexArrayModel*  tmp = this->VertexArrayModels[this->patchOffset];
+      tmp->newStripe();
+      int a = 0;
+      int b = -1;
+      tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.0,0.0);
+      tmp->addColor(0.3,0.0,0.0);
+      tmp->addIndice(1+b);
+      tmp->addIndice(4+a);
+      tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.0,0.4);
+      tmp->addColor(0.3,0.0,0.0);
+      tmp->addIndice(2+b);
+      tmp->addIndice(5+a);
+      tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.0,1.0);
+      tmp->addColor(0.1,0.0,0.0);
+      tmp->addIndice(3+b);
+      tmp->addIndice(6+a);
+
+      tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.0,1.0);
+      tmp->addColor(0.1,0.0,0.0);
+      tmp->addIndice(7+a);
+      //tmp->addIndice(6);
+
+      tmp->newStripe();
+
+      tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.0,0.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(5+b);
+      tmp->addIndice(8+a);
+      tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.0,0.4);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(6+b);
+      tmp->addIndice(9+a);
+      tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.0,1.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(7+b);
+      tmp->addIndice(10+a);
+      tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]+0.01);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.0,1.0);
+      tmp->addColor(0.1,0.1,0.1);
+      //tmp->addIndice(5);
+      tmp->addIndice(11+a);
+
+      tmp->newStripe();
+
+
+
+      tmp->addVertex(controlsTmp[3].position[0],controlsTmp[3].position[1], controlsTmp[3].position[2]);
+      tmp->addNormal(0,1,0);
+      tmp->addTexCoor(0.5,0.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(9+b);
+      tmp->addIndice(12+a);
+      tmp->addVertex(controlsTmp[4].position[0],controlsTmp[4].position[1], controlsTmp[4].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.5,0.5);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(10+b);
+      tmp->addIndice(13+a);
+      tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.5,1.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(11+b);
+      tmp->addIndice(14+a);
+      tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]+0.01);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(0.5,1.0);
+      tmp->addColor(0.1,0.1,0.1);
+
+      tmp->addIndice(15+a);
+      //tmp->addIndice(9);
+      tmp->newStripe();
+
+      tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(1.0,0.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(13+b);
+      tmp->addIndice(16+a);
+
+      tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]);
+      tmp->addNormal(0,1,0);
+      tmp->addTexCoor(1.0,0.5);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(14+b);
+      tmp->addIndice(17+a);
+      tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(1.0,1.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(15+b);
+      tmp->addIndice(18+a);
+      tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(1.0,1.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(19+a);
+      //tmp->addIndice(13);
+
+      tmp->newStripe();
+      tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(1.0,0.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(17+b);
+
+      tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]);
+      tmp->addNormal(0,1,0);
+      tmp->addTexCoor(1.0,0.5);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(18+b);
+
+      tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(1.0,1.0);
+      tmp->addColor(0.1,0.1,0.1);
+      tmp->addIndice(19+b);
+
+      tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]);
+      tmp->addNormal(1,0,0);
+      tmp->addTexCoor(1.0,1.0);
+      tmp->addColor(0.1,0.1,0.1);
+
+      tmp->newStripe();
+
+      tmp->finalize();
+      // End of DebugModel
+
+      this->patchOffset++;
+    }// For
+  } // For
+
+  // Overwrite Face->meshvert;
+  // Overwrite Face->n_meshverts;
+  int sz = (size0 -1)/2 * (size1 -1)/2; // num patches
+  Face->meshvert = patchOffset -sz;  //3*(patchOffset-sz)*level1*level1;
+  Face->n_meshverts = sz;
+  PRINTF(0)("BSP FILE: sz: %i. \n", sz);
+  PRINTF(0)("BSP FILE: Face->meshvert %i . \n", Face->meshvert);
+
+  //Face->n_meshverts = sz;
+}
+
+//!TODO: This is a good place to do LittleEndian to BigEndian conversion!
+void BspFile::swapAllBspCoordinates()
+{
+
+  for(int i = 0; i < this->numVertex ; ++i)
+  {
+    this->swapCoords(&((BspVertex *)this->vertice)[i].position[0]);
+    this->swapCoords(&((BspVertex *)this->vertice)[i].normal[0]);
+
+
+  }
+
+  for(int i = 0; i < this->numLeafs ; ++i)
+  {
+    this->swapCoords(this->leaves[i].mins);
+    this->swapCoords(this->leaves[i].maxs);
+
+  }
+
+  for(int i = 0; i < this->numPlanes; ++i)
+  {
+    float sto = this->planes[i].x;
+    this->planes[i].x =  this->planes[i].y;
+    this->planes[i].y =  this->planes[i].z;
+    this->planes[i].z = sto;
+    this->planes[i].d = scale * this->planes[i].d ;
+  }
+
+
+  for(int i = 0; i < this->numFaces; ++i)
+  {
+    this->swapCoords(this->faces[i].normal);
+  }
+
+}
+
+void BspFile::swapCoords(int *array)
+{
+  if( scale < 1)
+  {
+  int sto  =  array[0];
+  array[0] =  array[1] / (int) ( 1/ scale);
+  array[1] = array[2] / (int) (1/scale);
+  array[2] =  sto / (int) (1/scale);
+  }
+  else
+  {
+    int sto  =  array[0];
+    array[0] =  scale * array[1] ;
+    array[1] =  scale * array[2];
+    array[2] =  scale * sto ;
+  }
+
+}
+
+void BspFile::swapCoords(float * array)
+{
+  float sto  =  array[0];
+  array[0] =  scale * array[1];
+  array[1] =  scale * array[2];
+  array[2] =  scale * sto;
+}
+
Index: /trunk/src/lib/graphics/importer/bsp_file.h
===================================================================
--- /trunk/src/lib/graphics/importer/bsp_file.h	(revision 8186)
+++ /trunk/src/lib/graphics/importer/bsp_file.h	(revision 8186)
@@ -0,0 +1,216 @@
+/*
+ orxonox - the future of 3D-vertical-scrollers
+ 
+ Copyright (C) 2006 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: bottac@ee.ethz.ch
+ 
+  Inspired by:
+  Rendering Q3 Maps by Morgan McGuire                  http://graphics.cs.brown.edu/games/quake/quake3.html
+  Unofficial Quake 3 Map Specs by Kekoa Proudfoot      http://graphics.stanford.edu/~kekoa/q3/
+  Quake 3 Collision Detection by Nathan Ostgard        http://www.devmaster.net/articles/quake3collision/
+*/
+
+class SDL_Surface;
+class BspTreeNode;
+class Vector;
+class Material;
+class MoviePlayer;
+class VertexArrayModel;
+
+
+ struct plane
+{
+  float x;     //!< 1st component of the plane's normal
+  float y;     //!< 2nd component of the plane's normal
+  float z;     //!< 3rd component of the plane's normal
+  float d;     //!< distance of the plane to the origin
+};
+
+typedef struct
+{
+  float mins [ 3 ]; //!< Bounding box min coord.
+  float maxs [ 3 ]; //!< Bounding box max coord.
+  int face;         //!< First face for model.
+  int n_faces;      //!< Number of faces for model.
+  int brush;        //!< First brush for model.
+  int n_brushes;    //!< Number of brushes
+}
+model;
+
+typedef struct
+{
+  int plane;        //!< Plane index.
+  int left;         //!< 1st Child index. Negative numbers are leaf indices: -(leaf+1).
+  int right;        //!< 2nd Child index. Negative numbers are leaf indices: -(leaf+1).
+  int mins[ 3 ];    //!< Integer bounding box min coord.
+  int maxs[ 3 ];    //!< Integer bounding box max coord.
+}
+node;
+
+typedef struct
+{
+  int cluster;            //!< Visdata cluster index.
+  int area;               //!< Areaportal area.
+  int mins[ 3 ];          //!< Integer bounding box min coord.
+  int maxs[ 3 ];          //!< Integer bounding box max coord.
+  int leafface;           //!< First leafface for leaf.
+  int n_leaffaces;        //!< Number of leaffaces for leaf.
+  int leafbrush_first;    //!< leafbrush for leaf.
+  int n_leafbrushes;      //!< Number of leafbrushes for leaf.
+}
+leaf;
+
+struct brush
+{
+  int brushside; 	//!< First brushside for brush.
+  int n_brushsides; 	//!< Number of brushsides for brush.
+  int texture; 	        //!< Texture index.
+};
+
+typedef struct
+{
+  int plane;    //!< Plane index.
+  int texture; 	//!< Texture index.
+}
+brushside;
+
+struct face
+{
+  int texture;    	//!< Texture index.
+  int effect; 	        //!< Index into lump 12 (Effects), or -1.
+  int type; 	        //!< Face type. 1=polygon, 2=patch, 3=mesh, 4=billboard
+  int vertex; 	        //!< Index of first vertex.
+  int n_vertexes;       //!< Number of vertices.
+  int meshvert;         //!< Index of first meshvert.
+  int n_meshverts;      //!< Number of meshverts.
+  int lm_index;         //!< Lightmap index.
+  int lm_start [ 2 ];   //!< Corner of this face's lightmap image in lightmap.
+  int lm_size [ 2 ];     //!< Size of this face's lightmap image in lightmap.
+  float lm_origin [ 3 ] ;    //!<  World space origin of lightmap.
+  float lm_vecs [ 2 ][ 3 ];  //!< World space lightmap s and t unit vectors.
+  float normal[ 3 ];         //!< Surface normal.
+  int size [ 2 ] ;           //!< Patch dimensions.
+} ;
+
+typedef struct
+{
+  float position[ 3 ];        //!< Vertex position.
+  float texcoord[ 2 ][ 2 ];   //!< Vertex texture coordinates. [0][x]=surface, [1][x]=lightmap.
+  float normal[ 3 ];          //!< Vertex normal.
+  unsigned char color [ 4 ];  //!< Vertex color. RGBA.
+}
+BspVertex;
+
+typedef struct
+{
+  int offset;
+}
+meshvert;                    //!< Integer offset to mesh vertex
+
+typedef struct
+{
+  float position [ 3 ];
+}
+BspVec;
+
+typedef struct
+{
+  Material* mat;
+  MoviePlayer* aviMat;
+  bool alpha;
+  bool animated;
+}
+AMat;
+
+typedef struct
+{
+  unsigned char map [128][128][3];
+}
+lightmap;
+
+typedef struct
+{
+  char name[64];
+  int flags;
+  int contents;
+}
+BspTexture;
+
+class BspFile
+{
+  friend class BspManager;
+
+public:
+  BspFile();
+  int read(const char* name );
+  void build_tree();
+  void load_textures();
+  void tesselate( int iface );
+  BspTreeNode* get_root();
+  AMat loadMat( char* mat );
+  AMat loadAVI(char * mat);
+ 
+
+private:
+  BspTreeNode* root;
+  char header [ 280 ];       //!< Buffer for header of BSP-File
+  node* nodes;               //!< Buffer to store BSP-Tree-Nodes
+  leaf* leaves;              //!< Buffer to store BSP-Tree-Leaves
+  plane* planes;             //!< Buffer to store planes separateing the space
+  model* bspModels;          //!< Buffer to store BSP-Model-List
+  char* leafFaces;           //!< Buffer to store leafFaces
+  face* faces;               //!<
+  char* leafBrushes;         //!< Buffer to store brush indice
+  brush* brushes;            //!< Buffer to store  brushes
+  brushside* brushSides;     //!<
+  char* vertice;             //!<
+  meshvert* meshverts;       //!< Buffer to store meshverice
+  char* visData;             //!< Buffer to store visibility data
+  char* textures;            //!< Holds all the texture filename strings
+  char* patchVertice;        //!<
+  char* patchIndexes;
+  char* patchTrianglesPerRow;
+  lightmap* lightMaps;       //!< Buffer to store lightmap-images
+
+
+  int** patchRowIndexes;
+  VertexArrayModel** VertexArrayModels;
+  int patchOffset;
+
+  int numNodes;
+  int numLeafs;
+  int numVertex;
+  int numPlanes;
+  int numBspModels;
+  int numLeafFaces;
+  int numFaces;
+  int numLeafBrushes;
+  int numTextures;
+  int numPatches;
+  int numBrushSides;
+  int numLightMaps;
+  
+  float  scale;
+
+  BspTreeNode* build_tree_rec( int i );
+  unsigned int loadLightMapToGL(lightmap&);
+  AMat* Materials;
+  unsigned int* glLightMapTextures;
+  unsigned int whiteLightMap;
+  unsigned char whiteTexture[3];
+  void swapAllBspCoordinates();
+  void swapCoords(int * array);
+  void swapCoords(float * array);
+  SDL_Surface* testSurf;
+
+ 
+
+};
+
Index: /trunk/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- /trunk/src/lib/graphics/importer/bsp_manager.cc	(revision 8186)
+++ /trunk/src/lib/graphics/importer/bsp_manager.cc	(revision 8186)
@@ -0,0 +1,1050 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2006 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: bottac@ee.ethz.ch
+
+   Inspired by:
+   Rendering Q3 Maps by Morgan McGuire                  http://graphics.cs.brown.edu/games/quake/quake3.html
+   Unofficial Quake 3 Map Specs by Kekoa Proudfoot      http://graphics.stanford.edu/~kekoa/q3/
+
+   Collision detection adapted from:
+   Quake 3 Collision Detection by Nathan Ostgard        http://www.devmaster.net/articles/quake3collision/
+*/
+
+
+#include "vector.h"
+#include "bsp_file.h"
+#include "bsp_manager.h"
+#include "bsp_tree_leaf.h"
+#include "p_node.h"
+#include "state.h"
+#include "debug.h"
+#include "material.h"
+#include "camera.h"
+#include "vertex_array_model.h"
+#include "world_entities/player.h"
+#include "world_entities/playable.h"
+#include "util/loading/resource_manager.h"
+// STL Containers
+#include <vector>
+#include <deque>
+#include "movie_player.h"
+
+#include "cd_engine.h"
+
+#include "world_entity.h"
+
+#include "util/loading/load_param.h"
+#include "util/loading/factory.h"
+
+
+//CREATE_FACTORY( BspManager, CL_BSP_MODEL);
+
+BspManager::BspManager()
+{
+  /*// open a BSP file
+  this->bspFile = new BspFile();
+  this->bspFile->scale = 0.4f;
+  this->bspFile->read(ResourceManager::getFullName("test.bsp").c_str());
+  this->bspFile->build_tree();
+  this->root  = this->bspFile->get_root();
+  this->alreadyVisible = new bool [this->bspFile->numFaces];
+  */
+  CDEngine::getInstance()->setBSPModel(this);
+}
+
+
+/*
+BspManager::BspManager(const TiXmlElement* root)
+{
+
+
+  if( root != NULL)
+    this->loadParams(root);
+
+  CDEngine::getInstance()->setBSPModel(this);
+} */
+
+void BspManager::load(const char* fileName, float scale)
+{
+  //this->setClassID(CL_BSP_MODEL, "BspManager");
+    // open a BSP file
+  this->bspFile = new BspFile();
+  this->bspFile->scale =  scale;
+  this->bspFile->read(ResourceManager::getFullName(fileName).c_str());
+  this->bspFile->build_tree();
+  this->root  = this->bspFile->get_root();
+  this->alreadyVisible = new bool [this->bspFile->numFaces];
+
+
+}
+/*
+BspManager::BspManager(const char* fileName, float scale)
+{
+  // open a BSP file
+  this->bspFile = new BspFile();
+  this->bspFile->scale =  scale;
+  this->bspFile->read(fileName);
+  this->bspFile->build_tree();
+  this->root  = this->bspFile->get_root();
+  this->alreadyVisible = new bool [this->bspFile->numFaces];
+
+  CDEngine::getInstance()->setBSPModel(this);
+}
+*/
+
+const void BspManager::draw()
+{
+
+  /*
+  this->drawDebugCube(&this->out);
+  this->out1 = this->out;
+  this->out2 = this->out;
+  if(this->collPlane != NULL)
+  {
+  this->out1.x += this->collPlane->x*5.0;
+  this->out1.y += this->collPlane->y*5.0;
+  this->out1.z += this->collPlane->z*5.0;
+
+  this->out2.x += this->collPlane->x*10.0;
+  this->out2.y += this->collPlane->y*10.0;
+  this->out2.z += this->collPlane->z*10.0;
+  }
+  this->drawDebugCube(&this->out1);
+  this->drawDebugCube(&this->out2);
+  */
+  // Draw Debug Terrain
+  /*
+  this->bspFile->Materials[0]->select();
+  for(int i = 0; i <  this->bspFile->numPatches ; i++)
+        {
+                this->bspFile->VertexArrayModels[i]->draw();
+
+        }
+  */
+
+
+
+  // erase alreadyVisible
+  for(int i = 0; i < this->bspFile->numFaces; i++) this->alreadyVisible[i] = false;
+  float tmp = 0;
+  //this->opal.clear();
+  //this->trasparent.clear();
+  // Find all visible faces...
+
+  this->cam = State::getCamera()->getAbsCoor() ;
+  //this->ship = State::getCameraTargetNode()->getAbsCoor();
+
+
+
+
+
+  // this->viewDir=    State::getCameraTarget()->getAbsCoor() -  State::getCamera()->getAbsCoor() ;
+  float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z);
+
+  BspTreeNode*  ActLeaf = this->getLeaf(this->bspFile->root, &ship);
+  int viscluster = -1;
+  viscluster =((leaf*)(this->bspFile->leaves))[ ActLeaf->leafIndex].cluster; // get the players cluster (viscluster)
+
+
+
+  this->cam = State::getCameraTargetNode()->getAbsCoor();
+  // this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
+  this->outputStartsOut = true;
+  this->outputAllSolid = false;
+  this->outputFraction = 1.0f;
+
+  this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam);
+
+  //if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam);
+
+  if ( viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
+  {
+
+
+
+    // Iterate through all Leafspublic final double readLEDouble()
+    for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )
+    {
+      // cluster =  (this->bspFile->leaves)[i].cluster;
+      leaf& curLeaf = (this->bspFile->leaves)[i];
+      if(curLeaf.cluster<0) continue;
+
+
+      /** Do Frustum culling and draw 'em all **/
+      bool inFrustum = true;
+
+      Vector dir;
+      dir.x = State::getCameraNode()->getAbsDirX().x;
+      dir.y =  State::getCameraNode()->getAbsDirX().y;
+      dir.z =  State::getCameraNode()->getAbsDirX().z;
+      float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
+      //if(dist < 0) dist = -dist;
+      const float dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] - dist ;
+      const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist ;
+
+      if(dMins < -150.0 && dMaxs < -150.0) {
+        continue;
+      }
+      if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 3000  && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 3000) {
+        continue;
+      }
+
+
+      // Iterate through all faces
+      for (int j = 0; j < curLeaf.n_leaffaces ; ++j) {
+        const int g = (j +  curLeaf.leafface);
+        const int f = ((int *)this->bspFile->leafFaces)[g];
+        if (f >=0 && !this->isAlreadyVisible(f)) {
+          this->alreadyVisible[f] = true;
+
+          addFace(f); // "visibleFaces.append(f)"
+        }
+      }
+
+
+
+
+    } //for
+  } else {
+
+
+    unsigned int v;
+    unsigned char  visSet;
+
+    // Iterate through all Leafs
+
+    for(int i = 0; i <  this->bspFile->numLeafs   ; ++i ) {
+      leaf& camLeaf =  (this->bspFile->leaves)[ActLeaf->leafIndex] ;
+      leaf& curLeaf =  (this->bspFile->leaves)[i] ;
+      int& cluster =  curLeaf.cluster;
+
+      if(cluster < 0) continue;
+      v = ((viscluster *  ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8));
+      visSet =((char*) (this->bspFile->visData))[v + 8];
+
+      // gets bit of visSet
+      if( ((visSet) & (1 << (cluster &  7))) != 0 ) {
+
+        // Frustum culling
+
+        Vector dir;
+        dir.x = State::getCameraNode()->getAbsDirX().x;
+        dir.y =  State::getCameraNode()->getAbsDirX().y;
+        dir.z =  State::getCameraNode()->getAbsDirX().z;
+        const float dist =  dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z;
+        //if(dist < 0) dist = -dist;
+        const float dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] - dist;
+        const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist;
+
+        if(dMins < -50.0 && dMaxs < -  50.0) {
+          continue;
+        }
+
+
+        // Iterate through all faces
+        for (int j = 0; j < curLeaf.n_leaffaces ; ++j) {
+          const int g = (j +  curLeaf.leafface);
+          const int f = ((int *)this->bspFile->leafFaces)[g];
+
+          if (!this->isAlreadyVisible(f) && f>=0) {
+            this->addFace(f);
+            this->alreadyVisible[f] = true;
+          }
+
+        }
+
+      }// if
+
+    }//for
+
+  }//else
+
+  while(!this->opal.empty()) {
+    this->draw_face(this->opal.front());
+    this->opal.pop_front();
+  }
+  while(!this->trasparent.empty()) {
+    this->draw_face(this->trasparent.back());
+    this->trasparent.pop_back();
+  }
+  //glEnable(GL_TEXTURE_2D);
+  glActiveTextureARB(GL_TEXTURE1_ARB);
+  glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap);
+
+
+
+}//draw
+
+
+
+void BspManager::draw_face(int curface)
+{
+  face& curFace =  (this->bspFile->faces)[curface];
+  const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
+  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);
+
+  //  if(  curFace.texture < 0 ) return;
+  if(curFace.type == 2) {
+    this->draw_patch( &curFace);
+    return;
+  }
+  if(curFace.type != 1) return;
+  if((char*)(this->bspFile->textures)[curFace.texture*72]== 0) return;
+
+  if(this->lastTex != curFace.texture) {
+    if(this->bspFile->Materials[curFace.texture].animated) {
+      glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
+      glEnable(GL_BLEND);
+      if(this->bspFile->Materials[curFace.texture].aviMat->getStatus() == 2) this->bspFile->Materials[curFace.texture].aviMat->start(0);
+      this->bspFile->Materials[curFace.texture].aviMat->tick(0.005);
+      int n =  this->bspFile->Materials[curFace.texture].aviMat->getTexture();
+      glActiveTextureARB(GL_TEXTURE0_ARB);
+      glBindTexture(GL_TEXTURE_2D, n );
+      glDisable(GL_BLEND);
+    } else {
+      this->bspFile->Materials[curFace.texture].mat->select();
+      this->lastTex = curFace.texture;
+    }
+  }
+
+  if(curFace.lm_index < 0) {
+    glActiveTextureARB(GL_TEXTURE1_ARB);
+    glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap );
+    glEnable(GL_TEXTURE_2D);
+  } else {
+    glActiveTextureARB(GL_TEXTURE1_ARB);
+    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]);
+    glEnable(GL_TEXTURE_2D);
+  }
+
+  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+  // glColor4f(3.0,3.0,3.0,1.0);
+  glEnableClientState(GL_VERTEX_ARRAY );
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
+  glEnableClientState(GL_NORMAL_ARRAY );
+  //  glEnableClientState(GL_COLOR_ARRAY);
+
+
+  glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
+
+  glClientActiveTextureARB(GL_TEXTURE0_ARB);
+  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
+  //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+  glClientActiveTextureARB(GL_TEXTURE1_ARB);
+  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
+  //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+
+  glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0]));
+  // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0]));
+  glDrawElements(GL_TRIANGLES, curFace.n_meshverts,
+                 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert]));
+
+  glDisableClientState(GL_TEXTURE0_ARB);
+  glDisableClientState(GL_TEXTURE1_ARB);
+  glDisableClientState(GL_VERTEX_ARRAY );
+  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
+  glDisableClientState(GL_NORMAL_ARRAY );
+  // glDisableClientState(GL_COLOR_ARRAY);
+
+}
+
+
+void BspManager::draw_debug_face(int curface)
+{
+  face& curFace =  (this->bspFile->faces)[curface];
+  const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
+  int stride = 44;  // sizeof(Vertex)
+  int offset    = curFace.vertex;
+
+  // PRINTF(0)("BSP Manager: ");
+  // PRINTF(0)("BSP Manager: type: %i  \n", curFace.texture);
+
+  //  if(  curFace.texture < 0 ) return;
+  if(curFace.type == 2) {
+    this->draw_patch( &curFace);
+    return;
+  }
+  if(curFace.type == 3) return;
+  // if(this->bspFile->Materials[curFace.texture] != NULL)
+
+  this->bspFile->Materials[2].mat->select();
+  this->lastTex = 2;
+
+  glEnableClientState(GL_VERTEX_ARRAY );
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
+  glEnableClientState(GL_NORMAL_ARRAY );
+  //glEnableClientState(GL_COLOR_ARRAY);
+  // glEnableClientState(GL_VERTEX_ARRAY );
+  glClientActiveTextureARB(GL_TEXTURE0_ARB);
+  glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+  // glClientActiveTextureARB(GL_TEXTURE0_ARB);
+  glClientActiveTextureARB(GL_TEXTURE1_ARB);
+  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+  // glClientActiveTextureARB(GL_TEXTURE1_ARB);
+  // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
+  //glEnableClientState(GL_NORMAL_ARRAY );
+
+  glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0]));
+  //  glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0]));
+  glDrawElements(GL_TRIANGLES, curFace.n_meshverts,
+                 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert]));
+
+}
+
+void BspManager::draw_patch(face* Face)
+{
+  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) {
+    glActiveTextureARB(GL_TEXTURE1_ARB);
+    glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap);
+    glEnable(GL_TEXTURE_2D);
+  } else {
+    glActiveTextureARB(GL_TEXTURE1_ARB);
+    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[Face->lm_index]);
+    glEnable(GL_TEXTURE_2D);
+  }
+  //glColor4f(3.0,3.0,3.0,1.0);
+
+  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+  glEnable( GL_AUTO_NORMAL);
+  glEnableClientState(GL_VERTEX_ARRAY );
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
+  for(int i = Face->n_meshverts -1; i >=0   ; i--) {
+    //glFrontFace(GL_CW);
+    //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);
+
+
+    //glEnableClientState(GL_NORMAL_ARRAY );
+
+    glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0]));
+
+
+    glClientActiveTextureARB(GL_TEXTURE0_ARB);
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
+
+
+
+    glClientActiveTextureARB(GL_TEXTURE1_ARB);
+    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[1][0]));
+    //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+
+    //  glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
+
+
+
+
+    for(int row=6; row>=0; --row) {
+      glDrawElements(GL_TRIANGLE_STRIP, 2*(8), GL_UNSIGNED_INT,
+                     & (     (((GLuint*)  (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8]  ))  );
+    }
+
+    //glFrontFace(GL_CCW);
+  }
+  glDisableClientState(GL_TEXTURE0_ARB);
+  glDisableClientState(GL_TEXTURE1_ARB);
+  glDisable(GL_AUTO_NORMAL);
+  glDisableClientState(GL_VERTEX_ARRAY );
+  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
+
+
+}
+
+bool BspManager::isAlreadyVisible(int Face)
+{
+  return this->alreadyVisible[Face];
+}
+
+
+BspTreeNode*  BspManager::getLeaf(BspTreeNode* node, Vector* cam)
+{
+  float dist = 0;
+  while(!(node->isLeaf)) {
+    dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d;
+    if(dist >= 0.0f) {
+      node = node->left;
+    } else {
+      node = node->right;
+    }
+  }
+  return  node;
+}
+
+void BspManager::checkBrushRay(brush* curBrush)
+{
+  float EPSILON = 0.000001;
+  float startDistance;
+  float endDistance;
+
+  float startFraction = -1.0f;
+  float endFraction = 1.0f;
+  bool startsOut = false;
+  bool endsOut = false;
+
+  Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
+  Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
+
+  for (int i = 0; i < curBrush->n_brushsides; i++) {
+    brushside& curBrushSide =   this->bspFile->brushSides[curBrush->brushside + i]   ;
+    plane& curPlane  =   this->bspFile->planes[curBrushSide.plane] ;
+
+    startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d;
+    endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d;
+
+    if (startDistance > 0)
+      startsOut = true;
+    if (endDistance > 0)
+      endsOut = true;
+
+    // make sure the trace isn't completely on one side of the brush
+    if (startDistance > 0 && endDistance > 0) {   // both are in front of the plane, its outside of this brush
+      return;
+    }
+    if (startDistance <= 0 && endDistance <= 0) {   // both are behind this plane, it will get clipped by another one
+      continue;
+    }
+
+    // MMM... BEEFY
+    if (startDistance > endDistance) {   // line is entering into the brush
+      float fraction = (startDistance - EPSILON) / (startDistance - endDistance);  // *
+      if (fraction > startFraction)
+        startFraction = fraction;
+      // don't store plane
+      // this->collPlane = &curPlane;
+
+    } else {   // line is leaving the brush
+      float fraction = (startDistance + EPSILON) / (startDistance - endDistance);  // *
+      if (fraction < endFraction)
+        endFraction = fraction;
+      // don't store plane
+      //this->collPlane = & curPlane;
+
+    }
+
+  }
+  if (startsOut == false) {
+    this->outputStartsOut = false;
+    if (endsOut == false)
+      this->outputAllSolid = true;
+    return;
+  }
+
+  if (startFraction < endFraction) {
+    if (startFraction > -1.0f && startFraction < outputFraction) {
+      if (startFraction < 0)
+        startFraction = 0;
+      this->outputFraction = startFraction;
+    }
+  }
+
+}
+
+void BspManager::checkBrushRayN(brush* curBrush)
+{
+  float EPSILON = 0.000001;
+  float startDistance;
+  float endDistance;
+
+  float startFraction = -1.0f;
+  float endFraction = 1.0f;
+  bool startsOut = false;
+  bool endsOut = false;
+
+  Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
+  Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
+
+  for (int i = 0; i < curBrush->n_brushsides; i++) {
+    brushside& curBrushSide =   this->bspFile->brushSides[curBrush->brushside + i]   ;
+    plane& curPlane  =   this->bspFile->planes[curBrushSide.plane] ;
+
+    startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d;
+    endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d;
+
+    if (startDistance > 0)
+      startsOut = true;
+    if (endDistance > 0)
+      endsOut = true;
+
+    // make sure the trace isn't completely on one side of the brush
+    if (startDistance > 0 && endDistance > 0) {   // both are in front of the plane, its outside of this brush
+      return;
+    }
+    if (startDistance <= 0 && endDistance <= 0) {   // both are behind this plane, it will get clipped by another one
+      continue;
+    }
+
+    // MMM... BEEFY
+    if (startDistance > endDistance) {   // line is entering into the brush
+      float fraction = (startDistance - EPSILON) / (startDistance - endDistance);  // *
+      if (fraction > startFraction)
+        startFraction = fraction;
+      // store plane
+      this->collPlane = &curPlane;
+
+    } else {   // line is leaving the brush
+      float fraction = (startDistance + EPSILON) / (startDistance - endDistance);  // *
+      if (fraction < endFraction)
+        endFraction = fraction;
+      // store plane
+      this->collPlane = & curPlane;
+
+    }
+
+  }
+  if (startsOut == false) {
+    this->outputStartsOut = false;
+    if (endsOut == false)
+      this->outputAllSolid = true;
+    return;
+  }
+
+  if (startFraction < endFraction) {
+    if (startFraction > -1.0f && startFraction < outputFraction) {
+      if (startFraction < 0)
+        startFraction = 0;
+      this->outputFraction = startFraction;
+    }
+  }
+
+}
+
+
+void BspManager::checkCollisionRay(BspTreeNode* node, float startFraction, float endFraction, Vector* start, Vector* end)
+{
+
+
+  float EPSILON = 0.000001;
+  float  endDistance = (end)->x * (node->plane.x) +(end)->y * (node->plane.y) +(end)->z * (node->plane.z)  - node->d;
+  float  startDistance = (start)->x * (node->plane.x)+ (start)->y * (node->plane.y)+ (start)->z * (node->plane.z)- node->d;
+
+
+  if(node->isLeaf) {
+    leaf& curLeaf = this->bspFile->leaves[node->leafIndex];
+    for (int i = 0; i <  curLeaf.n_leafbrushes ; i++) {
+      brush& curBrush = this->bspFile->brushes[((int*)(this->bspFile->leafBrushes))[curLeaf.leafbrush_first+i]];
+      //object *brush = &BSP.brushes[BSP.leafBrushes[leaf->firstLeafBrush + i]];
+      if (curBrush.n_brushsides > 0   &&
+          ((((BspTexture*)(this->bspFile->textures))[curBrush.texture]).contents & 1))
+        // CheckBrush( brush );
+        this->checkBrushRay(&curBrush);
+      if(curBrush.n_brushsides <=0) this->outputAllSolid = true;
+    }
+    return;
+  }
+
+
+  if (startDistance >= 0 && endDistance >= 0)     // A
+  {   // both points are in front of the plane
+    // so check the front child
+    this->checkCollisionRay(node->left,0,0,start,end);
+  } else if (startDistance < 0 && endDistance < 0)  // B
+  {   // both points are behind the plane
+    // so check the back child
+    this->checkCollisionRay(node->right,0,0,start,end);
+  } else                                            // C
+  {   // the line spans the splitting plane
+    int side;
+    float fraction1, fraction2, middleFraction;
+    Vector middle;
+
+    // STEP 1: split the segment into two
+    if (startDistance < endDistance) {
+      side = 1; // back
+      float inverseDistance = 1.0f / (startDistance - endDistance);
+      fraction1 = (startDistance + EPSILON) * inverseDistance;
+      fraction2 = (startDistance + EPSILON) * inverseDistance;
+    } else if (endDistance < startDistance) {
+      side = 0; // front(start)->x * (node->plane.x)+
+      float inverseDistance = 1.0f / (startDistance - endDistance);
+      fraction1 = (startDistance + EPSILON) * inverseDistance;
+      fraction2 = (startDistance - EPSILON) * inverseDistance;
+    } else {
+      side = 0; // front
+      fraction1 = 1.0f;
+      fraction2 = 0.0f;
+    }
+
+    // STEP 2: make sure the numbers are valid
+    if (fraction1 < 0.0f) fraction1 = 0.0f;
+    else if (fraction1 > 1.0f) fraction1 = 1.0f;
+    if (fraction2 < 0.0f) fraction2 = 0.0f;
+    else if (fraction2 > 1.0f) fraction2 = 1.0f;
+
+    // STEP 3: calculate the middle point for the first side
+    middleFraction = startFraction +
+                     (endFraction - startFraction) * fraction1;
+
+    middle.x = start->x + fraction1 * (end->x - start->x);
+    middle.y = start->y + fraction1 * (end->y - start->y);
+    middle.z = start->z + fraction1 * (end->z - start->z);
+
+    // STEP 4: check the first side
+    //CheckNode( node->children[side], startFraction, middleFraction, start, middle );
+    if(side == 0) this->checkCollisionRay(node->left,startFraction, middleFraction, start, &middle );
+
+    else this->checkCollisionRay(node->right,startFraction, middleFraction,
+                                   start, &middle );
+
+    // STEP 5: calculate the middle point for the second side
+    middleFraction = startFraction +
+                     (endFraction - startFraction) * fraction2;
+
+    middle.x = start->x + fraction2 * (end->x - start->x);
+    middle.y = start->y + fraction2 * (end->y - start->y);
+    middle.z = start->z + fraction2 * (end->z - start->z);
+
+    // STEP 6: check the second side
+    if(side == 1)this->checkCollisionRay(node->left,middleFraction, endFraction, &middle, end);
+
+    else this->checkCollisionRay(node->right,middleFraction, endFraction,&middle, end );
+
+
+  }
+
+}
+
+
+
+void BspManager::checkCollisionRayN(BspTreeNode* node, float startFraction, float endFraction, Vector* start, Vector* end)
+{
+
+
+  float EPSILON = 0.000001;
+  float  endDistance = (end)->x * (node->plane.x) +(end)->y * (node->plane.y) +(end)->z * (node->plane.z)  - node->d;
+  float  startDistance = (start)->x * (node->plane.x)+ (start)->y * (node->plane.y)+ (start)->z * (node->plane.z)- node->d;
+
+
+  if(node->isLeaf) {
+    leaf& curLeaf = this->bspFile->leaves[node->leafIndex];
+    for (int i = 0; i <  curLeaf.n_leafbrushes ; i++) {
+      brush& curBrush = this->bspFile->brushes[((int*)(this->bspFile->leafBrushes))[curLeaf.leafbrush_first+i]];
+      //object *brush = &BSP.brushes[BSP.leafBrushes[leaf->firstLeafBrush + i]];
+      if (curBrush.n_brushsides > 0   &&
+          ((((BspTexture*)(this->bspFile->textures))[curBrush.texture]).contents & 1))
+        // CheckBrush( brush );
+        this->checkBrushRayN(&curBrush);
+      if(curBrush.n_brushsides <=0) this->outputAllSolid = true;
+    }
+    return;
+  }
+
+
+  if (startDistance >= 0 && endDistance >= 0)     // A
+  {   // both points are in front of the plane
+    // so check the front child
+    this->checkCollisionRayN(node->left,0,0,start,end);
+  } else if (startDistance < 0 && endDistance < 0)  // B
+  {   // both points are behind the plane
+    // so check the back child
+    this->checkCollisionRayN(node->right,0,0,start,end);
+  } else                                            // C
+  {   // the line spans the splitting plane
+    int side;
+    float fraction1, fraction2, middleFraction;
+    Vector middle;
+
+    // STEP 1: split the segment into two
+    if (startDistance < endDistance) {
+      side = 1; // back
+      float inverseDistance = 1.0f / (startDistance - endDistance);
+      fraction1 = (startDistance + EPSILON) * inverseDistance;
+      fraction2 = (startDistance + EPSILON) * inverseDistance;
+    } else if (endDistance < startDistance) {
+      side = 0; // front(start)->x * (node->plane.x)+
+      float inverseDistance = 1.0f / (startDistance - endDistance);
+      fraction1 = (startDistance + EPSILON) * inverseDistance;
+      fraction2 = (startDistance - EPSILON) * inverseDistance;
+    } else {
+      side = 0; // front
+      fraction1 = 1.0f;
+      fraction2 = 0.0f;
+    }
+
+    // STEP 2: make sure the numbers are valid
+    if (fraction1 < 0.0f) fraction1 = 0.0f;
+    else if (fraction1 > 1.0f) fraction1 = 1.0f;
+    if (fraction2 < 0.0f) fraction2 = 0.0f;
+    else if (fraction2 > 1.0f) fraction2 = 1.0f;
+
+    // STEP 3: calculate the middle point for the first side
+    middleFraction = startFraction +
+        (endFraction - startFraction) * fraction1;
+
+    middle.x = start->x + fraction1 * (end->x - start->x);
+    middle.y = start->y + fraction1 * (end->y - start->y);
+    middle.z = start->z + fraction1 * (end->z - start->z);
+
+    // STEP 4: check the first side
+    //CheckNode( node->children[side], startFraction, middleFraction, start, middle );
+    if(side == 0) this->checkCollisionRayN(node->left,startFraction, middleFraction, start, &middle );
+
+    else this->checkCollisionRayN(node->right,startFraction, middleFraction,
+                                 start, &middle );
+
+    // STEP 5: calculate the middle point for the second side
+    middleFraction = startFraction +
+        (endFraction - startFraction) * fraction2;
+
+    middle.x = start->x + fraction2 * (end->x - start->x);
+    middle.y = start->y + fraction2 * (end->y - start->y);
+    middle.z = start->z + fraction2 * (end->z - start->z);
+
+    // STEP 6: check the second side
+    if(side == 1)this->checkCollisionRayN(node->left,middleFraction, endFraction, &middle, end);
+
+    else this->checkCollisionRayN(node->right,middleFraction, endFraction,&middle, end );
+
+
+  }
+
+}
+
+void BspManager::checkCollision(WorldEntity* worldEntity)
+{
+  return;
+
+  Vector position = worldEntity->getAbsCoor();
+
+
+  Vector forwardDir = worldEntity->getAbsDirX();
+  forwardDir.x =2.0*forwardDir.x;
+  forwardDir.y =2.0*forwardDir.y;
+  forwardDir.z =2.0*forwardDir.z;
+
+  Vector upDir = worldEntity->getAbsDirY();
+  Vector dest = position;
+  dest.x  += forwardDir.x;
+  dest.y  += forwardDir.y;
+  dest.z  += forwardDir.z;
+  Vector out = Vector(-1875.0,-1875.0,-1875.0);
+  if(!worldEntity->isA(CL_PLAYABLE)) {
+
+
+
+
+  }
+  else {
+    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 dest2 = position2 + forwardDir;
+    dest = position - upDir;
+    Vector out1;
+    Vector out2;
+
+    this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 );
+    if(this->outputFraction == 1.0f)  out1 = dest;
+    else {
+      collision = true;
+      out1.x = position1.x + (dest1.x -position1.x) * this->outputFraction;
+      out1.y = position1.y + (dest1.y -position1.y) * this->outputFraction;
+      out1.z = position1.z + (dest1.z - position1.z) * this->outputFraction;
+
+    }
+
+    this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 );
+    if(this->outputFraction == 1.0f) out2= dest;
+    else
+    {
+      collision = true;
+    out2.x = position2.x + (dest2.x -position2.x) * this->outputFraction;
+    out2.y = position2.y + (dest2.y -position2.y) * this->outputFraction;
+    out2.z = position2.z + (dest2.z - position2.z) * this->outputFraction;
+
+    }
+
+    this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
+    if(this->outputFraction == 1.0f) 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(3*this->collPlane->x,3*this->collPlane->y,3*this->collPlane->z);
+    //this->out = out;
+    //this->out1 = out1;
+    //this->out2 = out2;
+    //this->drawDebugCube(&out1);
+    //this->drawDebugCube(&out2);
+
+    //this->drawDebugCube(&out3);
+
+    }
+
+    // Return the normal here: Normal's stored in this->collPlane;
+//    if(collision) worldEntity->collidesWithGround(out,out1,out2);
+
+  }
+
+}
+
+void  BspManager::checkCollision(BspTreeNode* node, Vector* cam)
+{
+  Vector next = this->cam;
+  next.x =   (State::getCameraTargetNode()->getLastAbsCoor()).x ;
+  next.y =   (State::getCameraTargetNode()->getLastAbsCoor()).y ;
+  next.z =   (State::getCameraTargetNode()->getLastAbsCoor()).z ;
+
+  float dist = 0;
+  if(!(node->isLeaf)) {
+    dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d;
+    if(dist > 4.0f) {
+      checkCollision(node->left,cam);
+      return;
+    }
+    if(dist < -4.0f) {
+      checkCollision(node->right,cam);
+      return;
+    }
+    if(dist<=4.0f && dist >= -4.0f) {
+      checkCollision(node->left,cam);
+      checkCollision(node->right,cam);
+      return;
+    }
+    return;
+  } else {
+
+    leaf& camLeaf =  ((leaf *)(this->bspFile->leaves))[(node->leafIndex ) ];
+
+    if (camLeaf.cluster < 0) {
+      this->drawDebugCube(&this->cam);
+      this->drawDebugCube(&next);
+      State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);
+      State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());
+    }
+
+
+    /*
+        for(int i = 0; i < camLeaf.n_leafbrushes && i < 10; i++ )
+        {
+                brush& curBrush = ((brush*)(this->bspFile->brushes))[(camLeaf.leafbrush_first +i)%this->bspFile->numLeafBrushes];
+                if(curBrush.n_brushsides < 0) return;
+                for(int j = 0; j < curBrush.n_brushsides; j++)
+                {
+                float dist = -0.1;
+                brushside& curBrushSide = ((brushside*)(this->bspFile->brushSides))[(curBrush.brushside +j)%this->bspFile->numBrushSides];
+                plane&      testPlane = ((plane*)(this->bspFile->planes))[curBrushSide.plane % this->bspFile->numPlanes];
+                dist = testPlane.x * this->cam.x +  testPlane.y * this->cam.y  +  testPlane.z * this->cam.z   -testPlane.d ;
+
+                if(dist < -0.01f) dist = -1.0f *dist;
+                if(dist < 1.0f){
+                                this->drawDebugCube(&this->cam);
+                                return;
+                              }
+                }
+
+        } */
+
+  }
+  return;
+}
+
+void BspManager::drawDebugCube(Vector* cam)
+{
+  glBegin(GL_QUADS);
+
+  // Bottom Face.  Red, 75% opaque, magnified texture
+
+  glNormal3f( 0.0f, -1.0f, 0.0f); // Needed for lighting
+  glColor4f(0.9,0.2,0.2,.75); // Basic polygon color
+
+  glTexCoord2f(0.800f, 0.800f); glVertex3f(cam->x-1.0f, cam->y-1.0f,cam->z -1.0f);
+  glTexCoord2f(0.200f, 0.800f); glVertex3f(cam->x+1.0f, cam->y-1.0f,cam->z -1.0f);
+  glTexCoord2f(0.200f, 0.200f); glVertex3f(cam->x+ 1.0f,cam->y -1.0f,cam->z +  1.0f);
+  glTexCoord2f(0.800f, 0.200f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z + 1.0f);
+
+
+  // Top face; offset.  White, 50% opaque.
+
+  glNormal3f( 0.0f, 1.0f, 0.0f);  glColor4f(0.5,0.5,0.5,.5);
+
+  glTexCoord2f(0.005f, 1.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.0f);
+  glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f,  cam->z +1.0f);
+  glTexCoord2f(1.995f, 0.005f); glVertex3f(cam->x+ 1.0f,  cam->y+1.0f,  cam->z +1.0f);
+  glTexCoord2f(1.995f, 1.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f);
+
+
+  // Far face.  Green, 50% opaque, non-uniform texture cooridinates.
+
+  glNormal3f( 0.0f, 0.0f,-1.0f);  glColor4f(0.2,0.9,0.2,.5);
+
+  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z -1.3f);
+  glTexCoord2f(2.995f, 2.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.3f);
+  glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x+ 1.0f,cam->y+  1.0f, cam->z -1.3f);
+  glTexCoord2f(0.005f, 0.005f); glVertex3f( cam->x+1.0f,cam->y -1.0f, cam->z -1.3f);
+
+
+  // Right face.  Blue; 25% opaque
+
+  glNormal3f( 1.0f, 0.0f, 0.0f);  glColor4f(0.2,0.2,0.9,.25);
+
+  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y -1.0f, cam->z -1.0f);
+  glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f);
+  glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z + 1.0f);
+  glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y-1.0f,  cam->z +1.0f);
+
+
+  // Front face; offset.  Multi-colored, 50% opaque.
+
+  glNormal3f( 0.0f, 0.0f, 1.0f);
+
+  glColor4f( 0.9f, 0.2f, 0.2f, 0.5f);
+  glTexCoord2f( 0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f,  cam->z +1.0f);
+  glColor4f( 0.2f, 0.9f, 0.2f, 0.5f);
+  glTexCoord2f( 0.995f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y-1.0f,  cam->z +1.0f);
+  glColor4f( 0.2f, 0.2f, 0.9f, 0.5f);
+  glTexCoord2f( 0.995f, 0.995f); glVertex3f( cam->x+1.0f,  cam->y+1.0f,  cam->z +1.0f);
+  glColor4f( 0.1f, 0.1f, 0.1f, 0.5f);
+  glTexCoord2f( 0.005f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f,  cam->z +1.0f);
+
+
+  // Left Face; offset.  Yellow, varying levels of opaque.
+
+  glNormal3f(-1.0f, 0.0f, 0.0f);
+
+  glColor4f(0.9,0.9,0.2,0.0);
+  glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z -1.0f);
+  glColor4f(0.9,0.9,0.2,0.66);
+  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x-1.0f,cam->y -1.0f,  cam->z +1.0f);
+  glColor4f(0.9,0.9,0.2,1.0);
+  glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f,  cam->z +1.0f);
+  glColor4f(0.9,0.9,0.2,0.33);
+  glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.0f);
+
+  glEnd();
+}
+
+void BspManager::addFace(int f)
+{
+  face& curFace =  ((face *)(this->bspFile->faces))[f];
+  if(this->bspFile->Materials[curFace.texture].alpha) this->trasparent.push_back(f);
+  else this->opal.push_back(f);
+}
Index: /trunk/src/lib/graphics/importer/bsp_manager.h
===================================================================
--- /trunk/src/lib/graphics/importer/bsp_manager.h	(revision 8186)
+++ /trunk/src/lib/graphics/importer/bsp_manager.h	(revision 8186)
@@ -0,0 +1,96 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+ 
+   Copyright (C) 2006 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: bottac@ee.ethz.ch
+   
+   Inspired by:
+   Rendering Q3 Maps by Morgan McGuire                  http://graphics.cs.brown.edu/games/quake/quake3.html
+   Unofficial Quake 3 Map Specs by Kekoa Proudfoot      http://graphics.stanford.edu/~kekoa/q3/
+   
+   Collision detection adapted from:
+   Quake 3 Collision Detection by Nathan Ostgard        http://www.devmaster.net/articles/quake3collision/
+*/
+
+#include <vector>
+#include <deque>
+
+// FORWARD DECLARATIONS
+class  BspFile;
+class BspTreeLeaf;
+class BspTreeNode;
+class Vector;
+class set;
+struct face;
+struct brush;
+struct plane;
+
+class WorldEntity;
+
+struct BspCollisionEvent
+{
+  Vector normal; //!< normal Vector, length 1
+  Vector place;  //!< Absoloute coordinates of collision
+};
+
+class BspManager
+{
+public:
+  // Constructors
+  BspManager();
+  
+  BspManager(const char* fileName, float scale = 0.4f);
+  void load(const char* fileName, float scale);
+
+  // Functions
+  const void draw();
+  void draw_debug_face(int Face); 
+  void draw_face(int Face);
+  void draw_patch(face* Face);
+  
+
+  void checkCollision(WorldEntity* worldEntity);
+
+private:
+  // Functions
+  BspTreeNode* getLeaf(BspTreeNode*  node,   Vector* cam) ;  //!< Traverses the tree
+  void  checkCollision(BspTreeNode* node, Vector* cam);
+  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  checkBrushRay(brush* curBrush);
+  void  checkBrushRayN(brush* curBrush);
+  void drawDebugCube(Vector* cam);
+  bool isAlreadyVisible(int Face);
+  void addFace(int Face);
+  
+  // Data
+  BspFile*  bspFile;
+  BspTreeNode* root;
+  Vector cam;
+  Vector ship;
+  Vector  viewDir;
+  plane* collPlane;
+  int lastTex;
+  
+  //obsolete
+  bool  outputStartsOut;
+  bool  outputAllSolid;
+  float outputFraction;
+  
+  bool * alreadyVisible;
+  // Deques to store the visible faces
+  ::std::deque<int> trasparent; //!< the ones with transparancy go here
+  ::std::deque<int> opal; //!< the others here.
+
+  Vector out;
+  Vector out1;
+  Vector out2;
+};
+
Index: /trunk/src/lib/graphics/importer/bsp_tree_leaf.cc
===================================================================
--- /trunk/src/lib/graphics/importer/bsp_tree_leaf.cc	(revision 8186)
+++ /trunk/src/lib/graphics/importer/bsp_tree_leaf.cc	(revision 8186)
@@ -0,0 +1,20 @@
+/*
+   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: bottac@ee.ethz.ch
+*/
+
+#include "bsp_tree_leaf.h"
+
+BspTreeLeaf::BspTreeLeaf()
+{
+  this->isLeaf = true;
+}
Index: /trunk/src/lib/graphics/importer/bsp_tree_leaf.h
===================================================================
--- /trunk/src/lib/graphics/importer/bsp_tree_leaf.h	(revision 8186)
+++ /trunk/src/lib/graphics/importer/bsp_tree_leaf.h	(revision 8186)
@@ -0,0 +1,30 @@
+/*
+   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: bottac@ee.ethz.ch
+*/
+#include "bsp_tree_node.h"
+class BspTreeLeaf : public BspTreeNode
+{
+  public:
+  BspTreeLeaf();
+  int leafIndex;
+/*
+  int cluster; //Visdata cluster index.
+  int area;   // Areaportal area.
+  int* mins;  // Integer bounding box min coord.
+  int* maxs; // Integer bounding box max coord.
+  int leafface; // First leafface for leaf.
+  int n_leaffaces; // Number of leaffaces for leaf.
+  int leafbrush; 	// First leafbrush for leaf.
+  int n_leafbrushes; // Number of leafbrushes for leaf.
+*/
+};
Index: /trunk/src/lib/graphics/importer/bsp_tree_node.cc
===================================================================
--- /trunk/src/lib/graphics/importer/bsp_tree_node.cc	(revision 8186)
+++ /trunk/src/lib/graphics/importer/bsp_tree_node.cc	(revision 8186)
@@ -0,0 +1,20 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2006 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: bottac@ee.ethz.ch
+*/
+
+#include "bsp_tree_node.h"
+
+BspTreeNode::BspTreeNode()
+{
+   this->isLeaf = false;
+}
Index: /trunk/src/lib/graphics/importer/bsp_tree_node.h
===================================================================
--- /trunk/src/lib/graphics/importer/bsp_tree_node.h	(revision 8186)
+++ /trunk/src/lib/graphics/importer/bsp_tree_node.h	(revision 8186)
@@ -0,0 +1,26 @@
+/*
+   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: bottac@ee.ethz.ch
+*/
+
+#include "vector.h"
+class BspTreeNode
+{
+ public:
+ BspTreeNode();
+ bool isLeaf;
+ int leafIndex;
+ BspTreeNode* left;
+ BspTreeNode* right; 
+ Vector plane;
+ float d;
+};
Index: /trunk/src/world_entities/WorldEntities.am
===================================================================
--- /trunk/src/world_entities/WorldEntities.am	(revision 8185)
+++ /trunk/src/world_entities/WorldEntities.am	(revision 8186)
@@ -15,4 +15,5 @@
                 world_entities/test_entity.cc \
                 world_entities/planet.cc \
+		world_entities/bsp_entity.cc \
                 \
                 world_entities/weapons/test_gun.cc \
@@ -67,4 +68,5 @@
                 test_entity.h \
                 planet.h \
+		bsp_entity.h \
                 \
                 weapons/test_gun.h \
Index: /trunk/src/world_entities/bsp_entity.cc
===================================================================
--- /trunk/src/world_entities/bsp_entity.cc	(revision 8186)
+++ /trunk/src/world_entities/bsp_entity.cc	(revision 8186)
@@ -0,0 +1,118 @@
+/*
+   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: ...
+   co-programmer: ...
+*/
+
+#include "bsp_entity.h"
+#include "util/loading/resource_manager.h"
+
+CREATE_FACTORY(BSPEntity, CL_BSP_ENTITY);
+
+
+/**
+ * constructs and loads a BSPEntity from a XML-element
+ * @param root the XML-element to load from
+ */
+BSPEntity::BSPEntity(const TiXmlElement* root)
+{
+  this->init();
+  if (root != NULL)
+    this->loadParams(root);
+}
+
+
+/**
+ * standard deconstructor
+ */
+BSPEntity::~BSPEntity ()
+{
+
+}
+
+void BSPEntity::setName(const std::string& name)
+{
+  printf("+++++++++++ LOADING NAME %s\n", name.c_str());
+
+  this->bspManager->load(name.c_str(), 0.1f);
+}
+
+
+
+/**
+ * initializes the BSPEntity
+ * @todo change this to what you wish
+ */
+void BSPEntity::init()
+{
+  this->bspManager = new BspManager();
+  this->setClassID(CL_BSP_ENTITY, "BSPEntity");
+
+  this->toList(OM_ENVIRON);
+
+  /**
+   * @todo: Write CL_BSP_ENTITY INTO THE src/defs/class_id.h (your own definition)
+   */
+
+}
+
+
+/**
+ * loads a BSPEntity from a XML-element
+ * @param root the XML-element to load from
+ * @todo make the class Loadable
+ */
+void BSPEntity::loadParams(const TiXmlElement* root)
+{
+  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
+ // WorldEntity::loadParam(root);
+
+  LoadParam(root, "Name", this, BSPEntity, setName)
+      .describe("Sets the of the BSP file.");
+
+/*  LoadParam(root, "Scale", this, BSpEntity, setScale)
+      .describe("Sets the scale factore of the bsp level.");
+*/
+
+  /**
+   * @todo: make the class Loadable
+   */
+}
+
+
+/**
+ * advances the BSPEntity about time seconds
+ * @param time the Time to step
+ */
+void BSPEntity::tick(float time)
+{
+
+}
+
+
+/**
+ * draws this worldEntity
+ */
+void BSPEntity::draw () const
+{
+  this->bspManager->draw();
+}
+
+
+/**
+ *
+ *
+ */
+void BSPEntity::collidesWith (WorldEntity* entity, const Vector& location)
+{
+
+}
Index: /trunk/src/world_entities/bsp_entity.h
===================================================================
--- /trunk/src/world_entities/bsp_entity.h	(revision 8186)
+++ /trunk/src/world_entities/bsp_entity.h	(revision 8186)
@@ -0,0 +1,40 @@
+/*!
+ * @file bsp_entity.h
+ * @brief description
+*/
+
+#ifndef _BSP_ENTITY_H
+#define _BSP_ENTITY_H
+
+#include "world_entity.h"
+#include "bsp_manager.h"
+
+#include "util/loading/factory.h"
+#include "util/loading/load_param.h"
+
+
+
+//! A Class to ...
+class BSPEntity : public WorldEntity
+{
+ 
+ public:
+  BSPEntity(const TiXmlElement* root = NULL);
+  virtual ~BSPEntity();
+
+  virtual void loadParams(const TiXmlElement* root);
+  
+  void setName(const std::string& name);
+
+  void init();
+
+  virtual void draw() const;
+  virtual void tick(float time);
+  virtual void collidesWith (WorldEntity* entity, const Vector& location);
+
+ private:
+   BspManager* bspManager;
+
+};
+
+#endif /* _BSP_ENTITY_H */
Index: /trunk/src/world_entities/world_entity.cc
===================================================================
--- /trunk/src/world_entities/world_entity.cc	(revision 8185)
+++ /trunk/src/world_entities/world_entity.cc	(revision 8186)
@@ -312,4 +312,43 @@
 
 /**
+ *  this function is called, when two entities collide
+ * @param entity: the world entity with whom it collides
+ *
+ * Implement behaviour like damage application or other miscellaneous collision stuff in this function
+ */
+void WorldEntity::collidesWithGround(const Vector& location)
+{
+  PRINTF(0)("BSP_GROUND: %s collides \n", this->getClassName() );
+}
+
+void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2)
+{
+  
+  // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassName() );
+  
+  Vector v = this->getAbsDirX();
+  v.x *= 10;
+  v.y *= 10;
+  v.z *= 10;
+  Vector u = this->getAbsDirY();
+  
+  if(feet.x == (u.x+this->getAbsCoor().x) &&  feet.y == u.y +this->getAbsCoor().y && feet.z == this->getAbsCoor().z)
+  {
+    
+  this->setAbsCoor(ray_2 - v);
+  }
+  else
+  {
+    if(ray_1.x == this->getAbsCoor().x + v.x && ray_1.y == this->getAbsCoor().y + v.y + 0.1 && ray_1.z ==this->getAbsCoor().z + v.z)
+    {
+      this->setAbsCoor(feet -u );  
+    }
+      
+    this->setAbsCoor(ray_2 - v);  
+   
+  }
+}
+
+/**
  *  this is called immediately after the Entity has been constructed, initialized and then Spawned into the World
  *
Index: /trunk/src/world_entities/world_entity.h
===================================================================
--- /trunk/src/world_entities/world_entity.h	(revision 8185)
+++ /trunk/src/world_entities/world_entity.h	(revision 8186)
@@ -63,5 +63,9 @@
   bool buildObbTree(int depth);
   virtual void collidesWith (WorldEntity* entity, const Vector& location);
-  /** @returns a reference to the obb tree of this worldentity */
+  virtual void collidesWithGround(const Vector& location);
+  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
+
+
+/** @returns a reference to the obb tree of this worldentity */
   inline BVTree* getOBBTree() const { return this->obbTree; };
   void drawBVTree(int depth, int drawMode) const;
