Project

General

Profile

Download (29.7 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / DistortedEffects.java @ 52358355

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library;
21

    
22
import android.opengl.GLES20;
23

    
24
import org.distorted.library.message.EffectListener;
25
import org.distorted.library.type.Data1D;
26
import org.distorted.library.type.Data2D;
27
import org.distorted.library.type.Data3D;
28
import org.distorted.library.type.Data4D;
29
import org.distorted.library.type.Data5D;
30
import org.distorted.library.type.Static3D;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
/**
34
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
35
 * <p>
36
 * The queues hold actual effects to be applied to a given (DistortedTexture,GridObject) combo.
37
 */
38
public class DistortedEffects
39
  {
40
  private static long mNextID =0;
41
  private long mID;
42

    
43
  private EffectQueueMatrix    mM;
44
  private EffectQueueFragment  mF;
45
  private EffectQueueVertex    mV;
46

    
47
  private boolean matrixCloned, vertexCloned, fragmentCloned;
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
    
51
  private void initializeEffectLists(DistortedEffects d, int flags)
52
    {
53
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
54
      {
55
      mM = d.mM;
56
      matrixCloned = true;
57
      }
58
    else
59
      {
60
      mM = new EffectQueueMatrix(mID);
61
      matrixCloned = false;
62
      }
63
    
64
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
65
      {
66
      mV = d.mV;
67
      vertexCloned = true;
68
      }
69
    else
70
      {
71
      mV = new EffectQueueVertex(mID);
72
      vertexCloned = false;
73
      }
74
    
75
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
76
      {
77
      mF = d.mF;
78
      fragmentCloned = true;
79
      }
80
    else
81
      {
82
      mF = new EffectQueueFragment(mID);
83
      fragmentCloned = false;
84
      }
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
   
89
  void drawPriv(float halfInputW, float halfInputH, GridObject grid, DistortedFramebuffer df, long currTime)
90
    {
91
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
92

    
93
    float halfZ = halfInputW*grid.zFactor;
94

    
95
    mM.compute(currTime);
96
    mM.send(df,halfInputW,halfInputH,halfZ);
97
      
98
    mV.compute(currTime);
99
    mV.send(halfInputW,halfInputH,halfZ);
100
        
101
    mF.compute(currTime);
102
    mF.send(halfInputW,halfInputH);
103

    
104
    grid.draw();
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
   
109
  void drawNoEffectsPriv(float halfInputW, float halfInputH, GridObject grid, DistortedFramebuffer df)
110
    {
111
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
112

    
113
    mM.sendZero(df,halfInputW,halfInputH,halfInputW*grid.zFactor);
114
    mV.sendZero();
115
    mF.sendZero();
116

    
117
    grid.draw();
118
    }
119
    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
   
122
  private void releasePriv()
123
    {
124
    if( !matrixCloned  ) mM.abortAll(false);
125
    if( !vertexCloned  ) mV.abortAll(false);
126
    if( !fragmentCloned) mF.abortAll(false);
127

    
128
    mM = null;
129
    mV = null;
130
    mF = null;
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  static void onDestroy()
136
    {
137
    mNextID = 0;
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
// PUBLIC API
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
/**
144
 * Create empty effect queue.
145
 */
146
  public DistortedEffects()
147
    {
148
    mID = mNextID++;
149
    initializeEffectLists(this,0);
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
/**
154
 * Copy constructor.
155
 * <p>
156
 * Whatever we do not clone gets created just like in the default constructor.
157
 *
158
 * @param dc    Source object to create our object from
159
 * @param flags A bitmask of values specifying what to copy.
160
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
161
 */
162
  public DistortedEffects(DistortedEffects dc, int flags)
163
    {
164
    mID = mNextID++;
165
    initializeEffectLists(dc,flags);
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
/**
170
 * Releases all resources. After this call, the queue should not be used anymore.
171
 */
172
  public synchronized void delete()
173
    {
174
    releasePriv();
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178
/**
179
 * Returns unique ID of this instance.
180
 *
181
 * @return ID of the object.
182
 */
183
  public long getID()
184
      {
185
      return mID;
186
      }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
/**
190
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
191
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
192
 * 
193
 * @param el A class implementing the EffectListener interface that wants to get notifications.
194
 */
195
  public void registerForMessages(EffectListener el)
196
    {
197
    mV.registerForMessages(el);
198
    mF.registerForMessages(el);
199
    mM.registerForMessages(el);
200
    }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203
/**
204
 * Removes the calling class from the list of Listeners.
205
 * 
206
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
207
 */
208
  public void deregisterForMessages(EffectListener el)
209
    {
210
    mV.deregisterForMessages(el);
211
    mF.deregisterForMessages(el);
212
    mM.deregisterForMessages(el);
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216
/**
217
 * Aborts all Effects.
218
 * @return Number of effects aborted.
219
 */
220
  public int abortAllEffects()
221
      {
222
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
223
      }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226
/**
227
 * Aborts all Effects of a given type, for example all MATRIX Effects.
228
 * 
229
 * @param type one of the constants defined in {@link EffectTypes}
230
 * @return Number of effects aborted.
231
 */
232
  public int abortEffects(EffectTypes type)
233
    {
234
    switch(type)
235
      {
236
      case MATRIX  : return mM.abortAll(true);
237
      case VERTEX  : return mV.abortAll(true);
238
      case FRAGMENT: return mF.abortAll(true);
239
      default      : return 0;
240
      }
241
    }
242
    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
/**
245
 * Aborts a single Effect.
246
 * 
247
 * @param id ID of the Effect we want to abort.
248
 * @return number of Effects aborted. Always either 0 or 1.
249
 */
250
  public int abortEffect(long id)
251
    {
252
    int type = (int)(id&EffectTypes.MASK);
253

    
254
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
255
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
256
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
257

    
258
    return 0;
259
    }
260

    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262
/**
263
 * Abort all Effects of a given name, for example all rotations.
264
 * 
265
 * @param name one of the constants defined in {@link EffectNames}
266
 * @return number of Effects aborted.
267
 */
268
  public int abortEffects(EffectNames name)
269
    {
270
    switch(name.getType())
271
      {
272
      case MATRIX  : return mM.removeByType(name);
273
      case VERTEX  : return mV.removeByType(name);
274
      case FRAGMENT: return mF.removeByType(name);
275
      default      : return 0;
276
      }
277
    }
278
    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280
/**
281
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
282
 * 
283
 * @param id Effect ID we want to print info about
284
 * @return <code>true</code> if a single Effect of type effectType has been found.
285
 */
286
    
287
  public boolean printEffect(long id)
288
    {
289
    int type = (int)(id&EffectTypes.MASK);
290

    
291
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
292
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
293
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
294

    
295
    return false;
296
    }
297
   
298
///////////////////////////////////////////////////////////////////////////////////////////////////   
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
// Individual effect functions.
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302
// Matrix-based effects
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304
/**
305
 * Moves the Object by a (possibly changing in time) vector.
306
 * 
307
 * @param vector 3-dimensional Data which at any given time will return a Static3D
308
 *               representing the current coordinates of the vector we want to move the Object with.
309
 * @return       ID of the effect added, or -1 if we failed to add one.
310
 */
311
  public long move(Data3D vector)
312
    {   
313
    return mM.add(EffectNames.MOVE,vector);
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317
/**
318
 * Scales the Object by (possibly changing in time) 3D scale factors.
319
 * 
320
 * @param scale 3-dimensional Data which at any given time returns a Static3D
321
 *              representing the current x- , y- and z- scale factors.
322
 * @return      ID of the effect added, or -1 if we failed to add one.
323
 */
324
  public long scale(Data3D scale)
325
    {   
326
    return mM.add(EffectNames.SCALE,scale);
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
/**
331
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
332
 *
333
 * @param scale The factor to scale all 3 dimensions with.
334
 * @return      ID of the effect added, or -1 if we failed to add one.
335
 */
336
  public long scale(float scale)
337
    {
338
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
/**
343
 * Rotates the Object by 'angle' degrees around the center.
344
 * Static axis of rotation is given by the last parameter.
345
 *
346
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
347
 * @param axis   Axis of rotation
348
 * @param center Coordinates of the Point we are rotating around.
349
 * @return       ID of the effect added, or -1 if we failed to add one.
350
 */
351
  public long rotate(Data1D angle, Static3D axis, Data3D center )
352
    {   
353
    return mM.add(EffectNames.ROTATE, angle, axis, center);
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357
/**
358
 * Rotates the Object by 'angle' degrees around the center.
359
 * Here both angle and axis can dynamically change.
360
 *
361
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
362
 * @param center    Coordinates of the Point we are rotating around.
363
 * @return          ID of the effect added, or -1 if we failed to add one.
364
 */
365
  public long rotate(Data4D angleaxis, Data3D center)
366
    {
367
    return mM.add(EffectNames.ROTATE, angleaxis, center);
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371
/**
372
 * Rotates the Object by quaternion.
373
 *
374
 * @param quaternion The quaternion describing the rotation.
375
 * @param center     Coordinates of the Point we are rotating around.
376
 * @return           ID of the effect added, or -1 if we failed to add one.
377
 */
378
  public long quaternion(Data4D quaternion, Data3D center )
379
    {
380
    return mM.add(EffectNames.QUATERNION,quaternion,center);
381
    }
382

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384
/**
385
 * Shears the Object.
386
 *
387
 * @param shear   The 3-tuple of shear factors. The first controls level
388
 *                of shearing in the X-axis, second - Y-axis and the third -
389
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
390
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
391
 * @param center  Center of shearing, i.e. the point which stays unmoved.
392
 * @return        ID of the effect added, or -1 if we failed to add one.
393
 */
394
  public long shear(Data3D shear, Data3D center)
395
    {
396
    return mM.add(EffectNames.SHEAR, shear, center);
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400
// Fragment-based effects  
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402
/**
403
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
404
 *        
405
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
406
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
407
 *               Valid range: <0,1>
408
 * @param color  Color to mix. (1,0,0) is RED.
409
 * @param region Region this Effect is limited to.
410
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
411
 * @return       ID of the effect added, or -1 if we failed to add one.
412
 */
413
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
414
    {
415
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419
/**
420
 * Makes the whole Object smoothly change all three of its RGB components.
421
 *
422
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
423
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
424
 *               Valid range: <0,1>
425
 * @param color  Color to mix. (1,0,0) is RED.
426
 * @return       ID of the effect added, or -1 if we failed to add one.
427
 */
428
  public long chroma(Data1D blend, Data3D color)
429
    {
430
    return mF.add(EffectNames.CHROMA, blend, color);
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434
/**
435
 * Makes a certain sub-region of the Object smoothly change its transparency level.
436
 *        
437
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
438
 *               moment: pixel.a *= alpha.
439
 *               Valid range: <0,1>
440
 * @param region Region this Effect is limited to. 
441
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
442
 * @return       ID of the effect added, or -1 if we failed to add one. 
443
 */
444
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
445
    {
446
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
/**
451
 * Makes the whole Object smoothly change its transparency level.
452
 *
453
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
454
 *               given moment: pixel.a *= alpha.
455
 *               Valid range: <0,1>
456
 * @return       ID of the effect added, or -1 if we failed to add one.
457
 */
458
  public long alpha(Data1D alpha)
459
    {
460
    return mF.add(EffectNames.ALPHA, alpha);
461
    }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464
/**
465
 * Makes a certain sub-region of the Object smoothly change its brightness level.
466
 *        
467
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
468
 *                   at any given moment. Valid range: <0,infinity)
469
 * @param region     Region this Effect is limited to.
470
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
471
 * @return           ID of the effect added, or -1 if we failed to add one.
472
 */
473
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
474
    {
475
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
476
    }
477

    
478
///////////////////////////////////////////////////////////////////////////////////////////////////
479
/**
480
 * Makes the whole Object smoothly change its brightness level.
481
 *
482
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
483
 *                   at any given moment. Valid range: <0,infinity)
484
 * @return           ID of the effect added, or -1 if we failed to add one.
485
 */
486
  public long brightness(Data1D brightness)
487
    {
488
    return mF.add(EffectNames.BRIGHTNESS, brightness);
489
    }
490

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492
/**
493
 * Makes a certain sub-region of the Object smoothly change its contrast level.
494
 *        
495
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
496
 *                 at any given moment. Valid range: <0,infinity)
497
 * @param region   Region this Effect is limited to.
498
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
499
 * @return         ID of the effect added, or -1 if we failed to add one.
500
 */
501
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
502
    {
503
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
504
    }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507
/**
508
 * Makes the whole Object smoothly change its contrast level.
509
 *
510
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
511
 *                 at any given moment. Valid range: <0,infinity)
512
 * @return         ID of the effect added, or -1 if we failed to add one.
513
 */
514
  public long contrast(Data1D contrast)
515
    {
516
    return mF.add(EffectNames.CONTRAST, contrast);
517
    }
518

    
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520
/**
521
 * Makes a certain sub-region of the Object smoothly change its saturation level.
522
 *        
523
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
524
 *                   at any given moment. Valid range: <0,infinity)
525
 * @param region     Region this Effect is limited to.
526
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
527
 * @return           ID of the effect added, or -1 if we failed to add one.
528
 */
529
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
530
    {
531
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
532
    }
533

    
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535
/**
536
 * Makes the whole Object smoothly change its saturation level.
537
 *
538
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
539
 *                   at any given moment. Valid range: <0,infinity)
540
 * @return           ID of the effect added, or -1 if we failed to add one.
541
 */
542
  public long saturation(Data1D saturation)
543
    {
544
    return mF.add(EffectNames.SATURATION, saturation);
545
    }
546

    
547
///////////////////////////////////////////////////////////////////////////////////////////////////
548
// Vertex-based effects  
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550
/**
551
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
552
 *
553
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
554
 *               currently being dragged with.
555
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
556
 * @param region Region that masks the Effect.
557
 * @return       ID of the effect added, or -1 if we failed to add one.
558
 */
559
  public long distort(Data3D vector, Data3D center, Data4D region)
560
    {  
561
    return mV.add(EffectNames.DISTORT, vector, center, region);
562
    }
563

    
564
///////////////////////////////////////////////////////////////////////////////////////////////////
565
/**
566
 * Distort the whole Object by a (possibly changing in time) vector of force.
567
 *
568
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
569
 *               currently being dragged with.
570
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
571
 * @return       ID of the effect added, or -1 if we failed to add one.
572
 */
573
  public long distort(Data3D vector, Data3D center)
574
    {
575
    return mV.add(EffectNames.DISTORT, vector, center, null);
576
    }
577

    
578
///////////////////////////////////////////////////////////////////////////////////////////////////
579
/**
580
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
581
 * a (possibly changing in time) point on the Object.
582
 *
583
 * @param vector Vector of force that deforms the shape of the whole Object.
584
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
585
 * @param region Region that masks the Effect.
586
 * @return       ID of the effect added, or -1 if we failed to add one.
587
 */
588
  public long deform(Data3D vector, Data3D center, Data4D region)
589
    {
590
    return mV.add(EffectNames.DEFORM, vector, center, region);
591
    }
592

    
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594
/**
595
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
596
 * a (possibly changing in time) point on the Object.
597
 *     
598
 * @param vector Vector of force that deforms the shape of the whole Object.
599
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
600
 * @return       ID of the effect added, or -1 if we failed to add one.
601
 */
602
  public long deform(Data3D vector, Data3D center)
603
    {  
604
    return mV.add(EffectNames.DEFORM, vector, center, null);
605
    }
606

    
607
///////////////////////////////////////////////////////////////////////////////////////////////////  
608
/**
609
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
610
 * away from the center (degree<=1)
611
 *
612
 * @param sink   The current degree of the Effect.
613
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
614
 * @param region Region that masks the Effect.
615
 * @return       ID of the effect added, or -1 if we failed to add one.
616
 */
617
  public long sink(Data1D sink, Data3D center, Data4D region)
618
    {
619
    return mV.add(EffectNames.SINK, sink, center, region);
620
    }
621

    
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623
/**
624
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
625
 * away from the center (degree<=1)
626
 *
627
 * @param sink   The current degree of the Effect.
628
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
629
 * @return       ID of the effect added, or -1 if we failed to add one.
630
 */
631
  public long sink(Data1D sink, Data3D center)
632
    {
633
    return mV.add(EffectNames.SINK, sink, center);
634
    }
635

    
636
///////////////////////////////////////////////////////////////////////////////////////////////////
637
/**
638
 * Pull all points around the center of the Effect towards a line passing through the center
639
 * (that's if degree>=1) or push them away from the line (degree<=1)
640
 *
641
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
642
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
643
 * @param region Region that masks the Effect.
644
 * @return       ID of the effect added, or -1 if we failed to add one.
645
 */
646
  public long pinch(Data2D pinch, Data3D center, Data4D region)
647
    {
648
    return mV.add(EffectNames.PINCH, pinch, center, region);
649
    }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652
/**
653
 * Pull all points around the center of the Effect towards a line passing through the center
654
 * (that's if degree>=1) or push them away from the line (degree<=1)
655
 *
656
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
657
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
658
 * @return       ID of the effect added, or -1 if we failed to add one.
659
 */
660
  public long pinch(Data2D pinch, Data3D center)
661
    {
662
    return mV.add(EffectNames.PINCH, pinch, center);
663
    }
664

    
665
///////////////////////////////////////////////////////////////////////////////////////////////////  
666
/**
667
 * Rotate part of the Object around the Center of the Effect by a certain angle.
668
 *
669
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
670
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
671
 * @param region Region that masks the Effect.
672
 * @return       ID of the effect added, or -1 if we failed to add one.
673
 */
674
  public long swirl(Data1D swirl, Data3D center, Data4D region)
675
    {    
676
    return mV.add(EffectNames.SWIRL, swirl, center, region);
677
    }
678

    
679
///////////////////////////////////////////////////////////////////////////////////////////////////
680
/**
681
 * Rotate the whole Object around the Center of the Effect by a certain angle.
682
 *
683
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
684
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
685
 * @return       ID of the effect added, or -1 if we failed to add one.
686
 */
687
  public long swirl(Data1D swirl, Data3D center)
688
    {
689
    return mV.add(EffectNames.SWIRL, swirl, center);
690
    }
691

    
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693
/**
694
 * Directional, sinusoidal wave effect.
695
 *
696
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
697
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
698
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
699
 *               describe the 'direction' of the wave.
700
 *               <p>
701
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
702
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
703
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
704
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
705
 *               <p>
706
 *               <p>
707
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
708
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
709
 *               will be sine shapes.
710
 *               <p>
711
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
712
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
713
 *               YZ-plane with be sine shapes.
714
 *               <p>
715
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
716
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
717
 *               value if sin at this point.
718
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
719
 * @return       ID of the effect added, or -1 if we failed to add one.
720
 */
721
  public long wave(Data5D wave, Data3D center)
722
    {
723
    return mV.add(EffectNames.WAVE, wave, center, null);
724
    }
725

    
726
///////////////////////////////////////////////////////////////////////////////////////////////////
727
/**
728
 * Directional, sinusoidal wave effect.
729
 *
730
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
731
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
732
 * @param region Region that masks the Effect.
733
 * @return       ID of the effect added, or -1 if we failed to add one.
734
 */
735
  public long wave(Data5D wave, Data3D center, Data4D region)
736
    {
737
    return mV.add(EffectNames.WAVE, wave, center, region);
738
    }
739
  }
(2-2/15)