commit 794e6c4f0ccb102e2e27dfcf97b3322edfe754de
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Sat Jun 25 23:54:24 2016 +0100

    Vertex3D: add configurable center

diff --git a/src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java b/src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
index 1450d68..2603861 100644
--- a/src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
+++ b/src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
@@ -57,17 +57,19 @@ public class Vertex3DActivity extends Activity implements OnSeekBarChangeListene
   // fields needed for the second 'apply vertex effects' screen
   //
   private SeekBar bar;
-  private TextView textDeform, textDistort, textSink, textSwirl;
+  private TextView textDeform, textDistort, textSink, textSwirl, textCenter;
   private int deformX, deformY, deformZ;
   private int distortX, distortY, distortZ;
   private int sinkA;
   private int swirlA;
+  private int centerX, centerY;
 
   private float fdeformX, fdeformY, fdeformZ;
   private float fdistortX, fdistortY, fdistortZ;
   private float fsinkA;
   private float fswirlA;
-    
+  private float fcenterX, fcenterY;
+
   private EffectNames[] effects = new EffectNames[4];
     
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -219,6 +221,15 @@ public class Vertex3DActivity extends Activity implements OnSeekBarChangeListene
     sinkA =  50;
     swirlA = 50;
 
+    centerX = 25;
+    centerY = 25;
+
+    textCenter = (TextView)findViewById(R.id.vertex3dcenterText);
+    setCenterText();
+
+    setBar(R.id.vertex3dcenterX, centerX);
+    setBar(R.id.vertex3dcenterY, centerY);
+
     addViews();
     }
     
@@ -419,7 +430,27 @@ public class Vertex3DActivity extends Activity implements OnSeekBarChangeListene
 
     textSwirl.setText("swirl("+fswirlA+")");
     }
-   
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void computeCenter()
+    {
+    fcenterX = (centerX*0.02f - 0.5f)*Vertex3DRenderer.SIZE;
+    fcenterY = (centerY*0.02f - 0.5f)*Vertex3DRenderer.SIZE;
+
+    Vertex3DRenderer.setCenter( fcenterX, fcenterY );
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void setCenterText()
+    {
+    fcenterX = ((int)(100*fcenterX))/100.0f;
+    fcenterY = ((int)(100*fcenterY))/100.0f;
+
+    textCenter.setText("center("+fcenterX+","+fcenterY+")");
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Overrides
 
@@ -472,6 +503,8 @@ public class Vertex3DActivity extends Activity implements OnSeekBarChangeListene
     {
     switch (bar.getId())
       {
+      case R.id.vertex3dcenterX     : centerX = progress; computeCenter() ; setCenterText()  ; break;
+      case R.id.vertex3dcenterY     : centerY = progress; computeCenter() ; setCenterText()  ; break;
       case R.id.vertex3ddeformBar1  : deformX = progress; computeDeform() ; setDeformText()  ; break;
       case R.id.vertex3ddeformBar2  : deformY = progress; computeDeform() ; setDeformText()  ; break;
       case R.id.vertex3ddeformBar3  : deformZ = progress; computeDeform() ; setDeformText()  ; break;
diff --git a/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java b/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
index 26a2bf6..654c0c1 100644
--- a/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
+++ b/src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
@@ -26,11 +26,13 @@ import android.opengl.GLSurfaceView;
 
 import org.distorted.examples.R;
 import org.distorted.library.Distorted;
+import org.distorted.library.DistortedBitmap;
 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.Dynamic2D;
 import org.distorted.library.type.Dynamic3D;
 import org.distorted.library.type.DynamicQuat;
 import org.distorted.library.type.Static1D;
@@ -48,6 +50,8 @@ import javax.microedition.khronos.opengles.GL10;
 
 class Vertex3DRenderer implements GLSurfaceView.Renderer
 {
+    public static final int SIZE = 100;
+
     private GLSurfaceView mView;
     private static DistortedObject mObject;
 
@@ -56,7 +60,8 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
     private DynamicQuat mQuatInt1, mQuatInt2;
 
     private static EffectNames[] order;
-    
+
+    private static Dynamic2D mCenterInter;
     private static Dynamic3D mDeformInter, mDistortInter;
     private static Dynamic1D mSinkInter, mSwirlInter;
 
@@ -95,6 +100,13 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
       mSwirlPoint.set(s);
       }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public static void setCenter(float x, float y)
+      {
+      mCenterPoint.set(x,y);
+      }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     public static void setOrder(EffectNames[] effects)
@@ -108,15 +120,15 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
     public static void setVertexEffects()
       {
       mObject.abortEffects(EffectTypes.VERTEX);
-	
+
       for( int i=0; i<=order.length-1 ; i++ )
         {
         switch(order[i])
           {
-          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;
+          case DEFORM : mObject.deform( mDeformInter , mCenterInter) ; break;
+          case DISTORT: mObject.distort(mDistortInter, mCenterInter) ; break;
+          case SINK   : mObject.sink(   mSinkInter   , mCenterInter) ; break;
+          case SWIRL  : mObject.swirl(  mSwirlInter  , mCenterInter) ; break;
           }
         }
       }
@@ -127,8 +139,8 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
       {
       mView = v;
 
-      mObject = new DistortedCubes( Vertex3DActivity.getCols(), Vertex3DActivity.getShape(), 100);
-      //mObject = new DistortedBitmap( 100, 100, 10);
+      mObject = new DistortedCubes( Vertex3DActivity.getCols(), Vertex3DActivity.getShape(), SIZE);
+      //mObject = new DistortedBitmap( SIZE, SIZE, 10);
 
       mObjWidth = mObject.getWidth();
       mObjHeight= mObject.getHeight();
@@ -139,11 +151,13 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
       mSwirlPoint  = new Static1D(0);
       mSinkPoint   = new Static1D(1);
 
+      mCenterInter  = new Dynamic2D();
       mDeformInter  = new Dynamic3D();
       mDistortInter = new Dynamic3D();
       mSwirlInter   = new Dynamic1D();
       mSinkInter    = new Dynamic1D();
 
+      mCenterInter.add(mCenterPoint);
       mDeformInter.add(mDeformPoint);
       mDistortInter.add(mDistortPoint);
       mSwirlInter.add(mSwirlPoint);
@@ -180,11 +194,11 @@ class Vertex3DRenderer implements GLSurfaceView.Renderer
 
       if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
         {
-        factor = (0.8f*height)/mObjHeight;
+        factor = (0.7f*height)/mObjHeight;
         }
       else
         {
-        factor = (0.8f*width)/mObjWidth;
+        factor = (0.7f*width)/mObjWidth;
         }
 
       mObject.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
diff --git a/src/main/res/layout/vertex3dlayout.xml b/src/main/res/layout/vertex3dlayout.xml
index 431b252..878ccf2 100644
--- a/src/main/res/layout/vertex3dlayout.xml
+++ b/src/main/res/layout/vertex3dlayout.xml
@@ -10,12 +10,55 @@
         android:layout_height="0dp"
         android:layout_weight="1" />
 
-    <Button
-        android:id="@+id/button1"
-        android:layout_width="fill_parent"
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:onClick="Default"
-        android:text="@string/Default" />
+        >
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="0.8">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:id="@+id/vertex3dcenterText"/>
+
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent">
+
+                <SeekBar
+                    android:layout_width="fill_parent"
+                    android:layout_height="wrap_content"
+                    android:id="@+id/vertex3dcenterX"
+                    android:layout_weight="0.5"
+                    android:paddingLeft="5dp"
+                    android:paddingRight="3dp"/>
+
+                <SeekBar
+                    android:layout_width="fill_parent"
+                    android:layout_height="wrap_content"
+                    android:id="@+id/vertex3dcenterY"
+                    android:layout_weight="0.5"
+                    android:paddingLeft="3dp"
+                    android:paddingRight="5dp"/>
+            </LinearLayout>
+
+        </LinearLayout>
+
+        <Button
+            android:id="@+id/buttonDefault"
+            android:layout_width="60dp"
+            android:layout_height="wrap_content"
+            android:onClick="Default"
+            android:text="@string/reset"
+            android:layout_gravity="right"/>
+    </LinearLayout>
 
     <ScrollView
         android:id="@+id/vertex3dscrollView"
