Index: /branches/bsp_model/src/lib/graphics/importer/bsp_file.cc
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/bsp_file.cc	(revision 7384)
+++ /branches/bsp_model/src/lib/graphics/importer/bsp_file.cc	(revision 7385)
@@ -20,10 +20,12 @@
 #include "debug.h"
 #include "material.h"
-#include "util/loading/resource_manager.h"
-
 #include "vertex_array_model.h"
 // Necessary ?
 #include "base_object.h"
 #include "vector.h"
+#include "util/loading/resource_manager.h"
+
+#include <SDL/SDL_endian.h>
+#include <SDL/SDL_image.h>
 
 using namespace std;
@@ -36,11 +38,10 @@
 }
 
-int BspFile::read(char* in_name)
+int BspFile::read(char* name)
 {
   int offset;
   int size;
   struct stat results;
-   char name [300];
-	  strcpy(name,ResourceManager::getFullName(in_name).c_str());
+  name = "/root/data/Kanti175.bsp";
   
    if (stat( name , &results) == 0)
@@ -138,5 +139,5 @@
     // Get the brushSides
     offset = ((int *)(header))[20];
-    size    = ((int *)(header))[21];
+    size    = SDL_SwapLE32(((int *)(header))[21]);
     PRINTF(0)("BSP FILE: BrushSidesSize: %i Bytes. \n", size);
     PRINTF(0)("BSP FILE: NumBrushSides: %i. \n", size / 8);
@@ -324,10 +325,10 @@
 void BspFile::load_textures()
 {
-  const char* absFileName;
+  char absFileName [228];
   char fileName [228];
   char ext [100];
   struct stat results;
 
-  this->Materials = new Material* [this->numTextures];
+  this->Materials = new AMat[this->numTextures];
   for(int i = 0 ; i < this->numTextures; i++)
   {
@@ -336,9 +337,9 @@
      // Check for tga
     strcpy(fileName, &this->textures[8+ 72*i]);
-    //strcpy (absFileName,"/root/data/trunk/");
+    strcpy (absFileName,"/root/data/trunk/");
     strcpy(ext, ".tga");
     strncat (fileName, ext, strlen(fileName));
-    //strncat(absFileName,fileName,strlen(fileName));
-    absFileName = ResourceManager::getFullName(fileName).c_str();
+    strncat(absFileName,fileName,strlen(fileName));
+    // absFileName = ResourceManager::getFullName(fileName);
   
     if(stat( absFileName , &results) == 0)
@@ -350,10 +351,10 @@
     // Check for TGA
     strcpy(fileName, &this->textures[8+ 72*i]);
-    //strcpy (absFileName,"/root/data/trunk/");
+    strcpy (absFileName,"/root/data/trunk/");
     strcpy(ext, ".TGA");
     strncat (fileName, ext, strlen(fileName));
-   // strncat(absFileName,fileName,strlen(fileName));
+    strncat(absFileName,fileName,strlen(fileName));
     // absFileName = ResourceManager::getFullName(fileName); 
-    absFileName = ResourceManager::getFullName(fileName).c_str();
+
     if(stat( absFileName , &results) == 0)
     {
@@ -364,10 +365,9 @@
     // Check for jpg
     strcpy(fileName, &this->textures[8+ 72*i]);
-    //strcpy (absFileName,"/root/data/trunk/");
+    strcpy (absFileName,"/root/data/trunk/");
     strcpy(ext, ".jpg");
     strncat (fileName, ext, strlen(fileName));
-    //strncat(absFileName,fileName,strlen(fileName));
+    strncat(absFileName,fileName,strlen(fileName));
     // absFileName = ResourceManager::getFullName(fileName);   
-    absFileName = ResourceManager::getFullName(fileName).c_str();
     if(stat( absFileName , &results) == 0)
     {
@@ -380,10 +380,9 @@
    // Check for JPG
    strcpy(fileName, &this->textures[8+ 72*i]);
-   //strcpy (absFileName,"/root/data/trunk/");
+   strcpy (absFileName,"/root/data/trunk/");
    strcpy(ext, ".JPG");
    strncat (fileName, ext, strlen(fileName));
-   //strncat(absFileName,fileName,strlen(fileName));
+   strncat(absFileName,fileName,strlen(fileName));
    // absFileName = ResourceManager::getFullName(fileName);
-    absFileName = ResourceManager::getFullName(fileName).c_str();
     if(stat( absFileName , &results) == 0)
     {
@@ -395,10 +394,9 @@
    // Check for jpeg
     strcpy(fileName, &this->textures[8+ 72*i]);
-    //strcpy (absFileName,"/root/data/trunk/");
+    strcpy (absFileName,"/root/data/trunk/");
     strcpy(ext, ".jpeg");
     strncat (fileName, ext, strlen(fileName));
-    //strncat(absFileName,fileName,strlen(fileName));
-   //  absFileName = ResourceManager::getFullName(fileName);
-    absFileName = ResourceManager::getFullName(fileName).c_str();
+    strncat(absFileName,fileName,strlen(fileName));
+    // absFileName = ResourceManager::getFullName(fileName);
     if(stat( absFileName , &results) == 0)
     {
@@ -411,10 +409,9 @@
     // Check for JPEG
     strcpy(fileName, &this->textures[8+ 72*i]);
-    //strcpy (absFileName,"/root/data/trunk/");
+    strcpy (absFileName,"/root/data/trunk/");
     strcpy(ext, ".JPEG");
     strncat (fileName, ext, strlen(fileName));
-    //strncat(absFileName,fileName,strlen(fileName));
+    strncat(absFileName,fileName,strlen(fileName));
     // absFileName = ResourceManager::getFullName(fileName);
-    absFileName = ResourceManager::getFullName(fileName).c_str();
     PRINTF(0)("BSP FILE: %s . \n", absFileName);
     if(stat( absFileName , &results) == 0)
@@ -427,10 +424,9 @@
    // Check for bmp
    strcpy(fileName, &this->textures[8+ 72*i]);
-   //strcpy (absFileName,"/root/data/trunk/");
+   strcpy (absFileName,"/root/data/trunk/");
    strcpy(ext, ".bmp");
    strncat (fileName, ext, strlen(fileName));
-   //strncat(absFileName,fileName,strlen(fileName));
-  //  absFileName = ResourceManager::getFullName(fileName);
-    absFileName = ResourceManager::getFullName(fileName).c_str();
+   strncat(absFileName,fileName,strlen(fileName));
+   // absFileName = ResourceManager::getFullName(fileName);
  
     if(stat( absFileName , &results) == 0)
@@ -443,10 +439,9 @@
    // Check for BMP
     strcpy(fileName, &this->textures[8+ 72*i]);
-    //strcpy (absFileName,"/root/data/trunk/");
+    strcpy (absFileName,"/root/data/trunk/");
     strcpy(ext, ".BMP");
     strncat (fileName, ext, strlen(fileName));
-  //  strncat(absFileName,fileName,strlen(fileName));
-   //  absFileName = ResourceManager::getFullName(fileName);
-    absFileName = ResourceManager::getFullName(fileName).c_str();
+    strncat(absFileName,fileName,strlen(fileName));
+    // absFileName = ResourceManager::getFullName(fileName);
 
     if(stat( absFileName , &results) == 0)
@@ -457,19 +452,31 @@
     }
 	// 	Default Material
-   	this->Materials[i] = new Material();
- 	this->Materials[i]->setDiffuse(0.1,0.1,0.1);
-   	this->Materials[i]->setAmbient(0.1,0.1,0.1 );
-   	this->Materials[i]->setSpecular(0.4,0.4,0.4);
+   	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]->setTransparency(1.0);
-	this->Materials[i]->setDiffuseMap("pictures/ground.tga");
-   	this->Materials[i]->setAmbientMap("pictures/ground.tga");
-        this->Materials[i]->setSpecularMap("pictures/ground.tga");
+   	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;
   }
 }
 
 
-Material* BspFile::loadMat(char* mat)
+AMat BspFile::loadMat(char* mat)
 {
+  AMat tmpAMat;
+  this->testSurf = NULL;
+
+  this->testSurf = IMG_Load(ResourceManager::getFullName(mat).c_str());
+  if(this->testSurf != NULL)
+	{
+  if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true;
+  else 				       tmpAMat.alpha = false;
+	}
+  else   tmpAMat.alpha = false;
+
   Material* tmp = new Material();
  	tmp->setDiffuse(1.0,1.0,1.0);
@@ -477,11 +484,13 @@
    	tmp->setSpecular(1.0,1.0,1.0);
    //	tmp->setShininess(.5);
-   	tmp->setTransparency(1.0);
+   //	tmp->setTransparency(1.0);
 
    	tmp->setDiffuseMap(mat);
    	tmp->setAmbientMap(mat);
         tmp->setSpecularMap(mat);
-
-  return tmp;
+  
+  tmpAMat.mat = tmp;
+
+  return tmpAMat;
 }
 
Index: /branches/bsp_model/src/lib/graphics/importer/bsp_file.h
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/bsp_file.h	(revision 7384)
+++ /branches/bsp_model/src/lib/graphics/importer/bsp_file.h	(revision 7385)
@@ -1,17 +1,17 @@
 /*
-   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
+ 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
 */
 
-
+class SDL_Surface;
 class BspTreeNode;
 class Vector;
@@ -19,143 +19,163 @@
 class VertexArrayModel;
 
-typedef struct 
+typedef struct
 {
   float x;
   float y;
   float z;
-  float d;	
-} plane;
+  float d;
+}
+plane;
 
 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; //
-} model;
+  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; //
+}
+model;
 
 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.
-} node;
+  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.
+}
+node;
 
 typedef struct
 {
-   int cluster; // 	Visdata cluster index.
-   int area; // 	Areaportal area.
-   int mins[3]; // Integer bounding box min coord.
-   int maxs[3]; // Integer bounding box max coord.
-   int leafface; // First leafface for leaf.
-   int n_leaffaces; //Number of leaffaces for leaf.
-   int leafbrush_first; // leafbrush for leaf.
-   int n_leafbrushes; // Number of leafbrushes for leaf.
-} leaf;
+  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;
 
 typedef struct
 {
-    int brushside; 	//First brushside for brush.
-    int n_brushsides; 	//Number of brushsides for brush.
-    int texture; 	//Texture index.
-} brush;
+  int brushside; 	//First brushside for brush.
+  int n_brushsides; 	//Number of brushsides for brush.
+  int texture; 	//Texture index.
+}
+brush;
 
 typedef struct
 {
-    int plane; //Plane index.
-    int texture; 	//Texture index.
-} brushside;
+  int plane; //Plane index.
+  int texture; 	//Texture index.
+}
+brushside;
 
- struct face
+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.
-}BspVertex;
+  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.
+}
+BspVertex;
 
 typedef struct
 {
-   int offset;
-} meshvert;
+  int offset;
+}
+meshvert;
 
-typedef struct 
+typedef struct
 {
- float position [3];
-} BspVec;
+  float position [ 3 ];
+}
+BspVec;
 
-class  BspFile
+typedef struct
 {
- public:
- BspFile();
- int read(char* name);
- void build_tree();
- void load_textures();
- void tesselate(int iface);
- BspTreeNode* get_root();
- Material * loadMat(char* mat);
+  Material* mat;
+  bool alpha;
+}
+AMat;
 
- 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
- char*  leafFaces;  // Buffer to store leafFaces
- char*  faces; //
- char*  leafBrushes; // Buffer to store brush indice
- char*  brushes; // Buffer to store  brushes
- char*  brushSides; //
- char*  vertice; //
- char*  meshverts;
- char*  visData;
- char* textures;
+class BspFile
+{
+  friend class BspManager;
+
+public:
+  BspFile();
+  int read( char* name );
+  void build_tree();
+  void load_textures();
+  void tesselate( int iface );
+  BspTreeNode* get_root();
+  AMat loadMat( char* mat );
 
 
- char*  patchVertice;
- char*  patchIndexes;
- char*  patchTrianglesPerRow;
- int**  patchRowIndexes;
- VertexArrayModel** VertexArrayModels;
- int 	   patchOffset;
+private:
+  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
+  char* leafFaces;           //!< Buffer to store leafFaces
+  char* faces;               //!<
+  char* leafBrushes;         //!< Buffer to store brush indice
+  char* brushes;             //!< Buffer to store  brushes
+  char* brushSides;          //!<
+  char* vertice;             //!<
+  char* meshverts;           //!<
+  char* visData;             //!<
+  char* textures;            //!<
 
- int numNodes;
- int numLeafs;
- int numVertex;
- int numPlanes;
- int numBspModels;
- int numLeafFaces;
- int numFaces;
- int numLeafBrushes;
- int numTextures;
- int numPatches;
- int numBrushSides;
- 
- BspTreeNode*  build_tree_rec(int i);
- Material**           Materials;
 
- 
+  char* patchVertice;
+  char* patchIndexes;
+  char* patchTrianglesPerRow;
+  int** patchRowIndexes;
+  VertexArrayModel** VertexArrayModels;
+  int patchOffset;
+
+  int numNodes;
+  int numLeafs;
+  int numVertex;
+  int numPlanes;
+  int numBspModels;
+  int numLeafFaces;
+  int numFaces;
+  int numLeafBrushes;
+  int numTextures;
+  int numPatches;
+  int numBrushSides;
+
+  BspTreeNode* build_tree_rec( int i );
+  AMat* Materials;
+  SDL_Surface* testSurf;
+
 };
 
Index: /branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 7384)
+++ /branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 7385)
@@ -17,5 +17,5 @@
 #include "bsp_file.h"
 #include "bsp_manager.h"
-#include "bsp_tree_node.h"
+#include "bsp_tree_leaf.h"
 #include "p_node.h"
 #include "state.h"
@@ -23,10 +23,9 @@
 #include "material.h"
 #include "camera.h"
-
 #include "vertex_array_model.h"
 
-
-
-
+// STL Containers
+#include <vector>
+#include <deque>
 
 
@@ -37,5 +36,5 @@
 	// open a BSP file
 	this->bspFile = new BspFile();
-	this->bspFile->read("Kanti175.bsp");
+	this->bspFile->read("/root/data/Kanti175.bsp");
 	this->bspFile->build_tree();
 	this->root  = this->bspFile->get_root();
@@ -64,5 +63,7 @@
    // erase alreadyVisible
    for(int i = 0; i < this->bspFile->numFaces; i++) this->alreadyVisible[i] = false;
- float tmp = 0;
+ 	float tmp = 0;
+   this->opal.clear();
+   this->trasparent.clear();	
   // Find all visible faces...
 
@@ -110,5 +111,5 @@
 					this->alreadyVisible[i] = true;
 				}
-				else */draw_face(f); // "visibleFaces.append(f)"
+				else */addFace(f); // "visibleFaces.append(f)"
     			}
 		}
@@ -150,5 +151,5 @@
   			if (!this->isAlreadyVisible(f) && f>=0) 
 			{
-					this->draw_face(f);
+					this->addFace(f);
 		    			this->alreadyVisible[f] = true;
 			}
@@ -161,4 +162,15 @@
 
     }//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();
+}
 
 
@@ -190,5 +202,5 @@
 	if(this->lastTex != curFace.texture)
 	{
-  	this->bspFile->Materials[curFace.texture]->select();
+  	this->bspFile->Materials[curFace.texture].mat->select();
 	this->lastTex = curFace.texture;
 	}
@@ -239,5 +251,5 @@
    // if(this->bspFile->Materials[curFace.texture] != NULL)	
 
-  	this->bspFile->Materials[2]->select();
+  	this->bspFile->Materials[2].mat->select();
 	this->lastTex = 2;
 
@@ -266,5 +278,5 @@
 		if(this->lastTex != Face->texture)
 		{
-	  	this->bspFile->Materials[Face->texture]->select();
+	  	this->bspFile->Materials[Face->texture].mat->select();
 		this->lastTex = Face->texture;
 		}
@@ -331,15 +343,15 @@
 	{
 		dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d;
-		if(dist > 1.0f)
+		if(dist > 4.0f)
 		{
 		 checkCollision(node->left,cam);
 		 return;
 		}
-		if(dist < -1.0f)
+		if(dist < -4.0f)
 		{
 		 checkCollision(node->right,cam);
 		 return;
 		}
-		if(dist<=1.0f && dist >= -1.0f)
+		if(dist<=4.0f && dist >= -4.0f)
 			{
 			checkCollision(node->left,cam);
@@ -357,5 +369,5 @@
 
 	
-
+/*
 	for(int i = 0; i < camLeaf.n_leafbrushes && i < 10; i++ )
 	{
@@ -376,5 +388,5 @@
 		}
 			
-	}
+	} */
 	
 	}
@@ -454,6 +466,11 @@
    glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.0f);
 
-
-
-		glEnd();
-}
+	glEnd();
+}
+
+void BspManager::addFace(int f)
+{
+ face& curFace =  ((face *)(this->bspFile->faces))[f];
+ if(this->bspFile->Materials[curFace.texture].alpha) this->trasparent.push_back(f);
+ else this->opal.push_back(f);
+}
Index: /branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/bsp_manager.h	(revision 7384)
+++ /branches/bsp_model/src/lib/graphics/importer/bsp_manager.h	(revision 7385)
@@ -12,4 +12,7 @@
    main-programmer: bottac@ee.ethz.ch
 */
+
+#include <vector>
+#include <deque>
 
 
@@ -40,5 +43,5 @@
  BspFile*  bspFile;
  BspTreeNode* root;
- BspTreeNode* getLeaf(BspTreeNode*  node, Vector* cam);  // Traverses the tree 
+ const BspTreeNode* getLeaf(const BspTreeNode*  node, const Vector& cam) const;  // Traverses the tree 
  void  checkCollision(BspTreeNode* node, Vector* cam);
  void drawDebugCube(Vector* cam);
@@ -48,5 +51,12 @@
  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.
+
 };
 
