Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 1a940548

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 EffectQueueMatrix    mM;
42
  private EffectQueueFragment  mF;
43
  private EffectQueueVertex    mV;
44

    
45
  private boolean matrixCloned, vertexCloned, fragmentCloned;
46
  private long mID;
47
  private int mSizeX, mSizeY, mSizeZ; // in screen space
48

    
49
  protected DistortedObjectGrid mGrid = null;
50

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

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

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

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

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  protected abstract DistortedObject deepCopy(int flags);
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  protected void initializeData(int x, int y, int z)
80
    {
81
    mSizeX= x;
82
    mSizeY= y;
83
    mSizeZ= z;
84

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

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

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

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

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

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

    
219
    }
220

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

    
237
    mID = DistortedObjectList.add(this);
238

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

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

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

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

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

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

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

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

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

    
431
    return 0;
432
    }
433

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

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

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

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

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

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

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

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

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

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

    
591
///////////////////////////////////////////////////////////////////////////////////////////////////
592
/**
593
 * Makes the whole Object smoothly change all three of its RGB components.
594
 *
595
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
596
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
597
 *               Valid range: <0,1>
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: pixel.a *= alpha.
612
 *               Valid range: <0,1>
613
 * @param region Region this Effect is limited to. 
614
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
615
 * @return       ID of the effect added, or -1 if we failed to add one. 
616
 */
617
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
618
    {
619
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
620
    }
621

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

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

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

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

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

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

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

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

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

    
751
///////////////////////////////////////////////////////////////////////////////////////////////////
752
/**
753
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
754
 * a (possibly changing in time) point on the Object.
755
 *
756
 * @param vector Vector of force that deforms the shape of the whole Object.
757
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
758
 * @param region Region that masks the Effect.
759
 * @return       ID of the effect added, or -1 if we failed to add one.
760
 */
761
  public long deform(Data3D vector, Data3D center, Data4D region)
762
    {
763
    return mV.add(EffectNames.DEFORM, vector, center, region);
764
    }
765

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

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

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

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

    
824
///////////////////////////////////////////////////////////////////////////////////////////////////
825
/**
826
 * Pull all points around the center of the Effect towards a line passing through the center
827
 * (that's if degree>=1) or push them away from the line (degree<=1)
828
 *
829
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
830
 * @param center 3-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 pinch(Data2D pinch, Data3D center)
834
    {
835
    return mV.add(EffectNames.PINCH, pinch, center);
836
    }
837

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

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

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

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