commit 209ea1c7470f91ff0230b537bb77c39ad52d70b9
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Mar 12 21:47:30 2020 +0000

    1. library: new API DistortedNode.setProjection()
    2. cube: adjustments for Pyraminx.

diff --git a/src/main/java/org/distorted/library/main/DistortedNode.java b/src/main/java/org/distorted/library/main/DistortedNode.java
index 553b5f2..1314411 100644
--- a/src/main/java/org/distorted/library/main/DistortedNode.java
+++ b/src/main/java/org/distorted/library/main/DistortedNode.java
@@ -39,6 +39,8 @@ import java.util.Collections;
  */
 public class DistortedNode implements InternalChildrenList.Parent
   {
+  private static final int DEFAULT_FBO_SIZE = 100;
+
   private MeshBase mMesh;
   private DistortedEffects mEffects;
   private InternalSurface mSurface;
@@ -49,6 +51,7 @@ public class DistortedNode implements InternalChildrenList.Parent
 
   private int mFboW, mFboH, mFboDepthStencil;
   private boolean mRenderWayOIT;
+  private float mFOV, mNear;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -257,12 +260,19 @@ public class DistortedNode implements InternalChildrenList.Parent
         }
       else
         {
-        width = 100;
-        height= 100;
+        width = DEFAULT_FBO_SIZE;
+        height= DEFAULT_FBO_SIZE;
         }
       }
 
-    return new DistortedFramebuffer(1,mFboDepthStencil, InternalSurface.TYPE_TREE, width, height);
+    DistortedFramebuffer fbo = new DistortedFramebuffer(1,mFboDepthStencil, InternalSurface.TYPE_TREE, width, height);
+
+    if( mFOV!=InternalOutputSurface.DEFAULT_FOV || mNear!=InternalOutputSurface.DEFAULT_NEAR )
+      {
+      fbo.setProjection(mFOV,mNear);
+      }
+
+    return fbo;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -292,6 +302,9 @@ public class DistortedNode implements InternalChildrenList.Parent
     mParent        = null;
     mRenderWayOIT  = false;
 
+    mFOV = InternalOutputSurface.DEFAULT_FOV;
+    mNear= InternalOutputSurface.DEFAULT_NEAR;
+
     mFboW            = 0;  // i.e. take this from
     mFboH            = 0;  // mEffects's stretch{X,Y}
     mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL;
@@ -317,6 +330,9 @@ public class DistortedNode implements InternalChildrenList.Parent
     mParent       = null;
     mRenderWayOIT = false;
 
+    mFOV = InternalOutputSurface.DEFAULT_FOV;
+    mNear= InternalOutputSurface.DEFAULT_NEAR;
+
     mFboW            = node.mFboW;
     mFboH            = node.mFboH;
     mFboDepthStencil = node.mFboDepthStencil;
@@ -523,6 +539,42 @@ public class DistortedNode implements InternalChildrenList.Parent
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Set Projection Matrix for the Framebuffer contained in this Node.
+ * <p>
+ * If this Node is a Leaf and has no Framebuffer in it, this call does nothing.
+ *
+ * @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
+ *            Valid values: 0<=fov<180. FOV==0 means 'parallel projection'.
+ * @param near The Near plane.
+ */
+  public void setProjection(float fov, float near)
+    {
+    if( fov < 180.0f && fov >=0.0f )
+      {
+      mFOV = fov;
+      }
+
+    if( near<   1.0f && near> 0.0f )
+      {
+      mNear= near;
+      }
+    else if( near<=0.0f )
+      {
+      mNear = 0.01f;
+      }
+    else if( near>=1.0f )
+      {
+      mNear=0.99f;
+      }
+
+    if( mData.mFBO!=null )
+      {
+      mData.mFBO.setProjection(mFOV,mNear);
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Enables/disables DEPTH and STENCIL buffers in the Framebuffer object that we render this Node to.
diff --git a/src/main/java/org/distorted/library/main/InternalOutputSurface.java b/src/main/java/org/distorted/library/main/InternalOutputSurface.java
index c687f01..3b76a30 100644
--- a/src/main/java/org/distorted/library/main/InternalOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/InternalOutputSurface.java
@@ -38,6 +38,9 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
   public static final int DEPTH_NO_STENCIL    = 1;
   public static final int BOTH_DEPTH_STENCIL  = 2;
 
+  public static final float DEFAULT_FOV = 60.0f;
+  public static final float DEFAULT_NEAR=  0.1f;
+
   float mFOV, mDistance, mNear, mMipmap;
   float[] mProjectionMatrix;
   int mDepthStencilCreated, mDepthStencil;
@@ -74,8 +77,8 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
 
     mProjectionMatrix = new float[16];
 
-    mFOV = 60.0f;
-    mNear=  0.5f;
+    mFOV = DEFAULT_FOV;
+    mNear= DEFAULT_NEAR;
 
     mDepthStencilCreated= (depthStencil== NO_DEPTH_NO_STENCIL ? DONT_CREATE:NOT_CREATED_YET);
     mDepthStencil = depthStencil;
@@ -227,8 +230,8 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
 
         surface.createProjection();
 
-        int maxw = surface.mWidth  > surface.mRealWidth  ? surface.mWidth  : surface.mRealWidth;
-        int maxh = surface.mHeight > surface.mRealHeight ? surface.mHeight : surface.mRealHeight;
+        int maxw = Math.max(surface.mWidth , surface.mRealWidth );
+        int maxh = Math.max(surface.mHeight, surface.mRealHeight);
 
         if (maxw > surface.mRealWidth || maxh > surface.mRealHeight)
           {
