commit 15873844a8de29fc2ed91a132fee61b024d93968
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Wed Aug 3 00:21:34 2016 +0100

    Simplify and spped up the DistortedCubes target.

diff --git a/src/main/java/org/distorted/library/DistortedCubesGrid.java b/src/main/java/org/distorted/library/DistortedCubesGrid.java
index 087d9fc..6af646a 100644
--- a/src/main/java/org/distorted/library/DistortedCubesGrid.java
+++ b/src/main/java/org/distorted/library/DistortedCubesGrid.java
@@ -413,63 +413,43 @@ class DistortedCubesGrid extends DistortedObjectGrid
    
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   private int addFrontVertex(int corner, int vertex, float centerX, float centerY, float vectZ, int col, int row, float[] position, float[] normal, float[] texture)
+   private int addFrontVertex(int corner, int vertex, float vectZ, int col, int row, float[] position, float[] normal, float[] texture)
      {
      remainingVert--;
-     /*
+
+     float x=0,y=0;
+     int index=0;
+
      switch(corner)
        {
-       case NW: android.util.Log.e("CUBES", "adding NW vertex!");
+       case NW: x = (float)col/mCols;
+                y = (float)row/mRows;
+                index = 0;
                 break;
-       case SW: android.util.Log.e("CUBES", "adding SW vertex!");
+       case SW: x = (float)col/mCols;
+                y = (float)(row+1)/mRows;
+                index = 1;
                 break;
-       case SE: android.util.Log.e("CUBES", "adding SE vertex!");
+       case NE: x = (float)(col+1)/mCols;
+                y = (float)row/mRows;
+                index = 2;
                 break;
-       case NE: android.util.Log.e("CUBES", "adding NE vertex!");
+       case SE: x = (float)(col+1)/mCols;
+                y = (float)(row+1)/mRows;
+                index = 3;
                 break;
        }
-     */
-     switch(corner)
-       {
-       case NW: position[3*vertex  ] = (centerX-0.5f)/mCols;
-                position[3*vertex+1] = (centerY+0.5f)/mRows;
-                position[3*vertex+2] = vectZ;
-                normal[3*vertex  ]   = mNormalX[0];
-                normal[3*vertex+1]   = mNormalY[0];
-                normal[3*vertex+2]   = mNormalZ[0];
-                texture[2*vertex  ]  = (float)col/mCols;
-                texture[2*vertex+1]  = (float)row/mRows;
-                return vertex+1;
-       case SW: position[3*vertex  ] = (centerX-0.5f)/mCols;
-                position[3*vertex+1] = (centerY-0.5f)/mRows;
-                position[3*vertex+2] = vectZ;
-                normal[3*vertex  ]   = mNormalX[1];
-                normal[3*vertex+1]   = mNormalY[1];
-                normal[3*vertex+2]   = mNormalZ[1];
-                texture[2*vertex  ]  = (float)col/mCols;
-                texture[2*vertex+1]  = (float)(row+1)/mRows;
-                return vertex+1;
-       case NE: position[3*vertex  ] = (centerX+0.5f)/mCols;
-                position[3*vertex+1] = (centerY+0.5f)/mRows;
-                position[3*vertex+2] = vectZ;
-                normal[3*vertex  ]   = mNormalX[2];
-                normal[3*vertex+1]   = mNormalY[2];
-                normal[3*vertex+2]   = mNormalZ[2];
-                texture[2*vertex  ]  = (float)(col+1)/mCols;
-                texture[2*vertex+1]  = (float)row/mRows;
-                return vertex+1;
-       case SE: position[3*vertex  ] = (centerX+0.5f)/mCols;
-                position[3*vertex+1] = (centerY-0.5f)/mRows;
-                position[3*vertex+2] = vectZ;
-                normal[3*vertex  ]   = mNormalX[3];
-                normal[3*vertex+1]   = mNormalY[3];
-                normal[3*vertex+2]   = mNormalZ[3];
-                texture[2*vertex  ]  = (float)(col+1)/mCols;
-                texture[2*vertex+1]  = (float)(row+1)/mRows;
-                return vertex+1;
-       }
 
-     return vertex;
+     position[3*vertex  ] = x-0.5f;
+     position[3*vertex+1] = 0.5f-y;
+     position[3*vertex+2] = vectZ;
+     normal[3*vertex  ]   = mNormalX[index];
+     normal[3*vertex+1]   = mNormalY[index];
+     normal[3*vertex+2]   = mNormalZ[index];
+     texture[2*vertex  ]  = x;
+     texture[2*vertex+1]  = y;
+
+     return vertex+1;
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -480,7 +460,6 @@ class DistortedCubesGrid extends DistortedObjectGrid
      boolean seenLand=false;
      boolean lastBlockIsNE = false;
      boolean currentBlockIsNE;
-     float centerX, centerY;
      float vectZ = front?FRONTZ:BACKZ;
 
      //android.util.Log.d("CUBES", "buildFrontBack");
@@ -496,8 +475,6 @@ class DistortedCubesGrid extends DistortedObjectGrid
          if( current%2 == 1 )
            {
            currentBlockIsNE = isNE(i,j);
-           centerX = j-(mCols-1.0f)/2.0f;
-           centerY = (mRows-1.0f)/2.0f-i;
 
            if( !seenLand && !front && ((vertex%2==1)^currentBlockIsNE) )
              {
@@ -511,14 +488,14 @@ class DistortedCubesGrid extends DistortedObjectGrid
            if( (last!=current) || (lastBlockIsNE^currentBlockIsNE) )
              {
              if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
-             vertex= addFrontVertex( currentBlockIsNE ? NW:SW, vertex, centerX, centerY, vectZ, j, i, position, normal, texture);
+             vertex= addFrontVertex( currentBlockIsNE ? NW:SW, vertex, vectZ, j, i, position, normal, texture);
              if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
              if( (lastBlockIsNE^currentBlockIsNE)
                  || (!front && !seenLand)       ) vertex = repeatLast(vertex,position,normal,texture);
-             vertex= addFrontVertex( currentBlockIsNE ? SW:NW, vertex, centerX, centerY, vectZ, j, i, position, normal, texture);
+             vertex= addFrontVertex( currentBlockIsNE ? SW:NW, vertex, vectZ, j, i, position, normal, texture);
              }
-           vertex= addFrontVertex( currentBlockIsNE ? NE:SE, vertex, centerX, centerY, vectZ, j, i, position, normal, texture);
-           vertex= addFrontVertex( currentBlockIsNE ? SE:NE, vertex, centerX, centerY, vectZ, j, i, position, normal, texture);
+           vertex= addFrontVertex( currentBlockIsNE ? NE:SE, vertex, vectZ, j, i, position, normal, texture);
+           vertex= addFrontVertex( currentBlockIsNE ? SE:NE, vertex, vectZ, j, i, position, normal, texture);
 
            seenLand = true;
            lastBlockIsNE = currentBlockIsNE;
