Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 6ebdbbf1

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.Data5D;
33
import org.distorted.library.type.Static3D;
34

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

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

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

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

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

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

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  protected abstract DistortedObject deepCopy(int flags);
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

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

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

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

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

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

    
217
    }
218

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

    
235
    mID = DistortedObjectList.add(this);
236

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

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

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

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

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

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

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

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

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

    
429
    return 0;
430
    }
431

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

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

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

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

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

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

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

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

    
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555
/**
556
 * Shears the Object.
557
 *
558
 * @param shear   The 3-tuple of shear factors. The first controls level
559
 *                of shearing in the X-axis, second - Y-axis and the third -
560
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
561
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
562
 * @param center  Center of shearing, i.e. the point which stays unmoved.
563
 * @return        ID of the effect added, or -1 if we failed to add one.
564
 */
565
  public long shear(Data3D shear, Data3D center)
566
    {
567
    return mM.add(EffectNames.SHEAR, shear, center);
568
    }
569

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

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

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

    
620
///////////////////////////////////////////////////////////////////////////////////////////////////
621
/**
622
 * Makes the whole Object smoothly change its transparency level.
623
 *
624
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
625
 *               given moment: pixel.a *= alpha.
626
 *               Valid range: <0,1>
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. Valid range: <0,infinity)
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. Valid range: <0,infinity)
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. Valid range: <0,infinity)
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. Valid range: <0,infinity)
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. Valid range: <0,infinity)
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. Valid range: <0,infinity)
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 3-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, Data3D 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 3-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, Data3D center)
745
    {
746
    return mV.add(EffectNames.DISTORT, vector, center, null);
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 3-dimensional Data that, at any given time, returns the Center of the Effect.
756
 * @param region Region that masks the Effect.
757
 * @return       ID of the effect added, or -1 if we failed to add one.
758
 */
759
  public long deform(Data3D vector, Data3D center, Data4D region)
760
    {
761
    return mV.add(EffectNames.DEFORM, vector, center, region);
762
    }
763

    
764
///////////////////////////////////////////////////////////////////////////////////////////////////
765
/**
766
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
767
 * a (possibly changing in time) point on the Object.
768
 *     
769
 * @param vector Vector of force that deforms the shape of the whole Object.
770
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
771
 * @return       ID of the effect added, or -1 if we failed to add one.
772
 */
773
  public long deform(Data3D vector, Data3D center)
774
    {  
775
    return mV.add(EffectNames.DEFORM, vector, center, null);
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 3-dimensional Data that, at any given time, returns the Center of the Effect.
785
 * @param region Region that masks the Effect.
786
 * @return       ID of the effect added, or -1 if we failed to add one.
787
 */
788
  public long sink(Data1D sink, Data3D center, Data4D region)
789
    {
790
    return mV.add(EffectNames.SINK, sink, center, region);
791
    }
792

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

    
807
///////////////////////////////////////////////////////////////////////////////////////////////////
808
/**
809
 * Pull all points around the center of the Effect towards a line passing through the center
810
 * (that's if degree>=1) or push them away from the line (degree<=1)
811
 *
812
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
813
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
814
 * @param region Region that masks the Effect.
815
 * @return       ID of the effect added, or -1 if we failed to add one.
816
 */
817
  public long pinch(Data2D pinch, Data3D center, Data4D region)
818
    {
819
    return mV.add(EffectNames.PINCH, pinch, center, region);
820
    }
821

    
822
///////////////////////////////////////////////////////////////////////////////////////////////////
823
/**
824
 * Pull all points around the center of the Effect towards a line passing through the center
825
 * (that's if degree>=1) or push them away from the line (degree<=1)
826
 *
827
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
828
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
829
 * @return       ID of the effect added, or -1 if we failed to add one.
830
 */
831
  public long pinch(Data2D pinch, Data3D center)
832
    {
833
    return mV.add(EffectNames.PINCH, pinch, center);
834
    }
835

    
836
///////////////////////////////////////////////////////////////////////////////////////////////////  
837
/**
838
 * Rotate part of the Object around the Center of the Effect by a certain angle.
839
 *
840
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
841
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
842
 * @param region Region that masks the Effect.
843
 * @return       ID of the effect added, or -1 if we failed to add one.
844
 */
845
  public long swirl(Data1D swirl, Data3D center, Data4D region)
846
    {    
847
    return mV.add(EffectNames.SWIRL, swirl, center, region);
848
    }
849

    
850
///////////////////////////////////////////////////////////////////////////////////////////////////
851
/**
852
 * Rotate the whole Object around the Center of the Effect by a certain angle.
853
 *
854
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
855
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
856
 * @return       ID of the effect added, or -1 if we failed to add one.
857
 */
858
  public long swirl(Data1D swirl, Data3D center)
859
    {
860
    return mV.add(EffectNames.SWIRL, swirl, center);
861
    }
862

    
863
///////////////////////////////////////////////////////////////////////////////////////////////////
864
/**
865
 * Directional, sinusoidal wave effect.
866
 *
867
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
868
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
869
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
870
 *               describe the 'direction' of the wave.
871
 *               <p>
872
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
873
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
874
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
875
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
876
 *               <p>
877
 *               <p>
878
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
879
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
880
 *               will be sine shapes.
881
 *               <p>
882
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
883
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
884
 *               YZ-plane with be sine shapes.
885
 *               <p>
886
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
887
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
888
 *               value if sin at this point.
889
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
890
 * @return       ID of the effect added, or -1 if we failed to add one.
891
 */
892
  public long wave(Data5D wave, Data3D center)
893
    {
894
    return mV.add(EffectNames.WAVE, wave, center, null);
895
    }
896

    
897
///////////////////////////////////////////////////////////////////////////////////////////////////
898
/**
899
 * Directional, sinusoidal wave effect.
900
 *
901
 * @param wave   see {@link DistortedObject#wave(Data5D,Data2D)}
902
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
903
 * @param region Region that masks the Effect.
904
 * @return       ID of the effect added, or -1 if we failed to add one.
905
 */
906
  public long wave(Data5D wave, Data3D center, Data4D region)
907
    {
908
    return mV.add(EffectNames.WAVE, wave, center, region);
909
    }
910
  }
(8-8/18)