commit c896c0b3a5e551135ad90d567a8953e296f498ae
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Feb 14 12:31:28 2020 +0000

    Simplifications for object movement.

diff --git a/src/main/java/org/distorted/magic/RubikSurfaceView.java b/src/main/java/org/distorted/magic/RubikSurfaceView.java
index cdd2afe6..4e52a23f 100644
--- a/src/main/java/org/distorted/magic/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/magic/RubikSurfaceView.java
@@ -54,7 +54,7 @@ public class RubikSurfaceView extends GLSurfaceView
     private int mButton = RubikSize.SIZE3.ordinal();
 
     private boolean mDragging, mBeginningRotation, mContinuingRotation;
-    private int mX, mY;
+    private float mX, mY;
     private int mLastTouchedFace;
     private float mCameraDistance;
     private int mScreenWidth, mScreenHeight, mScreenMin;
@@ -352,14 +352,14 @@ public class RubikSurfaceView extends GLSurfaceView
     public boolean onTouchEvent(MotionEvent event)
       {
       int action = event.getAction();
-      int x = (int)event.getX();
-      int y = (int)event.getY();
+      float x = event.getX() - mScreenWidth*0.5f;
+      float y = mScreenHeight*0.5f -event.getY();
 
       switch(action)
          {
          case MotionEvent.ACTION_DOWN: mX = x;
                                        mY = y;
-                                       mLastTouchedFace = mMovement.faceTouched(mQuatAccumulated,mCameraDistance, x,y, mScreenWidth, mScreenHeight);
+                                       mLastTouchedFace = mMovement.faceTouched(mQuatAccumulated,mCameraDistance, x, y);
 
                                        if( mLastTouchedFace != RubikCubeMovement.NONE )
                                          {
@@ -376,7 +376,7 @@ public class RubikSurfaceView extends GLSurfaceView
                                        break;
          case MotionEvent.ACTION_MOVE: if( mDragging )
                                          {
-                                         mTempCurrent.set(quatFromDrag(mX-x,mY-y));
+                                         mTempCurrent.set(quatFromDrag(mX-x,y-mY));
                                          mRenderer.setQuatCurrentOnNextRender();
 
                                          int minimumDist = (mScreenMin*mScreenMin)/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY);
@@ -397,14 +397,14 @@ public class RubikSurfaceView extends GLSurfaceView
 
                                          if( (mX-x)*(mX-x)+(mY-y)*(mY-y) > minimumDistToStartRotating )
                                            {
-                                           mMovement.addNewRotation(mQuatAccumulated,mLastTouchedFace, x,y, mScreenWidth, mScreenHeight);
+                                           mMovement.addNewRotation(mQuatAccumulated,mLastTouchedFace, x, y);
                                            mBeginningRotation = false;
                                            mContinuingRotation= true;
                                            }
                                          }
                                        else if( mContinuingRotation )
                                          {
-                                         mMovement.continueRotation(mQuatAccumulated,mLastTouchedFace, x,y, mScreenWidth, mScreenHeight);
+                                         mMovement.continueRotation(mQuatAccumulated,mLastTouchedFace, x, y, mScreenMin);
                                          }
                                        break;
          case MotionEvent.ACTION_UP  : if( mDragging )
diff --git a/src/main/java/org/distorted/object/RubikCubeMovement.java b/src/main/java/org/distorted/object/RubikCubeMovement.java
index 52488855..791f37c5 100644
--- a/src/main/java/org/distorted/object/RubikCubeMovement.java
+++ b/src/main/java/org/distorted/object/RubikCubeMovement.java
@@ -63,11 +63,9 @@ public class RubikCubeMovement
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    private void convertTouchPointToScreenSpace(Static4D accumulated, int x, int y, int scrW, int scrH)
+    private void convertTouchPointToScreenSpace(Static4D accumulated, float x, float y)
       {
-      float halfScrWidth  = scrW*0.5f;
-      float halfScrHeight = scrH*0.5f;
-      Static4D touchPoint = new Static4D(x-halfScrWidth, halfScrHeight-y, 0, 0);
+      Static4D touchPoint = new Static4D(x, y, 0, 0);
       Static4D rotatedTouchPoint= RubikSurfaceView.rotateVectorByInvertedQuat(touchPoint, accumulated);
 
       mPoint[0] = rotatedTouchPoint.get1();
@@ -192,11 +190,11 @@ public class RubikCubeMovement
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    public int faceTouched(Static4D accumulated, float cameraDistance, int x, int y, int scrW, int scrH)
+    public int faceTouched(Static4D accumulated, float cameraDistance, float x, float y)
       {
       float cubeHalfSize= mCube.returnCubeSizeInScreenSpace()*0.5f;
 
-      convertTouchPointToScreenSpace(accumulated,x,y, scrW, scrH);
+      convertTouchPointToScreenSpace(accumulated,x,y);
       convertCameraPointToScreenSpace(accumulated, cameraDistance);
 
       for(int face=FRONT; face<=BOTTOM; face++)
@@ -218,11 +216,11 @@ public class RubikCubeMovement
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    public void addNewRotation(Static4D accumulated, int lastTouchedFace, int x, int y, int scrW, int scrH)
+    public void addNewRotation(Static4D accumulated, int lastTouchedFace, float x, float y)
       {
       float cubeHalfSize= mCube.returnCubeSizeInScreenSpace()*0.5f;
 
-      convertTouchPointToScreenSpace(accumulated, x,y, scrW, scrH);
+      convertTouchPointToScreenSpace(accumulated,x,y);
       castTouchPointOntoFace(lastTouchedFace,cubeHalfSize,mDiff);
 
       mDiff[0] -= mTouchPointCastOntoFace[0];
@@ -243,9 +241,9 @@ public class RubikCubeMovement
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    public void continueRotation(Static4D accumulated, int lastTouchedFace, int x, int y, int scrW, int scrH)
+    public void continueRotation(Static4D accumulated, int lastTouchedFace, float x, float y, int scrMin)
       {
-      convertTouchPointToScreenSpace(accumulated, x,y, scrW, scrH);
+      convertTouchPointToScreenSpace(accumulated,x,y);
 
       mDiff[0] = mPoint[0]-mTouchPoint[0];
       mDiff[1] = mPoint[1]-mTouchPoint[1];
@@ -256,8 +254,6 @@ public class RubikCubeMovement
       int sign = retFaceRotationSign(lastTouchedFace);
       float angle = (mRotationVect==xAxis ? mDiff[yAxis] : -mDiff[xAxis]);
 
-      int scrMin = scrW<scrH ? scrW:scrH;
-
       mCube.continueRotation(SWIPING_SENSITIVITY*sign*angle/scrMin);
       }
 }
