commit 67038ddae6c0ce328d5bf9265147a8a2214d9559
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Mar 3 10:03:42 2020 +0000

    Correct the Rubik app for the recent changes to the library's Node.

diff --git a/src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java b/src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
index b1d982b..b1965a6 100644
--- a/src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
+++ b/src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
@@ -51,6 +51,7 @@ class MonaLisaRenderer implements GLSurfaceView.Renderer
     private MeshRectangles mMesh;
     private DistortedScreen mScreen;
     private Static3D mScale;
+    private float mBmpRatio;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -59,13 +60,13 @@ class MonaLisaRenderer implements GLSurfaceView.Renderer
       mView = v;
 
       // MonaLisa bitmap is 320x366, this is thus (90,108) pixels from the lower-left corner
-      Static3D centerLeft  = new Static3D( 90-320/2, 108-366/2,0);
+      Static3D centerLeft  = new Static3D( ( 90-320*0.5f)/320.0f, (108-366*0.5f)/366.0f, 0);
       // (176,111) from the lower left
-      Static3D centerRight = new Static3D(176-320/2, 111-366/2,0);
+      Static3D centerRight = new Static3D( (176-320*0.5f)/320.0f, (111-366*0.5f)/366.0f, 0);
 
       // two regions defining the areas affected by the Distort effect
-      Static4D rLeft  = new Static4D(-10, 10, 0, 25);
-      Static4D rRight = new Static4D( 10,  5, 0, 25);
+      Static4D rLeft  = new Static4D( -10/320.0f, 10/366.0f, 0, 25/320.0f);
+      Static4D rRight = new Static4D(  10/320.0f,  5/366.0f, 0, 25/320.0f);
 
       // two dynamics for interpolating through vectors of distortion. Interpolate
       // every 1000 miliseconds, indefinately ('0.0f').
@@ -73,19 +74,23 @@ class MonaLisaRenderer implements GLSurfaceView.Renderer
       Dynamic3D dRight= new Dynamic3D(1000,0.0f);
 
       // two vectors of distortion the left tip of the mouth gets distorted with -
-      // interpolated from (0,0,0) - i.e. no distortion - to (-20,20,0), i.e.
+      // interpolated from (0,0,0) - i.e. no distortion - to (-20 pixels, 20 pixels, 0), i.e.
       // slightly to the top left.
-      dLeft.add ( new Static3D(  0,  0, 0) );
-      dLeft.add ( new Static3D(-20, 20, 0) );
+      dLeft.add ( new Static3D(         0,         0, 0) );
+      dLeft.add ( new Static3D(-20/320.0f, 20/366.0f, 0) );
 
       // likewise two vectors the right tip is distorted with.
-      dRight.add( new Static3D(  0,  0, 0) );
-      dRight.add( new Static3D( 20, 10, 0) );
+      dRight.add( new Static3D(         0,         0, 0) );
+      dRight.add( new Static3D( 20/320.0f, 10/366.0f, 0) );
 
+      // Equip MonaLisa with the Effects we want to draw her with - i.e. two Distorts of the mouth
       mEffects = new DistortedEffects();
       mEffects.apply( new VertexEffectDistort(dLeft , centerLeft , rLeft ) );
       mEffects.apply( new VertexEffectDistort(dRight, centerRight, rRight) );
 
+      // ... and a Scale - so far by (1,1,1), i.e. no scale. The mScale point will be computed
+      // later, in onSurfaceChanged, when we actually know the size of the screen and know how
+      // much to scale the initial Mesh (which is 1x1x0 in size)
       mScale= new Static3D(1,1,1);
       mEffects.apply(new MatrixEffectScale(mScale));
 
@@ -103,11 +108,9 @@ class MonaLisaRenderer implements GLSurfaceView.Renderer
     
     public void onSurfaceChanged(GL10 glUnused, int width, int height) 
       {
-      float horiRatio = (float)width / mMesh.getStretchX();
-      float vertRatio = (float)height/ mMesh.getStretchY();
-      float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
+      float min= width>height ? height : width;
 
-      mScale.set( factor,factor,factor );
+      mScale.set( min, min*mBmpRatio, 1 );
       mScreen.resize(width, height);
       }
 
@@ -131,28 +134,19 @@ class MonaLisaRenderer implements GLSurfaceView.Renderer
         catch(IOException e) { }
         }  
 
-      int bmpHeight = bitmap.getHeight();
-      int bmpWidth  = bitmap.getWidth();
+      mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
 
       // We could have gotten here after the activity went to the background
       // for a brief amount of time; in this case mTexture is already created.
-      // Do not leak memory by creating it the second time around.
+      // Do not create it the second time around then.
       if( mTexture==null ) mTexture = new DistortedTexture();
 
       // likewise the Mesh
-      // This will make the Mesh stretched by bmpWidth x bmpHeight even before any effects
-      // are applied to it (the Mesh - MeshRectangles - is flat, so the third parameter does not
-      // not matter). bmpWight x bmpHeight is the size of the Bitmap, thus this means that we can
-      // conveniently work with Effects thinking in Bitmap's native size in pixels. The origin is
-      // in Bitmap's lower-left corner, thus e.g. a rotation which is meant to rotate the bitmap
-      // around its center has to be centered at (bmpWidth/2, bmpHeight/2, 0).
-      // Without this call, the default size of the Mesh is 1x1x0 ( or 1x1x1 in case of not-flat
-      // Meshes) so we would need to be rotating around (0.5,0.5,0.0).
-      if( mMesh==null )
-        {
-        mMesh = new MeshRectangles(9,9*bmpHeight/bmpWidth);
-        mMesh.setStretch(bmpWidth,bmpHeight,0);
-        }
+      // Create an underlying Mesh of 9x10 vertices - this is for the Distort
+      // effect to have vertices to distort. We multiply by mBmpRatio here so
+      // that the Mesh's cells are as close to squares as possible (when they
+      // finally be rendered with a Scale - see mScale)
+      if( mMesh==null ) mMesh = new MeshRectangles(9, (int)(9*mBmpRatio) );
 
       // even if mTexture wasn't null, we still need to call setTexture() on it
       // because every time activity goes to background, its OpenGL resources
@@ -160,10 +154,12 @@ class MonaLisaRenderer implements GLSurfaceView.Renderer
       // to recreate the internal OpenGL textures.
       mTexture.setTexture(bitmap);
 
+      // Build the Scene Graph - attach all Objects we want to be rendered to the Screen.
       mScreen.detachAll();
       mScreen.attach(mTexture,mEffects,mMesh);
 
-      // All effects are by default disabled!
+      // All effects are by default disabled! Enable all we need (and better only those)
+      // before the call to DistortedLibrary.onCreate(). Best done here.
       VertexEffectDistort.enable();
 
       try
