commit 815687bb8f89624e48a8eb6138be61a6b5995e11
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri Nov 4 17:11:15 2016 +0000

    Progress with 'Wind'

diff --git a/src/main/java/org/distorted/examples/wind/WindEffectsManager.java b/src/main/java/org/distorted/examples/wind/WindEffectsManager.java
new file mode 100644
index 0000000..fb5cafd
--- /dev/null
+++ b/src/main/java/org/distorted/examples/wind/WindEffectsManager.java
@@ -0,0 +1,35 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.examples.wind;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+import org.distorted.library.DistortedObject;
+
+class WindEffectsManager
+  {
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void apply(DistortedObject obj, int wind)
+    {
+
+    }
+  }
diff --git a/src/main/java/org/distorted/examples/wind/WindRenderer.java b/src/main/java/org/distorted/examples/wind/WindRenderer.java
index d32d804..98d17fb 100644
--- a/src/main/java/org/distorted/examples/wind/WindRenderer.java
+++ b/src/main/java/org/distorted/examples/wind/WindRenderer.java
@@ -29,9 +29,8 @@ import org.distorted.library.Distorted;
 import org.distorted.library.DistortedCubes;
 import org.distorted.library.DistortedObject;
 import org.distorted.library.EffectTypes;
-import org.distorted.library.type.DynamicQuat;
+import org.distorted.library.type.Static1D;
 import org.distorted.library.type.Static3D;
-import org.distorted.library.type.Static4D;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -45,13 +44,9 @@ class WindRenderer implements GLSurfaceView.Renderer
 {
    private GLSurfaceView mView;
    private DistortedObject mObject;
-   private DynamicQuat mQuatInt1, mQuatInt2;
-   private int mWind;
+   private WindEffectsManager mEffects;
    private int mObjWidth, mObjHeight;
 
-   Static4D mQuat1, mQuat2;
-   int mScreenMin;
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
    WindRenderer(GLSurfaceView view)
@@ -59,25 +54,17 @@ class WindRenderer implements GLSurfaceView.Renderer
       mView = view;
 
       mObject = new DistortedCubes(50,30,10,false);
+      mEffects = new WindEffectsManager();
 
       mObjWidth = mObject.getWidth();
       mObjHeight= mObject.getHeight();
-
-      mQuat1 = new Static4D(           0,         0,           0,          1);  // unity quaternion
-      mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);  // something semi-random that looks good
-
-      mQuatInt1 = new DynamicQuat(0,0.5f);
-      mQuatInt2 = new DynamicQuat(0,0.5f);
-
-      mQuatInt1.add(mQuat1);
-      mQuatInt2.add(mQuat2);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
    void setWind(int wind)
       {
-      mWind = wind;
+      mEffects.apply(mObject,wind);
       }
    
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -94,26 +81,17 @@ class WindRenderer implements GLSurfaceView.Renderer
     
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
       {
-      mScreenMin = width<height ? width:height;
-
       mObject.abortEffects(EffectTypes.MATRIX);
-      float factor;
+      float factor = 0.8f*(width<height? width:height)/mObjWidth;
 
-      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
-        {
-        factor = (0.8f*height)/mObjHeight;
-        }
-      else
-        {
-        factor = (0.8f*width)/mObjWidth;
-        }
-
-      mObject.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
+      mObject.move( new Static3D( (width-factor*mObjWidth)/2 + width/8 , (height-factor*mObjHeight)/2 -height/4 , 0) );
       mObject.scale(factor);
-      Static3D center = new Static3D(mObjWidth/2,mObjHeight/2, 0);
 
-      mObject.quaternion(mQuatInt1, center);
-      mObject.quaternion(mQuatInt2, center);
+      Static1D angle = new Static1D(-45);
+      Static3D axis  = new Static3D(0,0,1);
+      Static3D center= new Static3D(0,mObjHeight/2,0);
+
+      mObject.rotate(angle, axis, center);
 
       Distorted.onSurfaceChanged(width, height);
       }
diff --git a/src/main/java/org/distorted/examples/wind/WindSurfaceView.java b/src/main/java/org/distorted/examples/wind/WindSurfaceView.java
index b32be59..df967a5 100644
--- a/src/main/java/org/distorted/examples/wind/WindSurfaceView.java
+++ b/src/main/java/org/distorted/examples/wind/WindSurfaceView.java
@@ -29,7 +29,6 @@ import android.view.MotionEvent;
 
 class WindSurfaceView extends GLSurfaceView
 {
-    private int mX, mY;
     private WindRenderer mRenderer;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -38,9 +37,6 @@ class WindSurfaceView extends GLSurfaceView
       {
       super(c, attrs);
 
-      mX = -1;
-      mY = -1;
-
       if(!isInEditMode())
         {
         setEGLContextClientVersion(2);
@@ -60,79 +56,5 @@ class WindSurfaceView extends GLSurfaceView
       {
       return mRenderer;
       }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-    @Override public boolean onTouchEvent(MotionEvent event)
-      {
-      int action = event.getAction();
-      int x = (int)event.getX();
-      int y = (int)event.getY();
-
-      switch(action)
-         {
-         case MotionEvent.ACTION_DOWN: mX = x;
-                                       mY = y;
-                                       break;
-
-         case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 )
-                                         {
-                                         float px = mY-y;
-                                         float py = mX-x;
-                                         float pz = 0;
-                                         float plen = (float)Math.sqrt(px*px + py*py + pz*pz);
-
-                                         if( plen>0 )
-                                           {
-                                           px /= plen;
-                                           py /= plen;
-                                           pz /= plen;
-
-                                           float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
-                                           float sinA = (float)Math.sqrt(1-cosA*cosA);
-
-                                           mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
-                                           }
-                                         }
-                                       break;
-
-         case MotionEvent.ACTION_UP  : mX = -1;
-                                       mY = -1;
-
-                                       float qx = mRenderer.mQuat1.getX();
-                                       float qy = mRenderer.mQuat1.getY();
-                                       float qz = mRenderer.mQuat1.getZ();
-                                       float qw = mRenderer.mQuat1.getW();
-
-                                       float rx = mRenderer.mQuat2.getX();
-                                       float ry = mRenderer.mQuat2.getY();
-                                       float rz = mRenderer.mQuat2.getZ();
-                                       float rw = mRenderer.mQuat2.getW();
-
-                                       // This is quaternion multiplication. (tx.ty.tz.tw)
-                                       // is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw)
-                                       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
-                                       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
-                                       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
-                                       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
-
-                                       // The point of this is so that there are always
-                                       // exactly 2 quaternions: Quat1 representing the rotation
-                                       // accumulating only since the last screen touch, and Quat2
-                                       // which remembers the combined effect of all previous
-                                       // swipes.
-                                       // We cannot be accumulating an ever-growing list of quaternions
-                                       // and add a new one every time user swipes the screen - there
-                                       // is a limited number of slots in the EffectQueueMatrix!
-                                       mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
-                                       mRenderer.mQuat2.set(tx, ty, tz, tw);
-
-                                       break;
-         }
-
-      return true;
-      }
-
 }
-///////////////////////////////////////////////////////////////////////////////////////////////////
 
