Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffectQueues.java @ 7b8086eb

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 DistortedEffectQueues
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(DistortedEffectQueues 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(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
90
    {
91
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
92

    
93
    float halfZ = tex.mHalfX*grid.zFactor;
94

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

    
104
    grid.draw();
105
    }
106

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

    
113
    mM.sendZero(df,tex.mHalfX,tex.mHalfY,tex.mHalfX*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 DistortedEffectQueues()
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
 * We only call this from the descendant's classes' constructors where we have to pay attention
158
 * to give it the appropriate type of a DistortedObject!
159
 *
160
 * @param dc    Source object to create our object from
161
 * @param flags A bitmask of values specifying what to copy.
162
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
163
 */
164
  public DistortedEffectQueues(DistortedEffectQueues dc, int flags)
165
    {
166
    mID = mNextID++;
167
    initializeEffectLists(dc,flags);
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
/**
172
 * Draw the DistortedObject to the location specified by current Matrix effects.    
173
 * <p>
174
 * Must be called from a thread holding OpenGL Context
175
 *
176
 * @param currTime current time, in milliseconds.
177
 *        This gets passed on to Dynamics inside the Effects that are currently applied to the
178
 *        Object.
179
 */
180
  public void draw(long currTime, DistortedTexture tex, GridObject grid)
181
    {
182
    tex.createTexture();
183
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
184
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
185
    drawPriv(currTime, tex, grid, Distorted.mFramebuffer);
186
    DistortedFramebuffer.deleteAllMarked();
187
    DistortedTexture.deleteAllMarked();
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
/**
192
 * Draw the DistortedObject to the Framebuffer passed.
193
 * <p>
194
 * Must be called from a thread holding OpenGL Context
195
 *
196
 * @param currTime Current time, in milliseconds.
197
 * @param df       Framebuffer to render this to.
198
 */
199
  public void draw(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
200
    {
201
    tex.createTexture();
202
    df.setAsOutput();
203
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
204
    drawPriv(currTime, tex, grid, df);
205
    DistortedFramebuffer.deleteAllMarked();
206
    DistortedTexture.deleteAllMarked();
207
    }
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210
/**
211
 * Releases all resources.
212
 */
213
  public synchronized void delete()
214
    {
215
    releasePriv();
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
/**
220
 * Returns unique ID of this instance.
221
 *
222
 * @return ID of the object.
223
 */
224
  public long getID()
225
      {
226
      return mID;
227
      }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
/**
231
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
232
 * to one of the Effects that are currently applied to the DistortedObject.
233
 * 
234
 * @param el A class implementing the EffectListener interface that wants to get notifications.
235
 */
236
  public void addEventListener(EffectListener el)
237
    {
238
    mV.addListener(el);
239
    mF.addListener(el);
240
    mM.addListener(el);
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
/**
245
 * Removes the calling class from the list of Listeners.
246
 * 
247
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
248
 */
249
  public void removeEventListener(EffectListener el)
250
    {
251
    mV.removeListener(el);
252
    mF.removeListener(el);
253
    mM.removeListener(el);
254
    }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257
/**
258
 * Aborts all Effects.
259
 * @return Number of effects aborted.
260
 */
261
  public int abortAllEffects()
262
      {
263
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
264
      }
265

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267
/**
268
 * Aborts all Effects of a given type, for example all MATRIX Effects.
269
 * 
270
 * @param type one of the constants defined in {@link EffectTypes}
271
 * @return Number of effects aborted.
272
 */
273
  public int abortEffects(EffectTypes type)
274
    {
275
    switch(type)
276
      {
277
      case MATRIX  : return mM.abortAll(true);
278
      case VERTEX  : return mV.abortAll(true);
279
      case FRAGMENT: return mF.abortAll(true);
280
      default      : return 0;
281
      }
282
    }
283
    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285
/**
286
 * Aborts a single Effect.
287
 * 
288
 * @param id ID of the Effect we want to abort.
289
 * @return number of Effects aborted. Always either 0 or 1.
290
 */
291
  public int abortEffect(long id)
292
    {
293
    int type = (int)(id&EffectTypes.MASK);
294

    
295
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
296
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
297
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
298

    
299
    return 0;
300
    }
301

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303
/**
304
 * Abort all Effects of a given name, for example all rotations.
305
 * 
306
 * @param name one of the constants defined in {@link EffectNames}
307
 * @return number of Effects aborted.
308
 */
309
  public int abortEffects(EffectNames name)
310
    {
311
    switch(name.getType())
312
      {
313
      case MATRIX  : return mM.removeByType(name);
314
      case VERTEX  : return mV.removeByType(name);
315
      case FRAGMENT: return mF.removeByType(name);
316
      default      : return 0;
317
      }
318
    }
319
    
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321
/**
322
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
323
 * 
324
 * @param id Effect ID we want to print info about
325
 * @return <code>true</code> if a single Effect of type effectType has been found.
326
 */
327
    
328
  public boolean printEffect(long id)
329
    {
330
    int type = (int)(id&EffectTypes.MASK);
331

    
332
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
333
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
334
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
335

    
336
    return false;
337
    }
338
   
339
///////////////////////////////////////////////////////////////////////////////////////////////////   
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341
// Individual effect functions.
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
// Matrix-based effects
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345
/**
346
 * Moves the Object by a (possibly changing in time) vector.
347
 * 
348
 * @param vector 3-dimensional Data which at any given time will return a Static3D
349
 *               representing the current coordinates of the vector we want to move the Object with.
350
 * @return       ID of the effect added, or -1 if we failed to add one.
351
 */
352
  public long move(Data3D vector)
353
    {   
354
    return mM.add(EffectNames.MOVE,vector);
355
    }
356

    
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358
/**
359
 * Scales the Object by (possibly changing in time) 3D scale factors.
360
 * 
361
 * @param scale 3-dimensional Data which at any given time returns a Static3D
362
 *              representing the current x- , y- and z- scale factors.
363
 * @return      ID of the effect added, or -1 if we failed to add one.
364
 */
365
  public long scale(Data3D scale)
366
    {   
367
    return mM.add(EffectNames.SCALE,scale);
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371
/**
372
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
373
 *
374
 * @param scale The factor to scale all 3 dimensions with.
375
 * @return      ID of the effect added, or -1 if we failed to add one.
376
 */
377
  public long scale(float scale)
378
    {
379
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383
/**
384
 * Rotates the Object by 'angle' degrees around the center.
385
 * Static axis of rotation is given by the last parameter.
386
 *
387
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
388
 * @param axis   Axis of rotation
389
 * @param center Coordinates of the Point we are rotating around.
390
 * @return       ID of the effect added, or -1 if we failed to add one.
391
 */
392
  public long rotate(Data1D angle, Static3D axis, Data3D center )
393
    {   
394
    return mM.add(EffectNames.ROTATE, angle, axis, center);
395
    }
396

    
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398
/**
399
 * Rotates the Object by 'angle' degrees around the center.
400
 * Here both angle and axis can dynamically change.
401
 *
402
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
403
 * @param center    Coordinates of the Point we are rotating around.
404
 * @return          ID of the effect added, or -1 if we failed to add one.
405
 */
406
  public long rotate(Data4D angleaxis, Data3D center)
407
    {
408
    return mM.add(EffectNames.ROTATE, angleaxis, center);
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412
/**
413
 * Rotates the Object by quaternion.
414
 *
415
 * @param quaternion The quaternion describing the rotation.
416
 * @param center     Coordinates of the Point we are rotating around.
417
 * @return           ID of the effect added, or -1 if we failed to add one.
418
 */
419
  public long quaternion(Data4D quaternion, Data3D center )
420
    {
421
    return mM.add(EffectNames.QUATERNION,quaternion,center);
422
    }
423

    
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425
/**
426
 * Shears the Object.
427
 *
428
 * @param shear   The 3-tuple of shear factors. The first controls level
429
 *                of shearing in the X-axis, second - Y-axis and the third -
430
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
431
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
432
 * @param center  Center of shearing, i.e. the point which stays unmoved.
433
 * @return        ID of the effect added, or -1 if we failed to add one.
434
 */
435
  public long shear(Data3D shear, Data3D center)
436
    {
437
    return mM.add(EffectNames.SHEAR, shear, center);
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441
// Fragment-based effects  
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443
/**
444
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
445
 *        
446
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
447
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
448
 *               Valid range: <0,1>
449
 * @param color  Color to mix. (1,0,0) is RED.
450
 * @param region Region this Effect is limited to.
451
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
452
 * @return       ID of the effect added, or -1 if we failed to add one.
453
 */
454
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
455
    {
456
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
/**
461
 * Makes the whole Object smoothly change all three of its RGB components.
462
 *
463
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
464
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
465
 *               Valid range: <0,1>
466
 * @param color  Color to mix. (1,0,0) is RED.
467
 * @return       ID of the effect added, or -1 if we failed to add one.
468
 */
469
  public long chroma(Data1D blend, Data3D color)
470
    {
471
    return mF.add(EffectNames.CHROMA, blend, color);
472
    }
473

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475
/**
476
 * Makes a certain sub-region of the Object smoothly change its transparency level.
477
 *        
478
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
479
 *               moment: pixel.a *= alpha.
480
 *               Valid range: <0,1>
481
 * @param region Region this Effect is limited to. 
482
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
483
 * @return       ID of the effect added, or -1 if we failed to add one. 
484
 */
485
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
486
    {
487
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
488
    }
489

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491
/**
492
 * Makes the whole Object smoothly change its transparency level.
493
 *
494
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
495
 *               given moment: pixel.a *= alpha.
496
 *               Valid range: <0,1>
497
 * @return       ID of the effect added, or -1 if we failed to add one.
498
 */
499
  public long alpha(Data1D alpha)
500
    {
501
    return mF.add(EffectNames.ALPHA, alpha);
502
    }
503

    
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505
/**
506
 * Makes a certain sub-region of the Object smoothly change its brightness level.
507
 *        
508
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
509
 *                   at any given moment. Valid range: <0,infinity)
510
 * @param region     Region this Effect is limited to.
511
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
512
 * @return           ID of the effect added, or -1 if we failed to add one.
513
 */
514
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
515
    {
516
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
517
    }
518

    
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520
/**
521
 * Makes the whole Object smoothly change its brightness level.
522
 *
523
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
524
 *                   at any given moment. Valid range: <0,infinity)
525
 * @return           ID of the effect added, or -1 if we failed to add one.
526
 */
527
  public long brightness(Data1D brightness)
528
    {
529
    return mF.add(EffectNames.BRIGHTNESS, brightness);
530
    }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
/**
534
 * Makes a certain sub-region of the Object smoothly change its contrast level.
535
 *        
536
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
537
 *                 at any given moment. Valid range: <0,infinity)
538
 * @param region   Region this Effect is limited to.
539
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
540
 * @return         ID of the effect added, or -1 if we failed to add one.
541
 */
542
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
543
    {
544
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
545
    }
546

    
547
///////////////////////////////////////////////////////////////////////////////////////////////////
548
/**
549
 * Makes the whole Object smoothly change its contrast level.
550
 *
551
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
552
 *                 at any given moment. Valid range: <0,infinity)
553
 * @return         ID of the effect added, or -1 if we failed to add one.
554
 */
555
  public long contrast(Data1D contrast)
556
    {
557
    return mF.add(EffectNames.CONTRAST, contrast);
558
    }
559

    
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561
/**
562
 * Makes a certain sub-region of the Object smoothly change its saturation level.
563
 *        
564
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
565
 *                   at any given moment. Valid range: <0,infinity)
566
 * @param region     Region this Effect is limited to.
567
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
568
 * @return           ID of the effect added, or -1 if we failed to add one.
569
 */
570
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
571
    {
572
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
573
    }
574

    
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
/**
577
 * Makes the whole Object smoothly change its saturation level.
578
 *
579
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
580
 *                   at any given moment. Valid range: <0,infinity)
581
 * @return           ID of the effect added, or -1 if we failed to add one.
582
 */
583
  public long saturation(Data1D saturation)
584
    {
585
    return mF.add(EffectNames.SATURATION, saturation);
586
    }
587

    
588
///////////////////////////////////////////////////////////////////////////////////////////////////
589
// Vertex-based effects  
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591
/**
592
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
593
 *
594
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
595
 *               currently being dragged with.
596
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
597
 * @param region Region that masks the Effect.
598
 * @return       ID of the effect added, or -1 if we failed to add one.
599
 */
600
  public long distort(Data3D vector, Data3D center, Data4D region)
601
    {  
602
    return mV.add(EffectNames.DISTORT, vector, center, region);
603
    }
604

    
605
///////////////////////////////////////////////////////////////////////////////////////////////////
606
/**
607
 * Distort the whole Object by a (possibly changing in time) vector of force.
608
 *
609
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
610
 *               currently being dragged with.
611
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
612
 * @return       ID of the effect added, or -1 if we failed to add one.
613
 */
614
  public long distort(Data3D vector, Data3D center)
615
    {
616
    return mV.add(EffectNames.DISTORT, vector, center, null);
617
    }
618

    
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620
/**
621
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
622
 * a (possibly changing in time) point on the Object.
623
 *
624
 * @param vector Vector of force that deforms the shape of the whole Object.
625
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
626
 * @param region Region that masks the Effect.
627
 * @return       ID of the effect added, or -1 if we failed to add one.
628
 */
629
  public long deform(Data3D vector, Data3D center, Data4D region)
630
    {
631
    return mV.add(EffectNames.DEFORM, vector, center, region);
632
    }
633

    
634
///////////////////////////////////////////////////////////////////////////////////////////////////
635
/**
636
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
637
 * a (possibly changing in time) point on the Object.
638
 *     
639
 * @param vector Vector of force that deforms the shape of the whole Object.
640
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
641
 * @return       ID of the effect added, or -1 if we failed to add one.
642
 */
643
  public long deform(Data3D vector, Data3D center)
644
    {  
645
    return mV.add(EffectNames.DEFORM, vector, center, null);
646
    }
647

    
648
///////////////////////////////////////////////////////////////////////////////////////////////////  
649
/**
650
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
651
 * away from the center (degree<=1)
652
 *
653
 * @param sink   The current degree of the Effect.
654
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
655
 * @param region Region that masks the Effect.
656
 * @return       ID of the effect added, or -1 if we failed to add one.
657
 */
658
  public long sink(Data1D sink, Data3D center, Data4D region)
659
    {
660
    return mV.add(EffectNames.SINK, sink, center, region);
661
    }
662

    
663
///////////////////////////////////////////////////////////////////////////////////////////////////
664
/**
665
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
666
 * away from the center (degree<=1)
667
 *
668
 * @param sink   The current degree of the Effect.
669
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
670
 * @return       ID of the effect added, or -1 if we failed to add one.
671
 */
672
  public long sink(Data1D sink, Data3D center)
673
    {
674
    return mV.add(EffectNames.SINK, sink, center);
675
    }
676

    
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678
/**
679
 * Pull all points around the center of the Effect towards a line passing through the center
680
 * (that's if degree>=1) or push them away from the line (degree<=1)
681
 *
682
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
683
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
684
 * @param region Region that masks the Effect.
685
 * @return       ID of the effect added, or -1 if we failed to add one.
686
 */
687
  public long pinch(Data2D pinch, Data3D center, Data4D region)
688
    {
689
    return mV.add(EffectNames.PINCH, pinch, center, region);
690
    }
691

    
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693
/**
694
 * Pull all points around the center of the Effect towards a line passing through the center
695
 * (that's if degree>=1) or push them away from the line (degree<=1)
696
 *
697
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
698
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
699
 * @return       ID of the effect added, or -1 if we failed to add one.
700
 */
701
  public long pinch(Data2D pinch, Data3D center)
702
    {
703
    return mV.add(EffectNames.PINCH, pinch, center);
704
    }
705

    
706
///////////////////////////////////////////////////////////////////////////////////////////////////  
707
/**
708
 * Rotate part of the Object around the Center of the Effect by a certain angle.
709
 *
710
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
711
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
712
 * @param region Region that masks the Effect.
713
 * @return       ID of the effect added, or -1 if we failed to add one.
714
 */
715
  public long swirl(Data1D swirl, Data3D center, Data4D region)
716
    {    
717
    return mV.add(EffectNames.SWIRL, swirl, center, region);
718
    }
719

    
720
///////////////////////////////////////////////////////////////////////////////////////////////////
721
/**
722
 * Rotate the whole Object around the Center of the Effect by a certain angle.
723
 *
724
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
725
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
726
 * @return       ID of the effect added, or -1 if we failed to add one.
727
 */
728
  public long swirl(Data1D swirl, Data3D center)
729
    {
730
    return mV.add(EffectNames.SWIRL, swirl, center);
731
    }
732

    
733
///////////////////////////////////////////////////////////////////////////////////////////////////
734
/**
735
 * Directional, sinusoidal wave effect.
736
 *
737
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
738
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
739
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
740
 *               describe the 'direction' of the wave.
741
 *               <p>
742
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
743
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
744
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
745
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
746
 *               <p>
747
 *               <p>
748
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
749
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
750
 *               will be sine shapes.
751
 *               <p>
752
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
753
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
754
 *               YZ-plane with be sine shapes.
755
 *               <p>
756
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
757
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
758
 *               value if sin at this point.
759
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
760
 * @return       ID of the effect added, or -1 if we failed to add one.
761
 */
762
  public long wave(Data5D wave, Data3D center)
763
    {
764
    return mV.add(EffectNames.WAVE, wave, center, null);
765
    }
766

    
767
///////////////////////////////////////////////////////////////////////////////////////////////////
768
/**
769
 * Directional, sinusoidal wave effect.
770
 *
771
 * @param wave   see {@link DistortedEffectQueues#wave(Data5D,Data3D)}
772
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
773
 * @param region Region that masks the Effect.
774
 * @return       ID of the effect added, or -1 if we failed to add one.
775
 */
776
  public long wave(Data5D wave, Data3D center, Data4D region)
777
    {
778
    return mV.add(EffectNames.WAVE, wave, center, region);
779
    }
780
  }
(2-2/15)