Project

General

Profile

« Previous | Next » 

Revision 421c2728

Added by Leszek Koltunski almost 8 years ago

Change of names.

View differences:

src/main/java/org/distorted/library/Distorted.java
74 74
   */
75 75
  public static final int CLONE_FRAGMENT= 0x8;
76 76
  /**
77
   * When creating an instance of a DistortedObjectTree from another instance, clone the children Nodes.
77
   * When creating an instance of a DistortedTree from another instance, clone the children Nodes.
78 78
   * <p>
79 79
   * This is mainly useful for creating many similar sub-trees of Bitmaps and rendering then at different places
80 80
   * on the screen, with (optionally) different effects of the top-level root Bitmap.   
......
274 274
    return readTextFileFromRawResource( c, R.raw.main_fragment_shader);
275 275
    }
276 276

  
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

  
279
  static boolean isInitialized()
280
    {
281
    return mInitialized;
282
    }
283

  
277 284
///////////////////////////////////////////////////////////////////////////////////////////////////
278 285
/**
279 286
 * When OpenGL context gets created, you need to call this method so that the library can initialise its internal data structures.
......
328 335
    GLES20.glEnableVertexAttribArray(mNormalH);
329 336
    GLES20.glEnableVertexAttribArray(mTextureCoordH);
330 337
   
331
    DistortedObjectTree.reset();
338
    DistortedTree.reset();
332 339
    EffectMessageSender.startSending();
333 340
    }
334 341

  
......
341 348
    {
342 349
    DistortedTexture.onDestroy();
343 350
    DistortedFramebuffer.onDestroy();
344
    DistortedObjectTree.onDestroy();
351
    DistortedTree.onDestroy();
345 352
    EffectQueue.onDestroy();
346
    DistortedEffectQueues.onDestroy();
353
    DistortedEffects.onDestroy();
347 354
    EffectMessageSender.stopSending();
348 355
   
349 356
    mInitialized = false;
350 357
    }
351
  
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353
/**
354
 * Returns the true if onSurfaceCreated has been called already, and thus if the Library's is ready
355
 * to accept effect requests.
356
 * 
357
 * @return <code>true</code> if the Library is ready for action, <code>false</code> otherwise.
358
 */
359
  public static boolean isInitialized()
360
    {
361
    return mInitialized;  
362
    }
363 358

  
364 359
///////////////////////////////////////////////////////////////////////////////////////////////////
365 360
/**
src/main/java/org/distorted/library/DistortedEffectQueues.java
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.opengl.GLES20;
23

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

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
/**
34
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
35
 * <p>
36
 * The queues hold actual effects to be applied to a given (DistortedTexture,GridObject) combo.
37
 */
38
public class DistortedEffectQueues
39
  {
40
  private static long mNextID =0;
41
  private long mID;
42

  
43
  private EffectQueueMatrix    mM;
44
  private EffectQueueFragment  mF;
45
  private EffectQueueVertex    mV;
46

  
47
  private boolean matrixCloned, vertexCloned, fragmentCloned;
48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
    
51
  private void initializeEffectLists(DistortedEffectQueues d, int flags)
52
    {
53
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
54
      {
55
      mM = d.mM;
56
      matrixCloned = true;
57
      }
58
    else
59
      {
60
      mM = new EffectQueueMatrix(mID);
61
      matrixCloned = false;
62
      }
63
    
64
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
65
      {
66
      mV = d.mV;
67
      vertexCloned = true;
68
      }
69
    else
70
      {
71
      mV = new EffectQueueVertex(mID);
72
      vertexCloned = false;
73
      }
74
    
75
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
76
      {
77
      mF = d.mF;
78
      fragmentCloned = true;
79
      }
80
    else
81
      {
82
      mF = new EffectQueueFragment(mID);
83
      fragmentCloned = false;
84
      }
85
    }
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
   
89
  void drawPriv(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
90
    {
91
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
92

  
93
    float halfZ = tex.mHalfX*grid.zFactor;
94

  
95
    mM.compute(currTime);
96
    mM.send(df,tex.mHalfX,tex.mHalfY,halfZ);
97
      
98
    mV.compute(currTime);
99
    mV.send(tex.mHalfX,tex.mHalfY,halfZ);
100
        
101
    mF.compute(currTime);
102
    mF.send(tex.mHalfX,tex.mHalfY);
103

  
104
    grid.draw();
105
    }
106

  
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
   
109
  void drawNoEffectsPriv(DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
110
    {
111
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
112

  
113
    mM.sendZero(df,tex.mHalfX,tex.mHalfY,tex.mHalfX*grid.zFactor);
114
    mV.sendZero();
115
    mF.sendZero();
116

  
117
    grid.draw();
118
    }
119
    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
   
122
  private void releasePriv()
123
    {
124
    if( !matrixCloned  ) mM.abortAll(false);
125
    if( !vertexCloned  ) mV.abortAll(false);
126
    if( !fragmentCloned) mF.abortAll(false);
127

  
128
    mM = null;
129
    mV = null;
130
    mF = null;
131
    }
132

  
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

  
135
  static void onDestroy()
136
    {
137
    mNextID = 0;
138
    }
139

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
// PUBLIC API
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
/**
144
 * Create empty effect queue.
145
 */
146
  public DistortedEffectQueues()
147
    {
148
    mID = mNextID++;
149
    initializeEffectLists(this,0);
150
    }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
/**
154
 * Copy constructor.
155
 * <p>
156
 * Whatever we do not clone gets created just like in the default constructor.
157
 *
158
 * @param dc    Source object to create our object from
159
 * @param flags A bitmask of values specifying what to copy.
160
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
161
 */
162
  public DistortedEffectQueues(DistortedEffectQueues dc, int flags)
163
    {
164
    mID = mNextID++;
165
    initializeEffectLists(dc,flags);
166
    }
167

  
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
/**
170
 * Draw the (texture,grid) object to the Framebuffer passed.
171
 * <p>
172
 * Must be called from a thread holding OpenGL Context
173
 *
174
 * @param currTime Current time, in milliseconds.
175
 * @param df       Framebuffer to render this to.
176
 */
177
  public void draw(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
178
    {
179
    tex.createTexture();
180
    df.createFBO();
181
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, df.fboIds[0]);
182
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
183
    drawPriv(currTime, tex, grid, df);
184
    DistortedFramebuffer.deleteAllMarked();
185
    DistortedTexture.deleteAllMarked();
186
    }
187

  
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
/**
190
 * Releases all resources. After this call, the queue should not be used anymore.
191
 */
192
  public synchronized void delete()
193
    {
194
    releasePriv();
195
    }
196

  
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
/**
199
 * Returns unique ID of this instance.
200
 *
201
 * @return ID of the object.
202
 */
203
  public long getID()
204
      {
205
      return mID;
206
      }
207

  
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
/**
210
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
211
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
212
 * 
213
 * @param el A class implementing the EffectListener interface that wants to get notifications.
214
 */
215
  public void registerForMessages(EffectListener el)
216
    {
217
    mV.registerForMessages(el);
218
    mF.registerForMessages(el);
219
    mM.registerForMessages(el);
220
    }
221

  
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
/**
224
 * Removes the calling class from the list of Listeners.
225
 * 
226
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
227
 */
228
  public void deregisterForMessages(EffectListener el)
229
    {
230
    mV.deregisterForMessages(el);
231
    mF.deregisterForMessages(el);
232
    mM.deregisterForMessages(el);
233
    }
234

  
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
/**
237
 * Aborts all Effects.
238
 * @return Number of effects aborted.
239
 */
240
  public int abortAllEffects()
241
      {
242
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
243
      }
244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246
/**
247
 * Aborts all Effects of a given type, for example all MATRIX Effects.
248
 * 
249
 * @param type one of the constants defined in {@link EffectTypes}
250
 * @return Number of effects aborted.
251
 */
252
  public int abortEffects(EffectTypes type)
253
    {
254
    switch(type)
255
      {
256
      case MATRIX  : return mM.abortAll(true);
257
      case VERTEX  : return mV.abortAll(true);
258
      case FRAGMENT: return mF.abortAll(true);
259
      default      : return 0;
260
      }
261
    }
262
    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264
/**
265
 * Aborts a single Effect.
266
 * 
267
 * @param id ID of the Effect we want to abort.
268
 * @return number of Effects aborted. Always either 0 or 1.
269
 */
270
  public int abortEffect(long id)
271
    {
272
    int type = (int)(id&EffectTypes.MASK);
273

  
274
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
275
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
276
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
277

  
278
    return 0;
279
    }
280

  
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282
/**
283
 * Abort all Effects of a given name, for example all rotations.
284
 * 
285
 * @param name one of the constants defined in {@link EffectNames}
286
 * @return number of Effects aborted.
287
 */
288
  public int abortEffects(EffectNames name)
289
    {
290
    switch(name.getType())
291
      {
292
      case MATRIX  : return mM.removeByType(name);
293
      case VERTEX  : return mV.removeByType(name);
294
      case FRAGMENT: return mF.removeByType(name);
295
      default      : return 0;
296
      }
297
    }
298
    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
/**
301
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
302
 * 
303
 * @param id Effect ID we want to print info about
304
 * @return <code>true</code> if a single Effect of type effectType has been found.
305
 */
306
    
307
  public boolean printEffect(long id)
308
    {
309
    int type = (int)(id&EffectTypes.MASK);
310

  
311
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
312
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
313
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
314

  
315
    return false;
316
    }
317
   
318
///////////////////////////////////////////////////////////////////////////////////////////////////   
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320
// Individual effect functions.
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
// Matrix-based effects
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324
/**
325
 * Moves the Object by a (possibly changing in time) vector.
326
 * 
327
 * @param vector 3-dimensional Data which at any given time will return a Static3D
328
 *               representing the current coordinates of the vector we want to move the Object with.
329
 * @return       ID of the effect added, or -1 if we failed to add one.
330
 */
331
  public long move(Data3D vector)
332
    {   
333
    return mM.add(EffectNames.MOVE,vector);
334
    }
335

  
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337
/**
338
 * Scales the Object by (possibly changing in time) 3D scale factors.
339
 * 
340
 * @param scale 3-dimensional Data which at any given time returns a Static3D
341
 *              representing the current x- , y- and z- scale factors.
342
 * @return      ID of the effect added, or -1 if we failed to add one.
343
 */
344
  public long scale(Data3D scale)
345
    {   
346
    return mM.add(EffectNames.SCALE,scale);
347
    }
348

  
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350
/**
351
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
352
 *
353
 * @param scale The factor to scale all 3 dimensions with.
354
 * @return      ID of the effect added, or -1 if we failed to add one.
355
 */
356
  public long scale(float scale)
357
    {
358
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
359
    }
360

  
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362
/**
363
 * Rotates the Object by 'angle' degrees around the center.
364
 * Static axis of rotation is given by the last parameter.
365
 *
366
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
367
 * @param axis   Axis of rotation
368
 * @param center Coordinates of the Point we are rotating around.
369
 * @return       ID of the effect added, or -1 if we failed to add one.
370
 */
371
  public long rotate(Data1D angle, Static3D axis, Data3D center )
372
    {   
373
    return mM.add(EffectNames.ROTATE, angle, axis, center);
374
    }
375

  
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377
/**
378
 * Rotates the Object by 'angle' degrees around the center.
379
 * Here both angle and axis can dynamically change.
380
 *
381
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
382
 * @param center    Coordinates of the Point we are rotating around.
383
 * @return          ID of the effect added, or -1 if we failed to add one.
384
 */
385
  public long rotate(Data4D angleaxis, Data3D center)
386
    {
387
    return mM.add(EffectNames.ROTATE, angleaxis, center);
388
    }
389

  
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
/**
392
 * Rotates the Object by quaternion.
393
 *
394
 * @param quaternion The quaternion describing the rotation.
395
 * @param center     Coordinates of the Point we are rotating around.
396
 * @return           ID of the effect added, or -1 if we failed to add one.
397
 */
398
  public long quaternion(Data4D quaternion, Data3D center )
399
    {
400
    return mM.add(EffectNames.QUATERNION,quaternion,center);
401
    }
402

  
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404
/**
405
 * Shears the Object.
406
 *
407
 * @param shear   The 3-tuple of shear factors. The first controls level
408
 *                of shearing in the X-axis, second - Y-axis and the third -
409
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
410
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
411
 * @param center  Center of shearing, i.e. the point which stays unmoved.
412
 * @return        ID of the effect added, or -1 if we failed to add one.
413
 */
414
  public long shear(Data3D shear, Data3D center)
415
    {
416
    return mM.add(EffectNames.SHEAR, shear, center);
417
    }
418

  
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420
// Fragment-based effects  
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422
/**
423
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
424
 *        
425
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
426
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
427
 *               Valid range: <0,1>
428
 * @param color  Color to mix. (1,0,0) is RED.
429
 * @param region Region this Effect is limited to.
430
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
431
 * @return       ID of the effect added, or -1 if we failed to add one.
432
 */
433
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
434
    {
435
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
436
    }
437

  
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439
/**
440
 * Makes the whole Object smoothly change all three of its RGB components.
441
 *
442
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
443
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
444
 *               Valid range: <0,1>
445
 * @param color  Color to mix. (1,0,0) is RED.
446
 * @return       ID of the effect added, or -1 if we failed to add one.
447
 */
448
  public long chroma(Data1D blend, Data3D color)
449
    {
450
    return mF.add(EffectNames.CHROMA, blend, color);
451
    }
452

  
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454
/**
455
 * Makes a certain sub-region of the Object smoothly change its transparency level.
456
 *        
457
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
458
 *               moment: pixel.a *= alpha.
459
 *               Valid range: <0,1>
460
 * @param region Region this Effect is limited to. 
461
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
462
 * @return       ID of the effect added, or -1 if we failed to add one. 
463
 */
464
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
465
    {
466
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
467
    }
468

  
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470
/**
471
 * Makes the whole Object smoothly change its transparency level.
472
 *
473
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
474
 *               given moment: pixel.a *= alpha.
475
 *               Valid range: <0,1>
476
 * @return       ID of the effect added, or -1 if we failed to add one.
477
 */
478
  public long alpha(Data1D alpha)
479
    {
480
    return mF.add(EffectNames.ALPHA, alpha);
481
    }
482

  
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484
/**
485
 * Makes a certain sub-region of the Object smoothly change its brightness level.
486
 *        
487
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
488
 *                   at any given moment. Valid range: <0,infinity)
489
 * @param region     Region this Effect is limited to.
490
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
491
 * @return           ID of the effect added, or -1 if we failed to add one.
492
 */
493
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
494
    {
495
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
496
    }
497

  
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499
/**
500
 * Makes the whole Object smoothly change its brightness level.
501
 *
502
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
503
 *                   at any given moment. Valid range: <0,infinity)
504
 * @return           ID of the effect added, or -1 if we failed to add one.
505
 */
506
  public long brightness(Data1D brightness)
507
    {
508
    return mF.add(EffectNames.BRIGHTNESS, brightness);
509
    }
510

  
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512
/**
513
 * Makes a certain sub-region of the Object smoothly change its contrast level.
514
 *        
515
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
516
 *                 at any given moment. Valid range: <0,infinity)
517
 * @param region   Region this Effect is limited to.
518
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
519
 * @return         ID of the effect added, or -1 if we failed to add one.
520
 */
521
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
522
    {
523
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
524
    }
525

  
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527
/**
528
 * Makes the whole Object smoothly change its contrast level.
529
 *
530
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
531
 *                 at any given moment. Valid range: <0,infinity)
532
 * @return         ID of the effect added, or -1 if we failed to add one.
533
 */
534
  public long contrast(Data1D contrast)
535
    {
536
    return mF.add(EffectNames.CONTRAST, contrast);
537
    }
538

  
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540
/**
541
 * Makes a certain sub-region of the Object smoothly change its saturation level.
542
 *        
543
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
544
 *                   at any given moment. Valid range: <0,infinity)
545
 * @param region     Region this Effect is limited to.
546
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
547
 * @return           ID of the effect added, or -1 if we failed to add one.
548
 */
549
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
550
    {
551
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
552
    }
553

  
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555
/**
556
 * Makes the whole Object smoothly change its saturation level.
557
 *
558
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
559
 *                   at any given moment. Valid range: <0,infinity)
560
 * @return           ID of the effect added, or -1 if we failed to add one.
561
 */
562
  public long saturation(Data1D saturation)
563
    {
564
    return mF.add(EffectNames.SATURATION, saturation);
565
    }
566

  
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568
// Vertex-based effects  
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570
/**
571
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
572
 *
573
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
574
 *               currently being dragged with.
575
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
576
 * @param region Region that masks the Effect.
577
 * @return       ID of the effect added, or -1 if we failed to add one.
578
 */
579
  public long distort(Data3D vector, Data3D center, Data4D region)
580
    {  
581
    return mV.add(EffectNames.DISTORT, vector, center, region);
582
    }
583

  
584
///////////////////////////////////////////////////////////////////////////////////////////////////
585
/**
586
 * Distort the whole Object by a (possibly changing in time) vector of force.
587
 *
588
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
589
 *               currently being dragged with.
590
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
591
 * @return       ID of the effect added, or -1 if we failed to add one.
592
 */
593
  public long distort(Data3D vector, Data3D center)
594
    {
595
    return mV.add(EffectNames.DISTORT, vector, center, null);
596
    }
597

  
598
///////////////////////////////////////////////////////////////////////////////////////////////////
599
/**
600
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
601
 * a (possibly changing in time) point on the Object.
602
 *
603
 * @param vector Vector of force that deforms the shape of the whole Object.
604
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
605
 * @param region Region that masks the Effect.
606
 * @return       ID of the effect added, or -1 if we failed to add one.
607
 */
608
  public long deform(Data3D vector, Data3D center, Data4D region)
609
    {
610
    return mV.add(EffectNames.DEFORM, vector, center, region);
611
    }
612

  
613
///////////////////////////////////////////////////////////////////////////////////////////////////
614
/**
615
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
616
 * a (possibly changing in time) point on the Object.
617
 *     
618
 * @param vector Vector of force that deforms the shape of the whole Object.
619
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
620
 * @return       ID of the effect added, or -1 if we failed to add one.
621
 */
622
  public long deform(Data3D vector, Data3D center)
623
    {  
624
    return mV.add(EffectNames.DEFORM, vector, center, null);
625
    }
626

  
627
///////////////////////////////////////////////////////////////////////////////////////////////////  
628
/**
629
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
630
 * away from the center (degree<=1)
631
 *
632
 * @param sink   The current degree of the Effect.
633
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
634
 * @param region Region that masks the Effect.
635
 * @return       ID of the effect added, or -1 if we failed to add one.
636
 */
637
  public long sink(Data1D sink, Data3D center, Data4D region)
638
    {
639
    return mV.add(EffectNames.SINK, sink, center, region);
640
    }
641

  
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643
/**
644
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
645
 * away from the center (degree<=1)
646
 *
647
 * @param sink   The current degree of the Effect.
648
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
649
 * @return       ID of the effect added, or -1 if we failed to add one.
650
 */
651
  public long sink(Data1D sink, Data3D center)
652
    {
653
    return mV.add(EffectNames.SINK, sink, center);
654
    }
655

  
656
///////////////////////////////////////////////////////////////////////////////////////////////////
657
/**
658
 * Pull all points around the center of the Effect towards a line passing through the center
659
 * (that's if degree>=1) or push them away from the line (degree<=1)
660
 *
661
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
662
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
663
 * @param region Region that masks the Effect.
664
 * @return       ID of the effect added, or -1 if we failed to add one.
665
 */
666
  public long pinch(Data2D pinch, Data3D center, Data4D region)
667
    {
668
    return mV.add(EffectNames.PINCH, pinch, center, region);
669
    }
670

  
671
///////////////////////////////////////////////////////////////////////////////////////////////////
672
/**
673
 * Pull all points around the center of the Effect towards a line passing through the center
674
 * (that's if degree>=1) or push them away from the line (degree<=1)
675
 *
676
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
677
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
678
 * @return       ID of the effect added, or -1 if we failed to add one.
679
 */
680
  public long pinch(Data2D pinch, Data3D center)
681
    {
682
    return mV.add(EffectNames.PINCH, pinch, center);
683
    }
684

  
685
///////////////////////////////////////////////////////////////////////////////////////////////////  
686
/**
687
 * Rotate part of the Object around the Center of the Effect by a certain angle.
688
 *
689
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
690
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
691
 * @param region Region that masks the Effect.
692
 * @return       ID of the effect added, or -1 if we failed to add one.
693
 */
694
  public long swirl(Data1D swirl, Data3D center, Data4D region)
695
    {    
696
    return mV.add(EffectNames.SWIRL, swirl, center, region);
697
    }
698

  
699
///////////////////////////////////////////////////////////////////////////////////////////////////
700
/**
701
 * Rotate the whole Object around the Center of the Effect by a certain angle.
702
 *
703
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
704
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
705
 * @return       ID of the effect added, or -1 if we failed to add one.
706
 */
707
  public long swirl(Data1D swirl, Data3D center)
708
    {
709
    return mV.add(EffectNames.SWIRL, swirl, center);
710
    }
711

  
712
///////////////////////////////////////////////////////////////////////////////////////////////////
713
/**
714
 * Directional, sinusoidal wave effect.
715
 *
716
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
717
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
718
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
719
 *               describe the 'direction' of the wave.
720
 *               <p>
721
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
722
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
723
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
724
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
725
 *               <p>
726
 *               <p>
727
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
728
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
729
 *               will be sine shapes.
730
 *               <p>
731
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
732
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
733
 *               YZ-plane with be sine shapes.
734
 *               <p>
735
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
736
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
737
 *               value if sin at this point.
738
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
739
 * @return       ID of the effect added, or -1 if we failed to add one.
740
 */
741
  public long wave(Data5D wave, Data3D center)
742
    {
743
    return mV.add(EffectNames.WAVE, wave, center, null);
744
    }
745

  
746
///////////////////////////////////////////////////////////////////////////////////////////////////
747
/**
748
 * Directional, sinusoidal wave effect.
749
 *
750
 * @param wave   see {@link DistortedEffectQueues#wave(Data5D,Data3D)}
751
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
752
 * @param region Region that masks the Effect.
753
 * @return       ID of the effect added, or -1 if we failed to add one.
754
 */
755
  public long wave(Data5D wave, Data3D center, Data4D region)
756
    {
757
    return mV.add(EffectNames.WAVE, wave, center, region);
758
    }
759
  }
src/main/java/org/distorted/library/DistortedEffects.java
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.opengl.GLES20;
23

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

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
/**
34
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
35
 * <p>
36
 * The queues hold actual effects to be applied to a given (DistortedTexture,GridObject) combo.
37
 */
38
public class DistortedEffects
39
  {
40
  private static long mNextID =0;
41
  private long mID;
42

  
43
  private EffectQueueMatrix    mM;
44
  private EffectQueueFragment  mF;
45
  private EffectQueueVertex    mV;
46

  
47
  private boolean matrixCloned, vertexCloned, fragmentCloned;
48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
    
51
  private void initializeEffectLists(DistortedEffects d, int flags)
52
    {
53
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
54
      {
55
      mM = d.mM;
56
      matrixCloned = true;
57
      }
58
    else
59
      {
60
      mM = new EffectQueueMatrix(mID);
61
      matrixCloned = false;
62
      }
63
    
64
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
65
      {
66
      mV = d.mV;
67
      vertexCloned = true;
68
      }
69
    else
70
      {
71
      mV = new EffectQueueVertex(mID);
72
      vertexCloned = false;
73
      }
74
    
75
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
76
      {
77
      mF = d.mF;
78
      fragmentCloned = true;
79
      }
80
    else
81
      {
82
      mF = new EffectQueueFragment(mID);
83
      fragmentCloned = false;
84
      }
85
    }
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
   
89
  void drawPriv(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
90
    {
91
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
92

  
93
    float halfZ = tex.mHalfX*grid.zFactor;
94

  
95
    mM.compute(currTime);
96
    mM.send(df,tex.mHalfX,tex.mHalfY,halfZ);
97
      
98
    mV.compute(currTime);
99
    mV.send(tex.mHalfX,tex.mHalfY,halfZ);
100
        
101
    mF.compute(currTime);
102
    mF.send(tex.mHalfX,tex.mHalfY);
103

  
104
    grid.draw();
105
    }
106

  
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
   
109
  void drawNoEffectsPriv(DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
110
    {
111
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
112

  
113
    mM.sendZero(df,tex.mHalfX,tex.mHalfY,tex.mHalfX*grid.zFactor);
114
    mV.sendZero();
115
    mF.sendZero();
116

  
117
    grid.draw();
118
    }
119
    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
   
122
  private void releasePriv()
123
    {
124
    if( !matrixCloned  ) mM.abortAll(false);
125
    if( !vertexCloned  ) mV.abortAll(false);
126
    if( !fragmentCloned) mF.abortAll(false);
127

  
128
    mM = null;
129
    mV = null;
130
    mF = null;
131
    }
132

  
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

  
135
  static void onDestroy()
136
    {
137
    mNextID = 0;
138
    }
139

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
// PUBLIC API
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
/**
144
 * Create empty effect queue.
145
 */
146
  public DistortedEffects()
147
    {
148
    mID = mNextID++;
149
    initializeEffectLists(this,0);
150
    }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
/**
154
 * Copy constructor.
155
 * <p>
156
 * Whatever we do not clone gets created just like in the default constructor.
157
 *
158
 * @param dc    Source object to create our object from
159
 * @param flags A bitmask of values specifying what to copy.
160
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
161
 */
162
  public DistortedEffects(DistortedEffects dc, int flags)
163
    {
164
    mID = mNextID++;
165
    initializeEffectLists(dc,flags);
166
    }
167

  
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
/**
170
 * Draw the (texture,grid) object to the Framebuffer passed.
171
 * <p>
172
 * Must be called from a thread holding OpenGL Context
173
 *
174
 * @param currTime Current time, in milliseconds.
175
 * @param df       Framebuffer to render this to.
176
 */
177
  public void draw(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
178
    {
179
    tex.createTexture();
180
    df.createFBO();
181
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, df.fboIds[0]);
182
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
183
    drawPriv(currTime, tex, grid, df);
184
    DistortedFramebuffer.deleteAllMarked();
185
    DistortedTexture.deleteAllMarked();
186
    }
187

  
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
/**
190
 * Releases all resources. After this call, the queue should not be used anymore.
191
 */
192
  public synchronized void delete()
193
    {
194
    releasePriv();
195
    }
196

  
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
/**
199
 * Returns unique ID of this instance.
200
 *
201
 * @return ID of the object.
202
 */
203
  public long getID()
204
      {
205
      return mID;
206
      }
207

  
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
/**
210
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
211
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
212
 * 
213
 * @param el A class implementing the EffectListener interface that wants to get notifications.
214
 */
215
  public void registerForMessages(EffectListener el)
216
    {
217
    mV.registerForMessages(el);
218
    mF.registerForMessages(el);
219
    mM.registerForMessages(el);
220
    }
221

  
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
/**
224
 * Removes the calling class from the list of Listeners.
225
 * 
226
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
227
 */
228
  public void deregisterForMessages(EffectListener el)
229
    {
230
    mV.deregisterForMessages(el);
231
    mF.deregisterForMessages(el);
232
    mM.deregisterForMessages(el);
233
    }
234

  
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
/**
237
 * Aborts all Effects.
238
 * @return Number of effects aborted.
239
 */
240
  public int abortAllEffects()
241
      {
242
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
243
      }
244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246
/**
247
 * Aborts all Effects of a given type, for example all MATRIX Effects.
248
 * 
249
 * @param type one of the constants defined in {@link EffectTypes}
250
 * @return Number of effects aborted.
251
 */
252
  public int abortEffects(EffectTypes type)
253
    {
254
    switch(type)
255
      {
256
      case MATRIX  : return mM.abortAll(true);
257
      case VERTEX  : return mV.abortAll(true);
258
      case FRAGMENT: return mF.abortAll(true);
259
      default      : return 0;
260
      }
261
    }
262
    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264
/**
265
 * Aborts a single Effect.
266
 * 
267
 * @param id ID of the Effect we want to abort.
268
 * @return number of Effects aborted. Always either 0 or 1.
269
 */
270
  public int abortEffect(long id)
271
    {
272
    int type = (int)(id&EffectTypes.MASK);
273

  
274
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
275
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
276
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
277

  
278
    return 0;
279
    }
280

  
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282
/**
283
 * Abort all Effects of a given name, for example all rotations.
284
 * 
285
 * @param name one of the constants defined in {@link EffectNames}
286
 * @return number of Effects aborted.
287
 */
288
  public int abortEffects(EffectNames name)
289
    {
290
    switch(name.getType())
291
      {
292
      case MATRIX  : return mM.removeByType(name);
293
      case VERTEX  : return mV.removeByType(name);
294
      case FRAGMENT: return mF.removeByType(name);
295
      default      : return 0;
296
      }
297
    }
298
    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
/**
301
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
302
 * 
303
 * @param id Effect ID we want to print info about
304
 * @return <code>true</code> if a single Effect of type effectType has been found.
305
 */
306
    
307
  public boolean printEffect(long id)
308
    {
309
    int type = (int)(id&EffectTypes.MASK);
310

  
311
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
312
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
313
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
314

  
315
    return false;
316
    }
317
   
318
///////////////////////////////////////////////////////////////////////////////////////////////////   
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320
// Individual effect functions.
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
// Matrix-based effects
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324
/**
325
 * Moves the Object by a (possibly changing in time) vector.
326
 * 
327
 * @param vector 3-dimensional Data which at any given time will return a Static3D
328
 *               representing the current coordinates of the vector we want to move the Object with.
329
 * @return       ID of the effect added, or -1 if we failed to add one.
330
 */
331
  public long move(Data3D vector)
332
    {   
333
    return mM.add(EffectNames.MOVE,vector);
334
    }
335

  
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337
/**
338
 * Scales the Object by (possibly changing in time) 3D scale factors.
339
 * 
340
 * @param scale 3-dimensional Data which at any given time returns a Static3D
341
 *              representing the current x- , y- and z- scale factors.
342
 * @return      ID of the effect added, or -1 if we failed to add one.
343
 */
344
  public long scale(Data3D scale)
345
    {   
346
    return mM.add(EffectNames.SCALE,scale);
347
    }
348

  
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350
/**
351
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
352
 *
353
 * @param scale The factor to scale all 3 dimensions with.
354
 * @return      ID of the effect added, or -1 if we failed to add one.
355
 */
356
  public long scale(float scale)
357
    {
358
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
359
    }
360

  
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362
/**
363
 * Rotates the Object by 'angle' degrees around the center.
364
 * Static axis of rotation is given by the last parameter.
365
 *
366
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
367
 * @param axis   Axis of rotation
368
 * @param center Coordinates of the Point we are rotating around.
369
 * @return       ID of the effect added, or -1 if we failed to add one.
370
 */
371
  public long rotate(Data1D angle, Static3D axis, Data3D center )
372
    {   
373
    return mM.add(EffectNames.ROTATE, angle, axis, center);
374
    }
375

  
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377
/**
378
 * Rotates the Object by 'angle' degrees around the center.
379
 * Here both angle and axis can dynamically change.
380
 *
381
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
382
 * @param center    Coordinates of the Point we are rotating around.
383
 * @return          ID of the effect added, or -1 if we failed to add one.
384
 */
385
  public long rotate(Data4D angleaxis, Data3D center)
386
    {
387
    return mM.add(EffectNames.ROTATE, angleaxis, center);
388
    }
389

  
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
/**
392
 * Rotates the Object by quaternion.
393
 *
394
 * @param quaternion The quaternion describing the rotation.
395
 * @param center     Coordinates of the Point we are rotating around.
396
 * @return           ID of the effect added, or -1 if we failed to add one.
397
 */
398
  public long quaternion(Data4D quaternion, Data3D center )
399
    {
400
    return mM.add(EffectNames.QUATERNION,quaternion,center);
401
    }
402

  
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404
/**
405
 * Shears the Object.
406
 *
407
 * @param shear   The 3-tuple of shear factors. The first controls level
408
 *                of shearing in the X-axis, second - Y-axis and the third -
409
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
410
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
411
 * @param center  Center of shearing, i.e. the point which stays unmoved.
412
 * @return        ID of the effect added, or -1 if we failed to add one.
413
 */
414
  public long shear(Data3D shear, Data3D center)
415
    {
416
    return mM.add(EffectNames.SHEAR, shear, center);
417
    }
418

  
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420
// Fragment-based effects  
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422
/**
423
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
424
 *        
425
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
426
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
427
 *               Valid range: <0,1>
428
 * @param color  Color to mix. (1,0,0) is RED.
429
 * @param region Region this Effect is limited to.
430
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
431
 * @return       ID of the effect added, or -1 if we failed to add one.
432
 */
433
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
434
    {
435
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
436
    }
437

  
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439
/**
440
 * Makes the whole Object smoothly change all three of its RGB components.
441
 *
442
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
443
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
444
 *               Valid range: <0,1>
445
 * @param color  Color to mix. (1,0,0) is RED.
446
 * @return       ID of the effect added, or -1 if we failed to add one.
447
 */
448
  public long chroma(Data1D blend, Data3D color)
449
    {
450
    return mF.add(EffectNames.CHROMA, blend, color);
451
    }
452

  
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454
/**
455
 * Makes a certain sub-region of the Object smoothly change its transparency level.
456
 *        
457
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
458
 *               moment: pixel.a *= alpha.
459
 *               Valid range: <0,1>
460
 * @param region Region this Effect is limited to. 
461
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
462
 * @return       ID of the effect added, or -1 if we failed to add one. 
463
 */
464
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
465
    {
466
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
467
    }
468

  
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470
/**
471
 * Makes the whole Object smoothly change its transparency level.
472
 *
473
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
474
 *               given moment: pixel.a *= alpha.
475
 *               Valid range: <0,1>
476
 * @return       ID of the effect added, or -1 if we failed to add one.
477
 */
478
  public long alpha(Data1D alpha)
479
    {
480
    return mF.add(EffectNames.ALPHA, alpha);
481
    }
482

  
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484
/**
485
 * Makes a certain sub-region of the Object smoothly change its brightness level.
486
 *        
487
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
488
 *                   at any given moment. Valid range: <0,infinity)
489
 * @param region     Region this Effect is limited to.
490
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
491
 * @return           ID of the effect added, or -1 if we failed to add one.
492
 */
493
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
494
    {
495
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
496
    }
497

  
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499
/**
500
 * Makes the whole Object smoothly change its brightness level.
501
 *
502
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
503
 *                   at any given moment. Valid range: <0,infinity)
504
 * @return           ID of the effect added, or -1 if we failed to add one.
505
 */
506
  public long brightness(Data1D brightness)
507
    {
508
    return mF.add(EffectNames.BRIGHTNESS, brightness);
509
    }
510

  
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512
/**
513
 * Makes a certain sub-region of the Object smoothly change its contrast level.
514
 *        
515
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
516
 *                 at any given moment. Valid range: <0,infinity)
517
 * @param region   Region this Effect is limited to.
518
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
519
 * @return         ID of the effect added, or -1 if we failed to add one.
520
 */
521
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
522
    {
523
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
524
    }
525

  
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527
/**
528
 * Makes the whole Object smoothly change its contrast level.
529
 *
530
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
531
 *                 at any given moment. Valid range: <0,infinity)
532
 * @return         ID of the effect added, or -1 if we failed to add one.
533
 */
534
  public long contrast(Data1D contrast)
535
    {
536
    return mF.add(EffectNames.CONTRAST, contrast);
537
    }
538

  
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540
/**
541
 * Makes a certain sub-region of the Object smoothly change its saturation level.
542
 *        
543
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
544
 *                   at any given moment. Valid range: <0,infinity)
545
 * @param region     Region this Effect is limited to.
546
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
547
 * @return           ID of the effect added, or -1 if we failed to add one.
548
 */
549
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
550
    {
551
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
552
    }
553

  
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555
/**
556
 * Makes the whole Object smoothly change its saturation level.
557
 *
558
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
559
 *                   at any given moment. Valid range: <0,infinity)
560
 * @return           ID of the effect added, or -1 if we failed to add one.
561
 */
562
  public long saturation(Data1D saturation)
563
    {
564
    return mF.add(EffectNames.SATURATION, saturation);
565
    }
566

  
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568
// Vertex-based effects  
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570
/**
571
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
572
 *
573
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
574
 *               currently being dragged with.
575
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
576
 * @param region Region that masks the Effect.
577
 * @return       ID of the effect added, or -1 if we failed to add one.
578
 */
579
  public long distort(Data3D vector, Data3D center, Data4D region)
580
    {  
581
    return mV.add(EffectNames.DISTORT, vector, center, region);
582
    }
583

  
584
///////////////////////////////////////////////////////////////////////////////////////////////////
585
/**
586
 * Distort the whole Object by a (possibly changing in time) vector of force.
587
 *
588
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
589
 *               currently being dragged with.
590
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
591
 * @return       ID of the effect added, or -1 if we failed to add one.
592
 */
593
  public long distort(Data3D vector, Data3D center)
594
    {
595
    return mV.add(EffectNames.DISTORT, vector, center, null);
596
    }
597

  
598
///////////////////////////////////////////////////////////////////////////////////////////////////
599
/**
600
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
601
 * a (possibly changing in time) point on the Object.
602
 *
603
 * @param vector Vector of force that deforms the shape of the whole Object.
604
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
605
 * @param region Region that masks the Effect.
606
 * @return       ID of the effect added, or -1 if we failed to add one.
607
 */
608
  public long deform(Data3D vector, Data3D center, Data4D region)
609
    {
610
    return mV.add(EffectNames.DEFORM, vector, center, region);
611
    }
612

  
613
///////////////////////////////////////////////////////////////////////////////////////////////////
614
/**
615
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
616
 * a (possibly changing in time) point on the Object.
617
 *     
618
 * @param vector Vector of force that deforms the shape of the whole Object.
619
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
620
 * @return       ID of the effect added, or -1 if we failed to add one.
621
 */
622
  public long deform(Data3D vector, Data3D center)
623
    {  
624
    return mV.add(EffectNames.DEFORM, vector, center, null);
625
    }
626

  
627
///////////////////////////////////////////////////////////////////////////////////////////////////  
628
/**
629
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
630
 * away from the center (degree<=1)
631
 *
632
 * @param sink   The current degree of the Effect.
633
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
634
 * @param region Region that masks the Effect.
635
 * @return       ID of the effect added, or -1 if we failed to add one.
636
 */
637
  public long sink(Data1D sink, Data3D center, Data4D region)
638
    {
639
    return mV.add(EffectNames.SINK, sink, center, region);
640
    }
641

  
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643
/**
644
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
645
 * away from the center (degree<=1)
646
 *
647
 * @param sink   The current degree of the Effect.
648
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
649
 * @return       ID of the effect added, or -1 if we failed to add one.
650
 */
651
  public long sink(Data1D sink, Data3D center)
652
    {
653
    return mV.add(EffectNames.SINK, sink, center);
654
    }
655

  
656
///////////////////////////////////////////////////////////////////////////////////////////////////
657
/**
658
 * Pull all points around the center of the Effect towards a line passing through the center
659
 * (that's if degree>=1) or push them away from the line (degree<=1)
660
 *
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff