Index: trunk/src/lib/graphics/importer/bsp/bsp_manager.cc
===================================================================
--- trunk/src/lib/graphics/importer/bsp/bsp_manager.cc	(revision 10337)
+++ trunk/src/lib/graphics/importer/bsp/bsp_manager.cc	(revision 10519)
@@ -21,4 +21,5 @@
 
 
+#include "limits.h"
 #include "vector.h"
 #include "bsp_file.h"
@@ -300,50 +301,133 @@
 
   // now sort the transparent faces in the right order
-  int size = this->trasparent.size();
-
-  // bubble sort
-  bool hasSwapped = true;
-  Vector v1, v2;
-
-  while( hasSwapped)
-  {
-    hasSwapped = false;
-
-    for( int i = 0; i < size - 1; i++)
-    {
-      // sorting test
-      face& fac1 =  (this->bspFile->faces)[this->trasparent[i]];
-      face& fac2 =  (this->bspFile->faces)[this->trasparent[i+1]];
-
-      // get center of face 1
-      const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
-
-      // assign the values of the vertices
-      v1(curVertex[fac1.vertex].position[0], curVertex[fac1.vertex].position[1], curVertex[fac1.vertex].position[2]);
-      v2(curVertex[fac2.vertex].position[0], curVertex[fac2.vertex].position[1], curVertex[fac2.vertex].position[2]);
-      // relativly to observer
-      v1 = this->cam - v1;
-      v2 = this->cam - v2;
-
-
-
-      // swap if necessary
-      if( v1.len() - v2.len() > 1)
+  if (this->sortTransparency == 1) {
+      int size = this->trasparent.size();
+      
+      // bubble sort
+      bool hasSwapped = true;
+      Vector v1, v2;
+
+      // initialize distance array
+      float * distToPlayer = new float [size];
+      for (int i = 0; i < size; i++)
       {
-        // swap elements
-        int tmp = this->trasparent[i+1];
-        this->trasparent[i+1] = this->trasparent[i];
-        this->trasparent[i] = tmp;
-
-        //printf( "has swapped: %d\n", i );
-
-        //v1.debug();
-        //v2.debug();
-        hasSwapped = true;
+          face& fac1 =  (this->bspFile->faces)[this->trasparent[i]];
+//          face& fac2 =  (this->bspFile->faces)[this->trasparent[i+1]];
+
+          // get center of face 1
+          const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
+
+          if (this->sortTransparencyMore == 1)
+          {
+              // assign the values of the vertices
+              float maxDist = 0;
+              float curDist = 0;
+              int maxVert = fac1.vertex;
+              for (int v = 0; v < fac1.n_vertexes; v++)
+              {
+                    v1(curVertex[fac1.vertex + v].position[0], curVertex[fac1.vertex + v].position[1], curVertex[fac1.vertex + v].position[2]);
+                    curDist = (this->cam - v1).len();
+                    if (curDist > maxDist)
+                    {
+                        maxDist = curDist;
+                        maxVert = fac1.vertex + v;
+                    }
+              }
+              v1(curVertex[maxVert].position[0], curVertex[maxVert].position[1], curVertex[maxVert].position[2]);
+          }
+          else
+          {
+              v1(curVertex[fac1.vertex].position[0], curVertex[fac1.vertex].position[1], curVertex[fac1.vertex].position[2]);
+          }
+
+          // relativly to observer
+          v1 = this->cam - v1;
+
+          // save in array
+          distToPlayer[i] = v1.len();
       }
-    }
-  }
-  //printf("hasSwapped == false\n");
-
+
+      while( hasSwapped)
+      {
+        hasSwapped = false;
+
+        for( int i = 0; i < size - 1; i++)
+        {
+/*
+          // sorting test
+          face& fac1 =  (this->bspFile->faces)[this->trasparent[i]];
+          face& fac2 =  (this->bspFile->faces)[this->trasparent[i+1]];
+
+          // get center of face 1
+          const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
+          
+          if (this->sortTransparencyMore == 1)
+          {
+              // assign the values of the vertices
+              float maxDist = 0;
+              float curDist = 0;
+              int maxVert = fac1.vertex;
+              for (int v = 0; v < fac1.n_vertexes; v++)
+              {
+                    v1(curVertex[fac1.vertex + v].position[0], curVertex[fac1.vertex + v].position[1], curVertex[fac1.vertex + v].position[2]);
+                    curDist = (this->cam - v1).len();
+                    if (curDist > maxDist)
+                    {
+                        maxDist = curDist;
+                        maxVert = fac1.vertex + v;
+                    }
+              }
+              v1(curVertex[maxVert].position[0], curVertex[maxVert].position[1], curVertex[maxVert].position[2]);
+
+              maxDist = 0;
+              curDist = 0;
+              maxVert = fac1.vertex;
+              for (int v = 0; v < fac2.n_vertexes; v++)
+              {
+                    v2(curVertex[fac2.vertex + v].position[0], curVertex[fac2.vertex + v].position[1], curVertex[fac2.vertex + v].position[2]);
+                    curDist = (this->cam - v2).len();
+                    if (curDist > maxDist)
+                    {
+                        maxDist = curDist;
+                        maxVert = fac2.vertex + v;
+                    }
+              }
+              v2(curVertex[maxVert].position[0], curVertex[maxVert].position[1], curVertex[maxVert].position[2]);
+          }
+          else
+          {
+              v1(curVertex[fac1.vertex].position[0], curVertex[fac1.vertex].position[1], curVertex[fac1.vertex].position[2]);
+              v2(curVertex[fac2.vertex].position[0], curVertex[fac2.vertex].position[1], curVertex[fac2.vertex].position[2]);
+          }
+
+          // relativly to observer
+          v1 = this->cam - v1;
+          v2 = this->cam - v2;
+
+
+*/
+          // swap if necessary
+//          if( v1.len() - v2.len() > 1)
+          if( distToPlayer[i] - distToPlayer[i+1] > 1)
+          {
+            // swap elements
+            float tmp1 = distToPlayer[i+1];
+            distToPlayer[i+1] = distToPlayer[i];
+            distToPlayer[i] = tmp1;
+            
+            int tmp2 = this->trasparent[i+1];
+            this->trasparent[i+1] = this->trasparent[i];
+            this->trasparent[i] = tmp2;
+
+            //printf( "has swapped: %d\n", i );
+
+            //v1.debug();
+            //v2.debug();
+            hasSwapped = true;
+          }
+        }
+      }
+      //printf("hasSwapped == false\n");
+  }
 
 
