Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ ffbf279e

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.opengl.GLES20;
24
import android.opengl.GLUtils;
25

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

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

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

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  protected abstract DistortedObject deepCopy(int flags);
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  protected void initializeData()
62
    {
63
    mID             = DistortedObjectList.add(this);
64
    mTextureDataH   = new int[1];
65
    mTextureDataH[0]= 0;
66
    mBmp            = new Bitmap[1];
67
    mBmp[0]         = null;
68
    mBitmapSet      = new boolean[1];
69
    mBitmapSet[0]   = false;
70
      
71
    initializeEffectLists(this,0);
72
      
73
    if( Distorted.isInitialized() ) resetTexture();
74
    }
75
    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
    
78
  protected void initializeEffectLists(DistortedObject d, int flags)
79
    {
80
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
81
      {
82
      mM = d.mM;
83
      matrixCloned = true;
84
      }
85
    else
86
      {
87
      mM = new EffectQueueMatrix(d);
88
      matrixCloned = false;
89
      }
90
    
91
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
92
      {
93
      mV = d.mV;
94
      vertexCloned = true;
95
      }
96
    else
97
      {
98
      mV = new EffectQueueVertex(d);
99
      vertexCloned = false;
100
      }
101
    
102
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
103
      {
104
      mF = d.mF;
105
      fragmentCloned = true;
106
      }
107
    else
108
      {
109
      mF = new EffectQueueFragment(d);
110
      fragmentCloned = false;
111
      }
112
    }
113
    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115
// this will be called on startup and every time OpenGL context has been lost
116
// also call this from the constructor if the OpenGL context has been created already.
117
    
118
  void resetTexture()
119
    {
120
    if( mTextureDataH!=null )
121
      {
122
      if( mTextureDataH[0]==0 ) GLES20.glGenTextures(1, mTextureDataH, 0);
123

    
124
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
125
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR );
126
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR );
127
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
128
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
129
       
130
      if( mBmp!=null && mBmp[0]!=null)
131
        {
132
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, mBmp[0], 0);
133
        mBmp[0] = null;
134
        }
135
      }
136
    }
137
  
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
   
140
  void drawPriv(long currTime, DistortedProjection dp)
141
    {
142
    GLES20.glViewport(0, 0, dp.width, dp.height);
143
      
144
    mM.compute(currTime);
145
    mM.send(mViewMatrix, dp);
146
      
147
    mV.compute(currTime);
148
    mV.postprocess();
149
    mV.send();
150
        
151
    mF.compute(currTime);
152
    mF.postprocess(mViewMatrix);
153
    mF.send();
154
       
155
    mGrid.draw();
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
   
160
  void drawNoEffectsPriv(DistortedProjection dp)
161
    {
162
    GLES20.glViewport(0, 0, dp.width, dp.height);
163
    mM.sendNoEffects(dp);
164
    mV.sendZero();
165
    mF.sendZero();
166
    mGrid.draw();
167
    }
168
    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170
   
171
  void releasePriv()
172
    {
173
    if( matrixCloned  ==false) mM.abortAll(false);
174
    if( vertexCloned  ==false) mV.abortAll(false);
175
    if( fragmentCloned==false) mF.abortAll(false);
176

    
177
    mBmp          = null;
178
    mGrid         = null;
179
    mM            = null;
180
    mV            = null;
181
    mF            = null;
182
    mTextureDataH = null;
183
    }
184
 
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

    
187
  long getBitmapID()
188
      {
189
      return mBmp==null ? 0 : mBmp.hashCode();
190
      }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193
/**
194
 * Default empty constructor so that derived classes can call it
195
 */
196
  public DistortedObject()
197
    {
198

    
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202
/**
203
 * Copy constructor used to create a DistortedObject based on various parts of another object.
204
 * <p>
205
 * Whatever we do not clone gets created just like in the default constructor.
206
 * We only call this from the descendant's classes' constructors where we have to pay attention
207
 * to give it the appropriate type of a DistortedObject!
208
 *
209
 * @param dc    Source object to create our object from
210
 * @param flags A bitmask of values specifying what to copy.
211
 *              For example, CLONE_BITMAP | CLONE_MATRIX.
212
 */
213
  public DistortedObject(DistortedObject dc, int flags)
214
    {
215
    initializeEffectLists(dc,flags);
216

    
217
    mID = DistortedObjectList.add(this);
218

    
219
    mSizeX = dc.mSizeX;
220
    mSizeY = dc.mSizeY;
221
    mSizeZ = dc.mSizeZ;
222
    mGrid  = dc.mGrid;
223

    
224
    if( (flags & Distorted.CLONE_BITMAP) != 0 )
225
      {
226
      mTextureDataH = dc.mTextureDataH;
227
      mBmp          = dc.mBmp;
228
      mBitmapSet    = dc.mBitmapSet;
229
      }
230
    else
231
      {
232
      mTextureDataH   = new int[1];
233
      mTextureDataH[0]= 0;
234
      mBitmapSet      = new boolean[1];
235
      mBitmapSet[0]   = false;
236
      mBmp            = new Bitmap[1];
237
      mBmp[0]         = null;
238

    
239
      if( Distorted.isInitialized() ) resetTexture();
240
      }
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
/**
245
 * Draw the DistortedObject to the location specified by current Matrix effects.    
246
 *     
247
 * @param currTime current time, in milliseconds, as returned by System.currentTimeMillis().
248
 *        This gets passed on to Interpolators inside the Effects that are currently applied to the 
249
 *        Object.
250
 */
251
  public void draw(long currTime)
252
    {
253
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
254
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
255
    GLES20.glUniform1i(Distorted.mTextureUniformH, 0);
256
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
257
      
258
    drawPriv(currTime, Distorted.mProjection);
259
    }
260
 
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262
/**
263
 * Releases all resources.
264
 */
265
  public synchronized void release()
266
    {
267
    releasePriv();
268
    DistortedObjectList.remove(this);
269
    }
270

    
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272
/**
273
 * Sets the underlying android.graphics.Bitmap object and uploads it to the GPU. 
274
 * <p>
275
 * You can only recycle() the passed Bitmap once the OpenGL context gets created (i.e. after call 
276
 * to onSurfaceCreated) because only after this point can the Library upload it to the GPU!
277
 * 
278
 * @param bmp The android.graphics.Bitmap object to apply effects to and display.
279
 */
280
   
281
  public void setBitmap(Bitmap bmp)
282
    {
283
    mBitmapSet[0] = true;
284
      
285
    if( Distorted.isInitialized() )
286
      {
287
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
288
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
289
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);
290
      }
291
    else
292
      {
293
      mBmp[0] = bmp;
294
      }
295
    }
296
    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298
/**
299
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
300
 * to one of the Effects that are currently applied to the DistortedObject.
301
 * 
302
 * @param el A class implementing the EffectListener interface that wants to get notifications.
303
 */
304
  public void addEventListener(EffectListener el)
305
    {
306
    mV.addListener(el);
307
    mF.addListener(el);
308
    mM.addListener(el);
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
/**
313
 * Removes the calling class from the list of Listeners.
314
 * 
315
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
316
 */
317
  public void removeEventListener(EffectListener el)
318
    {
319
    mV.removeListener(el);
320
    mF.removeListener(el);
321
    mM.removeListener(el);
322
    }
323
   
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325
/**
326
 * Returns the height of the DistortedObject.
327
 *    
328
 * @return height of the object, in pixels.
329
 */
330
  public int getWidth()
331
     {
332
     return mSizeX;   
333
     }
334

    
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336
/**
337
 * Returns the width of the DistortedObject.
338
 * 
339
 * @return width of the Object, in pixels.
340
 */
341
  public int getHeight()
342
      {
343
      return mSizeY;  
344
      }
345
    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347
/**
348
 * Returns the depth of the DistortedObject.
349
 * 
350
 * @return depth of the Object, in pixels.
351
 */
352
  public int getDepth()
353
      {
354
      return mSizeZ;  
355
      }
356
        
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358
/**
359
 * Returns unique ID of this instance.
360
 * 
361
 * @return ID of the object.
362
 */
363
  public long getID()
364
      {
365
      return mID;  
366
      }
367
    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369
/**
370
 * Aborts all Effects.
371
 * @return Number of effects aborted.
372
 */
373
  public int abortAllEffects()
374
      {
375
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
376
      }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379
/**
380
 * Aborts all Effects of a given type, for example all MATRIX Effects.
381
 * 
382
 * @param type one of the constants defined in {@link EffectTypes}
383
 * @return Number of effects aborted.
384
 */
385
  public int abortEffects(EffectTypes type)
386
    {
387
    switch(type)
388
      {
389
      case MATRIX  : return mM.abortAll(true);
390
      case VERTEX  : return mV.abortAll(true);
391
      case FRAGMENT: return mF.abortAll(true);
392
      default      : return 0;
393
      }
394
    }
395
    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
/**
398
 * Aborts a single Effect.
399
 * 
400
 * @param id ID of the Effect we want to abort.
401
 * @return number of Effects aborted. Always either 0 or 1.
402
 */
403
  public int abortEffect(long id)
404
    {
405
    int type = (int)(id&EffectTypes.MASK);
406

    
407
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
408
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
409
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
410

    
411
    return 0;
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415
/**
416
 * Abort all Effects of a given name, for example all rotations.
417
 * 
418
 * @param name one of the constants defined in {@link EffectNames}
419
 * @return number of Effects aborted.
420
 */
421
  public int abortEffects(EffectNames name)
422
    {
423
    switch(name.getType())
424
      {
425
      case MATRIX  : return mM.removeByType(name);
426
      case VERTEX  : return mV.removeByType(name);
427
      case FRAGMENT: return mF.removeByType(name);
428
      default      : return 0;
429
      }
430
    }
431
    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433
/**
434
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
435
 * 
436
 * @param id Effect ID we want to print info about
437
 * @return <code>true</code> if a single Effect of type effectType has been found.
438
 */
439
    
440
  public boolean printEffect(long id)
441
    {
442
    int type = (int)(id&EffectTypes.MASK);
443

    
444
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
445
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
446
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
447

    
448
    return false;
449
    }
450
   
451
///////////////////////////////////////////////////////////////////////////////////////////////////   
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
// Individual effect functions.
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455
// Matrix-based effects
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457
/**
458
 * Moves the Object by a (possibly changing in time) vector.
459
 * 
460
 * @param vector 3-dimensional Data which at any given time will return a Static3D
461
 *               representing the current coordinates of the vector we want to move the Object with.
462
 * @return       ID of the effect added, or -1 if we failed to add one.
463
 */
464
  public long move(Data3D vector)
465
    {   
466
    return mM.add(EffectNames.MOVE,vector);
467
    }
468

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470
/**
471
 * Scales the Object by (possibly changing in time) 3D scale factors.
472
 * 
473
 * @param scale 3-dimensional Dynamic which at any given time returns a Static3D
474
 *              representing the current x- , y- and z- scale factors.
475
 * @return      ID of the effect added, or -1 if we failed to add one.
476
 */
477
  public long scale(Data3D scale)
478
    {   
479
    return mM.add(EffectNames.SCALE,scale);
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483
/**
484
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
485
 *
486
 * @param scale The factor to scale all 3 dimensions with.
487
 * @return      ID of the effect added, or -1 if we failed to add one.
488
 */
489
  public long scale(float scale)
490
    {
491
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
492
    }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495
/**
496
 * Rotates the Object by 'angle' degrees around the center.
497
 * Static axis of rotation is given by the last parameter.
498
 *
499
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
500
 * @param axis   Axis of rotation
501
 * @param center Coordinates of the Point we are rotating around.
502
 * @return       ID of the effect added, or -1 if we failed to add one.
503
 */
504
  public long rotate(Data1D angle, Static3D axis, Data3D center )
505
    {   
506
    return mM.add(EffectNames.ROTATE, angle, axis, center);
507
    }
508

    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510
/**
511
 * Rotates the Object by 'angle' degrees around the center.
512
 * Here both angle and axis can dynamically change.
513
 *
514
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
515
 * @param center    Coordinates of the Point we are rotating around.
516
 * @return          ID of the effect added, or -1 if we failed to add one.
517
 */
518
  public long rotate(Data4D angleaxis, Data3D center)
519
    {
520
    return mM.add(EffectNames.ROTATE, angleaxis, center);
521
    }
522

    
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524
/**
525
 * Rotates the Object by quaternion.
526
 *
527
 * @param quaternion The quaternion describing the rotation.
528
 * @param center     Coordinates of the Point we are rotating around.
529
 * @return           ID of the effect added, or -1 if we failed to add one.
530
 */
531
  public long quaternion(Data4D quaternion, Data3D center )
532
    {
533
    return mM.add(EffectNames.QUATERNION,quaternion,center);
534
    }
535

    
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537
/**
538
 * Shears the Object.
539
 *
540
 * @param shear   The 3-tuple of shear factors.
541
 * @param center  Center of shearing, i.e. the point which stays unmoved.
542
 * @return        ID of the effect added, or -1 if we failed to add one.
543
 */
544
  public long shear(Data3D shear, Data3D center)
545
    {
546
    return mM.add(EffectNames.SHEAR, shear, center);
547
    }
548

    
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550
// Fragment-based effects  
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552
/**
553
 * Creates macroblocks at and around point defined by the Region.
554
 * 
555
 * @param size   1-dimensional Dynamic which, at any given time, returns the size of the macroblocks.
556
 * @param region Region this Effect is limited to.
557
 * @return       ID of the effect added, or -1 if we failed to add one.
558
 */
559
  public long macroblock(Data1D size, Data4D region)
560
    {
561
    return mF.add(EffectNames.MACROBLOCK, size, region);
562
    }
563

    
564
///////////////////////////////////////////////////////////////////////////////////////////////////
565
/**
566
 * Creates macroblocks on the whole Object.
567
 *
568
 * @param size   1-dimensional Data which, at any given time, returns the size of the macroblocks.
569
 * @return       ID of the effect added, or -1 if we failed to add one.
570
 */
571
  public long macroblock(Data1D size)
572
    {
573
    return mF.add(EffectNames.MACROBLOCK, size);
574
    }
575

    
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577
/**
578
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
579
 *        
580
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
581
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color
582
 * @param color  Color to mix. (1,0,0) is RED.
583
 * @param region Region this Effect is limited to.
584
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
585
 * @return       ID of the effect added, or -1 if we failed to add one.
586
 */
587
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
588
    {
589
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
590
    }
591

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

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

    
621
///////////////////////////////////////////////////////////////////////////////////////////////////
622
/**
623
 * Makes the whole Object smoothly change its transparency level.
624
 *
625
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
626
 *               given moment.
627
 * @return       ID of the effect added, or -1 if we failed to add one.
628
 */
629
  public long alpha(Data1D alpha)
630
    {
631
    return mF.add(EffectNames.ALPHA, alpha);
632
    }
633

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

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

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

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

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

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

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

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

    
749
///////////////////////////////////////////////////////////////////////////////////////////////////
750
/**
751
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
752
 * a (possibly changing in time) point on the Object.
753
 *     
754
 * @param vector Vector of force that deforms the shape of the whole Object.
755
 * @param center 2-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 deform(Data3D vector, Data2D center)
759
    {  
760
    return mV.add(EffectNames.DEFORM, vector, center);
761
    }
762

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

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

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

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