Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffectQueues.java @ 1942537e

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 release()
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
 *     
174
 * @param currTime current time, in milliseconds.
175
 *        This gets passed on to Dynamics inside the Effects that are currently applied to the
176
 *        Object.
177
 */
178
  public void draw(long currTime, DistortedTexture tex, GridObject grid)
179
    {
180
    tex.createTexture();
181
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
182
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
183
    drawPriv(currTime, tex, grid, Distorted.mFramebuffer);
184
    DistortedFramebuffer.deleteAllMarked();
185
    DistortedTexture.deleteAllMarked();
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
/**
190
 * Draw the DistortedObject to the Framebuffer passed.
191
 *
192
 * @param currTime Current time, in milliseconds.
193
 * @param df       Framebuffer to render this to.
194
 */
195
  public void draw(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
196
    {
197
    tex.createTexture();
198
    df.setAsOutput();
199
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
200
    drawPriv(currTime, tex, grid, df);
201
    DistortedFramebuffer.deleteAllMarked();
202
    DistortedTexture.deleteAllMarked();
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206
/**
207
 * Releases all resources.
208
 */
209
  public synchronized void delete()
210
    {
211
    releasePriv();
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215
/**
216
 * Returns unique ID of this instance.
217
 *
218
 * @return ID of the object.
219
 */
220
  public long getID()
221
      {
222
      return mID;
223
      }
224

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

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

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

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

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

    
295
    return 0;
296
    }
297

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

    
328
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
329
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
330
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
331

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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