commit 350cc2f5c3421759651efed484d9de137d733253
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Tue Oct 18 12:19:31 2016 +0100

    Make the WAVE effect 5D (extra parameter 'offset')

diff --git a/src/main/java/org/distorted/library/Distorted.java b/src/main/java/org/distorted/library/Distorted.java
index b87126e..7f0f8e5 100644
--- a/src/main/java/org/distorted/library/Distorted.java
+++ b/src/main/java/org/distorted/library/Distorted.java
@@ -85,11 +85,11 @@ public class Distorted
   private static final String TAG = Distorted.class.getSimpleName();
   private static boolean mInitialized = false;
   
-  static int mPositionH;      // pass in model position information
-  static int mTextureUniformH;// pass in the texture.
-  static int mNormalH;        // pass in model normal information.
-  static int mTextureCoordH;  // pass in model texture coordinate information.
-  static int mProgramH;       // This is a handle to our shading program.  
+  static int mPositionH;        // pass in model position information
+  static int mTextureUniformH;  // pass in the texture.
+  static int mNormalH;          // pass in model normal information.
+  static int mTextureCoordH;    // pass in model texture coordinate information.
+  static int mProgramH;         // This is a handle to our shading program.
 
   static DistortedProjection mProjection = new DistortedProjection();
   static float mFOV = 60.0f;
diff --git a/src/main/java/org/distorted/library/DistortedBitmap.java b/src/main/java/org/distorted/library/DistortedBitmap.java
index 31e8685..63e7b19 100644
--- a/src/main/java/org/distorted/library/DistortedBitmap.java
+++ b/src/main/java/org/distorted/library/DistortedBitmap.java
@@ -104,7 +104,7 @@ public class DistortedBitmap extends DistortedObject
  * Copy constructor.
  *
  * @param db Object to copy
- * @param flags {@see DistortedObject#DistortedObject(DistortedObject,int)}
+ * @param flags see {@see DistortedObject#DistortedObject(DistortedObject,int)}
  */
    public DistortedBitmap(DistortedBitmap db, int flags)
      {
diff --git a/src/main/java/org/distorted/library/DistortedCubes.java b/src/main/java/org/distorted/library/DistortedCubes.java
index 9cf9852..8e639bc 100644
--- a/src/main/java/org/distorted/library/DistortedCubes.java
+++ b/src/main/java/org/distorted/library/DistortedCubes.java
@@ -102,7 +102,7 @@ public class DistortedCubes extends DistortedObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Convenience constructor
+ * Convenience constructor.
  */
  public DistortedCubes(int cols, String desc, int gridSize)
    {
@@ -114,7 +114,7 @@ public class DistortedCubes extends DistortedObject
  * Copy constructor.
  *
  * @param dc Object to copy
- * @param flags {@see DistortedObject#DistortedObject(DistortedObject,int)}
+ * @param flags see {@see DistortedObject#DistortedObject(DistortedObject,int)}
  */
  public DistortedCubes(DistortedCubes dc, int flags)
    {
diff --git a/src/main/java/org/distorted/library/DistortedObject.java b/src/main/java/org/distorted/library/DistortedObject.java
index 4efc903..48b81f7 100644
--- a/src/main/java/org/distorted/library/DistortedObject.java
+++ b/src/main/java/org/distorted/library/DistortedObject.java
@@ -29,6 +29,7 @@ import org.distorted.library.type.Data1D;
 import org.distorted.library.type.Data2D;
 import org.distorted.library.type.Data3D;
 import org.distorted.library.type.Data4D;
+import org.distorted.library.type.Data5D;
 import org.distorted.library.type.Static3D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -816,8 +817,10 @@ public abstract class DistortedObject
 /**
  * Directional, sinusoidal wave effect.
  *
- * @param wave   A 4-dimensional data structure describing the wave: first member is the amplitude,
- *               second is the wave length, and the next two describe the 'direction' of the wave.
+ * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
+ *               second is the wave length, third is the offset (i.e. when offset = PI/2, the sine
+ *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
+ *               describe the 'direction' of the wave.
  *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
  *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
  *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
@@ -830,11 +833,12 @@ public abstract class DistortedObject
  *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
  *               YZ-plane with be sine shapes.
  *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
- *               is entirely 'horizontal' and moves point (x,y,0) in direction V.
+ *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
+ *               value if sin at this point.
  * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
  */
-  public long wave(Data4D wave, Data2D center)
+  public long wave(Data5D wave, Data2D center)
     {
     return mV.add(EffectNames.WAVE, wave, center, null);
     }
@@ -843,26 +847,12 @@ public abstract class DistortedObject
 /**
  * Directional, sinusoidal wave effect.
  *
- * @param wave   A 4-dimensional data structure describing the wave: first member is the amplitude,
- *               second is the wave length, and the next two describe the 'direction' of the wave.
- *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
- *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
- *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
- *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
- *
- *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
- *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
- *               will be sine shapes.
- *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
- *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
- *               YZ-plane with be sine shapes.
- *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
- *               is entirely 'horizontal' and moves point (x,y,0) in direction V.
- * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
+ * @param wave   see {@see wave(Data5D,Data2D)}
+ * @param center see {@see wave(Data5D,Data2D)}
  * @param region Region that masks the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
  */
-  public long wave(Data4D wave, Data2D center, Data4D region)
+  public long wave(Data5D wave, Data2D center, Data4D region)
     {
     return mV.add(EffectNames.WAVE, wave, center, region);
     }
diff --git a/src/main/java/org/distorted/library/EffectQueueFragment.java b/src/main/java/org/distorted/library/EffectQueueFragment.java
index 85e90dd..03e3989 100644
--- a/src/main/java/org/distorted/library/EffectQueueFragment.java
+++ b/src/main/java/org/distorted/library/EffectQueueFragment.java
@@ -44,7 +44,7 @@ class EffectQueueFragment extends EffectQueue
   
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
-  public EffectQueueFragment(DistortedObject obj)
+  EffectQueueFragment(DistortedObject obj)
     { 
     super(obj,NUM_UNIFORMS,INDEX);
     }
diff --git a/src/main/java/org/distorted/library/EffectQueueMatrix.java b/src/main/java/org/distorted/library/EffectQueueMatrix.java
index 4b746f8..3fd011f 100644
--- a/src/main/java/org/distorted/library/EffectQueueMatrix.java
+++ b/src/main/java/org/distorted/library/EffectQueueMatrix.java
@@ -50,7 +50,7 @@ class EffectQueueMatrix extends EffectQueue
   
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
-  public EffectQueueMatrix(DistortedObject obj)
+  EffectQueueMatrix(DistortedObject obj)
     { 
     super(obj,NUM_UNIFORMS, INDEX );
     }
diff --git a/src/main/java/org/distorted/library/EffectQueueVertex.java b/src/main/java/org/distorted/library/EffectQueueVertex.java
index 3b65bfb..61b876f 100644
--- a/src/main/java/org/distorted/library/EffectQueueVertex.java
+++ b/src/main/java/org/distorted/library/EffectQueueVertex.java
@@ -26,14 +26,17 @@ import org.distorted.library.type.Data1D;
 import org.distorted.library.type.Data2D;
 import org.distorted.library.type.Data3D;
 import org.distorted.library.type.Data4D;
+import org.distorted.library.type.Data5D;
 import org.distorted.library.type.Dynamic1D;
 import org.distorted.library.type.Dynamic2D;
 import org.distorted.library.type.Dynamic3D;
 import org.distorted.library.type.Dynamic4D;
+import org.distorted.library.type.Dynamic5D;
 import org.distorted.library.type.Static1D;
 import org.distorted.library.type.Static2D;
 import org.distorted.library.type.Static3D;
 import org.distorted.library.type.Static4D;
+import org.distorted.library.type.Static5D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -47,7 +50,7 @@ class EffectQueueVertex extends EffectQueue
   
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
-  public EffectQueueVertex(DistortedObject obj)
+  EffectQueueVertex(DistortedObject obj)
     { 
     super(obj,NUM_UNIFORMS,INDEX);
     }
@@ -157,11 +160,11 @@ class EffectQueueVertex extends EffectQueue
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Do various post-processing on already computed effects.
 // 1) here unlike in the fragment queue, we don't have to multiply the points by ModelView matrix because that gets done in the shader.
-// 2) in case of SWIRL, switch the angle from degrees to radians
+// 2) in case of SWIRL, switch the angles from degrees to radians
 // 3) likewise in case of WAVE
 // 4) In case of DISTORT, invert the Y-axis
   
-  void postprocess(int effect)
+  private void postprocess(int effect)
     {
     if( mName[effect]==EffectNames.SWIRL.ordinal() )
       {
@@ -171,6 +174,7 @@ class EffectQueueVertex extends EffectQueue
       {
       mUniforms[NUM_UNIFORMS*effect+2] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+2]/180);
       mUniforms[NUM_UNIFORMS*effect+3] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+3]/180);
+      mUniforms[NUM_UNIFORMS*effect+4] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+4]/180);
       }
     if( mName[effect]==EffectNames.DISTORT.ordinal() )
       {
@@ -181,21 +185,24 @@ class EffectQueueVertex extends EffectQueue
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // wave
 
-  synchronized long add(EffectNames eln, Data4D data, Data2D center, Data4D region)
+  synchronized long add(EffectNames eln, Data5D data, Data2D center, Data4D region)
     {
     if( mMax[INDEX]>mNumEffects )
       {
       EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
 
-      if( data instanceof Dynamic4D)
-        mInter[0][mNumEffects] = (Dynamic4D)data;
-      else if( data instanceof Static4D)
+      if( data instanceof Dynamic5D)
+        mInter[0][mNumEffects] = (Dynamic5D)data;
+      else if( data instanceof Static5D)
         {
+        Static5D tmp = (Static5D)data;
+
         mInter[0][mNumEffects] = null;
-        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static4D)data).getX();
-        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static4D)data).getY();
-        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static4D)data).getZ();
-        mUniforms[NUM_UNIFORMS*mNumEffects+3] = ((Static4D)data).getW();
+        mUniforms[NUM_UNIFORMS*mNumEffects  ] = tmp.getX();
+        mUniforms[NUM_UNIFORMS*mNumEffects+1] = tmp.getY();
+        mUniforms[NUM_UNIFORMS*mNumEffects+2] = tmp.getZ();
+        mUniforms[NUM_UNIFORMS*mNumEffects+3] = tmp.getW();
+        mUniforms[NUM_UNIFORMS*mNumEffects+4] = tmp.getV();
         }
 
       return addPriv(eln,center,region);
@@ -217,10 +224,12 @@ class EffectQueueVertex extends EffectQueue
         mInter[0][mNumEffects] = (Dynamic3D)data;
       else if( data instanceof Static3D)
         {
+        Static3D tmp = (Static3D)data;
+
         mInter[0][mNumEffects] = null;
-        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static3D)data).getX();
-        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)data).getY();
-        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)data).getZ();
+        mUniforms[NUM_UNIFORMS*mNumEffects  ] = tmp.getX();
+        mUniforms[NUM_UNIFORMS*mNumEffects+1] = tmp.getY();
+        mUniforms[NUM_UNIFORMS*mNumEffects+2] = tmp.getZ();
         }
 
       return addPriv(eln,center,region);
diff --git a/src/main/java/org/distorted/library/type/Dynamic1D.java b/src/main/java/org/distorted/library/type/Dynamic1D.java
index 0e7386d..74afe65 100644
--- a/src/main/java/org/distorted/library/type/Dynamic1D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic1D.java
@@ -24,7 +24,7 @@ import java.util.Vector;
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /** 
 * A 1-dimensional implementation of the Dynamic class to interpolate between a list
-* of Float1Ds.
+* of Static1Ds.
 */
 
 public class Dynamic1D extends Dynamic implements Data1D
diff --git a/src/main/java/org/distorted/library/type/Dynamic2D.java b/src/main/java/org/distorted/library/type/Dynamic2D.java
index c634cb7..9015988 100644
--- a/src/main/java/org/distorted/library/type/Dynamic2D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic2D.java
@@ -24,7 +24,7 @@ import java.util.Vector;
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /** 
 * A 2-dimensional implementation of the Dynamic class to interpolate between a list
-* of Float2Ds.
+* of Static2Ds.
 */
 
 public class Dynamic2D extends Dynamic implements Data2D
diff --git a/src/main/java/org/distorted/library/type/Dynamic3D.java b/src/main/java/org/distorted/library/type/Dynamic3D.java
index dda2bf0..94f0dc4 100644
--- a/src/main/java/org/distorted/library/type/Dynamic3D.java
+++ b/src/main/java/org/distorted/library/type/Dynamic3D.java
@@ -24,7 +24,7 @@ import java.util.Vector;
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /** 
 * A 3-dimensional implementation of the Dynamic class to interpolate between a list
-* of Float3Ds.
+* of Static3Ds.
 */
 
 public class Dynamic3D extends Dynamic implements Data3D
diff --git a/src/main/res/raw/main_vertex_shader.glsl b/src/main/res/raw/main_vertex_shader.glsl
index 84d3825..fe1d1b7 100644
--- a/src/main/res/raw/main_vertex_shader.glsl
+++ b/src/main/res/raw/main_vertex_shader.glsl
@@ -425,17 +425,18 @@ void wave(in int effect, inout vec4 v, inout vec4 n)
 
   if( deg != 0.0 && length != 0.0 )
     {
-    float alpha = vUniforms[effect].z;
-    float beta  = vUniforms[effect].w;
+    float offset= vUniforms[effect  ].z;
+    float alpha = vUniforms[effect  ].w;
+    float beta  = vUniforms[effect+1].x;
 
     float sinA = sin(alpha);
     float cosA = cos(alpha);
     float sinB = sin(beta);
     float cosB = cos(beta);
 
-    float angle= 1.578*(ps.x*cosB-ps.y*sinB) / length;
+    float angle= 1.578*(ps.x*cosB-ps.y*sinB) / length + offset;
 
-    vec3 dir   = vec3(sinB*cosA,cosB*cosA,sinA);
+    vec3 dir= vec3(sinB*cosA,cosB*cosA,sinA);
 
     v.xyz += sin(angle)*deg*dir;
 
