Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 02ef26bc

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.graphics.Bitmap;
23
import android.graphics.Matrix;
24
import android.opengl.GLES20;
25
import android.opengl.GLUtils;
26

    
27
import org.distorted.library.message.EffectListener;
28
import org.distorted.library.type.Data1D;
29
import org.distorted.library.type.Data2D;
30
import org.distorted.library.type.Data3D;
31
import org.distorted.library.type.Data4D;
32
import org.distorted.library.type.Static3D;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
/**
36
 * All Objects to which Distorted Graphics effects can be applied need to be extended from here.
37
 */
38
public abstract class DistortedObject 
39
  {
40
  private static float[] mViewMatrix   = new float[16];
41
   
42
  protected EffectQueueMatrix    mM;
43
  protected EffectQueueFragment  mF;
44
  protected EffectQueueVertex    mV;
45

    
46
  protected boolean matrixCloned, vertexCloned, fragmentCloned;
47
 
48
  protected DistortedObjectGrid mGrid = null;
49
  protected long mID;
50
  protected int mSizeX, mSizeY, mSizeZ; // in screen space
51

    
52
  protected Bitmap[] mBmp= null; //
53
  int[] mTextureDataH;           // have to be shared among all the cloned Objects
54
  boolean[] mBitmapSet;          //
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
// We have to flip vertically every single Bitmap that we get fed with.
58
//
59
// Reason: textures read from files are the only objects in OpenGL which have their origins at the
60
// upper-left corner. Everywhere else the origin is in the lower-left corner. Thus we have to flip.
61
// The alternative solution, namely inverting the y-coordinate of the TexCoord does not really work-
62
// i.e. it works only in case of rendering directly to the screen, but if we render to an FBO and
63
// then take the FBO and render to screen, (DistortedNode does so!) things get inverted as textures
64
// created from FBO have their origins in the lower-left... Mindfuck!
65

    
66
  private static Bitmap flipBitmap(Bitmap src)
67
    {
68
    Matrix matrix = new Matrix();
69
    matrix.preScale(1.0f,-1.0f);
70

    
71
    return Bitmap.createBitmap(src,0,0,src.getWidth(),src.getHeight(), matrix,true);
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  protected abstract DistortedObject deepCopy(int flags);
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  protected void initializeData()
81
    {
82
    mID             = DistortedObjectList.add(this);
83
    mTextureDataH   = new int[1];
84
    mTextureDataH[0]= 0;
85
    mBmp            = new Bitmap[1];
86
    mBmp[0]         = null;
87
    mBitmapSet      = new boolean[1];
88
    mBitmapSet[0]   = false;
89
      
90
    initializeEffectLists(this,0);
91
      
92
    if( Distorted.isInitialized() ) resetTexture();
93
    }
94
    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
    
97
  protected void initializeEffectLists(DistortedObject d, int flags)
98
    {
99
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
100
      {
101
      mM = d.mM;
102
      matrixCloned = true;
103
      }
104
    else
105
      {
106
      mM = new EffectQueueMatrix(d);
107
      matrixCloned = false;
108
      }
109
    
110
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
111
      {
112
      mV = d.mV;
113
      vertexCloned = true;
114
      }
115
    else
116
      {
117
      mV = new EffectQueueVertex(d);
118
      vertexCloned = false;
119
      }
120
    
121
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
122
      {
123
      mF = d.mF;
124
      fragmentCloned = true;
125
      }
126
    else
127
      {
128
      mF = new EffectQueueFragment(d);
129
      fragmentCloned = false;
130
      }
131
    }
132
    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
// this will be called on startup and every time OpenGL context has been lost
135
// also call this from the constructor if the OpenGL context has been created already.
136
    
137
  void resetTexture()
138
    {
139
    if( mTextureDataH!=null )
140
      {
141
      if( mTextureDataH[0]==0 ) GLES20.glGenTextures(1, mTextureDataH, 0);
142

    
143
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
144
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR );
145
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR );
146
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
147
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
148
       
149
      if( mBmp!=null && mBmp[0]!=null)
150
        {
151
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp[0]), 0);
152
        mBmp[0] = null;
153
        }
154
      }
155
    }
156
  
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
   
159
  void drawPriv(long currTime, DistortedProjection dp)
160
    {
161
    GLES20.glViewport(0, 0, dp.width, dp.height);
162
      
163
    mM.compute(currTime);
164
    mM.send(mViewMatrix, dp);
165
      
166
    mV.compute(currTime);
167
    mV.send();
168
        
169
    mF.compute(currTime);
170
    mF.send();
171
       
172
    mGrid.draw();
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176
   
177
  void drawNoEffectsPriv(DistortedProjection dp)
178
    {
179
    GLES20.glViewport(0, 0, dp.width, dp.height);
180
    mM.sendNoEffects(dp);
181
    mV.sendZero();
182
    mF.sendZero();
183
    mGrid.draw();
184
    }
185
    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187
   
188
  void releasePriv()
189
    {
190
    if( matrixCloned  ==false) mM.abortAll(false);
191
    if( vertexCloned  ==false) mV.abortAll(false);
192
    if( fragmentCloned==false) mF.abortAll(false);
193

    
194
    mBmp          = null;
195
    mGrid         = null;
196
    mM            = null;
197
    mV            = null;
198
    mF            = null;
199
    mTextureDataH = null;
200
    }
201
 
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

    
204
  long getBitmapID()
205
      {
206
      return mBmp==null ? 0 : mBmp.hashCode();
207
      }
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210
/**
211
 * Default empty constructor so that derived classes can call it
212
 */
213
  public DistortedObject()
214
    {
215

    
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
/**
220
 * Copy constructor used to create a DistortedObject based on various parts of another object.
221
 * <p>
222
 * Whatever we do not clone gets created just like in the default constructor.
223
 * We only call this from the descendant's classes' constructors where we have to pay attention
224
 * to give it the appropriate type of a DistortedObject!
225
 *
226
 * @param dc    Source object to create our object from
227
 * @param flags A bitmask of values specifying what to copy.
228
 *              For example, CLONE_BITMAP | CLONE_MATRIX.
229
 */
230
  public DistortedObject(DistortedObject dc, int flags)
231
    {
232
    initializeEffectLists(dc,flags);
233

    
234
    mID = DistortedObjectList.add(this);
235

    
236
    mSizeX = dc.mSizeX;
237
    mSizeY = dc.mSizeY;
238
    mSizeZ = dc.mSizeZ;
239
    mGrid  = dc.mGrid;
240

    
241
    if( (flags & Distorted.CLONE_BITMAP) != 0 )
242
      {
243
      mTextureDataH = dc.mTextureDataH;
244
      mBmp          = dc.mBmp;
245
      mBitmapSet    = dc.mBitmapSet;
246
      }
247
    else
248
      {
249
      mTextureDataH   = new int[1];
250
      mTextureDataH[0]= 0;
251
      mBitmapSet      = new boolean[1];
252
      mBitmapSet[0]   = false;
253
      mBmp            = new Bitmap[1];
254
      mBmp[0]         = null;
255

    
256
      if( Distorted.isInitialized() ) resetTexture();
257
      }
258
    }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261
/**
262
 * Draw the DistortedObject to the location specified by current Matrix effects.    
263
 *     
264
 * @param currTime current time, in milliseconds, as returned by System.currentTimeMillis().
265
 *        This gets passed on to Interpolators inside the Effects that are currently applied to the 
266
 *        Object.
267
 */
268
  public void draw(long currTime)
269
    {
270
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
271
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
272
    GLES20.glUniform1i(Distorted.mTextureUniformH, 0);
273
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
274
      
275
    drawPriv(currTime, Distorted.mProjection);
276
    }
277
 
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279
/**
280
 * Releases all resources.
281
 */
282
  public synchronized void release()
283
    {
284
    releasePriv();
285
    DistortedObjectList.remove(this);
286
    }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
/**
290
 * Sets the underlying android.graphics.Bitmap object and uploads it to the GPU. 
291
 * <p>
292
 * You can only recycle() the passed Bitmap once the OpenGL context gets created (i.e. after call 
293
 * to onSurfaceCreated) because only after this point can the Library upload it to the GPU!
294
 * 
295
 * @param bmp The android.graphics.Bitmap object to apply effects to and display.
296
 */
297
   
298
  public void setBitmap(Bitmap bmp)
299
    {
300
    mBitmapSet[0] = true;
301
      
302
    if( Distorted.isInitialized() )
303
      {
304
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
305
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
306
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(bmp), 0);
307
      }
308
    else
309
      {
310
      mBmp[0] = bmp;
311
      }
312
    }
313
    
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315
/**
316
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
317
 * to one of the Effects that are currently applied to the DistortedObject.
318
 * 
319
 * @param el A class implementing the EffectListener interface that wants to get notifications.
320
 */
321
  public void addEventListener(EffectListener el)
322
    {
323
    mV.addListener(el);
324
    mF.addListener(el);
325
    mM.addListener(el);
326
    }
327

    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
/**
330
 * Removes the calling class from the list of Listeners.
331
 * 
332
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
333
 */
334
  public void removeEventListener(EffectListener el)
335
    {
336
    mV.removeListener(el);
337
    mF.removeListener(el);
338
    mM.removeListener(el);
339
    }
340
   
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
/**
343
 * Returns the height of the DistortedObject.
344
 *    
345
 * @return height of the object, in pixels.
346
 */
347
  public int getWidth()
348
     {
349
     return mSizeX;   
350
     }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353
/**
354
 * Returns the width of the DistortedObject.
355
 * 
356
 * @return width of the Object, in pixels.
357
 */
358
  public int getHeight()
359
      {
360
      return mSizeY;  
361
      }
362
    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364
/**
365
 * Returns the depth of the DistortedObject.
366
 * 
367
 * @return depth of the Object, in pixels.
368
 */
369
  public int getDepth()
370
      {
371
      return mSizeZ;  
372
      }
373
        
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375
/**
376
 * Returns unique ID of this instance.
377
 * 
378
 * @return ID of the object.
379
 */
380
  public long getID()
381
      {
382
      return mID;  
383
      }
384
    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386
/**
387
 * Aborts all Effects.
388
 * @return Number of effects aborted.
389
 */
390
  public int abortAllEffects()
391
      {
392
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
393
      }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396
/**
397
 * Aborts all Effects of a given type, for example all MATRIX Effects.
398
 * 
399
 * @param type one of the constants defined in {@link EffectTypes}
400
 * @return Number of effects aborted.
401
 */
402
  public int abortEffects(EffectTypes type)
403
    {
404
    switch(type)
405
      {
406
      case MATRIX  : return mM.abortAll(true);
407
      case VERTEX  : return mV.abortAll(true);
408
      case FRAGMENT: return mF.abortAll(true);
409
      default      : return 0;
410
      }
411
    }
412
    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414
/**
415
 * Aborts a single Effect.
416
 * 
417
 * @param id ID of the Effect we want to abort.
418
 * @return number of Effects aborted. Always either 0 or 1.
419
 */
420
  public int abortEffect(long id)
421
    {
422
    int type = (int)(id&EffectTypes.MASK);
423

    
424
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
425
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
426
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
427

    
428
    return 0;
429
    }
430

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432
/**
433
 * Abort all Effects of a given name, for example all rotations.
434
 * 
435
 * @param name one of the constants defined in {@link EffectNames}
436
 * @return number of Effects aborted.
437
 */
438
  public int abortEffects(EffectNames name)
439
    {
440
    switch(name.getType())
441
      {
442
      case MATRIX  : return mM.removeByType(name);
443
      case VERTEX  : return mV.removeByType(name);
444
      case FRAGMENT: return mF.removeByType(name);
445
      default      : return 0;
446
      }
447
    }
448
    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
/**
451
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
452
 * 
453
 * @param id Effect ID we want to print info about
454
 * @return <code>true</code> if a single Effect of type effectType has been found.
455
 */
456
    
457
  public boolean printEffect(long id)
458
    {
459
    int type = (int)(id&EffectTypes.MASK);
460

    
461
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
462
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
463
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
464

    
465
    return false;
466
    }
467
   
468
///////////////////////////////////////////////////////////////////////////////////////////////////   
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470
// Individual effect functions.
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472
// Matrix-based effects
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474
/**
475
 * Moves the Object by a (possibly changing in time) vector.
476
 * 
477
 * @param vector 3-dimensional Data which at any given time will return a Static3D
478
 *               representing the current coordinates of the vector we want to move the Object with.
479
 * @return       ID of the effect added, or -1 if we failed to add one.
480
 */
481
  public long move(Data3D vector)
482
    {   
483
    return mM.add(EffectNames.MOVE,vector);
484
    }
485

    
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487
/**
488
 * Scales the Object by (possibly changing in time) 3D scale factors.
489
 * 
490
 * @param scale 3-dimensional Dynamic which at any given time returns a Static3D
491
 *              representing the current x- , y- and z- scale factors.
492
 * @return      ID of the effect added, or -1 if we failed to add one.
493
 */
494
  public long scale(Data3D scale)
495
    {   
496
    return mM.add(EffectNames.SCALE,scale);
497
    }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500
/**
501
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
502
 *
503
 * @param scale The factor to scale all 3 dimensions with.
504
 * @return      ID of the effect added, or -1 if we failed to add one.
505
 */
506
  public long scale(float scale)
507
    {
508
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
509
    }
510

    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512
/**
513
 * Rotates the Object by 'angle' degrees around the center.
514
 * Static axis of rotation is given by the last parameter.
515
 *
516
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
517
 * @param axis   Axis of rotation
518
 * @param center Coordinates of the Point we are rotating around.
519
 * @return       ID of the effect added, or -1 if we failed to add one.
520
 */
521
  public long rotate(Data1D angle, Static3D axis, Data3D center )
522
    {   
523
    return mM.add(EffectNames.ROTATE, angle, axis, center);
524
    }
525

    
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527
/**
528
 * Rotates the Object by 'angle' degrees around the center.
529
 * Here both angle and axis can dynamically change.
530
 *
531
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
532
 * @param center    Coordinates of the Point we are rotating around.
533
 * @return          ID of the effect added, or -1 if we failed to add one.
534
 */
535
  public long rotate(Data4D angleaxis, Data3D center)
536
    {
537
    return mM.add(EffectNames.ROTATE, angleaxis, center);
538
    }
539

    
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541
/**
542
 * Rotates the Object by quaternion.
543
 *
544
 * @param quaternion The quaternion describing the rotation.
545
 * @param center     Coordinates of the Point we are rotating around.
546
 * @return           ID of the effect added, or -1 if we failed to add one.
547
 */
548
  public long quaternion(Data4D quaternion, Data3D center )
549
    {
550
    return mM.add(EffectNames.QUATERNION,quaternion,center);
551
    }
552

    
553
///////////////////////////////////////////////////////////////////////////////////////////////////
554
/**
555
 * Shears the Object.
556
 *
557
 * @param shear   The 3-tuple of shear factors.
558
 * @param center  Center of shearing, i.e. the point which stays unmoved.
559
 * @return        ID of the effect added, or -1 if we failed to add one.
560
 */
561
  public long shear(Data3D shear, Data3D center)
562
    {
563
    return mM.add(EffectNames.SHEAR, shear, center);
564
    }
565

    
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567
// Fragment-based effects  
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569
/**
570
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
571
 *        
572
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
573
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
574
 *               Valid range: <0,1>
575
 * @param color  Color to mix. (1,0,0) is RED.
576
 * @param region Region this Effect is limited to.
577
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
578
 * @return       ID of the effect added, or -1 if we failed to add one.
579
 */
580
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
581
    {
582
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
583
    }
584

    
585
///////////////////////////////////////////////////////////////////////////////////////////////////
586
/**
587
 * Makes the whole Object smoothly change all three of its RGB components.
588
 *
589
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
590
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
591
 *               Valid range: <0,1>
592
 * @param color  Color to mix. (1,0,0) is RED.
593
 * @return       ID of the effect added, or -1 if we failed to add one.
594
 */
595
  public long chroma(Data1D blend, Data3D color)
596
    {
597
    return mF.add(EffectNames.CHROMA, blend, color);
598
    }
599

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601
/**
602
 * Makes a certain sub-region of the Object smoothly change its transparency level.
603
 *        
604
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
605
 *               moment: pixel.a *= alpha.
606
 *               Valid range: <0,1>
607
 * @param region Region this Effect is limited to. 
608
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
609
 * @return       ID of the effect added, or -1 if we failed to add one. 
610
 */
611
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
612
    {
613
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
614
    }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617
/**
618
 * Makes the whole Object smoothly change its transparency level.
619
 *
620
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
621
 *               given moment: pixel.a *= alpha.
622
 *               Valid range: <0,1>
623
 * @return       ID of the effect added, or -1 if we failed to add one.
624
 */
625
  public long alpha(Data1D alpha)
626
    {
627
    return mF.add(EffectNames.ALPHA, alpha);
628
    }
629

    
630
///////////////////////////////////////////////////////////////////////////////////////////////////
631
/**
632
 * Makes a certain sub-region of the Object smoothly change its brightness level.
633
 *        
634
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
635
 *                   at any given moment. Valid range: <0,infinity)
636
 * @param region     Region this Effect is limited to.
637
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
638
 * @return           ID of the effect added, or -1 if we failed to add one.
639
 */
640
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
641
    {
642
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
643
    }
644

    
645
///////////////////////////////////////////////////////////////////////////////////////////////////
646
/**
647
 * Makes the whole Object smoothly change its brightness level.
648
 *
649
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
650
 *                   at any given moment. Valid range: <0,infinity)
651
 * @return           ID of the effect added, or -1 if we failed to add one.
652
 */
653
  public long brightness(Data1D brightness)
654
    {
655
    return mF.add(EffectNames.BRIGHTNESS, brightness);
656
    }
657

    
658
///////////////////////////////////////////////////////////////////////////////////////////////////
659
/**
660
 * Makes a certain sub-region of the Object smoothly change its contrast level.
661
 *        
662
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
663
 *                 at any given moment. Valid range: <0,infinity)
664
 * @param region   Region this Effect is limited to.
665
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
666
 * @return         ID of the effect added, or -1 if we failed to add one.
667
 */
668
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
669
    {
670
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
671
    }
672

    
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674
/**
675
 * Makes the whole Object smoothly change its contrast level.
676
 *
677
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
678
 *                 at any given moment. Valid range: <0,infinity)
679
 * @return         ID of the effect added, or -1 if we failed to add one.
680
 */
681
  public long contrast(Data1D contrast)
682
    {
683
    return mF.add(EffectNames.CONTRAST, contrast);
684
    }
685

    
686
///////////////////////////////////////////////////////////////////////////////////////////////////
687
/**
688
 * Makes a certain sub-region of the Object smoothly change its saturation level.
689
 *        
690
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
691
 *                   at any given moment. Valid range: <0,infinity)
692
 * @param region     Region this Effect is limited to.
693
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
694
 * @return           ID of the effect added, or -1 if we failed to add one.
695
 */
696
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
697
    {
698
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
699
    }
700

    
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702
/**
703
 * Makes the whole Object smoothly change its saturation level.
704
 *
705
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
706
 *                   at any given moment. Valid range: <0,infinity)
707
 * @return           ID of the effect added, or -1 if we failed to add one.
708
 */
709
  public long saturation(Data1D saturation)
710
    {
711
    return mF.add(EffectNames.SATURATION, saturation);
712
    }
713

    
714
///////////////////////////////////////////////////////////////////////////////////////////////////
715
// Vertex-based effects  
716
///////////////////////////////////////////////////////////////////////////////////////////////////
717
/**
718
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
719
 *
720
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
721
 *               currently being dragged with.
722
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
723
 * @param region Region that masks the Effect.
724
 * @return       ID of the effect added, or -1 if we failed to add one.
725
 */
726
  public long distort(Data3D vector, Data2D center, Data4D region)
727
    {  
728
    return mV.add(EffectNames.DISTORT, vector, center, region);
729
    }
730

    
731
///////////////////////////////////////////////////////////////////////////////////////////////////
732
/**
733
 * Distort the whole Object by a (possibly changing in time) vector of force.
734
 *
735
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
736
 *               currently being dragged with.
737
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
738
 * @return       ID of the effect added, or -1 if we failed to add one.
739
 */
740
  public long distort(Data3D vector, Data2D center)
741
    {
742
    return mV.add(EffectNames.DISTORT, vector, center, null);
743
    }
744

    
745
///////////////////////////////////////////////////////////////////////////////////////////////////
746
/**
747
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
748
 * a (possibly changing in time) point on the Object.
749
 *     
750
 * @param vector Vector of force that deforms the shape of the whole Object.
751
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
752
 * @return       ID of the effect added, or -1 if we failed to add one.
753
 */
754
  public long deform(Data3D vector, Data2D center)
755
    {  
756
    return mV.add(EffectNames.DEFORM, vector, center, null);
757
    }
758

    
759
///////////////////////////////////////////////////////////////////////////////////////////////////  
760
/**
761
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
762
 * away from the center (degree<=1)
763
 *
764
 * @param sink   The current degree of the Effect.
765
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
766
 * @param region Region that masks the Effect.
767
 * @return       ID of the effect added, or -1 if we failed to add one.
768
 */
769
  public long sink(Data1D sink, Data2D center, Data4D region)
770
    {
771
    return mV.add(EffectNames.SINK, sink, center, region);
772
    }
773

    
774
///////////////////////////////////////////////////////////////////////////////////////////////////
775
/**
776
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
777
 * away from the center (degree<=1)
778
 *
779
 * @param sink   The current degree of the Effect.
780
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
781
 * @return       ID of the effect added, or -1 if we failed to add one.
782
 */
783
  public long sink(Data1D sink, Data2D center)
784
    {
785
    return mV.add(EffectNames.SINK, sink, center);
786
    }
787

    
788
///////////////////////////////////////////////////////////////////////////////////////////////////  
789
/**
790
 * Rotate part of the Object around the Center of the Effect by a certain angle.
791
 *
792
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
793
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
794
 * @param region Region that masks the Effect.
795
 * @return       ID of the effect added, or -1 if we failed to add one.
796
 */
797
  public long swirl(Data1D swirl, Data2D center, Data4D region)
798
    {    
799
    return mV.add(EffectNames.SWIRL, swirl, center, region);
800
    }
801

    
802
///////////////////////////////////////////////////////////////////////////////////////////////////
803
/**
804
 * Rotate the whole Object around the Center of the Effect by a certain angle.
805
 *
806
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
807
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
808
 * @return       ID of the effect added, or -1 if we failed to add one.
809
 */
810
  public long swirl(Data1D swirl, Data2D center)
811
    {
812
    return mV.add(EffectNames.SWIRL, swirl, center);
813
    }
814

    
815
///////////////////////////////////////////////////////////////////////////////////////////////////
816
/**
817
 * Directional, sinusoidal wave effect.
818
 *
819
 * @param wave   A 3-dimensional data structure describing the wave: first member is the amplitude,
820
 *               second is the angle (in degrees, as always) the direction of the wave forms with
821
 *               the X-axis, and the third is the wave length.
822
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
823
 * @return       ID of the effect added, or -1 if we failed to add one.
824
 */
825
  public long wave(Data4D wave, Data2D center)
826
    {
827
    return mV.add(EffectNames.WAVE, wave, center, null);
828
    }
829

    
830
///////////////////////////////////////////////////////////////////////////////////////////////////
831
/**
832
 * Directional, sinusoidal wave effect.
833
 *
834
 * @param wave   A 3-dimensional data structure describing the wave: first member is the amplitude,
835
 *               second is the angle (in degrees, as always) the direction of the wave forms with
836
 *               the X-axis, and the third is the wave length.
837
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
838
 * @param region Region that masks the Effect.
839
 * @return       ID of the effect added, or -1 if we failed to add one.
840
 */
841
  public long wave(Data4D wave, Data2D center, Data4D region)
842
    {
843
    return mV.add(EffectNames.WAVE, wave, center, region);
844
    }
845
  }
(8-8/18)