commit 15ed35e644e0a3491e615418a788595f11b74535
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Dec 10 22:33:33 2018 +0000

    MeshCubes: Correct texturing of side walls. Everything should be correct now.

diff --git a/src/main/java/org/distorted/library/mesh/MeshCubes.java b/src/main/java/org/distorted/library/mesh/MeshCubes.java
index 98ad025..130980f 100644
--- a/src/main/java/org/distorted/library/mesh/MeshCubes.java
+++ b/src/main/java/org/distorted/library/mesh/MeshCubes.java
@@ -674,25 +674,12 @@ public class MeshCubes extends MeshBase
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// TODO
-// Texturing of side walls still not quite right. Example:
-
-// 5x5x4 :
-//
-// 1 1 1 1 1
-// 1 0 0 0 1
-// 1 0 0 0 1
-// 1 0 0 0 1
-// 1 1 1 1 1
-//
-// - then the right and bottom internal walls don't look right.
 
   private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs)
      {
      //android.util.Log.e("CUBES", "adding Side vertex!");
      float x, y, z;
-     int row, col;
-     float tmp1, tmp2;
+     int row, col, texX, texY;
 
      switch(curr.side)
        {
@@ -714,28 +701,12 @@ public class MeshCubes extends MeshBase
                    attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
                    attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
 
-                   /////////////////////////////////////////////////////////////////
-                   // clever stuff so that the sides of the mesh are textured nicely
-                   tmp1 = (float)(row-slice)/mRows;
-                   tmp2 = tmp1+1.0f;
-
-                   if( tmp2 != (int)tmp2 )
-                     {
-                     if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f;
-                     else            tmp2 = tmp2 - (int)tmp2;
-
-                     if( ((int)tmp1)%2 != 0 ) tmp2 = 1.0f-tmp2;
-                     }
-                   else
-                     {
-                     tmp2 = ((int)tmp2)%2;
-                     if( tmp2<0.0f ) tmp2= -tmp2;
-                     }
-                   /////////////////////////////////////////////////////////////////
-                   // end clever stuff
+                   texY = (mRows-row+slice)%(2*mRows);
+                   if( texY>mRows ) texY = 2*mRows-texY;
 
                    attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
-                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = tmp2;
+                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = (float)texY/mRows;
+
                    break;
        case SOUTH: row = curr.row+1;
                    col = (back ? (curr.col+1):(curr.col));
@@ -755,28 +726,12 @@ public class MeshCubes extends MeshBase
                    attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
                    attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
 
-                   /////////////////////////////////////////////////////////////////
-                   // clever stuff so that the sides of the mesh are textured nicely
-                   tmp1 = (float)(row+slice)/mRows;
-                   tmp2 = tmp1-1.0f;
-
-                   if( tmp2 != (int)tmp2 )
-                     {
-                     if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f;
-                     else            tmp2 = tmp2 - (int)tmp2;
-
-                     if( ((int)tmp1)%2 == 0 ) tmp2 = 1.0f-tmp2;
-                     }
-                   else
-                     {
-                     tmp2 = ((int)tmp2)%2;
-                     if( tmp2<0.0f ) tmp2= -tmp2;
-                     }
-                   /////////////////////////////////////////////////////////////////
-                   // end clever stuff
+                   texY = (mRows-row+slice)%(2*mRows);
+                   if( texY>mRows ) texY = 2*mRows-texY;
 
                    attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
-                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = tmp2;
+                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = (float)texY/mRows;
+
                    break;
        case WEST : row = (back  ? (curr.row+1):(curr.row));
                    col = curr.col;
@@ -796,28 +751,12 @@ public class MeshCubes extends MeshBase
                    attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
                    attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
 
-                   /////////////////////////////////////////////////////////////////
-                   // clever stuff so that the sides of the mesh are textured nicely
-                   tmp1 = (float)(col-slice)/mCols;
-                   tmp2 = tmp1+1.0f;
+                   texX = (col+slice)%(2*mCols);
+                   if( texX>mCols ) texX = 2*mCols-texX;
 
-                   if( tmp2 != (int)tmp2 )
-                     {
-                     if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f;
-                     else            tmp2 = tmp2 - (int)tmp2;
+                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)texX/mCols;
+                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-y;
 
-                     if( ((int)tmp1)%2 != 0 ) tmp2 = 1.0f-tmp2;
-                     }
-                   else
-                     {
-                     tmp2 = ((int)tmp2)%2;
-                     if( tmp2<0.0f ) tmp2= -tmp2;
-                     }
-                   /////////////////////////////////////////////////////////////////
-                   // end clever stuff
-
-                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = tmp2;
-                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
                    break;
        case EAST : row = (back  ? (curr.row):(curr.row+1));
                    col = (curr.col+1);
@@ -837,28 +776,12 @@ public class MeshCubes extends MeshBase
                    attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
                    attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
 
-                   /////////////////////////////////////////////////////////////////
-                   // clever stuff so that the sides of the mesh are textured nicely
-                   tmp1 = (float)(col+slice)/mCols;
-                   tmp2 = tmp1-1.0f;
+                   texX = (col+slice)%(2*mCols);
+                   if( texX>mCols ) texX = 2*mCols-texX;
 
-                   if( tmp2 != (int)tmp2 )
-                     {
-                     if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f;
-                     else            tmp2 = tmp2 - (int)tmp2;
+                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)texX/mCols;
+                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-y;
 
-                     if( ((int)tmp1)%2 == 0 ) tmp2 = 1.0f-tmp2;
-                     }
-                   else
-                     {
-                     tmp2 = ((int)tmp2)%2;
-                     if( tmp2<0.0f ) tmp2= -tmp2;
-                     }
-                   /////////////////////////////////////////////////////////////////
-                   // end clever stuff
-
-                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = tmp2;
-                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
                    break;
        }
 
