commit 84ddf691739951a0d2de42b8a3467380e4118a6c
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Mar 10 17:39:48 2020 +0000

    Fixes for the Projection matrix, FOV.
    
    There was a confusion between the Projection of the Node onto the Screen, and the Projection of the Cubits on the Node.

diff --git a/src/main/java/org/distorted/magic/RubikRenderer.java b/src/main/java/org/distorted/magic/RubikRenderer.java
index 4731f522..1d3cea11 100644
--- a/src/main/java/org/distorted/magic/RubikRenderer.java
+++ b/src/main/java/org/distorted/magic/RubikRenderer.java
@@ -39,7 +39,6 @@ import javax.microedition.khronos.opengles.GL10;
 
 public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
 {
-    static final float CAMERA_DISTANCE = 0.6f;  // 0.6 of the length of min(scrHeight,scrWidth)
     public static final int NODE_FBO_SIZE = 600;
 
     private RubikSurfaceView mView;
@@ -311,10 +310,6 @@ public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
       {
       if( mNewObject!=null ) mNewObject.createTexture();
 
-      double halfFOVInRadians = Math.atan( 1.0f/(2*CAMERA_DISTANCE) );
-      float fovInDegrees = (float)(2*halfFOVInRadians*(180/Math.PI));
-
-      mScreen.setProjection( fovInDegrees, 0.1f);
       mScreen.resize(width, height);
       mView.setScreenSize(width,height);
 
diff --git a/src/main/java/org/distorted/magic/RubikSurfaceView.java b/src/main/java/org/distorted/magic/RubikSurfaceView.java
index c417ef8e..25d3c775 100644
--- a/src/main/java/org/distorted/magic/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/magic/RubikSurfaceView.java
@@ -45,7 +45,16 @@ public class RubikSurfaceView extends GLSurfaceView
     // Every 1/12 the distance of min(scrWidth,scrHeight) the direction of cube rotation will reset.
     private final static int DIRECTION_SENSITIVITY=  12;
 
-    private final Static4D CAMERA_POINT = new Static4D(0, 0, RubikRenderer.CAMERA_DISTANCE, 0);
+    // 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.
+    // Take a look how the CAMERA_POINT is used in onTouchEvent - (x,y) there are expressed in sort of
+    // 'half-NDC' coordinates i.e. they range from +0.5 to -0.5; thus CAMERA_POINT also needs to be
+    // in 'half-NDC'. Since in this coordinate system the height of the screen is equal to 1, then the
+    // Z-distance from the center of the object to the camera is equal to (scrHeight/2)/tan(FOV/2) =
+    // 0.5/tan(30) = sqrt(3)/2.
+    // Why is the Z-distance between the camera and the object equal to (scrHeight/2)/tan(FOV/2)?
+    // Because of the way the View part of the ModelView matrix is constructed in EffectQueueMatrix.send().
+    private final Static4D CAMERA_POINT = new Static4D(0, 0, (float)Math.sqrt(3)*0.5f, 0);
 
     private RubikRenderer mRenderer;
     private RubikObjectMovement mMovement;
