Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 985ea9c5

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.postprocess();
168
    mV.send();
169
        
170
    mF.compute(currTime);
171
    mF.postprocess(mViewMatrix);
172
    mF.send();
173
       
174
    mGrid.draw();
175
    }
176

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

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

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

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

    
218
    }
219

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

    
236
    mID = DistortedObjectList.add(this);
237

    
238
    mSizeX = dc.mSizeX;
239
    mSizeY = dc.mSizeY;
240
    mSizeZ = dc.mSizeZ;
241
    mGrid  = dc.mGrid;
242

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

    
258
      if( Distorted.isInitialized() ) resetTexture();
259
      }
260
    }
261

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

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

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

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

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

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

    
430
    return 0;
431
    }
432

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

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

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

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

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

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

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

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

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

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569
// Fragment-based effects  
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571
/**
572
 * Creates macroblocks at and around point defined by the Region.
573
 * 
574
 * @param size   1-dimensional Dynamic which, at any given time, returns the size of the macroblocks.
575
 * @param region Region this Effect is limited to.
576
 * @return       ID of the effect added, or -1 if we failed to add one.
577
 */
578
  public long macroblock(Data1D size, Data4D region)
579
    {
580
    return mF.add(EffectNames.MACROBLOCK, size, region);
581
    }
582

    
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584
/**
585
 * Creates macroblocks on the whole Object.
586
 *
587
 * @param size   1-dimensional Data which, at any given time, returns the size of the macroblocks.
588
 * @return       ID of the effect added, or -1 if we failed to add one.
589
 */
590
  public long macroblock(Data1D size)
591
    {
592
    return mF.add(EffectNames.MACROBLOCK, size);
593
    }
594

    
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596
/**
597
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
598
 *        
599
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
600
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color
601
 * @param color  Color to mix. (1,0,0) is RED.
602
 * @param region Region this Effect is limited to.
603
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
604
 * @return       ID of the effect added, or -1 if we failed to add one.
605
 */
606
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
607
    {
608
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
609
    }
610

    
611
///////////////////////////////////////////////////////////////////////////////////////////////////
612
/**
613
 * Makes the whole Object smoothly change all three of its RGB components.
614
 *
615
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
616
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color
617
 * @param color  Color to mix. (1,0,0) is RED.
618
 * @return       ID of the effect added, or -1 if we failed to add one.
619
 */
620
  public long chroma(Data1D blend, Data3D color)
621
    {
622
    return mF.add(EffectNames.CHROMA, blend, color);
623
    }
624

    
625
///////////////////////////////////////////////////////////////////////////////////////////////////
626
/**
627
 * Makes a certain sub-region of the Object smoothly change its transparency level.
628
 *        
629
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
630
 *               moment.
631
 * @param region Region this Effect is limited to. 
632
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
633
 * @return       ID of the effect added, or -1 if we failed to add one. 
634
 */
635
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
636
    {
637
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
638
    }
639

    
640
///////////////////////////////////////////////////////////////////////////////////////////////////
641
/**
642
 * Makes the whole Object smoothly change its transparency level.
643
 *
644
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
645
 *               given moment.
646
 * @return       ID of the effect added, or -1 if we failed to add one.
647
 */
648
  public long alpha(Data1D alpha)
649
    {
650
    return mF.add(EffectNames.ALPHA, alpha);
651
    }
652

    
653
///////////////////////////////////////////////////////////////////////////////////////////////////
654
/**
655
 * Makes a certain sub-region of the Object smoothly change its brightness level.
656
 *        
657
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
658
 *                   at any given moment.
659
 * @param region     Region this Effect is limited to.
660
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
661
 * @return           ID of the effect added, or -1 if we failed to add one.
662
 */
663
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
664
    {
665
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
666
    }
667

    
668
///////////////////////////////////////////////////////////////////////////////////////////////////
669
/**
670
 * Makes the whole Object smoothly change its brightness level.
671
 *
672
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
673
 *                   at any given moment.
674
 * @return           ID of the effect added, or -1 if we failed to add one.
675
 */
676
  public long brightness(Data1D brightness)
677
    {
678
    return mF.add(EffectNames.BRIGHTNESS, brightness);
679
    }
680

    
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682
/**
683
 * Makes a certain sub-region of the Object smoothly change its contrast level.
684
 *        
685
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
686
 *                 at any given moment.
687
 * @param region   Region this Effect is limited to.
688
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
689
 * @return         ID of the effect added, or -1 if we failed to add one.
690
 */
691
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
692
    {
693
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
694
    }
695

    
696
///////////////////////////////////////////////////////////////////////////////////////////////////
697
/**
698
 * Makes the whole Object smoothly change its contrast level.
699
 *
700
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
701
 *                 at any given moment.
702
 * @return         ID of the effect added, or -1 if we failed to add one.
703
 */
704
  public long contrast(Data1D contrast)
705
    {
706
    return mF.add(EffectNames.CONTRAST, contrast);
707
    }
708

    
709
///////////////////////////////////////////////////////////////////////////////////////////////////
710
/**
711
 * Makes a certain sub-region of the Object smoothly change its saturation level.
712
 *        
713
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
714
 *                   at any given moment.
715
 * @param region     Region this Effect is limited to.
716
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
717
 * @return           ID of the effect added, or -1 if we failed to add one.
718
 */
719
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
720
    {
721
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
722
    }
723

    
724
///////////////////////////////////////////////////////////////////////////////////////////////////
725
/**
726
 * Makes the whole Object smoothly change its saturation level.
727
 *
728
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
729
 *                   at any given moment.
730
 * @return           ID of the effect added, or -1 if we failed to add one.
731
 */
732
  public long saturation(Data1D saturation)
733
    {
734
    return mF.add(EffectNames.SATURATION, saturation);
735
    }
736

    
737
///////////////////////////////////////////////////////////////////////////////////////////////////
738
// Vertex-based effects  
739
///////////////////////////////////////////////////////////////////////////////////////////////////
740
/**
741
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
742
 *
743
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
744
 *               currently being dragged with.
745
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
746
 * @param region Region that masks the Effect.
747
 * @return       ID of the effect added, or -1 if we failed to add one.
748
 */
749
  public long distort(Data3D vector, Data2D center, Data4D region)
750
    {  
751
    return mV.add(EffectNames.DISTORT, vector, center, region);
752
    }
753

    
754
///////////////////////////////////////////////////////////////////////////////////////////////////
755
/**
756
 * Distort the whole Object by a (possibly changing in time) vector of force.
757
 *
758
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
759
 *               currently being dragged with.
760
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
761
 * @return       ID of the effect added, or -1 if we failed to add one.
762
 */
763
  public long distort(Data3D vector, Data2D center)
764
    {
765
    return mV.add(EffectNames.DISTORT, vector, center);
766
    }
767

    
768
///////////////////////////////////////////////////////////////////////////////////////////////////
769
/**
770
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
771
 * a (possibly changing in time) point on the Object.
772
 *     
773
 * @param vector Vector of force that deforms the shape of the whole Object.
774
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
775
 * @return       ID of the effect added, or -1 if we failed to add one.
776
 */
777
  public long deform(Data3D vector, Data2D center)
778
    {  
779
    return mV.add(EffectNames.DEFORM, vector, center);
780
    }
781

    
782
///////////////////////////////////////////////////////////////////////////////////////////////////  
783
/**
784
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
785
 * away from the center (degree<=1)
786
 *
787
 * @param sink   The current degree of the Effect.
788
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
789
 * @param region Region that masks the Effect.
790
 * @return       ID of the effect added, or -1 if we failed to add one.
791
 */
792
  public long sink(Data1D sink, Data2D center, Data4D region)
793
    {
794
    return mV.add(EffectNames.SINK, sink, center, region);
795
    }
796

    
797
///////////////////////////////////////////////////////////////////////////////////////////////////
798
/**
799
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
800
 * away from the center (degree<=1)
801
 *
802
 * @param sink   The current degree of the Effect.
803
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
804
 * @return       ID of the effect added, or -1 if we failed to add one.
805
 */
806
  public long sink(Data1D sink, Data2D center)
807
    {
808
    return mV.add(EffectNames.SINK, sink, center);
809
    }
810

    
811
///////////////////////////////////////////////////////////////////////////////////////////////////  
812
/**
813
 * Rotate part of the Object around the Center of the Effect by a certain angle.
814
 *
815
 * @param swirl  The degree of Swirl. Positive values swirl clockwise.
816
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
817
 * @param region Region that masks the Effect.
818
 * @return       ID of the effect added, or -1 if we failed to add one.
819
 */
820
  public long swirl(Data1D swirl, Data2D center, Data4D region)
821
    {    
822
    return mV.add(EffectNames.SWIRL, swirl, center, region);
823
    }
824

    
825
///////////////////////////////////////////////////////////////////////////////////////////////////
826
/**
827
 * Rotate the whole Object around the Center of the Effect by a certain angle.
828
 *
829
 * @param swirl  The degree of Swirl. Positive values swirl clockwise.
830
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
831
 * @return       ID of the effect added, or -1 if we failed to add one.
832
 */
833
  public long swirl(Data1D swirl, Data2D center)
834
    {
835
    return mV.add(EffectNames.SWIRL, swirl, center);
836
    }
837
  }
(8-8/18)