commit e8b2f3119e4393c679ded9b79e61d6d47b4e30d1
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Wed Jan 18 21:15:25 2017 +0000

    boundingVertices fully work now!

diff --git a/src/main/java/org/distorted/library/DistortedEffects.java b/src/main/java/org/distorted/library/DistortedEffects.java
index 9da288b..073f34f 100644
--- a/src/main/java/org/distorted/library/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/DistortedEffects.java
@@ -86,8 +86,6 @@ public class DistortedEffects
 
   private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
 
-private int mL, mR, mT, mB;
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   static void createProgram(Resources resources)
@@ -184,6 +182,7 @@ private int mL, mR, mT, mB;
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // DEBUG ONLY
 
+  @SuppressWarnings("unused")
   private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedFramebuffer df, float[] mvp, float[] vertices)
     {
     int len  = vertices.length/3;
@@ -193,8 +192,6 @@ private int mL, mR, mT, mB;
     int maxy = Integer.MIN_VALUE;
     int wx,wy;
 
-int l=-1,r=-1,t=-1,b=-1;
-
     float x,y,z, X,Y,W, ndcX,ndcY;
 
     for(int i=0; i<len; i++)
@@ -213,10 +210,10 @@ int l=-1,r=-1,t=-1,b=-1;
       wx = (int)(df.mWidth *(ndcX+1)/2);
       wy = (int)(df.mHeight*(ndcY+1)/2);
 
-      if( wx<minx ) { minx = wx; l = i; }
-      if( wx>maxx ) { maxx = wx; r = i; }
-      if( wy<miny ) { miny = wy; t = i; }
-      if( wy>maxy ) { maxy = wy; b = i; }
+      if( wx<minx ) minx = wx;
+      if( wx>maxx ) maxx = wx;
+      if( wy<miny ) miny = wy;
+      if( wy>maxy ) maxy = wy;
       }
 
     mDebugProgram.useProgram();
@@ -236,12 +233,6 @@ int l=-1,r=-1,t=-1,b=-1;
 
     GLES20.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES20.GL_FLOAT, false, 0, mQuadPositions);
     GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
-
-    if( l!=mL )
-      {
-      mL = l;
-      android.util.Log.e("effects", "l="+l+" ("+vertices[3*l]+","+vertices[3*l+1]+","+vertices[3*l+2]+")");
-      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -300,7 +291,7 @@ int l=-1,r=-1,t=-1,b=-1;
       }
 
     /// DEBUG ONLY //////
-    displayBoundingRect(halfInputH, halfInputW, halfZ, df, mM.getMVP(), mesh.getBoundingVertices() );
+    // displayBoundingRect(halfInputH, halfInputW, halfZ, df, mM.getMVP(), mesh.getBoundingVertices() );
     /// END DEBUG ///////
     }
 
diff --git a/src/main/java/org/distorted/library/MeshCubes.java b/src/main/java/org/distorted/library/MeshCubes.java
index a89927c..1814059 100644
--- a/src/main/java/org/distorted/library/MeshCubes.java
+++ b/src/main/java/org/distorted/library/MeshCubes.java
@@ -292,7 +292,7 @@ public class MeshCubes extends MeshObject
   private int addLeftmost(float[] temp, int row, int index)
     {
     float x2 = retLeftmost(row)/mCols - 0.5f;
-    float y2 = (float)row      /mRows - 0.5f;
+    float y2 = 0.5f - (float)row/mRows;
 
     if( index>1 )
       {
@@ -301,7 +301,7 @@ public class MeshCubes extends MeshObject
       float x1 = temp[2*index-2];
       float y1 = temp[2*index-1];
 
-      while( (x0-x2)*(y0-y1) <= (x0-x1)*(y0-y2) )
+      while( (x0-x2)*(y0-y1) >= (x0-x1)*(y0-y2) )
         {
         if( --index>1 )
           {
@@ -324,7 +324,7 @@ public class MeshCubes extends MeshObject
   private int addRightmost(float[] temp, int row, int index)
     {
     float x2 = retRightmost(row)/mCols - 0.5f;
-    float y2 = (float)row       /mRows - 0.5f;
+    float y2 = 0.5f - (float)row/mRows;
 
     if( index>1 )
       {
@@ -333,7 +333,7 @@ public class MeshCubes extends MeshObject
       float x1 = temp[2*index-2];
       float y1 = temp[2*index-1];
 
-      while( (x0-x2)*(y0-y1) >= (x0-x1)*(y0-y2) )
+      while( (x0-x2)*(y0-y1) <= (x0-x1)*(y0-y2) )
         {
         if( --index>1 )
           {
