commit 4da7d87a458fd298539f544fa68ec49f17c06e4e
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Jun 19 19:19:43 2020 +0100

    Simplify dragging. Now there's only 1 Quat, rather than the old way with two (Accumulated, Current).

diff --git a/src/main/java/org/distorted/main/RubikPreRender.java b/src/main/java/org/distorted/main/RubikPreRender.java
index 91cd1eec..dd59a6d5 100644
--- a/src/main/java/org/distorted/main/RubikPreRender.java
+++ b/src/main/java/org/distorted/main/RubikPreRender.java
@@ -45,8 +45,8 @@ public class RubikPreRender implements EffectListener
 
   private RubikSurfaceView mView;
   private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation,
-                  mSetQuatCurrent, mSetQuatAccumulated, mChangeObject, mSetupObject, mSolveObject,
-                  mScrambleObject, mInitializeObject, mSetTextureMap, mResetAllTextureMaps;
+                  mSetQuat, mChangeObject, mSetupObject, mSolveObject, mScrambleObject,
+                  mInitializeObject, mSetTextureMap, mResetAllTextureMaps;
   private boolean mCanRotate, mCanPlay;
   private boolean mIsSolved;
   private RubikObjectList mNextObject;
@@ -77,8 +77,7 @@ public class RubikPreRender implements EffectListener
     mRemoveRotation       = false;
     mRemovePatternRotation= false;
     mAddRotation          = false;
-    mSetQuatCurrent       = false;
-    mSetQuatAccumulated   = false;
+    mSetQuat              = false;
     mChangeObject         = false;
     mSetupObject          = false;
     mSolveObject          = false;
@@ -108,7 +107,7 @@ public class RubikPreRender implements EffectListener
     Context con = mView.getContext();
     Resources res = con.getResources();
 
-    mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated(), moves, res);
+    mNewObject = object.create(size, mView.getQuat(), moves, res);
 
     if( mNewObject!=null )
       {
@@ -318,18 +317,10 @@ public class RubikPreRender implements EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private void setQuatCurrentNow()
+  private void setQuatNow()
     {
-    mSetQuatCurrent = false;
-    mView.setQuatCurrent();
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private void setQuatAccumulatedNow()
-    {
-    mSetQuatAccumulated = false;
-    mView.setQuatAccumulated();
+    mSetQuat = false;
+    mView.setQuat();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -425,24 +416,16 @@ public class RubikPreRender implements EffectListener
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  void setQuatCurrentOnNextRender()
-    {
-    mSetQuatCurrent = true;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  void setQuatAccumulatedOnNextRender()
+  void setQuatOnNextRender()
     {
-    mSetQuatAccumulated = true;
+    mSetQuat = true;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   void preRender()
     {
-    if( mSetQuatCurrent        ) setQuatCurrentNow();
-    if( mSetQuatAccumulated    ) setQuatAccumulatedNow();
+    if( mSetQuat               ) setQuatNow();
     if( mFinishRotation        ) finishRotationNow();
     if( mRemoveRotation        ) removeRotationNow();
     if( mRemovePatternRotation ) removePatternRotationNow();
diff --git a/src/main/java/org/distorted/main/RubikSurfaceView.java b/src/main/java/org/distorted/main/RubikSurfaceView.java
index 85f253d7..5ced07af 100644
--- a/src/main/java/org/distorted/main/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/main/RubikSurfaceView.java
@@ -50,10 +50,8 @@ public class RubikSurfaceView extends GLSurfaceView
     // Moving the finger from the middle of the vertical screen to the right edge will rotate a
     // given face by SWIPING_SENSITIVITY/2 degrees.
     private final static int SWIPING_SENSITIVITY  = 240;
-    // Moving the finger by 0.33 of an inch will start a Rotation.
-    private final static float ROTATION_SENSITIVITY =  0.33f;
-    // Every 0.33 of an inch the direction of cube drag will reset.
-    private final static float DIRECTION_SENSITIVITY=  0.33f;
+    // Moving the finger by 0.3 of an inch will start a Rotation.
+    private final static float ROTATION_SENSITIVITY = 0.3f;
 
     // Where did we get this sqrt(3)/2 ? From the (default, i.e. 60 degrees - see InternalOutputSurface!)
     // FOV of the projection matrix of the Node onto the Screen.
@@ -86,10 +84,8 @@ public class RubikSurfaceView extends GLSurfaceView
     private int mFirstIndex, mLastIndex;
     private int mDensity;
 
-    private static Static4D mQuatCurrent    = new Static4D(0,0,0,1);
-    private static Static4D mQuatAccumulated= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
-    private static Static4D mTempCurrent    = new Static4D(0,0,0,1);
-    private static Static4D mTempAccumulated= new Static4D(0,0,0,1);
+    private static Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
+    private static Static4D mTemp= new Static4D(0,0,0,1);
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -124,30 +120,16 @@ public class RubikSurfaceView extends GLSurfaceView
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    void setQuatAccumulated()
+    void setQuat()
       {
-      mQuatAccumulated.set(mTempAccumulated);
+      mQuat.set(mTemp);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    void setQuatCurrent()
+    Static4D getQuat()
       {
-      mQuatCurrent.set(mTempCurrent);
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-    Static4D getQuatAccumulated()
-      {
-      return mQuatAccumulated;
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-    Static4D getQuatCurrent()
-      {
-      return mQuatCurrent;
+      return mQuat;
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -200,7 +182,7 @@ public class RubikSurfaceView extends GLSurfaceView
     private void computeCurrentAxis(Static3D axis)
       {
       Static4D axis4D = new Static4D(axis.get0(), axis.get1(), axis.get2(), 0);
-      Static4D result = rotateVectorByQuat(axis4D, mQuatAccumulated);
+      Static4D result = rotateVectorByQuat(axis4D, mQuat);
 
       mAxisX =result.get0();
       mAxisY =result.get1();
@@ -338,8 +320,8 @@ public class RubikSurfaceView extends GLSurfaceView
       else
         {
         Static4D touchPoint1 = new Static4D(x, y, 0, 0);
-        Static4D rotatedTouchPoint1= rotateVectorByInvertedQuat(touchPoint1, mQuatAccumulated);
-        Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuatAccumulated);
+        Static4D rotatedTouchPoint1= rotateVectorByInvertedQuat(touchPoint1, mQuat);
+        Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
 
         if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint1,rotatedCamera) )
           {
@@ -380,18 +362,10 @@ public class RubikSurfaceView extends GLSurfaceView
 
     private void drag(float x, float y)
       {
-      if( retFingerDragDistanceInInches(mX,mY,x,y) > DIRECTION_SENSITIVITY )
-        {
-        mX = x;
-        mY = y;
-        mTempAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated));
-        mTempCurrent.set(0f, 0f, 0f, 1f);
-        mPreRender.setQuatCurrentOnNextRender();
-        mPreRender.setQuatAccumulatedOnNextRender();
-        }
-
-      mTempCurrent.set(quatFromDrag(mX-x,y-mY));
-      mPreRender.setQuatCurrentOnNextRender();
+      mTemp.set(quatMultiply(quatFromDrag(mX-x,y-mY), mQuat));
+      mPreRender.setQuatOnNextRender();
+      mX = x;
+      mY = y;
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -443,7 +417,7 @@ public class RubikSurfaceView extends GLSurfaceView
       mStartRotY = y;
 
       Static4D touchPoint2 = new Static4D(x, y, 0, 0);
-      Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuatAccumulated);
+      Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuat);
 
       Static2D res = mMovement.newRotation(rotatedTouchPoint2);
       RubikObject object = mPreRender.getObject();
@@ -486,10 +460,8 @@ public class RubikSurfaceView extends GLSurfaceView
       float x = (event.getX() - mScreenWidth*0.5f)/mScreenMin;
       float y = (mScreenHeight*0.5f -event.getY())/mScreenMin;
 
-
       //android.util.Log.e("view", "num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
 
-
       if( mBeginningRotation )
         {
         if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
@@ -517,10 +489,14 @@ public class RubikSurfaceView extends GLSurfaceView
       {
       mNumFingersDown++;
 
-      //android.util.Log.e("view", "down1 num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
+      int index = event.getActionIndex();
+      float x = event.getX();
+      float y = event.getY();
 
-      mX = (event.getX() - mScreenWidth*0.5f)/mScreenMin;
-      mY = (mScreenHeight*0.5f -event.getY())/mScreenMin;
+      android.util.Log.e("view", "down1 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
+
+      mX = (x - mScreenWidth*0.5f)/mScreenMin;
+      mY = (mScreenHeight*0.5f -y)/mScreenMin;
 
       setUpDragOrRotate(true,mX,mY);
       }
@@ -531,15 +507,11 @@ public class RubikSurfaceView extends GLSurfaceView
       {
       mNumFingersDown--;
 
-      //android.util.Log.e("view", "up1 num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
+      int index = event.getActionIndex();
+      float x = event.getX();
+      float y = event.getY();
 
-      if( mDragging )
-        {
-        mTempAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated));
-        mTempCurrent.set(0f, 0f, 0f, 1f);
-        mPreRender.setQuatCurrentOnNextRender();
-        mPreRender.setQuatAccumulatedOnNextRender();
-        }
+      android.util.Log.e("view", "up1 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
 
       if( mContinuingRotation )
         {
@@ -569,7 +541,11 @@ public class RubikSurfaceView extends GLSurfaceView
         finishRotation();
         }
 
-      //android.util.Log.e("view", "down2 num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
+      int index = event.getActionIndex();
+      float x = event.getX();
+      float y = event.getY();
+
+      android.util.Log.e("view", "down2 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -578,7 +554,11 @@ public class RubikSurfaceView extends GLSurfaceView
       {
       mNumFingersDown--;
 
-      //android.util.Log.e("view", "up2 num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
+      int index = event.getActionIndex();
+      float x = event.getX();
+      float y = event.getY();
+
+      android.util.Log.e("view", "up2 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/RubikCube.java b/src/main/java/org/distorted/objects/RubikCube.java
index 8d90c2e7..c069833b 100644
--- a/src/main/java/org/distorted/objects/RubikCube.java
+++ b/src/main/java/org/distorted/objects/RubikCube.java
@@ -99,10 +99,10 @@ class RubikCube extends RubikObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture,
+  RubikCube(int size, Static4D quat, DistortedTexture texture,
             MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res)
     {
-    super(size, 60, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.CUBE, res);
+    super(size, 60, quat, texture, mesh, effects, moves, RubikObjectList.CUBE, res);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/RubikObject.java b/src/main/java/org/distorted/objects/RubikObject.java
index 4ba67304..b83d6d89 100644
--- a/src/main/java/org/distorted/objects/RubikObject.java
+++ b/src/main/java/org/distorted/objects/RubikObject.java
@@ -69,7 +69,7 @@ public abstract class RubikObject extends DistortedNode
   private int mRotAxis;
   private Static3D[] mOrigPos;
   private Static3D mNodeScale;
-  private Static4D mQuatAccumulated;
+  private Static4D mQuat;
   private Cubit[] mCubits;
   private int mSize;
   private RubikObjectList mList;
@@ -85,13 +85,12 @@ public abstract class RubikObject extends DistortedNode
   DistortedTexture mTexture;
 
   MatrixEffectScale mScaleEffect;
-  MatrixEffectQuaternion mQuatCEffect;
-  MatrixEffectQuaternion mQuatAEffect;
+  MatrixEffectQuaternion mQuatEffect;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture,
-              MeshRectangles nodeMesh, DistortedEffects nodeEffects, int[][] moves, RubikObjectList list, Resources res)
+  RubikObject(int size, int fov, Static4D quat, DistortedTexture nodeTexture, MeshRectangles nodeMesh,
+              DistortedEffects nodeEffects, int[][] moves, RubikObjectList list, Resources res)
     {
     super(nodeTexture,nodeEffects,nodeMesh);
 
@@ -109,7 +108,7 @@ public abstract class RubikObject extends DistortedNode
     mSize = size;
     computeStartAndStep(mOrigPos);
     mNodeScale= new Static3D(1,1,1);
-    mQuatAccumulated = quatAcc;
+    mQuat = quat;
 
     mRotationAngle= new Dynamic1D();
     mRotationAxis = new Static3D(1,0,0);
@@ -121,8 +120,7 @@ public abstract class RubikObject extends DistortedNode
 
     float scale = OBJECT_SCREEN_RATIO*NODE_FBO_SIZE/mSize;
     mScaleEffect = new MatrixEffectScale(new Static3D(scale,scale,scale));
-    mQuatCEffect = new MatrixEffectQuaternion(quatCur, CENTER);
-    mQuatAEffect = new MatrixEffectQuaternion(quatAcc, CENTER);
+    mQuatEffect  = new MatrixEffectQuaternion(quat, CENTER);
 
     MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
     nodeEffects.apply(nodeScaleEffect);
@@ -163,8 +161,7 @@ public abstract class RubikObject extends DistortedNode
       }
 
     mEffects.apply(mRotateEffect);
-    mEffects.apply(mQuatAEffect);
-    mEffects.apply(mQuatCEffect);
+    mEffects.apply(mQuatEffect);
     mEffects.apply(mScaleEffect);
 
     attach( new DistortedNode(mTexture,mEffects,mMesh) );
@@ -349,7 +346,7 @@ public abstract class RubikObject extends DistortedNode
 
   public Static4D getRotationQuat()
       {
-      return mQuatAccumulated;
+      return mQuat;
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/RubikObjectList.java b/src/main/java/org/distorted/objects/RubikObjectList.java
index 715e4d32..99cda2e0 100644
--- a/src/main/java/org/distorted/objects/RubikObjectList.java
+++ b/src/main/java/org/distorted/objects/RubikObjectList.java
@@ -322,7 +322,7 @@ public enum RubikObjectList
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public RubikObject create(int size, Static4D quatCur, Static4D quatAcc, int[][] moves, Resources res)
+  public RubikObject create(int size, Static4D quat, int[][] moves, Resources res)
     {
     DistortedTexture texture = new DistortedTexture();
     DistortedEffects effects = new DistortedEffects();
@@ -330,8 +330,8 @@ public enum RubikObjectList
 
     switch(ordinal())
       {
-      case 0: return new RubikCube    (size, quatCur, quatAcc, texture, mesh, effects, moves, res);
-      case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects, moves, res);
+      case 0: return new RubikCube    (size, quat, texture, mesh, effects, moves, res);
+      case 1: return new RubikPyraminx(size, quat, texture, mesh, effects, moves, res);
       }
 
     return null;
diff --git a/src/main/java/org/distorted/objects/RubikPyraminx.java b/src/main/java/org/distorted/objects/RubikPyraminx.java
index eee28109..60f83a21 100644
--- a/src/main/java/org/distorted/objects/RubikPyraminx.java
+++ b/src/main/java/org/distorted/objects/RubikPyraminx.java
@@ -99,10 +99,10 @@ public class RubikPyraminx extends RubikObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture,
+  RubikPyraminx(int size, Static4D quat, DistortedTexture texture,
                 MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res)
     {
-    super(size, 30, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.PYRA, res);
+    super(size, 30, quat, texture, mesh, effects, moves, RubikObjectList.PYRA, res);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
