commit 752c6b57bb227292e6c28438b955fcb892f7acc6
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Tue Apr 25 17:21:45 2017 +0100

    Progress with the last 2 Apps: Effects3D and Wind (not done yet)

diff --git a/src/main/java/org/distorted/examples/effects3d/Effects3DEffect.java b/src/main/java/org/distorted/examples/effects3d/Effects3DEffect.java
index e25a7d0..8da600d 100644
--- a/src/main/java/org/distorted/examples/effects3d/Effects3DEffect.java
+++ b/src/main/java/org/distorted/examples/effects3d/Effects3DEffect.java
@@ -131,16 +131,24 @@ class Effects3DEffect implements SeekBar.OnSeekBarChangeListener
                               float sinAnorm = (float)Math.sin(qa/2)/len;
                               mSta4.set(sinAnorm*qx,sinAnorm*qy,sinAnorm*qz, cosA);
                               break;
-      case MOVE             : float sw = mAct.get().getScreenWidth()/50.0f;
-                              float sh = mAct.get().getScreenWidth()/50.0f;
-                              float xm = (mInter[0]-50)*sw;
-                              float ym = (mInter[1]-50)*sh;
-                              float zm = (mInter[2]-50)*(sw+sh)/2;
+      case MOVE             : float s  = 0.04f;
+                              float xm = (mInter[0]-50)*s;
+                              float ym = (mInter[1]-50)*s;
+                              float zm = (mInter[2]-50)*s;
                               mSta3.set(xm,ym,zm);
                               break;
-      case SCALE            : float xs = (mInter[0]>50 ? 0.18f : 0.018f)*(mInter[0]-50) + 1;
-                              float ys = (mInter[1]>50 ? 0.18f : 0.018f)*(mInter[1]-50) + 1;
-                              float zs = (mInter[2]>50 ? 0.18f : 0.018f)*(mInter[2]-50) + 1;
+      case SCALE            : double coeff = Math.PI / 100;
+
+                              if( mInter[0]<=  0 ) mInter[0]= 1;
+                              if( mInter[0]>=100 ) mInter[0]=99;
+                              if( mInter[1]<=  0 ) mInter[1]= 1;
+                              if( mInter[1]>=100 ) mInter[1]=99;
+                              if( mInter[2]<=  0 ) mInter[2]= 1;
+                              if( mInter[2]>=100 ) mInter[2]=99;
+
+                              float xs = (float)Math.tan((mInter[0]-50)*coeff);
+                              float ys = (float)Math.tan((mInter[1]-50)*coeff);
+                              float zs = (float)Math.tan((mInter[2]-50)*coeff);
                               mSta3.set(xs,ys,zs);
                               break;
       case SHEAR            : float xsh = (mInter[0]-50)/25.0f;
@@ -205,7 +213,16 @@ class Effects3DEffect implements SeekBar.OnSeekBarChangeListener
       case 1: mInter[0] = 50;
       }
 
-    if( mName==EffectNames.ROTATE || mName==EffectNames.QUATERNION ) mInter[1]= 100;
+    if( mName==EffectNames.ROTATE || mName==EffectNames.QUATERNION )
+      {
+      mInter[1]= 100;
+      }
+    if( mName==EffectNames.SCALE )
+      {
+      mInter[0]= 75;
+      mInter[1]= 75;
+      mInter[2]= 75;
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -261,11 +278,9 @@ class Effects3DEffect implements SeekBar.OnSeekBarChangeListener
 
   private void fillCenterStatics()
     {
-    Effects3DActivity act = mAct.get();
-
-    float x = (mInterCenter[0]*0.012f - 0.1f)*act.getWidth();
-    float y = (mInterCenter[1]*0.012f - 0.1f)*act.getHeight();
-    float z = (mInterCenter[2]*0.012f - 0.1f)*act.getDepth();
+    float x = (mInterCenter[0]-50)*0.02f;
+    float y = (mInterCenter[1]-50)*0.02f;
+    float z = (mInterCenter[2]-50)*0.02f;
 
     mCenterSta.set(x,y,z);
     }
@@ -283,9 +298,9 @@ class Effects3DEffect implements SeekBar.OnSeekBarChangeListener
 
   private void setCenterText()
     {
-    int f0 = (int)mCenterSta.getX();
-    int f1 = (int)mCenterSta.getY();
-    int f2 = (int)mCenterSta.getZ();
+    float f0 = ((int)(mCenterSta.getX()*100))/100.0f;
+    float f1 = ((int)(mCenterSta.getY()*100))/100.0f;
+    float f2 = ((int)(mCenterSta.getZ()*100))/100.0f;
 
     mTextCenter.setText("center ("+f0+","+f1+","+f2+")");
     }
diff --git a/src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java b/src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
index 51ea6f0..e92575b 100644
--- a/src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
+++ b/src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
@@ -173,12 +173,30 @@ class Effects3DRenderer implements GLSurfaceView.Renderer
     public void onSurfaceChanged(GL10 glUnused, int width, int height)
       {
       mScreenMin = width<height ? width:height;
+      Static3D centerRot = new Static3D(0,0,0);
 
-      mObjectEffects.abortEffects(EffectTypes.MATRIX);
+      //// BACKGROUND ////////////
+      // quite tricky: move the background exactly to the FAR plane! (see DistortedOutputSurface.setProjection() )
+      float distToScreen = height/(2.0f*(float)Math.tan(FOV*Math.PI/360));
+      float distToFar    = distToScreen*(2-NEAR);
+      float factor       = distToFar / distToScreen;
       mBackgroundEffects.abortEffects(EffectTypes.MATRIX);
-      mCenterEffects.abortEffects(EffectTypes.MATRIX);
-      mRegionEffects.abortEffects(EffectTypes.MATRIX);
+      mBackgroundEffects.move(new Static3D( 0, 0, -(distToFar-distToScreen)/width ) );
+      mBackgroundEffects.scale(new Static3D(factor,factor,1.0f) );
+
+      //// OBJECT //////////////
+      float qObj= ((float)width/height)*((float)mObjHeight/mObjWidth);
+      float sObj= 0.8f;
+
+      mObjectEffects.abortEffects(EffectTypes.MATRIX);
+      mObjectEffects.quaternion(mQuatInt1, centerRot);
+      mObjectEffects.quaternion(mQuatInt2, centerRot);
+      mObjectEffects.scale(  qObj<1 ? (new Static3D(sObj,sObj*qObj,sObj)) : (new Static3D(sObj/qObj,sObj,sObj/qObj)) );
+
+
 
+
+      /*
       float factorCen;
       int centerSize = mCenterTexture.getWidth();
       int regionSize = mRegionTexture.getWidth();
@@ -200,23 +218,24 @@ class Effects3DRenderer implements GLSurfaceView.Renderer
 
       mFactorReg = 2*mFactorObj*act.getRegionR()/regionSize;
       mRegionScalePoint.set(mFactorReg,mFactorReg,mFactorReg);
+      */
 
-      Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0);
-
-      mObjectEffects.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
-      mObjectEffects.scale(mFactorObj);
-      mObjectEffects.quaternion(mQuatInt1, rotateObj);
-      mObjectEffects.quaternion(mQuatInt2, rotateObj);
-
-      Static3D rotateCen = new Static3D(width/2,height/2, 0);
 
-      mCenterEffects.quaternion(mQuatInt1, rotateCen);
-      mCenterEffects.quaternion(mQuatInt2, rotateCen);
+      //// CENTER //////////////
+      float qCen= ((float)width/height);
+      float sCen= 0.1f;
 
-      mCenterEffects.move( new Static3D( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 ,
-                                  (height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , mFactorObj*mObjDepth/2+10) );
+      mCenterEffects.abortEffects(EffectTypes.MATRIX);
+      /*
+      mCenterEffects.quaternion(mQuatInt1, centerRot);
+      mCenterEffects.quaternion(mQuatInt2, centerRot);
+      mCenterEffects.move( new Static3D(0,0,0.5f) );
       mCenterEffects.move(mCenterInter);
-      mCenterEffects.scale(factorCen);
+      mCenterEffects.scale(qObj<1 ? (new Static3D(sCen,sCen*qCen,sCen)) : (new Static3D(sCen/qCen,sCen,sCen/qCen)));
+      */
+/*
+      //// REGION //////////////
+      mRegionEffects.abortEffects(EffectTypes.MATRIX);
 
       mRegionEffects.quaternion(mQuatInt1, rotateCen);
       mRegionEffects.quaternion(mQuatInt2, rotateCen);
@@ -227,15 +246,7 @@ class Effects3DRenderer implements GLSurfaceView.Renderer
       mRegionEffects.move(mRegionInter);
       mRegionEffects.scale(mRegionScaleInter);
       mRegionEffects.move( new Static3D( -regionSize/2 , -regionSize/2 , 0) );
-
-      int backgroundSize = mBackgroundTexture.getWidth();
-      float factorBackX = ((float)width)/backgroundSize;
-      float factorBackY = ((float)height)/backgroundSize;
-
-      // quite tricky: move the background exactly to the FAR plane! (see DistortedOutputSurface.setProjection() )
-      mBackgroundEffects.move(new Static3D( -width/2, -height/2, -height*(1.0f-NEAR)/(2.0f*(float)Math.tan(FOV*Math.PI/360))) );
-      mBackgroundEffects.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) );
-
+      */
       mScreen.resize(width, height);
       }
 
diff --git a/src/main/java/org/distorted/examples/wind/WindRenderer.java b/src/main/java/org/distorted/examples/wind/WindRenderer.java
index e9881f4..c122216 100644
--- a/src/main/java/org/distorted/examples/wind/WindRenderer.java
+++ b/src/main/java/org/distorted/examples/wind/WindRenderer.java
@@ -21,7 +21,6 @@ package org.distorted.examples.wind;
 
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.opengl.GLES30;
 import android.opengl.GLSurfaceView;
 
 import org.distorted.examples.R;
@@ -85,22 +84,22 @@ class WindRenderer implements GLSurfaceView.Renderer
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-    
+
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
       {
-      mEffects.abortAllEffects();
-
-      float factor = ( (float)(width<height? width:height) )/(mObjHeight + 1.4f*mObjWidth);
-
-      mEffects.move( new Static3D( factor*mObjHeight*0.58f , factor*mObjHeight*0.08f , 0) );
-      mEffects.scale(factor);
-
+      float q= ((float)width/height)*((float)mObjHeight/mObjWidth);
+      float scale = 0.5f;
       Static1D angle = new Static1D(-45);
       Static3D axis  = new Static3D(0,0,1);
-      Static3D center= new Static3D(0,mObjHeight/2,0);
+      Static3D center= new Static3D( -scale/2,0,0 );
+      Static3D move  = new Static3D( 0,((float)width/height)*(1-scale/2)-0.5f,0 );
+
+      mEffects.abortAllEffects();
+      //mEffects.move( move );
+      //mEffects.rotate(angle, axis, center);
+      //mManager.apply(mEffects,mWind);
+      mEffects.scale(q<1 ? (new Static3D(scale,scale*q,scale)) : (new Static3D(scale/q,scale,scale/q)));
 
-      mEffects.rotate(angle, axis, center);
-      mManager.apply(mEffects,mWind);
       mScreen.resize(width, height);
       }
 
