Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffectQueues.java @ 3ef3364d

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
    DistortedFramebuffer.deleteAllMarked();
92

    
93
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
94

    
95
    float halfZ = tex.mHalfX*grid.zFactor;
96

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

    
106
    grid.draw();
107
    }
108

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

    
115
    mM.sendZero(df,tex.mHalfX,tex.mHalfY,tex.mHalfX*grid.zFactor);
116
    mV.sendZero();
117
    mF.sendZero();
118

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

    
130
    mM = null;
131
    mV = null;
132
    mF = null;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
// PUBLIC API
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
/**
139
 * Create empty effect queue.
140
 */
141
  public DistortedEffectQueues()
142
    {
143
    mID = mNextID++;
144
    initializeEffectLists(this,0);
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148
/**
149
 * Copy constructor.
150
 * <p>
151
 * Whatever we do not clone gets created just like in the default constructor.
152
 * We only call this from the descendant's classes' constructors where we have to pay attention
153
 * to give it the appropriate type of a DistortedObject!
154
 *
155
 * @param dc    Source object to create our object from
156
 * @param flags A bitmask of values specifying what to copy.
157
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
158
 */
159
  public DistortedEffectQueues(DistortedEffectQueues dc, int flags)
160
    {
161
    mID = mNextID++;
162
    initializeEffectLists(dc,flags);
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
/**
167
 * Draw the DistortedObject to the location specified by current Matrix effects.    
168
 *     
169
 * @param currTime current time, in milliseconds.
170
 *        This gets passed on to Dynamics inside the Effects that are currently applied to the
171
 *        Object.
172
 */
173
  public void draw(long currTime, DistortedTexture tex, GridObject grid)
174
    {
175
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
176
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
177
    drawPriv(currTime, tex, grid, Distorted.mFramebuffer);
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
/**
182
 * Draw the DistortedObject to the Framebuffer passed.
183
 *
184
 * @param currTime Current time, in milliseconds.
185
 * @param df       Framebuffer to render this to.
186
 */
187
  public void draw(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
188
    {
189
    df.setAsOutput();
190
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
191
    drawPriv(currTime, tex, grid, df);
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
/**
196
 * Releases all resources.
197
 */
198
  public synchronized void delete()
199
    {
200
    releasePriv();
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204
/**
205
 * Returns unique ID of this instance.
206
 *
207
 * @return ID of the object.
208
 */
209
  public long getID()
210
      {
211
      return mID;
212
      }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215
/**
216
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
217
 * to one of the Effects that are currently applied to the DistortedObject.
218
 * 
219
 * @param el A class implementing the EffectListener interface that wants to get notifications.
220
 */
221
  public void addEventListener(EffectListener el)
222
    {
223
    mV.addListener(el);
224
    mF.addListener(el);
225
    mM.addListener(el);
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
/**
230
 * Removes the calling class from the list of Listeners.
231
 * 
232
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
233
 */
234
  public void removeEventListener(EffectListener el)
235
    {
236
    mV.removeListener(el);
237
    mF.removeListener(el);
238
    mM.removeListener(el);
239
    }
240

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242
/**
243
 * Aborts all Effects.
244
 * @return Number of effects aborted.
245
 */
246
  public int abortAllEffects()
247
      {
248
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
249
      }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252
/**
253
 * Aborts all Effects of a given type, for example all MATRIX Effects.
254
 * 
255
 * @param type one of the constants defined in {@link EffectTypes}
256
 * @return Number of effects aborted.
257
 */
258
  public int abortEffects(EffectTypes type)
259
    {
260
    switch(type)
261
      {
262
      case MATRIX  : return mM.abortAll(true);
263
      case VERTEX  : return mV.abortAll(true);
264
      case FRAGMENT: return mF.abortAll(true);
265
      default      : return 0;
266
      }
267
    }
268
    
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
/**
271
 * Aborts a single Effect.
272
 * 
273
 * @param id ID of the Effect we want to abort.
274
 * @return number of Effects aborted. Always either 0 or 1.
275
 */
276
  public int abortEffect(long id)
277
    {
278
    int type = (int)(id&EffectTypes.MASK);
279

    
280
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
281
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
282
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
283

    
284
    return 0;
285
    }
286

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288
/**
289
 * Abort all Effects of a given name, for example all rotations.
290
 * 
291
 * @param name one of the constants defined in {@link EffectNames}
292
 * @return number of Effects aborted.
293
 */
294
  public int abortEffects(EffectNames name)
295
    {
296
    switch(name.getType())
297
      {
298
      case MATRIX  : return mM.removeByType(name);
299
      case VERTEX  : return mV.removeByType(name);
300
      case FRAGMENT: return mF.removeByType(name);
301
      default      : return 0;
302
      }
303
    }
304
    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306
/**
307
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
308
 * 
309
 * @param id Effect ID we want to print info about
310
 * @return <code>true</code> if a single Effect of type effectType has been found.
311
 */
312
    
313
  public boolean printEffect(long id)
314
    {
315
    int type = (int)(id&EffectTypes.MASK);
316

    
317
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
318
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
319
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
320

    
321
    return false;
322
    }
323
   
324
///////////////////////////////////////////////////////////////////////////////////////////////////   
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326
// Individual effect functions.
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328
// Matrix-based effects
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
/**
331
 * Moves the Object by a (possibly changing in time) vector.
332
 * 
333
 * @param vector 3-dimensional Data which at any given time will return a Static3D
334
 *               representing the current coordinates of the vector we want to move the Object with.
335
 * @return       ID of the effect added, or -1 if we failed to add one.
336
 */
337
  public long move(Data3D vector)
338
    {   
339
    return mM.add(EffectNames.MOVE,vector);
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
/**
344
 * Scales the Object by (possibly changing in time) 3D scale factors.
345
 * 
346
 * @param scale 3-dimensional Data which at any given time returns a Static3D
347
 *              representing the current x- , y- and z- scale factors.
348
 * @return      ID of the effect added, or -1 if we failed to add one.
349
 */
350
  public long scale(Data3D scale)
351
    {   
352
    return mM.add(EffectNames.SCALE,scale);
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356
/**
357
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
358
 *
359
 * @param scale The factor to scale all 3 dimensions with.
360
 * @return      ID of the effect added, or -1 if we failed to add one.
361
 */
362
  public long scale(float scale)
363
    {
364
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
/**
369
 * Rotates the Object by 'angle' degrees around the center.
370
 * Static axis of rotation is given by the last parameter.
371
 *
372
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
373
 * @param axis   Axis of rotation
374
 * @param center Coordinates of the Point we are rotating around.
375
 * @return       ID of the effect added, or -1 if we failed to add one.
376
 */
377
  public long rotate(Data1D angle, Static3D axis, Data3D center )
378
    {   
379
    return mM.add(EffectNames.ROTATE, angle, axis, center);
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383
/**
384
 * Rotates the Object by 'angle' degrees around the center.
385
 * Here both angle and axis can dynamically change.
386
 *
387
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
388
 * @param center    Coordinates of the Point we are rotating around.
389
 * @return          ID of the effect added, or -1 if we failed to add one.
390
 */
391
  public long rotate(Data4D angleaxis, Data3D center)
392
    {
393
    return mM.add(EffectNames.ROTATE, angleaxis, center);
394
    }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
/**
398
 * Rotates the Object by quaternion.
399
 *
400
 * @param quaternion The quaternion describing the rotation.
401
 * @param center     Coordinates of the Point we are rotating around.
402
 * @return           ID of the effect added, or -1 if we failed to add one.
403
 */
404
  public long quaternion(Data4D quaternion, Data3D center )
405
    {
406
    return mM.add(EffectNames.QUATERNION,quaternion,center);
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410
/**
411
 * Shears the Object.
412
 *
413
 * @param shear   The 3-tuple of shear factors. The first controls level
414
 *                of shearing in the X-axis, second - Y-axis and the third -
415
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
416
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
417
 * @param center  Center of shearing, i.e. the point which stays unmoved.
418
 * @return        ID of the effect added, or -1 if we failed to add one.
419
 */
420
  public long shear(Data3D shear, Data3D center)
421
    {
422
    return mM.add(EffectNames.SHEAR, shear, center);
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426
// Fragment-based effects  
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
/**
429
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
430
 *        
431
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
432
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
433
 *               Valid range: <0,1>
434
 * @param color  Color to mix. (1,0,0) is RED.
435
 * @param region Region this Effect is limited to.
436
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
437
 * @return       ID of the effect added, or -1 if we failed to add one.
438
 */
439
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
440
    {
441
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445
/**
446
 * Makes the whole Object smoothly change all three of its RGB components.
447
 *
448
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
449
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
450
 *               Valid range: <0,1>
451
 * @param color  Color to mix. (1,0,0) is RED.
452
 * @return       ID of the effect added, or -1 if we failed to add one.
453
 */
454
  public long chroma(Data1D blend, Data3D color)
455
    {
456
    return mF.add(EffectNames.CHROMA, blend, color);
457
    }
458

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

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

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

    
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505
/**
506
 * Makes the whole 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
 * @return           ID of the effect added, or -1 if we failed to add one.
511
 */
512
  public long brightness(Data1D brightness)
513
    {
514
    return mF.add(EffectNames.BRIGHTNESS, brightness);
515
    }
516

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

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
/**
534
 * Makes the whole 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
 * @return         ID of the effect added, or -1 if we failed to add one.
539
 */
540
  public long contrast(Data1D contrast)
541
    {
542
    return mF.add(EffectNames.CONTRAST, contrast);
543
    }
544

    
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546
/**
547
 * Makes a certain sub-region of the Object smoothly change its saturation level.
548
 *        
549
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
550
 *                   at any given moment. Valid range: <0,infinity)
551
 * @param region     Region this Effect is limited to.
552
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
553
 * @return           ID of the effect added, or -1 if we failed to add one.
554
 */
555
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
556
    {
557
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
558
    }
559

    
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561
/**
562
 * Makes the whole 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
 * @return           ID of the effect added, or -1 if we failed to add one.
567
 */
568
  public long saturation(Data1D saturation)
569
    {
570
    return mF.add(EffectNames.SATURATION, saturation);
571
    }
572

    
573
///////////////////////////////////////////////////////////////////////////////////////////////////
574
// Vertex-based effects  
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
/**
577
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
578
 *
579
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
580
 *               currently being dragged with.
581
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
582
 * @param region Region that masks the Effect.
583
 * @return       ID of the effect added, or -1 if we failed to add one.
584
 */
585
  public long distort(Data3D vector, Data3D center, Data4D region)
586
    {  
587
    return mV.add(EffectNames.DISTORT, vector, center, region);
588
    }
589

    
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591
/**
592
 * Distort the whole 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
 * @return       ID of the effect added, or -1 if we failed to add one.
598
 */
599
  public long distort(Data3D vector, Data3D center)
600
    {
601
    return mV.add(EffectNames.DISTORT, vector, center, null);
602
    }
603

    
604
///////////////////////////////////////////////////////////////////////////////////////////////////
605
/**
606
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
607
 * a (possibly changing in time) point on the Object.
608
 *
609
 * @param vector Vector of force that deforms the shape of the whole Object.
610
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
611
 * @param region Region that masks the Effect.
612
 * @return       ID of the effect added, or -1 if we failed to add one.
613
 */
614
  public long deform(Data3D vector, Data3D center, Data4D region)
615
    {
616
    return mV.add(EffectNames.DEFORM, vector, center, region);
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
 * @return       ID of the effect added, or -1 if we failed to add one.
627
 */
628
  public long deform(Data3D vector, Data3D center)
629
    {  
630
    return mV.add(EffectNames.DEFORM, vector, center, null);
631
    }
632

    
633
///////////////////////////////////////////////////////////////////////////////////////////////////  
634
/**
635
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
636
 * away from the center (degree<=1)
637
 *
638
 * @param sink   The current degree of the Effect.
639
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
640
 * @param region Region that masks the Effect.
641
 * @return       ID of the effect added, or -1 if we failed to add one.
642
 */
643
  public long sink(Data1D sink, Data3D center, Data4D region)
644
    {
645
    return mV.add(EffectNames.SINK, sink, center, region);
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
 * @return       ID of the effect added, or -1 if we failed to add one.
656
 */
657
  public long sink(Data1D sink, Data3D center)
658
    {
659
    return mV.add(EffectNames.SINK, sink, center);
660
    }
661

    
662
///////////////////////////////////////////////////////////////////////////////////////////////////
663
/**
664
 * Pull all points around the center of the Effect towards a line passing through the center
665
 * (that's if degree>=1) or push them away from the line (degree<=1)
666
 *
667
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
668
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
669
 * @param region Region that masks the Effect.
670
 * @return       ID of the effect added, or -1 if we failed to add one.
671
 */
672
  public long pinch(Data2D pinch, Data3D center, Data4D region)
673
    {
674
    return mV.add(EffectNames.PINCH, pinch, center, region);
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
 * @return       ID of the effect added, or -1 if we failed to add one.
685
 */
686
  public long pinch(Data2D pinch, Data3D center)
687
    {
688
    return mV.add(EffectNames.PINCH, pinch, center);
689
    }
690

    
691
///////////////////////////////////////////////////////////////////////////////////////////////////  
692
/**
693
 * Rotate part of the Object around the Center of the Effect by a certain angle.
694
 *
695
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
696
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
697
 * @param region Region that masks the Effect.
698
 * @return       ID of the effect added, or -1 if we failed to add one.
699
 */
700
  public long swirl(Data1D swirl, Data3D center, Data4D region)
701
    {    
702
    return mV.add(EffectNames.SWIRL, swirl, center, region);
703
    }
704

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

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

    
752
///////////////////////////////////////////////////////////////////////////////////////////////////
753
/**
754
 * Directional, sinusoidal wave effect.
755
 *
756
 * @param wave   see {@link DistortedEffectQueues#wave(Data5D,Data3D)}
757
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
758
 * @param region Region that masks the Effect.
759
 * @return       ID of the effect added, or -1 if we failed to add one.
760
 */
761
  public long wave(Data5D wave, Data3D center, Data4D region)
762
    {
763
    return mV.add(EffectNames.WAVE, wave, center, region);
764
    }
765
  }
(2-2/15)