Index: branches/bsp_model/src/lib/graphics/importer/bsp_file.cc
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_file.cc	(revision 7392)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_file.cc	(revision 7395)
@@ -1,12 +1,12 @@
 /*
    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
@@ -34,7 +34,5 @@
 // Constructor
 BspFile::BspFile()
-{
-
-}
+{}
 
 int BspFile::read(char* name)
@@ -44,69 +42,68 @@
   struct stat results;
   name = "/root/data/Kanti175.bsp";
-  
-   if (stat( name , &results) == 0)
-  {
-     PRINTF(0)("BSP FILE: Datei gefunden. \n");
-     ifstream bspFile (name, ios::in | ios::binary);
-     bspFile.read(this->header, 260);
-     PRINTF(0)("BSP FILE: BSPVersion: %i. \n", ((int *)(header) )[1]);
-     if((((int *)(header) )[1]) == 46)    PRINTF(0)("BSP FILE: This is the good one! :-)  \n");
-     else    PRINTF(0)("BSP FILE: Wrong BSPVersion.\n");
-
-     // Get the Nodes
-    offset = ((int *)(header) )[8];
-    size    = ((int *)(header))[9];
-    PRINTF(0)("BSP FILE: NodeSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumNodes: %i. \n", size / 36);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size %36);
-    PRINTF(0)("BSP FILE: NodeOffset: %i. \n", offset);
-    this->numNodes = size/36;
-    this->nodes = new char [size];
-    bspFile.seekg(offset);
-    bspFile.read(this->nodes, size);
-
-     // and their Planes
-    offset = ((int *)(header) )[6];
-    size    = ((int *)(header))[7];
-    PRINTF(0)("BSP FILE: PlanesSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumPlanes: %i. \n", size / 16);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size %16);
-    PRINTF(0)("BSP FILE: PlanesOffset: %i. \n", offset);
-    this->numPlanes = size/16;
-    this->planes = new char [size];
-    bspFile.seekg(offset);
-    bspFile.read(this->planes, size);
-
-     // Get the Leafs
-    offset = ((int *)(header) )[10];
-    size    = ((int *)(header))[11];
-    PRINTF(0)("BSP FILE: LeaveSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumLeaves: %i. \n", size / 48);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 48);
-    PRINTF(0)("BSP FILE: LeaveOffset: %i. \n", offset);
-    this->numLeafs = size/48;
-    this->leaves = new char [size];
-    bspFile.seekg(offset);
-    bspFile.read(this->leaves, size);
+
+  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 = ((int *)(header))[16];
-    size    = ((int *)(header))[17];
-    PRINTF(0)("BSP FILE: ModelsSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumModels: %i. \n", size / 40);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 40);
-    PRINTF(0)("BSP FILE: ModelsOffset: %i. \n", offset);
-    this->numBspModels = size/40;
-    this->bspModels = new char [size];
-    bspFile.seekg(offset);
-    bspFile.read(this->bspModels, size);
+    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 = ((int *)(header))[12];
-    size    = ((int *)(header))[13];
-    PRINTF(0)("BSP FILE: leafFacesSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumleafFaces: %i. \n", size / 4);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 4);
-    PRINTF(0)("BSP FILE: leafFacesOffset: %i. \n", offset);
+    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];
@@ -115,10 +112,10 @@
 
     // Get the leafBrushes
-    offset = ((int *)(header))[14];
-    size    = ((int *)(header))[15];
-    PRINTF(0)("BSP FILE: leafBrushesSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumleafBrushes: %i. \n", size / 4);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 4);
-    PRINTF(0)("BSP FILE: leafBrushesOffset: %i. \n", offset);
+    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];
@@ -127,10 +124,10 @@
 
     // Get the brushes
-    offset = ((int *)(header))[18];
-    size    = ((int *)(header))[19];
-    PRINTF(0)("BSP FILE: BrushesSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumBrushes: %i. \n", size / 12);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 12);
-    PRINTF(0)("BSP FILE: BrushesOffset: %i. \n", offset);
+    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 / 12);
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 12);
+    PRINTF(4)("BSP FILE: BrushesOffset: %i. \n", offset);
     this->brushes = new char [size];
     bspFile.seekg(offset);
@@ -138,10 +135,10 @@
 
     // Get the brushSides
-    offset = ((int *)(header))[20];
+    offset =   SDL_SwapLE32(((int *)(header))[20]);
     size    = SDL_SwapLE32(((int *)(header))[21]);
-    PRINTF(0)("BSP FILE: BrushSidesSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumBrushSides: %i. \n", size / 8);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 8);
-    PRINTF(0)("BSP FILE: BrushSidesOffset: %i. \n", offset);
+    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->brushSides = new char [size];
     this->numBrushSides = size/8;
@@ -150,10 +147,10 @@
 
     // Get the Vertice
-    offset = ((int *)(header))[22];
-    size    = ((int *)(header))[23];
-    PRINTF(0)("BSP FILE: VerticeSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumVertice: %i. \n", size / 44);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 44);
-    PRINTF(0)("BSP FILE: VerticeOffset: %i. \n", offset);
+    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];
@@ -162,10 +159,10 @@
 
     // Get the MeshVerts
-    offset = ((int *)(header))[24];
-    size    = ((int *)(header))[25];
-    PRINTF(0)("BSP FILE: MeshVertsSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumMeshVerts: %i. \n", size / 4);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 4);
-    PRINTF(0)("BSP FILE: MeshVertsOffset: %i. \n", offset);
+    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 / 4);
+    PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4);
+    PRINTF(4)("BSP FILE: MeshVertsOffset: %i. \n", offset);
     this->meshverts = new char [size];
     bspFile.seekg(offset);
@@ -173,18 +170,18 @@
 
     // Get the Faces
-    offset = ((int *)(header))[28];
-    size    = ((int *)(header))[29];
-    PRINTF(0)("BSP FILE: FacesSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumFaces: %i. \n", size / 104);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 104);
-    PRINTF(0)("BSP FILE: FacesOffset: %i. \n", offset);
-    this->numFaces = size/104;
-    this->faces = new char [size];
-    bspFile.seekg(offset);
-    bspFile.read(this->faces, size);
+    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 Visdata
-    offset = ((int *)(header))[34];
-    size    = ((int *)(header))[35];
+    offset = SDL_SwapLE32(((int *)(header))[34]);
+    size    = SDL_SwapLE32(((int *)(header))[35]);
 
     this->visData = new char [size];
@@ -192,12 +189,12 @@
     bspFile.read(this->visData, size);
 
-    PRINTF(0)("BSP FILE: VisDataSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumVisData: %i. \n", size /1 - 8);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 1);
-    PRINTF(0)("BSP FILE: VisDataOffset: %i. \n", offset);
+    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 = ((int *)(header))[4];
-    size    = ((int *)(header))[5];
+    offset = SDL_SwapLE32(((int *)(header))[4]);
+    size    = SDL_SwapLE32(((int *)(header))[5]);
 
     this->textures= new char [size];
@@ -205,52 +202,48 @@
     bspFile.read(this->textures, size);
 
-    PRINTF(0)("BSP FILE: TextureSize: %i Bytes. \n", size);
-    PRINTF(0)("BSP FILE: NumTextures: %i. \n", size /72);
-    PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 72);
-    PRINTF(0)("BSP FILE: TextureOffset: %i. \n", offset);
+    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(0)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]);
-   this->load_textures();
-
-   // 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 (	cFace.type == 2) 
-		this->numPatches += (cFace.size[0] -1 ) / 2  * (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];
+    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();
+
+    // 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 (	cFace.type == 2)
+        this->numPatches += (cFace.size[0] -1 ) / 2  * (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);
     // Do tesselation for all Faces of type 2
-   for( int i = 0; i < this->numFaces; i++)
-	{
-	if (	((face *)(this->faces))[i].type == 2) 
-		this->tesselate(i);
-	}
-
-  PRINTF(0)("BSP FILE:PatchOffset: %i . \n", this->patchOffset);
-
-     return  1; 
+    for( int i = 0; i < this->numFaces; i++) {
+      if (	((face *)(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;
   }
-  else
-  {
-     PRINTF(0)("BSP FILE: Datei nicht gefunden. \n");
-     return -1;
-  }
- 
+
 }
 
@@ -258,67 +251,61 @@
 {
 
-   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);
+  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);
 }
 
 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);
+  // 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
- return thisNode;
+  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;
 }
 
 BspTreeNode* BspFile::get_root()
 {
-return root;
+  return root;
 }
 
@@ -331,9 +318,8 @@
 
   this->Materials = new AMat[this->numTextures];
-  for(int i = 0 ; i < this->numTextures; i++)
-  {
+  for(int i = 0 ; i < this->numTextures; i++) {
     PRINTF(0)("BSP FILE: Texture : %s. \n", &this->textures[8+ 72*i]);
-   
-     // Check for tga
+
+    // Check for tga
     strcpy(fileName, &this->textures[8+ 72*i]);
     strcpy (absFileName,"/root/data/trunk/");
@@ -342,10 +328,9 @@
     strncat(absFileName,fileName,strlen(fileName));
     // absFileName = ResourceManager::getFullName(fileName);
-  
-    if(stat( absFileName , &results) == 0)
-    {
-        PRINTF(0)("BSP FILE: gefunden . \n");
-	this->Materials[i] = this->loadMat(fileName);
-	continue;
+
+    if(stat( absFileName , &results) == 0) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] = this->loadMat(fileName);
+      continue;
     }
     // Check for TGA
@@ -355,11 +340,10 @@
     strncat (fileName, ext, strlen(fileName));
     strncat(absFileName,fileName,strlen(fileName));
-    // absFileName = ResourceManager::getFullName(fileName); 
-
-    if(stat( absFileName , &results) == 0)
-    {
-        PRINTF(0)("BSP FILE: gefunden . \n");
-	this->Materials[i] = this->loadMat(fileName);
-	continue;
+    // absFileName = ResourceManager::getFullName(fileName);
+
+    if(stat( absFileName , &results) == 0) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] = this->loadMat(fileName);
+      continue;
     }
     // Check for jpg
@@ -369,28 +353,26 @@
     strncat (fileName, ext, strlen(fileName));
     strncat(absFileName,fileName,strlen(fileName));
-    // absFileName = ResourceManager::getFullName(fileName);   
-    if(stat( absFileName , &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 (absFileName,"/root/data/trunk/");
-   strcpy(ext, ".JPG");
-   strncat (fileName, ext, strlen(fileName));
-   strncat(absFileName,fileName,strlen(fileName));
-   // absFileName = ResourceManager::getFullName(fileName);
-    if(stat( absFileName , &results) == 0)
-    {
-        PRINTF(0)("BSP FILE: gefunden . \n");
-	this->Materials[i] =this->loadMat(fileName);
-	continue;
-    }
-
-   // Check for jpeg
+    // absFileName = ResourceManager::getFullName(fileName);
+    if(stat( absFileName , &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 (absFileName,"/root/data/trunk/");
+    strcpy(ext, ".JPG");
+    strncat (fileName, ext, strlen(fileName));
+    strncat(absFileName,fileName,strlen(fileName));
+    // absFileName = ResourceManager::getFullName(fileName);
+    if(stat( absFileName , &results) == 0) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] =this->loadMat(fileName);
+      continue;
+    }
+
+    // Check for jpeg
     strcpy(fileName, &this->textures[8+ 72*i]);
     strcpy (absFileName,"/root/data/trunk/");
@@ -399,9 +381,8 @@
     strncat(absFileName,fileName,strlen(fileName));
     // absFileName = ResourceManager::getFullName(fileName);
-    if(stat( absFileName , &results) == 0)
-    {
-        PRINTF(0)("BSP FILE: gefunden . \n");
- 	this->Materials[i] =this->loadMat(fileName);
-	continue;
+    if(stat( absFileName , &results) == 0) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] =this->loadMat(fileName);
+      continue;
     }
 
@@ -415,27 +396,25 @@
     // absFileName = ResourceManager::getFullName(fileName);
     PRINTF(0)("BSP FILE: %s . \n", absFileName);
-    if(stat( absFileName , &results) == 0)
-    {
-        PRINTF(0)("BSP FILE: gefunden . \n");
-        this->Materials[i] =this->loadMat(fileName);
-	continue;
-    }
-
-   // Check for bmp
-   strcpy(fileName, &this->textures[8+ 72*i]);
-   strcpy (absFileName,"/root/data/trunk/");
-   strcpy(ext, ".bmp");
-   strncat (fileName, ext, strlen(fileName));
-   strncat(absFileName,fileName,strlen(fileName));
-   // absFileName = ResourceManager::getFullName(fileName);
- 
-    if(stat( absFileName , &results) == 0)
-    {
-        PRINTF(0)("BSP FILE: gefunden . \n");
-	this->Materials[i] =this->loadMat(fileName);
-	continue;
-    }
-
-   // Check for BMP
+    if(stat( absFileName , &results) == 0) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] =this->loadMat(fileName);
+      continue;
+    }
+
+    // Check for bmp
+    strcpy(fileName, &this->textures[8+ 72*i]);
+    strcpy (absFileName,"/root/data/trunk/");
+    strcpy(ext, ".bmp");
+    strncat (fileName, ext, strlen(fileName));
+    strncat(absFileName,fileName,strlen(fileName));
+    // absFileName = ResourceManager::getFullName(fileName);
+
+    if(stat( absFileName , &results) == 0) {
+      PRINTF(0)("BSP FILE: gefunden . \n");
+      this->Materials[i] =this->loadMat(fileName);
+      continue;
+    }
+
+    // Check for BMP
     strcpy(fileName, &this->textures[8+ 72*i]);
     strcpy (absFileName,"/root/data/trunk/");
@@ -445,21 +424,20 @@
     // absFileName = ResourceManager::getFullName(fileName);
 
-    if(stat( absFileName , &results) == 0)
-    {
-        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/ground.tga");
-   	this->Materials[i].mat->setAmbientMap("pictures/ground.tga");
-        this->Materials[i].mat->setSpecularMap("pictures/ground.tga");
-	this->Materials[i].alpha = false;
+    if(stat( absFileName , &results) == 0) {
+      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/ground.tga");
+    this->Materials[i].mat->setAmbientMap("pictures/ground.tga");
+    this->Materials[i].mat->setSpecularMap("pictures/ground.tga");
+    this->Materials[i].alpha = false;
   }
 }
@@ -472,22 +450,20 @@
 
   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;
+  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(1.0);
-
-   	tmp->setDiffuseMap(mat);
-   	tmp->setAmbientMap(mat);
-        tmp->setSpecularMap(mat);
-  
+  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(1.0);
+
+  tmp->setDiffuseMap(mat);
+  tmp->setAmbientMap(mat);
+  tmp->setSpecularMap(mat);
+
   tmpAMat.mat = tmp;
 
@@ -497,325 +473,316 @@
 void BspFile::tesselate(int iface)
 {
-	 face*  Face =  & (((face *)(this->faces))[iface]);
-	 BspVertex *  BspVrtx = (BspVertex*)this->vertice; 
-	 int level = 7;
-	 int level1 = 8;
-
-	// For each patch...
-	for(int i = 0; i <(Face->size[0] - 1)    ; i+=2)
-	{
-		for(int j = 0; j <(Face->size[1] -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 * Face->size[0])+ i + l+ Face->size[0]*k].position[0];
-					controls[k +3*l]. position[1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1];
-					controls[k +3*l]. position[2] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; /*Face->n_vertexes*/ 
-
-				       controlsTmp[2-k +6-3*l]. position[0] =   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0];
-					controlsTmp[2-k +6-3*l]. position[1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1];
-					controlsTmp[2-k +6-3*l]. position[2] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; /*Face->n_vertexes*/ 
-
-					VControls[k +3*l]. position[0] =   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0];
-					VControls[k +3*l]. position[1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1];
-					VControls[k +3*l]. position[2] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2];
-
-					VControls[k +3*l]. normal[0] =   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].normal[0];
-					VControls[k +3*l]. normal[1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].normal[1];
-					VControls[k +3*l]. normal[2] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].normal[2];
-
-					VControls[k +3*l]. texcoord[0][0]=   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].texcoord[0][0];
-					VControls[k +3*l]. texcoord[0][1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].texcoord[0][1];
-					VControls[k +3*l]. texcoord[1][0] =   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].texcoord[1][0];
-					VControls[k +3*l]. texcoord[1][1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*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 = (Face->size[0] -1)/2 * (Face->size[1] -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; 
+  face*  Face =  & (((face *)(this->faces))[iface]);
+  BspVertex *  BspVrtx = (BspVertex*)this->vertice;
+  int level = 7;
+  int level1 = 8;
+
+  // For each patch...
+  for(int i = 0; i <(Face->size[0] - 1)    ; i+=2) {
+    for(int j = 0; j <(Face->size[1] -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 * Face->size[0])+ i + l+ Face->size[0]*k].position[0];
+          controls[k +3*l]. position[1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1];
+          controls[k +3*l]. position[2] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; /*Face->n_vertexes*/
+
+          controlsTmp[2-k +6-3*l]. position[0] =   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0];
+          controlsTmp[2-k +6-3*l]. position[1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1];
+          controlsTmp[2-k +6-3*l]. position[2] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; /*Face->n_vertexes*/
+
+          VControls[k +3*l]. position[0] =   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0];
+          VControls[k +3*l]. position[1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1];
+          VControls[k +3*l]. position[2] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2];
+
+          VControls[k +3*l]. normal[0] =   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].normal[0];
+          VControls[k +3*l]. normal[1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].normal[1];
+          VControls[k +3*l]. normal[2] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].normal[2];
+
+          VControls[k +3*l]. texcoord[0][0]=   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].texcoord[0][0];
+          VControls[k +3*l]. texcoord[0][1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].texcoord[0][1];
+          VControls[k +3*l]. texcoord[1][0] =   BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].texcoord[1][0];
+          VControls[k +3*l]. texcoord[1][1] =   BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*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 = (Face->size[0] -1)/2 * (Face->size[1] -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;
 }
Index: branches/bsp_model/src/lib/graphics/importer/bsp_file.h
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_file.h	(revision 7392)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_file.h	(revision 7395)
@@ -21,8 +21,8 @@
 typedef struct
 {
-  float x;
-  float y;
-  float z;
-  float d;
+  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
 }
 plane;
@@ -30,10 +30,10 @@
 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; //
+  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;
@@ -41,9 +41,9 @@
 typedef struct
 {
-  int plane; //Plane index.
-  int left; //Children indices. Negative numbers are leaf indices: -(leaf+1).
-  int right;
-  int mins[ 3 ]; //Integer bounding box min coord.
-  int maxs[ 3 ]; //Integer bounding box max coord.
+  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;
@@ -51,12 +51,12 @@
 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.
+  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;
@@ -64,7 +64,7 @@
 typedef struct
 {
-  int brushside; 	//First brushside for brush.
-  int n_brushsides; 	//Number of brushsides for brush.
-  int texture; 	//Texture index.
+  int brushside; 	//!< First brushside for brush.
+  int n_brushsides; 	//!< Number of brushsides for brush.
+  int texture; 	        //!< Texture index.
 }
 brush;
@@ -72,6 +72,6 @@
 typedef struct
 {
-  int plane; //Plane index.
-  int texture; 	//Texture index.
+  int plane;    //!< Plane index.
+  int texture; 	//!< Texture index.
 }
 brushside;
@@ -79,26 +79,26 @@
 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.
+  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=surface, 1=lightmap.
-  float normal[ 3 ]; // Vertex normal.
-  unsigned char color [ 4 ]; //  Vertex color. RGBA.
+  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;
@@ -108,5 +108,5 @@
   int offset;
 }
-meshvert;
+meshvert;                    //!< Integer offset to mesh vertex
 
 typedef struct
@@ -140,10 +140,10 @@
   BspTreeNode* root;
   char header [ 280 ];       //!< Buffer for header of BSP-File
-  char* nodes;               //!< Buffer to store BSP-Tree-Nodes
-  char* leaves;              //!< Buffer to store BSP-Tree-Leaves
-  char* planes;              //!< Buffer to store planes separateing the space
-  char* bspModels;           //!< Buffer to store BSP-Model-List
+  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
-  char* faces;               //!<
+  face* faces;               //!<
   char* leafBrushes;         //!< Buffer to store brush indice
   char* brushes;             //!< Buffer to store  brushes
@@ -153,9 +153,9 @@
   char* visData;             //!<
   char* textures;            //!<
-
-
   char* patchVertice;
   char* patchIndexes;
   char* patchTrianglesPerRow;
+  
+  
   int** patchRowIndexes;
   VertexArrayModel** VertexArrayModels;
Index: branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 7392)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 7395)
@@ -1,12 +1,12 @@
 /*
    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
@@ -34,143 +34,136 @@
 BspManager::BspManager()
 {
-	// open a BSP file
-	this->bspFile = new BspFile();
-	this->bspFile->read("/root/data/Kanti175.bsp");
-	this->bspFile->build_tree();
-	this->root  = this->bspFile->get_root();
-	this->alreadyVisible = new bool [this->bspFile->numFaces];
+  // open a BSP file
+  this->bspFile = new BspFile();
+  this->bspFile->read("/root/data/Kanti175.bsp");
+  this->bspFile->build_tree();
+  this->root  = this->bspFile->get_root();
+  this->alreadyVisible = new bool [this->bspFile->numFaces];
 }
 
 void BspManager::draw()
 {
-	
-
-
-
-
- // 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();	
+
+
+
+
+
+  // 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->cam = 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)
-
-
- 
-   // Test Collision Detection
-	this->checkCollision(this->root, &this->cam);
-
-    if (true)//(((int *)(this->bspFile->header))[35] == 0)  || viscluster < 0)  // if (sizeof(Visdata) == 0)
+  this->cam = State::getCamera()->getAbsCoor() ;
+  this->ship = State::getCameraTargetNode()->getAbsCoor();
+
+
+
+
+  this->cam = 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->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
+
+  if ((((int *)(this->bspFile->header))[35] == 0)  || viscluster < 0)  //!< if (sizeof(Visdata) == 0)
+  {
+    /** Do Frustum culling and draw 'em all **/
+
+    // Iterate through all Leafs
+    for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )
     {
-	// Do Frustum culling and draw 'em all
-	
-	// Iterate through all Leafs
-	for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )	
-	{
-	 	// cluster =  ((leaf *)(this->bspFile->leaves))[i].cluster;
-		leaf& curLeaf = ((leaf *)(this->bspFile->leaves))[i];
-	
-		
-		// Iterate through all faces
-		for (int j = 0; j < curLeaf.n_leaffaces ; ++j)
-		{
-  			 const int f = ( j +  ((leaf *) (this->bspFile->leaves))[i].leafface) % this->bspFile->numFaces;
-  			if (f >=0 && !this->isAlreadyVisible(f)) 
-			{
-      				this->alreadyVisible[f] = true;
-			/*	if(ActLeaf->leafIndex == i)
-				{
-					this->alreadyVisible[i] = false;
-					this->draw_debug_face(f);
-					this->alreadyVisible[i] = true;
-				}
-				else */addFace(f); // "visibleFaces.append(f)"
-    			}
-		}
-				 
-	
-
-         
-	} //for
-    }
-    else
-   {
-	 int cluster;
-	int seven = 7;
-	unsigned char  one = 1;
- 	unsigned int v;
-	unsigned char  visSet;
-	
-	// Iterate through all Leafs
-	
-	for(int i = 0; i <  this->bspFile->numLeafs   ; ++i )	
-	{
-		leaf& camLeaf =  ((leaf *)(this->bspFile->leaves))[ActLeaf->leafIndex] ;
-		leaf& curLeaf = ((leaf *)(this->bspFile->leaves))[i] ;
-	 	cluster =  curLeaf.cluster;
-		if(cluster <0) continue;
-         	v = ((viscluster *  ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8));
-         	visSet =((unsigned char*) (this->bspFile->visData))[v+8];
-		//   PRINTF(0)("BSP Manager: visibility ");         	
-
-
-	if( ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster &  7))) == 0 ) // < 20 || ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster &  7)))  >= 128)
-	{
-		// Iterate through all faces
-		for (int j = 0; j < curLeaf.n_leaffaces ; ++j)
-		{
-  			 const int f = (j +  curLeaf.leafface) % this->bspFile->numFaces;
-		
-
-  			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();
-}
+      // cluster =  (this->bspFile->leaves)[i].cluster;
+      leaf& curLeaf = (this->bspFile->leaves)[i];
+
+
+      // Iterate through all faces
+      for (int j = 0; j < curLeaf.n_leaffaces ; ++j) {
+        const int f = ( j +  ((leaf *) (this->bspFile->leaves))[i].leafface) % this->bspFile->numFaces;
+        if (f >=0 && !this->isAlreadyVisible(f)) {
+          this->alreadyVisible[f] = true;
+          /*	if(ActLeaf->leafIndex == i)
+          	{
+          		this->alreadyVisible[i] = false;
+          		this->draw_debug_face(f);
+          		this->alreadyVisible[i] = true;
+          	}  
+                else */
+          addFace(f); // "visibleFaces.append(f)"
+        }
+      }
+
+
+
+
+    } //for
+  } else {
+    int cluster;
+    int seven = 7;
+    unsigned char  one = 1;
+    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] ;
+      cluster =  curLeaf.cluster;
+      
+      if(cluster <0) continue;
+      v = ((viscluster *  ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8));
+      visSet =((unsigned char*) (this->bspFile->visData))[v+8];
+   
+      
+      if( ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster &  7))) == 0 )
+      {
+        // Iterate through all faces
+        for (int j = 0; j < curLeaf.n_leaffaces ; ++j)
+        {
+          const int f = (j +  curLeaf.leafface) % this->bspFile->numFaces;
+
+
+          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();
+  }
 
 
@@ -178,48 +171,44 @@
 
 void BspManager::draw_leaf()
-{
-
-}
+{}
 
 void BspManager::draw_face(int curface)
 {
- face& curFace =  ((face *)(this->bspFile->faces))[curface];
- const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
- int stride = 44;  // sizeof(Vertex)
- int offset    = curFace.vertex;
-	
+  face& curFace =  (this->bspFile->faces)[curface];
+  const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
+  int stride = sizeof(BspVertex);  // 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)	
-	if(this->lastTex != curFace.texture)
-	{
-  	this->bspFile->Materials[curFace.texture].mat->select();
-	this->lastTex = 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)
+  if(this->lastTex != curFace.texture) {
+    this->bspFile->Materials[curFace.texture].mat->select();
+    this->lastTex = curFace.texture;
+  }
   glEnableClientState(GL_VERTEX_ARRAY );
   glEnableClientState(GL_TEXTURE_COORD_ARRAY );
   glEnableClientState(GL_NORMAL_ARRAY );
-//  glEnableClientState(GL_COLOR_ARRAY);	
-  // glEnableClientState(GL_VERTEX_ARRAY );
-	
+  //  glEnableClientState(GL_COLOR_ARRAY);
+  
+
   glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
-   // glClientActiveTextureARB(GL_TEXTURE0_ARB);
+  // glClientActiveTextureARB(GL_TEXTURE0_ARB);
   glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
-   // glClientActiveTextureARB(GL_TEXTURE1_ARB);
-   // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
-   //glEnableClientState(GL_NORMAL_ARRAY );
+  // glClientActiveTextureARB(GL_TEXTURE1_ARB);
+  // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
+
 
   glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0]));
-    // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[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]));
+                 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert]));
 
 
@@ -227,6 +216,6 @@
   glDisableClientState(GL_TEXTURE_COORD_ARRAY );
   glDisableClientState(GL_NORMAL_ARRAY );
-// glDisableClientState(GL_COLOR_ARRAY);
-	
+  // glDisableClientState(GL_COLOR_ARRAY);
+
 }
 
@@ -234,85 +223,81 @@
 void BspManager::draw_debug_face(int curface)
 {
- face& curFace =  ((face *)(this->bspFile->faces))[curface];
- const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
- int stride = 44;  // sizeof(Vertex)
- int offset    = curFace.vertex;
-	
+  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;
+
+  //  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_COLOR_ARRAY);
   // glEnableClientState(GL_VERTEX_ARRAY );
-	
+
   glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
-   // glClientActiveTextureARB(GL_TEXTURE0_ARB);
+  // glClientActiveTextureARB(GL_TEXTURE0_ARB);
   glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
-   // glClientActiveTextureARB(GL_TEXTURE1_ARB);
-   // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
-   //glEnableClientState(GL_NORMAL_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]));
+  //  glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0]));
   glDrawElements(GL_TRIANGLES, curFace.n_meshverts,
-                             GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert]));
-	
+                 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;
-		}
-
-	for(int i = 0; i < Face->n_meshverts  ; i++)
-	{
-	   //glFrontFace(GL_CW);	
-	   //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);	
-	   glEnableClientState(GL_VERTEX_ARRAY );
-	   glEnableClientState(GL_TEXTURE_COORD_ARRAY );
-	   glEnableClientState(GL_NORMAL_ARRAY );
-
-	   glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0]));
-	   glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
-	   glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
-
-	   // We'll need multitexture suport for lightning
-     	   //glClientActiveTextureARB(GL_TEXTURE0_ARB);
-           //glTexCoordPointer(2, GL_FLOAT,0, &vertex[0].textureCoord);
-          //glClientActiveTextureARB(GL_TEXTURE1_ARB);
-          //glTexCoordPointer(2, GL_FLOAT, sizeof(BSPVertex), &vertex[0].lightmapCoord);
-
-
-		for(int row=0; row<7; ++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);
-	}
-		
+  if(this->lastTex != Face->texture) {
+    this->bspFile->Materials[Face->texture].mat->select();
+    this->lastTex = Face->texture;
+  }
+
+  for(int i = 0; i < Face->n_meshverts  ; i++) {
+    //glFrontFace(GL_CW);
+    //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);
+    glEnableClientState(GL_VERTEX_ARRAY );
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY );
+    glEnableClientState(GL_NORMAL_ARRAY );
+
+    glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0]));
+    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
+    glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
+
+    // We'll need multitexture suport for lightning
+    //glClientActiveTextureARB(GL_TEXTURE0_ARB);
+    //glTexCoordPointer(2, GL_FLOAT,0, &vertex[0].textureCoord);
+    //glClientActiveTextureARB(GL_TEXTURE1_ARB);
+    //glTexCoordPointer(2, GL_FLOAT, sizeof(BSPVertex), &vertex[0].lightmapCoord);
+
+
+    for(int row=0; row<7; ++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);
+  }
+
 }
 
 bool BspManager::isAlreadyVisible(int Face)
 {
-	return this->alreadyVisible[Face];
+  return this->alreadyVisible[Face];
 }
 
@@ -320,157 +305,147 @@
 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;
+  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::checkCollision(BspTreeNode* node, Vector* cam)
 {
-	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);}
-
-	
-/*
-	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;
+  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);}
+
+
+    /*
+    	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();
+  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);
-}
+  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: branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_manager.h	(revision 7392)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_manager.h	(revision 7395)
@@ -1,12 +1,12 @@
 /*
    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
@@ -28,34 +28,34 @@
 {
 public:
-// Constructors
- BspManager();
+  // Constructors
+  BspManager();
 
-// Functions
- void draw();
- void draw_leaf();
- void draw_debug_face(int Face);
- void draw_face(int Face);
- void draw_patch(face* Face);
- 
+  // Functions
+  void draw();
+  void draw_leaf();
+  void draw_debug_face(int Face);
+  void draw_face(int Face);
+  void draw_patch(face* Face);
+
 
 private:
-// Functions
- BspFile*  bspFile;
- BspTreeNode* root;
- const BspTreeNode* getLeaf(const BspTreeNode*  node, const Vector& cam) const;  // Traverses the tree 
- void  checkCollision(BspTreeNode* node, Vector* cam);
- void drawDebugCube(Vector* cam);
- Vector cam;
- Vector ship;
- Vector  viewDir;
- bool * alreadyVisible;
- bool isAlreadyVisible(int Face);
- void addFace(int Face);
- int lastTex;
+  // Functions
+  BspFile*  bspFile;
+  BspTreeNode* root;
+  BspTreeNode* getLeaf(BspTreeNode*  node,   Vector* cam) ;  //!< Traverses the tree
+  void  checkCollision(BspTreeNode* node, Vector* cam);
+  void drawDebugCube(Vector* cam);
+  Vector cam;
+  Vector ship;
+  Vector  viewDir;
+  bool * alreadyVisible;
+  bool isAlreadyVisible(int Face);
+  void addFace(int Face);
+  int lastTex;
 
 
-// Vectors to store the visible faces
- ::std::deque<int> trasparent; // the ones with transparancy go here
- ::std::deque<int> opal; // the others here.
+  // Deques to store the visible faces
+  ::std::deque<int> trasparent; //!< the ones with transparancy go here
+  ::std::deque<int> opal; //!< the others here.
 
 };
