commit 98455aa28e1a9014323b35f51700ec0d451d63b6
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Wed Dec 7 23:58:47 2016 +0000

    Turn the former 'FOV' app into 'Projection' app that also checks the (x,y) the camera looks at.

diff --git a/src/main/java/org/distorted/library/Distorted.java b/src/main/java/org/distorted/library/Distorted.java
index 220b3f2..927939d 100644
--- a/src/main/java/org/distorted/library/Distorted.java
+++ b/src/main/java/org/distorted/library/Distorted.java
@@ -91,7 +91,7 @@ public class Distorted
   static int mTextureCoordH;    // pass in model texture coordinate information.
   static int mProgramH;         // This is a handle to our shading program.
 
-  static DistortedFramebuffer mFramebuffer = new DistortedFramebuffer(0);
+  static DistortedFramebuffer mFramebuffer = new DistortedFramebuffer(0); // output to the screen
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -284,15 +284,17 @@ public class Distorted
 // Public API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Sets Vertical Field of View angle. This changes the Projection Matrix.  
+ * Sets Vertical Field of View angle and the point the camera is looking at. This changes the Projection Matrix.
  *   
  * @param fov Vertical Field Of View angle, in degrees. If T is the middle of the top edge of the 
  *            screen, E is the eye point, and B is the middle of the bottom edge of the screen, then 
  *            fov = angle(TEB)
+ * @param x   X-coordinate of the point the camera is looking at. -scrWidth/2 &lt; x &lt; scrWidth/2
+ * @param y   Y-coordinate of the point the camera is looking at. -scrHeight/2 &lt; y &lt; scrHeight/2
  */
-  public static void setFov(float fov)
+  public static void setProjection(float fov, float x, float y)
     {
-    mFramebuffer.setProjection(fov,0.0f,0.0f);
+    mFramebuffer.setProjection(fov,x,y);
     }
   
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/DistortedFramebuffer.java b/src/main/java/org/distorted/library/DistortedFramebuffer.java
index 59356be..cb26f49 100644
--- a/src/main/java/org/distorted/library/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/DistortedFramebuffer.java
@@ -63,38 +63,34 @@ public class DistortedFramebuffer
 
   private void createProjection()
     {
-    if( mFOV>0.0f )  // perspective projection
+    if( mWidth>0 && mHeight>0 )
       {
-      float ratio  = (float) mWidth / mHeight;
-      float left   =-ratio;
-      float right  = ratio;
-      float bottom = -1.0f;
-      float top    =  1.0f;
-      float near= (float)(top / Math.tan(mFOV*Math.PI/360));
-      mDistance = (int)(mHeight*near/(top-bottom));
-      float far = 2*mDistance-near;
-      mDepth = (int)((far-near)/2);
-
-      if( far<=0 )
+      if( mFOV>0.0f )  // perspective projection
         {
-        android.util.Log.e("FBO", "error: far<=0. width="+mWidth+" height="+mHeight+
-                           " mFOV="+mFOV+" mDistance="+mDistance+" far="+far+" near="+near);
-        }
-      else
+        float left   =(-mX-mWidth )/mHeight;
+        float right  =(-mX+mWidth )/mHeight;
+        float bottom =(-mY-mHeight)/mHeight;
+        float top    =(-mY+mHeight)/mHeight;
+        float near= (float)( (top-bottom) / (2*Math.tan(mFOV*Math.PI/360)) );
+        mDistance = (int)(mHeight*near/(top-bottom));
+        float far = 2*mDistance-near;
+        mDepth = (int)((far-near)/2);
+
         Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
-      }
-    else             // parallel projection
-      {
-      float left   =-mWidth/2;
-      float right  = mWidth/2;
-      float bottom =-mHeight/2;
-      float top    = mHeight/2;
-      float near= (float)(top / Math.tan(Math.PI/360));
-      mDistance = (int)(mHeight*near/(top-bottom));
-      float far = 2*mDistance-near;
-      mDepth = (int)((far-near)/2);
-
-      Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
+        }
+      else             // parallel projection
+        {
+        float left   =-mX-mWidth/2;
+        float right  =-mX+mWidth/2;
+        float bottom =-mY-mHeight/2;
+        float top    =-mY+mHeight/2;
+        float near= (float)( (top-bottom) / (2*Math.tan(Math.PI/360)) );
+        mDistance = (int)(mHeight*near/(top-bottom));
+        float far = 2*mDistance-near;
+        mDepth = (int)((far-near)/2);
+
+        Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
+        }
       }
     }
 
diff --git a/src/main/java/org/distorted/library/EffectTypes.java b/src/main/java/org/distorted/library/EffectTypes.java
index ad18dbc..101c6a4 100644
--- a/src/main/java/org/distorted/library/EffectTypes.java
+++ b/src/main/java/org/distorted/library/EffectTypes.java
@@ -63,7 +63,7 @@ public enum EffectTypes
                       // EffectQueueMatrix.setMax(int)
 
     maxtable[1] = 5;  // Max 5 VERTEX Effects
-    maxtable[2] = 3;  // Max 3 FRAGMENT Effects
+    maxtable[2] = 5;  // Max 3 FRAGMENT Effects
     }
 ///////////////////////////////////////////////////////////////////////////////////////////////////
   }
