commit 4c42bc15070b8098a444f20c32f59b87fbba2c2d
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Mar 3 11:58:37 2020 +0000

    Some cleanups in MonaLisa, Bean & Sink.

diff --git a/src/main/java/org/distorted/examples/bean/BeanRenderer.java b/src/main/java/org/distorted/examples/bean/BeanRenderer.java
index 22ecbbb..1fc309d 100644
--- a/src/main/java/org/distorted/examples/bean/BeanRenderer.java
+++ b/src/main/java/org/distorted/examples/bean/BeanRenderer.java
@@ -93,7 +93,8 @@ class BeanRenderer implements GLSurfaceView.Renderer
       mEffects.apply( new VertexEffectDistort(dynRight, pointRight, regionRight));
       mEffects.apply( new MatrixEffectScale(mScale) );
 
-      mScreen = new DistortedScreen();
+      mTexture = new DistortedTexture();
+      mScreen  = new DistortedScreen();
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -134,8 +135,6 @@ class BeanRenderer implements GLSurfaceView.Renderer
        }
       
      mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
-
-     if( mTexture==null ) mTexture = new DistortedTexture();
      mTexture.setTexture(bitmap);
 
      // we need a denser Mesh lattice this time for the Distorts to look good.
diff --git a/src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java b/src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
index 18722e1..437cddb 100644
--- a/src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
+++ b/src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
@@ -59,42 +59,48 @@ class MonaLisaRenderer implements GLSurfaceView.Renderer
       {
       mView = v;
 
+      // Centers of the Effects.
+      // center = (0,0,0) would be the midpoint of the Bitmap.
       // MonaLisa bitmap is 320x366, this is thus (90,108) pixels from the lower-left corner
       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*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/320.0f, 10/366.0f, 0, 25/320.0f);
-      Static4D rRight = new Static4D(  10/320.0f,  5/366.0f, 0, 25/320.0f);
+      // two Regions defining the areas affected by the Distort effect
+      // a Region is like a mask that specifies which area around the Center is affected by
+      // the Distort. Here (-10,10,0) pixels from the left center, with radius 25 pixels
+      Static4D regionLeft  = new Static4D( -10/320.0f, 10/366.0f, 0, 25/320.0f);
+      // and likewise (10,5,0) pixels from the right Center, radius 25 pixels.
+      Static4D regionRight = new Static4D(  10/320.0f,  5/366.0f, 0, 25/320.0f);
 
       // two dynamics for interpolating through vectors of distortion. Interpolate
       // every 1000 milliseconds, indefinitely ('0.0f').
-      Dynamic3D dLeft = new Dynamic3D(1000,0.0f);
-      Dynamic3D dRight= new Dynamic3D(1000,0.0f);
+      Dynamic3D degLeft = new Dynamic3D(1000,0.0f);
+      Dynamic3D degRight= 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 pixels, 20 pixels, 0), i.e.
-      // slightly to the top left.
-      dLeft.add ( new Static3D(         0,         0, 0) );
-      dLeft.add ( new Static3D(-20/320.0f, 20/366.0f, 0) );
+      // interpolated from (0,0,0) - i.e. no distortion - to (-20 pixels, 20 pixels, 0),
+      // i.e. slightly to the top left.
+      degLeft.add ( new Static3D(         0,         0, 0) );
+      degLeft.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/320.0f, 10/366.0f, 0) );
+      degRight.add( new Static3D(         0,         0, 0) );
+      degRight.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) );
+      mEffects.apply( new VertexEffectDistort( degLeft , centerLeft , regionLeft ) );
+      mEffects.apply( new VertexEffectDistort( degRight, centerRight, regionRight) );
 
       // ... 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
+      // later, in onSurfaceChanged, when we actually know the size of the screen and thus how
       // much to scale the initial Mesh (which is 1x1x0 in size)
       mScale= new Static3D(1,1,1);
       mEffects.apply(new MatrixEffectScale(mScale));
 
-      mScreen = new DistortedScreen();
+      mTexture = new DistortedTexture();
+      mScreen  = new DistortedScreen();
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -136,22 +142,15 @@ class MonaLisaRenderer implements GLSurfaceView.Renderer
 
       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 create it the second time around then.
-      if( mTexture==null ) mTexture = new DistortedTexture();
-
-      // likewise the Mesh
       // 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
-      // - including Textures - get deleted. We always need to call setTexture()
-      // to recreate the internal OpenGL textures.
+      // Every time activity goes to background, its OpenGL resources - including
+      // Textures - get deleted. We always need to call setTexture() here to
+      // recreate the internal OpenGL textures.
       mTexture.setTexture(bitmap);
 
       // Build the Scene Graph - attach all Objects we want to be rendered to the Screen.
diff --git a/src/main/java/org/distorted/examples/sink/SinkRenderer.java b/src/main/java/org/distorted/examples/sink/SinkRenderer.java
index 995dc1c..0bd4721 100644
--- a/src/main/java/org/distorted/examples/sink/SinkRenderer.java
+++ b/src/main/java/org/distorted/examples/sink/SinkRenderer.java
@@ -58,14 +58,15 @@ class SinkRenderer implements GLSurfaceView.Renderer
 
   SinkRenderer(GLSurfaceView v)
     { 
-    mView = v;
+    mView    = v;
+    mTexture = new DistortedTexture();
+    mEffects = new DistortedEffects();
+    mScreen  = new DistortedScreen();
 
     Dynamic1D sinkStrength = new Dynamic1D(2000,0.0f);
     sinkStrength.add(new Static1D(1.0f));
     sinkStrength.add(new Static1D(0.2f));
 
-    mEffects = new DistortedEffects();
-
     // strength [changing in time from 1.0 to 0.2 and back],
     // center   [(0,0,0), i.e. center of the bitmap],
     // region   [null - apply to the whole bitmap
@@ -74,8 +75,6 @@ class SinkRenderer implements GLSurfaceView.Renderer
 
     mScale = new Static3D(1,1,1);
     mEffects.apply(new MatrixEffectScale(mScale));
-
-    mScreen = new DistortedScreen();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -117,7 +116,6 @@ class SinkRenderer implements GLSurfaceView.Renderer
       
     mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
 
-    if( mTexture==null ) mTexture = new DistortedTexture();
     mTexture.setTexture(bitmap);
 
     if( mMesh==null ) mMesh = new MeshRectangles(30,(int)(30*mBmpRatio));
