commit d44ac567afeb467cff849b6ed298793dc22a4c5f
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Mon Jul 25 23:27:25 2016 +0100

    Minor stuff - make the Bitmaps and the Cubes agree on the size of the grid, mostly.

diff --git a/src/main/java/org/distorted/library/DistortedBitmap.java b/src/main/java/org/distorted/library/DistortedBitmap.java
index eddbf9e..355f0aa 100644
--- a/src/main/java/org/distorted/library/DistortedBitmap.java
+++ b/src/main/java/org/distorted/library/DistortedBitmap.java
@@ -70,8 +70,8 @@ public class DistortedBitmap extends DistortedObject
  */
    public DistortedBitmap(int width, int height, int cols)
      {     
-     int xsize = cols;
-     int ysize = cols*height/width;
+     int xsize = (cols+1);
+     int ysize = (cols+1)*height/width;
      
      if( xsize<2   ) xsize=  2;
      if( xsize>256 ) xsize=256;
diff --git a/src/main/java/org/distorted/library/DistortedBitmapGrid.java b/src/main/java/org/distorted/library/DistortedBitmapGrid.java
index cc65166..6f39e58 100644
--- a/src/main/java/org/distorted/library/DistortedBitmapGrid.java
+++ b/src/main/java/org/distorted/library/DistortedBitmapGrid.java
@@ -31,15 +31,22 @@ class DistortedBitmapGrid extends DistortedObjectGrid
 
   DistortedBitmapGrid(int xLength, int yLength)
     {
+    float tmpx,tmpy,tmpz;
+    float[] bufferData;
+
     dataLength = 2*xLength*(yLength-1)+2*(yLength-2); // (yLength-1) strips, 2*xLength triangles in each, plus 2 degenerate triangles per each of (yLength-2) joins 
+
+    ////////////////////////////////////////////////////////////
+    // vertex indices
+
+    int offset=0;
     final short[] indexData = new short[dataLength];
-    
-    int offset=0;    
-    for(int y=0; y<yLength-1; y++) 
+
+    for(int y=0; y<yLength-1; y++)
       {
       if (y>0) indexData[offset++] = (short) (y*xLength); // Degenerate begin: repeat first vertex
 
-      for (int x = 0; x < xLength; x++) 
+      for (int x = 0; x < xLength; x++)
         {
         indexData[offset++] = (short) (( y   *xLength)+x);
         indexData[offset++] = (short) (((y+1)*xLength)+x);
@@ -48,24 +55,14 @@ class DistortedBitmapGrid extends DistortedObjectGrid
       if (y<yLength-2) indexData[offset++] = (short) (((y+1)*xLength) + (xLength-1)); // Degenerate end: repeat last vertex
       }
 
-    // for(int g=0; g<dataLength; g++) Log.e(TAG_BACKGROUND, "index["+g+"]="+indexData[g]);
+    // for(int g=0; g<dataLength; g++) Log.e("grid", "index["+g+"]="+indexData[g]);
 
-    float[] bufferData = new float[NORMAL_DATA_SIZE*dataLength];
+    ////////////////////////////////////////////////////////////
+    // texture
 
     offset=0;
-    for(int i=0; i<dataLength; i++)
-      {
-      bufferData[offset++] = 0.0f; // x
-      bufferData[offset++] = 0.0f; // y
-      bufferData[offset++] = 1.0f; // z
-      }
-    mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
-    mGridNormals.put(bufferData).position(0); 
-
-    float tmpx,tmpy,tmpz;
     bufferData = new float[TEX_DATA_SIZE*dataLength];
 
-    offset=0;
     for(int i=0; i<dataLength; i++)
       {
       tmpx = ((float)(indexData[offset/2]%xLength))/(xLength-1);
@@ -74,11 +71,14 @@ class DistortedBitmapGrid extends DistortedObjectGrid
       bufferData[offset++] = tmpx; // s=x
       bufferData[offset++] = tmpy; // t=y
       }
-    mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
-    mGridTexture.put(bufferData).position(0); 
+    mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
+    mGridTexture.put(bufferData).position(0);
 
-    //for(int g=0; g<dataLength; g++) Log.e(TAG_BACKGROUND, "tex["+g+"]=("+bufferData[2*g]+","+bufferData[2*g+1]+")");
-    //Log.e(TAG, "regWidth="+(2*mRegW)+" regHeight="+(2*mRegH)+" xLength="+xLength+" yLength="+yLength);
+    //for(int g=0; g<dataLength; g++) Log.e("grid", "tex["+g+"]=("+bufferData[2*g]+","+bufferData[2*g+1]+")");
+    //Log.e("grid", "regWidth="+(2*mRegW)+" regHeight="+(2*mRegH)+" xLength="+xLength+" yLength="+yLength);
+
+    ////////////////////////////////////////////////////////////
+    // vertex positions
 
     offset=0;
     bufferData= new float[POSITION_DATA_SIZE*dataLength];
@@ -93,9 +93,24 @@ class DistortedBitmapGrid extends DistortedObjectGrid
       bufferData[offset++] = (0.5f-tmpy); // y
       bufferData[offset++] =        tmpz; // z
       }
-    mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
-    mGridPositions.put(bufferData).position(0); 
+    mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
+    mGridPositions.put(bufferData).position(0);
+
+    //for(int g=0; g<dataLength; g++) android.util.Log.e("grid", "pos["+g+"]=("+bufferData[3*g]+","+bufferData[3*g+1]+")");
+ 
+    ////////////////////////////////////////////////////////////
+    // normals
 
-    //for(int g=0; g<dataLength; g++) android.util.Log.e("BACKGROUND", "pos["+g+"]=("+bufferData[3*g]+","+bufferData[3*g+1]+")");
+    offset=0;
+    bufferData = new float[NORMAL_DATA_SIZE*dataLength];
+
+    for(int i=0; i<dataLength; i++)
+      {
+      bufferData[offset++] = 0.0f; // x
+      bufferData[offset++] = 0.0f; // y
+      bufferData[offset++] = 1.0f; // z
+      }
+    mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();                                                        
+    mGridNormals.put(bufferData).position(0);
     }
   }
\ No newline at end of file
