commit eada161a38d8c972160b8debc1b289c1f3743dd8
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Mon Nov 14 17:41:43 2016 +0000

    Make the effect Center be always 3D.

diff --git a/src/main/java/org/distorted/library/DistortedObject.java b/src/main/java/org/distorted/library/DistortedObject.java
index ea05c04..86c00c7 100644
--- a/src/main/java/org/distorted/library/DistortedObject.java
+++ b/src/main/java/org/distorted/library/DistortedObject.java
@@ -723,11 +723,11 @@ public abstract class DistortedObject
  *
  * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
  *               currently being dragged with.
- * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
+ * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
  * @param region Region that masks the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
  */
-  public long distort(Data3D vector, Data2D center, Data4D region)
+  public long distort(Data3D vector, Data3D center, Data4D region)
     {  
     return mV.add(EffectNames.DISTORT, vector, center, region);
     }
@@ -738,10 +738,10 @@ public abstract class DistortedObject
  *
  * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
  *               currently being dragged with.
- * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
+ * @param center 3-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 distort(Data3D vector, Data2D center)
+  public long distort(Data3D vector, Data3D center)
     {
     return mV.add(EffectNames.DISTORT, vector, center, null);
     }
@@ -752,10 +752,10 @@ public abstract class DistortedObject
  * a (possibly changing in time) point on the Object.
  *     
  * @param vector Vector of force that deforms the shape of the whole Object.
- * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
+ * @param center 3-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 deform(Data3D vector, Data2D center)
+  public long deform(Data3D vector, Data3D center)
     {  
     return mV.add(EffectNames.DEFORM, vector, center, null);
     }
@@ -766,11 +766,11 @@ public abstract class DistortedObject
  * away from the center (degree<=1)
  *
  * @param sink   The current degree of the Effect.
- * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
+ * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
  * @param region Region that masks the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
  */
-  public long sink(Data1D sink, Data2D center, Data4D region)
+  public long sink(Data1D sink, Data3D center, Data4D region)
     {
     return mV.add(EffectNames.SINK, sink, center, region);
     }
@@ -781,10 +781,10 @@ public abstract class DistortedObject
  * away from the center (degree<=1)
  *
  * @param sink   The current degree of the Effect.
- * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
+ * @param center 3-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 sink(Data1D sink, Data2D center)
+  public long sink(Data1D sink, Data3D center)
     {
     return mV.add(EffectNames.SINK, sink, center);
     }
@@ -794,11 +794,11 @@ public abstract class DistortedObject
  * Rotate part of the Object around the Center of the Effect by a certain angle.
  *
  * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
- * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
+ * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
  * @param region Region that masks the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
  */
-  public long swirl(Data1D swirl, Data2D center, Data4D region)
+  public long swirl(Data1D swirl, Data3D center, Data4D region)
     {    
     return mV.add(EffectNames.SWIRL, swirl, center, region);
     }
@@ -808,10 +808,10 @@ public abstract class DistortedObject
  * Rotate the whole Object around the Center of the Effect by a certain angle.
  *
  * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
- * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
+ * @param center 3-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 swirl(Data1D swirl, Data2D center)
+  public long swirl(Data1D swirl, Data3D center)
     {
     return mV.add(EffectNames.SWIRL, swirl, center);
     }
@@ -842,10 +842,10 @@ public abstract class DistortedObject
  *               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 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.
+ * @param center 3-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(Data5D wave, Data2D center)
+  public long wave(Data5D wave, Data3D center)
     {
     return mV.add(EffectNames.WAVE, wave, center, null);
     }
@@ -855,11 +855,11 @@ public abstract class DistortedObject
  * Directional, sinusoidal wave effect.
  *
  * @param wave   see {@link DistortedObject#wave(Data5D,Data2D)}
- * @param center see {@link DistortedObject#wave(Data5D,Data2D)}
+ * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
  * @param region Region that masks the Effect.
  * @return       ID of the effect added, or -1 if we failed to add one.
  */
-  public long wave(Data5D wave, Data2D center, Data4D region)
+  public long wave(Data5D wave, Data3D center, Data4D region)
     {
     return mV.add(EffectNames.WAVE, wave, center, region);
     }
diff --git a/src/main/java/org/distorted/library/EffectNames.java b/src/main/java/org/distorted/library/EffectNames.java
index 3d70f95..4ed254d 100644
--- a/src/main/java/org/distorted/library/EffectNames.java
+++ b/src/main/java/org/distorted/library/EffectNames.java
@@ -53,7 +53,7 @@ public enum EffectNames
    * <p>
    * Unity: angle==0
    */
-  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           , 1, false, true ),
+  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           , 4, false, true ),
  /**
    * Rotate the whole Object around a center point (in quaternion notation).
    * <p>
@@ -90,13 +90,13 @@ public enum EffectNames
 
  /////////////////////////////////////////////////////////////////////////////////
  // VERTEX EFFECTS
- // Always 12 Uniforms: 6 per-effect interpolated values, 2-dimensional center of
+ // Always 12 Uniforms: 5 per-effect interpolated values, 3-dimensional center of
  // the effect, 4-dimensional Region
  /**
    * Apply a 3D vector of force to area around a point on the surface of the Object.
    * <p>
    * Uniforms: (forceX ,forceY ,forceZ  ,UNUSED  ,
-   *            UNUSED , UNUSED,centerX ,centerY ,
+   *            UNUSED , centerX ,centerY , centerZ,
    *            regionX,regionY,regionRX,regionRY)
    * <p>
    * Unity: (forceX,forceY,forceZ) = (0,0,0)
@@ -106,7 +106,7 @@ public enum EffectNames
    * Deform the whole Object by applying a 2D vector of force to a center point.
    * <p>
    * Uniforms: (forceX,forceY,UNUSED,UNUSED,
-   *            UNUSED,UNUSED,centerX,centerY,
+   *            UNUSED,centerX,centerY,centerZ,
    *            UNUSED,UNUSED,UNUSED,UNUSED)
    * <p>
    * Unity: (forceX,forceY) = (0,0)
@@ -116,7 +116,7 @@ public enum EffectNames
    * Pull (or push away) all points around a center point to (from) it.
    * <p>
    * Uniforms: (sinkFactor,UNUSED,UNUSED,UNUSED,
-   *            UNUSED,UNUSED,centerX,centerY,
+   *            UNUSED,centerX,centerY,centerZ,
    *            regionX,regionY,regionRX,regionRY)
    * <p>
    * Unity: sinkFactor = 1
@@ -126,7 +126,7 @@ public enum EffectNames
    * Smoothly rotate a limited area around a center point.
    * <p>
    * Uniforms: (swirlAngle,UNUSED,UNUSED,UNUSED,
-   *            UNUSED, UNUSED,centerX,centerY,
+   *            UNUSED, centerX,centerY,centerZ,
    *            regionX,regionY,regionRX,regionRY)
    * <p>
    * Unity: swirlAngle = 0
@@ -137,7 +137,7 @@ public enum EffectNames
    * parameters. Details: {@link DistortedObject#wave(Data5D,Data2D)}
    * <p>
    * Uniforms: (amplitude,length,phase,angleAlpha,
-   *            angleBeta, UNUSED,centerX,centerY,
+   *            angleBeta,centerX,centerY,centerZ,
    *            regionX,regionY,regionRX,regionRY)
    * <p>
    * Unity: amplitude  = 0
diff --git a/src/main/java/org/distorted/library/EffectQueueVertex.java b/src/main/java/org/distorted/library/EffectQueueVertex.java
index 8f0ac99..0433c59 100644
--- a/src/main/java/org/distorted/library/EffectQueueVertex.java
+++ b/src/main/java/org/distorted/library/EffectQueueVertex.java
@@ -109,10 +109,11 @@ class EffectQueueVertex extends EffectQueue
 
       if( mInter[2][i]!=null )  // center
         {
-        mInter[2][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+6, mCurrentDuration[i], step);
+        mInter[2][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+5, mCurrentDuration[i], step);
 
-        mUniforms[NUM_UNIFORMS*i+6] = mUniforms[NUM_UNIFORMS*i+6]-mObjHalfX;
-        mUniforms[NUM_UNIFORMS*i+7] =-mUniforms[NUM_UNIFORMS*i+7]+mObjHalfY;
+        mUniforms[NUM_UNIFORMS*i+5] = mUniforms[NUM_UNIFORMS*i+5]-mObjHalfX;
+        mUniforms[NUM_UNIFORMS*i+6] =-mUniforms[NUM_UNIFORMS*i+6]+mObjHalfY;
+        mUniforms[NUM_UNIFORMS*i+7] = mUniforms[NUM_UNIFORMS*i+7]-mObjHalfZ;
         }
 
       mCurrentDuration[i] += step;
@@ -187,7 +188,7 @@ class EffectQueueVertex extends EffectQueue
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // wave
 
-  synchronized long add(EffectNames eln, Data5D data, Data2D center, Data4D region)
+  synchronized long add(EffectNames eln, Data5D data, Data3D center, Data4D region)
     {
     if( mMax[INDEX]>mNumEffects )
       {
@@ -218,7 +219,7 @@ class EffectQueueVertex extends EffectQueue
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // deform,distort
 
-  synchronized long add(EffectNames eln, Data3D data, Data2D center, Data4D region)
+  synchronized long add(EffectNames eln, Data3D data, Data3D center, Data4D region)
     {
     if( mMax[INDEX]>mNumEffects )
       {
@@ -247,7 +248,7 @@ class EffectQueueVertex extends EffectQueue
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // sink, swirl
 
-  synchronized long add(EffectNames eln, Data1D data, Data2D center, Data4D region)
+  synchronized long add(EffectNames eln, Data1D data, Data3D center, Data4D region)
     {
     if( mMax[INDEX]>mNumEffects )
       {
@@ -272,7 +273,7 @@ class EffectQueueVertex extends EffectQueue
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // sink, swirl
 
-  synchronized long add(EffectNames eln, Data1D data, Data2D center)
+  synchronized long add(EffectNames eln, Data1D data, Data3D center)
     {
     if( mMax[INDEX]>mNumEffects )
       {
@@ -296,7 +297,7 @@ class EffectQueueVertex extends EffectQueue
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
   
-  private long addPriv(EffectNames eln, Data2D center, Data4D region)
+  private long addPriv(EffectNames eln, Data3D center, Data4D region)
     {
     if( region!=null )
       {
@@ -327,15 +328,16 @@ class EffectQueueVertex extends EffectQueue
       mInter[1][mNumEffects] = null;
       }
 
-    if( center instanceof Dynamic2D)
+    if( center instanceof Dynamic3D)
       {
-      mInter[2][mNumEffects] = (Dynamic2D)center;
+      mInter[2][mNumEffects] = (Dynamic3D)center;
       }
-    else if( center instanceof Static2D)
+    else if( center instanceof Static3D)
       {
       mInter[2][mNumEffects] = null;
-      mUniforms[NUM_UNIFORMS*mNumEffects+6] = ((Static2D)center).getX()-mObjHalfX;
-      mUniforms[NUM_UNIFORMS*mNumEffects+7] =-((Static2D)center).getY()+mObjHalfY;
+      mUniforms[NUM_UNIFORMS*mNumEffects+5] = ((Static3D)center).getX()-mObjHalfX;
+      mUniforms[NUM_UNIFORMS*mNumEffects+6] =-((Static3D)center).getY()+mObjHalfY;
+      mUniforms[NUM_UNIFORMS*mNumEffects+7] = ((Static3D)center).getZ()-mObjHalfZ;
       }
 
     long ret= addBase(eln);
diff --git a/src/main/res/raw/main_vertex_shader.glsl b/src/main/res/raw/main_vertex_shader.glsl
index 1c97a5d..09c950d 100644
--- a/src/main/res/raw/main_vertex_shader.glsl
+++ b/src/main/res/raw/main_vertex_shader.glsl
@@ -208,7 +208,7 @@ void restrictZ(inout float v)
   
 void deform(in int effect, inout vec4 v)
   {
-  vec2 center = vUniforms[effect+1].zw;
+  vec2 center = vUniforms[effect+1].yz;
   vec2 force = vUniforms[effect].xy;    // force = vec(MM')
   vec2 vert_vec, horz_vec; 
   vec2 signXY = sign(center-v.xy);
@@ -286,7 +286,7 @@ void deform(in int effect, inout vec4 v)
         
 void distort(in int effect, inout vec4 v, inout vec4 n)
   {
-  vec2 center = vUniforms[effect+1].zw;
+  vec2 center = vUniforms[effect+1].yz;
   vec2 ps = center-v.xy;
   vec3 force = vUniforms[effect].xyz;
   float d = degree(vUniforms[effect+2],center,ps);
@@ -314,7 +314,7 @@ void distort(in int effect, inout vec4 v, inout vec4 n)
  
 void sink(in int effect,inout vec4 v)
   {
-  vec2 center = vUniforms[effect+1].zw;
+  vec2 center = vUniforms[effect+1].yz;
   vec2 ps = center-v.xy;
   float h = vUniforms[effect].x;
   float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h);
@@ -331,7 +331,7 @@ void sink(in int effect,inout vec4 v)
 
 void swirl(in int effect, inout vec4 v)
   {
-  vec2 center  = vUniforms[effect+1].zw;
+  vec2 center  = vUniforms[effect+1].yz;
   vec2 PS = center-v.xy;
   vec4 SO = vUniforms[effect+2];
   float d1_circle = degree_region(SO,PS);
@@ -416,7 +416,7 @@ void swirl(in int effect, inout vec4 v)
 
 void wave(in int effect, inout vec4 v, inout vec4 n)
   {
-  vec2 center     = vUniforms[effect+1].zw;
+  vec2 center     = vUniforms[effect+1].yz;
   float amplitude = vUniforms[effect  ].x;
   float length    = vUniforms[effect  ].y;
 
