Project

General

Profile

« Previous | Next » 

Revision eada161a

Added by Leszek Koltunski over 7 years ago

Make the effect Center be always 3D.

View differences:

src/main/java/org/distorted/library/DistortedObject.java
723 723
 *
724 724
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
725 725
 *               currently being dragged with.
726
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
726
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
727 727
 * @param region Region that masks the Effect.
728 728
 * @return       ID of the effect added, or -1 if we failed to add one.
729 729
 */
730
  public long distort(Data3D vector, Data2D center, Data4D region)
730
  public long distort(Data3D vector, Data3D center, Data4D region)
731 731
    {  
732 732
    return mV.add(EffectNames.DISTORT, vector, center, region);
733 733
    }
......
738 738
 *
739 739
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
740 740
 *               currently being dragged with.
741
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
741
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
742 742
 * @return       ID of the effect added, or -1 if we failed to add one.
743 743
 */
744
  public long distort(Data3D vector, Data2D center)
744
  public long distort(Data3D vector, Data3D center)
745 745
    {
746 746
    return mV.add(EffectNames.DISTORT, vector, center, null);
747 747
    }
......
752 752
 * a (possibly changing in time) point on the Object.
753 753
 *     
754 754
 * @param vector Vector of force that deforms the shape of the whole Object.
755
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
755
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
756 756
 * @return       ID of the effect added, or -1 if we failed to add one.
757 757
 */
758
  public long deform(Data3D vector, Data2D center)
758
  public long deform(Data3D vector, Data3D center)
759 759
    {  
760 760
    return mV.add(EffectNames.DEFORM, vector, center, null);
761 761
    }
......
766 766
 * away from the center (degree<=1)
767 767
 *
768 768
 * @param sink   The current degree of the Effect.
769
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
769
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
770 770
 * @param region Region that masks the Effect.
771 771
 * @return       ID of the effect added, or -1 if we failed to add one.
772 772
 */
773
  public long sink(Data1D sink, Data2D center, Data4D region)
773
  public long sink(Data1D sink, Data3D center, Data4D region)
774 774
    {
775 775
    return mV.add(EffectNames.SINK, sink, center, region);
776 776
    }
......
781 781
 * away from the center (degree<=1)
782 782
 *
783 783
 * @param sink   The current degree of the Effect.
784
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
784
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
785 785
 * @return       ID of the effect added, or -1 if we failed to add one.
786 786
 */
787
  public long sink(Data1D sink, Data2D center)
787
  public long sink(Data1D sink, Data3D center)
788 788
    {
789 789
    return mV.add(EffectNames.SINK, sink, center);
790 790
    }
......
794 794
 * Rotate part of the Object around the Center of the Effect by a certain angle.
795 795
 *
796 796
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
797
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
797
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
798 798
 * @param region Region that masks the Effect.
799 799
 * @return       ID of the effect added, or -1 if we failed to add one.
800 800
 */
801
  public long swirl(Data1D swirl, Data2D center, Data4D region)
801
  public long swirl(Data1D swirl, Data3D center, Data4D region)
802 802
    {    
803 803
    return mV.add(EffectNames.SWIRL, swirl, center, region);
804 804
    }
......
808 808
 * Rotate the whole Object around the Center of the Effect by a certain angle.
809 809
 *
810 810
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
811
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
811
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
812 812
 * @return       ID of the effect added, or -1 if we failed to add one.
813 813
 */
814
  public long swirl(Data1D swirl, Data2D center)
814
  public long swirl(Data1D swirl, Data3D center)
815 815
    {
816 816
    return mV.add(EffectNames.SWIRL, swirl, center);
817 817
    }
......
842 842
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
843 843
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
844 844
 *               value if sin at this point.
845
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
845
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
846 846
 * @return       ID of the effect added, or -1 if we failed to add one.
847 847
 */
848
  public long wave(Data5D wave, Data2D center)
848
  public long wave(Data5D wave, Data3D center)
849 849
    {
850 850
    return mV.add(EffectNames.WAVE, wave, center, null);
851 851
    }
......
855 855
 * Directional, sinusoidal wave effect.
856 856
 *
857 857
 * @param wave   see {@link DistortedObject#wave(Data5D,Data2D)}
858
 * @param center see {@link DistortedObject#wave(Data5D,Data2D)}
858
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
859 859
 * @param region Region that masks the Effect.
860 860
 * @return       ID of the effect added, or -1 if we failed to add one.
861 861
 */
862
  public long wave(Data5D wave, Data2D center, Data4D region)
862
  public long wave(Data5D wave, Data3D center, Data4D region)
863 863
    {
864 864
    return mV.add(EffectNames.WAVE, wave, center, region);
865 865
    }
src/main/java/org/distorted/library/EffectNames.java
53 53
   * <p>
54 54
   * Unity: angle==0
55 55
   */
56
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           , 1, false, true ),
56
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           , 4, false, true ),
57 57
 /**
58 58
   * Rotate the whole Object around a center point (in quaternion notation).
59 59
   * <p>
......
90 90

  
91 91
 /////////////////////////////////////////////////////////////////////////////////
92 92
 // VERTEX EFFECTS
93
 // Always 12 Uniforms: 6 per-effect interpolated values, 2-dimensional center of
93
 // Always 12 Uniforms: 5 per-effect interpolated values, 3-dimensional center of
94 94
 // the effect, 4-dimensional Region
95 95
 /**
96 96
   * Apply a 3D vector of force to area around a point on the surface of the Object.
97 97
   * <p>
98 98
   * Uniforms: (forceX ,forceY ,forceZ  ,UNUSED  ,
99
   *            UNUSED , UNUSED,centerX ,centerY ,
99
   *            UNUSED , centerX ,centerY , centerZ,
100 100
   *            regionX,regionY,regionRX,regionRY)
101 101
   * <p>
102 102
   * Unity: (forceX,forceY,forceZ) = (0,0,0)
......
106 106
   * Deform the whole Object by applying a 2D vector of force to a center point.
107 107
   * <p>
108 108
   * Uniforms: (forceX,forceY,UNUSED,UNUSED,
109
   *            UNUSED,UNUSED,centerX,centerY,
109
   *            UNUSED,centerX,centerY,centerZ,
110 110
   *            UNUSED,UNUSED,UNUSED,UNUSED)
111 111
   * <p>
112 112
   * Unity: (forceX,forceY) = (0,0)
......
116 116
   * Pull (or push away) all points around a center point to (from) it.
117 117
   * <p>
118 118
   * Uniforms: (sinkFactor,UNUSED,UNUSED,UNUSED,
119
   *            UNUSED,UNUSED,centerX,centerY,
119
   *            UNUSED,centerX,centerY,centerZ,
120 120
   *            regionX,regionY,regionRX,regionRY)
121 121
   * <p>
122 122
   * Unity: sinkFactor = 1
......
126 126
   * Smoothly rotate a limited area around a center point.
127 127
   * <p>
128 128
   * Uniforms: (swirlAngle,UNUSED,UNUSED,UNUSED,
129
   *            UNUSED, UNUSED,centerX,centerY,
129
   *            UNUSED, centerX,centerY,centerZ,
130 130
   *            regionX,regionY,regionRX,regionRY)
131 131
   * <p>
132 132
   * Unity: swirlAngle = 0
......
137 137
   * parameters. Details: {@link DistortedObject#wave(Data5D,Data2D)}
138 138
   * <p>
139 139
   * Uniforms: (amplitude,length,phase,angleAlpha,
140
   *            angleBeta, UNUSED,centerX,centerY,
140
   *            angleBeta,centerX,centerY,centerZ,
141 141
   *            regionX,regionY,regionRX,regionRY)
142 142
   * <p>
143 143
   * Unity: amplitude  = 0
src/main/java/org/distorted/library/EffectQueueVertex.java
109 109

  
110 110
      if( mInter[2][i]!=null )  // center
111 111
        {
112
        mInter[2][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+6, mCurrentDuration[i], step);
112
        mInter[2][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+5, mCurrentDuration[i], step);
113 113

  
114
        mUniforms[NUM_UNIFORMS*i+6] = mUniforms[NUM_UNIFORMS*i+6]-mObjHalfX;
115
        mUniforms[NUM_UNIFORMS*i+7] =-mUniforms[NUM_UNIFORMS*i+7]+mObjHalfY;
114
        mUniforms[NUM_UNIFORMS*i+5] = mUniforms[NUM_UNIFORMS*i+5]-mObjHalfX;
115
        mUniforms[NUM_UNIFORMS*i+6] =-mUniforms[NUM_UNIFORMS*i+6]+mObjHalfY;
116
        mUniforms[NUM_UNIFORMS*i+7] = mUniforms[NUM_UNIFORMS*i+7]-mObjHalfZ;
116 117
        }
117 118

  
118 119
      mCurrentDuration[i] += step;
......
187 188
///////////////////////////////////////////////////////////////////////////////////////////////////
188 189
// wave
189 190

  
190
  synchronized long add(EffectNames eln, Data5D data, Data2D center, Data4D region)
191
  synchronized long add(EffectNames eln, Data5D data, Data3D center, Data4D region)
191 192
    {
192 193
    if( mMax[INDEX]>mNumEffects )
193 194
      {
......
218 219
///////////////////////////////////////////////////////////////////////////////////////////////////
219 220
// deform,distort
220 221

  
221
  synchronized long add(EffectNames eln, Data3D data, Data2D center, Data4D region)
222
  synchronized long add(EffectNames eln, Data3D data, Data3D center, Data4D region)
222 223
    {
223 224
    if( mMax[INDEX]>mNumEffects )
224 225
      {
......
247 248
///////////////////////////////////////////////////////////////////////////////////////////////////
248 249
// sink, swirl
249 250

  
250
  synchronized long add(EffectNames eln, Data1D data, Data2D center, Data4D region)
251
  synchronized long add(EffectNames eln, Data1D data, Data3D center, Data4D region)
251 252
    {
252 253
    if( mMax[INDEX]>mNumEffects )
253 254
      {
......
272 273
///////////////////////////////////////////////////////////////////////////////////////////////////
273 274
// sink, swirl
274 275

  
275
  synchronized long add(EffectNames eln, Data1D data, Data2D center)
276
  synchronized long add(EffectNames eln, Data1D data, Data3D center)
276 277
    {
277 278
    if( mMax[INDEX]>mNumEffects )
278 279
      {
......
296 297

  
297 298
///////////////////////////////////////////////////////////////////////////////////////////////////
298 299
  
299
  private long addPriv(EffectNames eln, Data2D center, Data4D region)
300
  private long addPriv(EffectNames eln, Data3D center, Data4D region)
300 301
    {
301 302
    if( region!=null )
302 303
      {
......
327 328
      mInter[1][mNumEffects] = null;
328 329
      }
329 330

  
330
    if( center instanceof Dynamic2D)
331
    if( center instanceof Dynamic3D)
331 332
      {
332
      mInter[2][mNumEffects] = (Dynamic2D)center;
333
      mInter[2][mNumEffects] = (Dynamic3D)center;
333 334
      }
334
    else if( center instanceof Static2D)
335
    else if( center instanceof Static3D)
335 336
      {
336 337
      mInter[2][mNumEffects] = null;
337
      mUniforms[NUM_UNIFORMS*mNumEffects+6] = ((Static2D)center).getX()-mObjHalfX;
338
      mUniforms[NUM_UNIFORMS*mNumEffects+7] =-((Static2D)center).getY()+mObjHalfY;
338
      mUniforms[NUM_UNIFORMS*mNumEffects+5] = ((Static3D)center).getX()-mObjHalfX;
339
      mUniforms[NUM_UNIFORMS*mNumEffects+6] =-((Static3D)center).getY()+mObjHalfY;
340
      mUniforms[NUM_UNIFORMS*mNumEffects+7] = ((Static3D)center).getZ()-mObjHalfZ;
339 341
      }
340 342

  
341 343
    long ret= addBase(eln);
src/main/res/raw/main_vertex_shader.glsl
208 208
  
209 209
void deform(in int effect, inout vec4 v)
210 210
  {
211
  vec2 center = vUniforms[effect+1].zw;
211
  vec2 center = vUniforms[effect+1].yz;
212 212
  vec2 force = vUniforms[effect].xy;    // force = vec(MM')
213 213
  vec2 vert_vec, horz_vec; 
214 214
  vec2 signXY = sign(center-v.xy);
......
286 286
        
287 287
void distort(in int effect, inout vec4 v, inout vec4 n)
288 288
  {
289
  vec2 center = vUniforms[effect+1].zw;
289
  vec2 center = vUniforms[effect+1].yz;
290 290
  vec2 ps = center-v.xy;
291 291
  vec3 force = vUniforms[effect].xyz;
292 292
  float d = degree(vUniforms[effect+2],center,ps);
......
314 314
 
315 315
void sink(in int effect,inout vec4 v)
316 316
  {
317
  vec2 center = vUniforms[effect+1].zw;
317
  vec2 center = vUniforms[effect+1].yz;
318 318
  vec2 ps = center-v.xy;
319 319
  float h = vUniforms[effect].x;
320 320
  float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h);
......
331 331

  
332 332
void swirl(in int effect, inout vec4 v)
333 333
  {
334
  vec2 center  = vUniforms[effect+1].zw;
334
  vec2 center  = vUniforms[effect+1].yz;
335 335
  vec2 PS = center-v.xy;
336 336
  vec4 SO = vUniforms[effect+2];
337 337
  float d1_circle = degree_region(SO,PS);
......
416 416

  
417 417
void wave(in int effect, inout vec4 v, inout vec4 n)
418 418
  {
419
  vec2 center     = vUniforms[effect+1].zw;
419
  vec2 center     = vUniforms[effect+1].yz;
420 420
  float amplitude = vUniforms[effect  ].x;
421 421
  float length    = vUniforms[effect  ].y;
422 422

  

Also available in: Unified diff