commit 261fe5bd7c3f64628f5affc279e77084e9976f28
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Thu Jun 23 16:22:42 2016 +0100

    Improvements to the Cubes & Vertex3D apps.

diff --git a/src/main/java/org/distorted/examples/cubes/CubesRenderer.java b/src/main/java/org/distorted/examples/cubes/CubesRenderer.java
index 410c278..4c98ac7 100644
--- a/src/main/java/org/distorted/examples/cubes/CubesRenderer.java
+++ b/src/main/java/org/distorted/examples/cubes/CubesRenderer.java
@@ -27,6 +27,7 @@ import javax.microedition.khronos.opengles.GL10;
 
 import org.distorted.examples.R;
 
+import org.distorted.library.DistortedObject;
 import org.distorted.library.EffectTypes;
 import org.distorted.library.type.DynamicQuat;
 import org.distorted.library.DistortedCubes;
@@ -43,12 +44,10 @@ import android.opengl.GLSurfaceView;
 
 class CubesRenderer implements GLSurfaceView.Renderer 
 {
-    private static final int SIZE = 100;
-	
-    private int mCols, mRows;
-	
     private GLSurfaceView mView;
-    private DistortedCubes mCubes;
+    private DistortedObject mObject;
+    private int mObjWidth, mObjHeight;
+
     private DynamicQuat mQuatInt1, mQuatInt2;
     
     Static4D mQuat1, mQuat2;
@@ -59,14 +58,12 @@ class CubesRenderer implements GLSurfaceView.Renderer
     public CubesRenderer(GLSurfaceView v) 
       {
       mView = v;
-      
-      String shape = CubesActivity.getShape();
-      
-      mCols = CubesActivity.getCols();
-      mRows = shape.length() / mCols;
-      
-      mCubes = new DistortedCubes( mCols, shape, SIZE);
-      
+
+      mObject = new DistortedCubes( CubesActivity.getCols(), CubesActivity.getShape(), 100);
+
+      mObjWidth = mObject.getWidth();
+      mObjHeight= mObject.getHeight();
+
       mQuat1 = new Static4D(0,0,0,1);  // unity
       mQuat2 = new Static4D(0,0,0,1);  // quaternions
       
@@ -84,7 +81,7 @@ class CubesRenderer implements GLSurfaceView.Renderer
       GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
       GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
       
-      mCubes.draw(System.currentTimeMillis());
+      mObject.draw(System.currentTimeMillis());
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -93,29 +90,24 @@ class CubesRenderer implements GLSurfaceView.Renderer
       {
       mScreenMin = width<height ? width:height;
     	
-      mCubes.abortEffects(EffectTypes.MATRIX);
+      mObject.abortEffects(EffectTypes.MATRIX);
+      float factor;
 
-      if( mRows/mCols > height/width )
+      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
         {
-        int w = (height*mRows)/mCols;
-        float factor = (float)height/(mRows*SIZE);
-
-        mCubes.move( new Static3D((width-w)/2,0,0) );
-        mCubes.scale(factor);
-        }  
+        factor = (0.8f*height)/mObjHeight;
+        }
       else
-        {   
-        int h = (width*mRows)/mCols;
-        float factor = (float)width/(mCols*SIZE);
-
-        mCubes.move( new Static3D(0,(height-h)/2,0) );
-        mCubes.scale(factor);
+        {
+        factor = (0.8f*width)/mObjWidth;
         }
-    
-      Static3D center = new Static3D(mCols*SIZE/2,mRows*SIZE/2, 0);
-      
-      mCubes.quaternion(mQuatInt1, center);
-      mCubes.quaternion(mQuatInt2, center);
+
+      mObject.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
+      mObject.scale(factor);
+      Static3D center = new Static3D(mObjWidth/2,mObjHeight/2, 0);
+
+      mObject.quaternion(mQuatInt1, center);
+      mObject.quaternion(mQuatInt2, center);
        
       Distorted.onSurfaceChanged(width, height); 
       }
@@ -140,7 +132,7 @@ class CubesRenderer implements GLSurfaceView.Renderer
         catch(IOException e) { }
         }  
       
-      mCubes.setBitmap(bitmap);
+      mObject.setBitmap(bitmap);
       
       try
         {
diff --git a/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java b/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
index 7e9f649..26a2bf6 100644
--- a/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
+++ b/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
@@ -27,11 +27,11 @@ import android.opengl.GLSurfaceView;
 import org.distorted.examples.R;
 import org.distorted.library.Distorted;
 import org.distorted.library.DistortedCubes;
+import org.distorted.library.DistortedObject;
 import org.distorted.library.EffectNames;
 import org.distorted.library.EffectTypes;
 import org.distorted.library.type.Dynamic1D;
 import org.distorted.library.type.Dynamic3D;
-import org.distorted.library.type.Dynamic4D;
 import org.distorted.library.type.DynamicQuat;
 import org.distorted.library.type.Static1D;
 import org.distorted.library.type.Static2D;
@@ -48,11 +48,11 @@ import javax.microedition.khronos.opengles.GL10;
 
 class Vertex3DRenderer implements GLSurfaceView.Renderer
 {
-    private static final int SIZE = 100;
-
     private GLSurfaceView mView;
-    private static DistortedCubes mCube;
-    private int mCols, mRows;
+    private static DistortedObject mObject;
+
+    private int mObjWidth, mObjHeight;
+
     private DynamicQuat mQuatInt1, mQuatInt2;
 
     private static EffectNames[] order;
@@ -107,16 +107,16 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
 
     public static void setVertexEffects()
       {
-      mCube.abortEffects(EffectTypes.VERTEX);
+      mObject.abortEffects(EffectTypes.VERTEX);
 	
       for( int i=0; i<=order.length-1 ; i++ )
         {
         switch(order[i])
           {
-          case DEFORM : mCube.deform( mDeformInter , mCenterPoint) ; break;
-          case DISTORT: mCube.distort(mDistortInter, mCenterPoint) ; break;
-          case SINK   : mCube.sink(   mSinkInter   , mCenterPoint) ; break;
-          case SWIRL  : mCube.swirl(  mSwirlInter  , mCenterPoint) ; break;
+          case DEFORM : mObject.deform( mDeformInter , mCenterPoint) ; break;
+          case DISTORT: mObject.distort(mDistortInter, mCenterPoint) ; break;
+          case SINK   : mObject.sink(   mSinkInter   , mCenterPoint) ; break;
+          case SWIRL  : mObject.swirl(  mSwirlInter  , mCenterPoint) ; break;
           }
         }
       }
@@ -127,13 +127,12 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
       {
       mView = v;
 
-      String shape = Vertex3DActivity.getShape();
+      mObject = new DistortedCubes( Vertex3DActivity.getCols(), Vertex3DActivity.getShape(), 100);
+      //mObject = new DistortedBitmap( 100, 100, 10);
 
-      mCols = Vertex3DActivity.getCols();
-      mRows = shape.length() / mCols;
+      mObjWidth = mObject.getWidth();
+      mObjHeight= mObject.getHeight();
 
-      mCube = new DistortedCubes( mCols, shape, SIZE);
-      
       mCenterPoint = new Static2D(0,0);
       mDeformPoint = new Static3D(0,0,0);
       mDistortPoint= new Static3D(1,1,1);
@@ -167,7 +166,7 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
       GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
       GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
       
-      mCube.draw(System.currentTimeMillis());
+      mObject.draw(System.currentTimeMillis());
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -176,25 +175,25 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
       {
       mScreenMin = width<height ? width:height;
 
-      mCube.abortEffects(EffectTypes.MATRIX);
+      mObject.abortEffects(EffectTypes.MATRIX);
       float factor;
 
-      if( width*mRows > height*mCols ) // screen is more 'horizontal' than the shape
+      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
         {
-        factor = ((float)height)/((mRows+2)*SIZE);
-}
+        factor = (0.8f*height)/mObjHeight;
+        }
       else
         {
-        factor = ((float)width)/((mCols+2)*SIZE);
+        factor = (0.8f*width)/mObjWidth;
         }
 
-      mCube.move( new Static3D( (width-factor*mCols*SIZE)/2 , (height-factor*mRows*SIZE)/2 , 0) );
-      mCube.scale(factor);
+      mObject.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
+      mObject.scale(factor);
 
-      Static3D center = new Static3D(mCols*SIZE/2,mRows*SIZE/2, 0);
+      Static3D center = new Static3D(mObjWidth/2,mObjHeight/2, 0);
 
-      mCube.quaternion(mQuatInt1, center);
-      mCube.quaternion(mQuatInt2, center);
+      mObject.quaternion(mQuatInt1, center);
+      mObject.quaternion(mQuatInt2, center);
 
       setVertexEffects();
 
@@ -221,7 +220,7 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
         catch(IOException e) { }
         }  
       
-      mCube.setBitmap(bitmap);
+      mObject.setBitmap(bitmap);
       
       try
         {
