Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ c1e24646

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.content.res.Resources;
23
import android.opengl.GLES30;
24
import android.opengl.Matrix;
25

    
26
import org.distorted.library.message.EffectListener;
27
import org.distorted.library.program.DistortedProgram;
28
import org.distorted.library.program.FragmentCompilationException;
29
import org.distorted.library.program.FragmentUniformsException;
30
import org.distorted.library.program.LinkingException;
31
import org.distorted.library.program.VertexCompilationException;
32
import org.distorted.library.program.VertexUniformsException;
33
import org.distorted.library.type.Data1D;
34
import org.distorted.library.type.Data2D;
35
import org.distorted.library.type.Data3D;
36
import org.distorted.library.type.Data4D;
37
import org.distorted.library.type.Data5D;
38
import org.distorted.library.type.Static3D;
39

    
40
import java.io.InputStream;
41
import java.nio.ByteBuffer;
42
import java.nio.ByteOrder;
43
import java.nio.FloatBuffer;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46
/**
47
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
48
 * <p>
49
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
50
 */
51
public class DistortedEffects
52
  {
53
  private static final int POSITION_DATA_SIZE= 3; // Main Program: size of the position data in elements
54
  private static final int NORMAL_DATA_SIZE  = 3; // Main Program: size of the normal data in elements
55
  private static final int TEX_DATA_SIZE     = 2; // Main Program: size of the texture coordinate data in elements.
56

    
57
  /// MAIN PROGRAM ///
58
  private static DistortedProgram mMainProgram;
59
  private static int mMainTextureH;
60
  private static boolean[] mEffectEnabled = new boolean[EffectNames.size()];
61

    
62
  static
63
    {
64
    int len = EffectNames.size();
65

    
66
    for(int i=0; i<len; i++)
67
      {
68
      mEffectEnabled[i] = false;
69
      }
70
    }
71

    
72
  /// BLIT PROGRAM ///
73
  private static DistortedProgram mBlitProgram;
74
  private static int mBlitTextureH;
75
  private static int mBlitObjDH;
76
  private static int mBlitMVPMatrixH;
77
  private static final FloatBuffer mQuadPositions;
78

    
79
  static
80
    {
81
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
82
    mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
83
    mQuadPositions.put(positionData).position(0);
84
    }
85

    
86
  /// DEBUG ONLY /////
87
  private static DistortedProgram mDebugProgram;
88

    
89
  private static int mDebugObjDH;
90
  private static int mDebugMVPMatrixH;
91
  /// END DEBUG //////
92

    
93
  private static float[] mMVPMatrix = new float[16];
94
  private static float[] mTmpMatrix = new float[16];
95

    
96
  private static long mNextID =0;
97
  private long mID;
98

    
99
  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(true,DistortedSurface.TYPE_SYST,1,1);
100

    
101
  private EffectQueueMatrix      mM;
102
  private EffectQueueFragment    mF;
103
  private EffectQueueVertex      mV;
104
  private EffectQueuePostprocess mP;
105

    
106
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
  static void createProgram(Resources resources)
111
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
112
    {
113
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
114
    final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
115

    
116
    String mainVertHeader= ("#version 100\n");
117
    String mainFragHeader= ("#version 100\n");
118

    
119
    EffectNames name;
120
    EffectTypes type;
121
    boolean foundF = false;
122
    boolean foundV = false;
123

    
124
    for(int i=0; i<mEffectEnabled.length; i++)
125
      {
126
      if( mEffectEnabled[i] )
127
        {
128
        name = EffectNames.getName(i);
129
        type = EffectNames.getType(i);
130

    
131
        if( type == EffectTypes.VERTEX )
132
          {
133
          mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
134
          foundV = true;
135
          }
136
        else if( type == EffectTypes.FRAGMENT )
137
          {
138
          mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
139
          foundF = true;
140
          }
141
        }
142
      }
143

    
144
    mainVertHeader += ("#define NUM_VERTEX "   + ( foundV ? getMaxVertex()   : 0 ) + "\n");
145
    mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMaxFragment() : 0 ) + "\n");
146

    
147
    //android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
148
    //android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
149

    
150
    mMainProgram = new DistortedProgram(mainVertStream,mainFragStream, mainVertHeader, mainFragHeader);
151

    
152
    int mainProgramH = mMainProgram.getProgramHandle();
153
    EffectQueueFragment.getUniforms(mainProgramH);
154
    EffectQueueVertex.getUniforms(mainProgramH);
155
    EffectQueueMatrix.getUniforms(mainProgramH);
156
    mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
157

    
158
    // BLIT PROGRAM ////////////////////////////////////
159
    final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
160
    final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
161

    
162
    String blitVertHeader= ("#version 100\n#define NUM_VERTEX 0\n"  );
163
    String blitFragHeader= ("#version 100\n#define NUM_FRAGMENT 0\n");
164

    
165
    mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader);
166

    
167
    int blitProgramH = mBlitProgram.getProgramHandle();
168
    mBlitTextureH  = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
169
    mBlitObjDH     = GLES30.glGetUniformLocation( blitProgramH, "u_objD");
170
    mBlitMVPMatrixH= GLES30.glGetUniformLocation( blitProgramH, "u_MVPMatrix");
171

    
172
    // DEBUG ONLY //////////////////////////////////////
173
    final InputStream debugVertexStream   = resources.openRawResource(R.raw.test_vertex_shader);
174
    final InputStream debugFragmentStream = resources.openRawResource(R.raw.test_fragment_shader);
175

    
176
    mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, "#version 100\n", "#version 100\n");
177

    
178
    int debugProgramH = mDebugProgram.getProgramHandle();
179
    mDebugObjDH = GLES30.glGetUniformLocation( debugProgramH, "u_objD");
180
    mDebugMVPMatrixH = GLES30.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
181
    // END DEBUG  //////////////////////////////////////
182
    }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

    
186
  private void initializeEffectLists(DistortedEffects d, int flags)
187
    {
188
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
189
      {
190
      mM = d.mM;
191
      matrixCloned = true;
192
      }
193
    else
194
      {
195
      mM = new EffectQueueMatrix(mID);
196
      matrixCloned = false;
197
      }
198
    
199
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
200
      {
201
      mV = d.mV;
202
      vertexCloned = true;
203
      }
204
    else
205
      {
206
      mV = new EffectQueueVertex(mID);
207
      vertexCloned = false;
208
      }
209
    
210
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
211
      {
212
      mF = d.mF;
213
      fragmentCloned = true;
214
      }
215
    else
216
      {
217
      mF = new EffectQueueFragment(mID);
218
      fragmentCloned = false;
219
      }
220

    
221
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
222
      {
223
      mP = d.mP;
224
      postprocessCloned = true;
225
      }
226
    else
227
      {
228
      mP = new EffectQueuePostprocess(mID);
229
      postprocessCloned = false;
230
      }
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234
// DEBUG ONLY
235

    
236
  @SuppressWarnings("unused")
237
  private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedOutputSurface surface, float[] mvp, float[] vertices)
238
    {
239
    int len  = vertices.length/3;
240
    int minx = Integer.MAX_VALUE;
241
    int maxx = Integer.MIN_VALUE;
242
    int miny = Integer.MAX_VALUE;
243
    int maxy = Integer.MIN_VALUE;
244
    int wx,wy;
245

    
246
    float x,y,z, X,Y,W, ndcX,ndcY;
247

    
248
    for(int i=0; i<len; i++)
249
      {
250
      x = 2*halfX*vertices[3*i  ];
251
      y = 2*halfY*vertices[3*i+1];
252
      z = 2*halfZ*vertices[3*i+2];
253

    
254
      X = mvp[ 0]*x + mvp[ 4]*y + mvp[ 8]*z + mvp[12];
255
      Y = mvp[ 1]*x + mvp[ 5]*y + mvp[ 9]*z + mvp[13];
256
      W = mvp[ 3]*x + mvp[ 7]*y + mvp[11]*z + mvp[15];
257

    
258
      ndcX = X/W;
259
      ndcY = Y/W;
260

    
261
      wx = (int)(surface.mWidth *(ndcX+1)/2);
262
      wy = (int)(surface.mHeight*(ndcY+1)/2);
263

    
264
      if( wx<minx ) minx = wx;
265
      if( wx>maxx ) maxx = wx;
266
      if( wy<miny ) miny = wy;
267
      if( wy>maxy ) maxy = wy;
268
      }
269

    
270
    mDebugProgram.useProgram();
271
    surface.setAsOutput();
272

    
273
    Matrix.setIdentityM( mTmpMatrix, 0);
274
    Matrix.translateM  ( mTmpMatrix, 0, minx-surface.mWidth/2, maxy-surface.mHeight/2, -surface.mDistance);
275
    Matrix.scaleM      ( mTmpMatrix, 0, (float)(maxx-minx)/(2*halfX), (float)(maxy-miny)/(2*halfY), 1.0f);
276
    Matrix.translateM  ( mTmpMatrix, 0, halfX,-halfY, 0);
277
    Matrix.multiplyMM  ( mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
278

    
279
    GLES30.glUniform2f(mDebugObjDH, 2*halfX, 2*halfY);
280
    GLES30.glUniformMatrix4fv(mDebugMVPMatrixH, 1, false, mMVPMatrix , 0);
281

    
282
    GLES30.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
283
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
284
    }
285

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

    
288
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
289
    {
290
    mM.compute(currTime);
291
    mV.compute(currTime);
292
    mF.compute(currTime);
293
    mP.compute(currTime);
294

    
295
    float halfZ = halfW*mesh.zFactor;
296
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight);
297

    
298
    if( mP.mNumEffects==0 )
299
      {
300
      mMainProgram.useProgram();
301
      GLES30.glUniform1i(mMainTextureH, 0);
302
      surface.setAsOutput();
303
      mM.send(surface,halfW,halfH,halfZ);
304
      mV.send(halfW,halfH,halfZ);
305
      mF.send(halfW,halfH);
306
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
307
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
308
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
309
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
310
      }
311
    else
312
      {
313
      if( mV.mNumEffects==0 && mF.mNumEffects==0 && (mesh instanceof MeshFlat) && mM.canUseShortcut() )
314
        {
315
        mM.constructMatrices(surface,halfW,halfH);
316
        mP.render(2*halfW, 2*halfH, mM.getMVP(), surface);
317
        }
318
      else
319
        {
320
        mMainProgram.useProgram();
321
        GLES30.glUniform1i(mMainTextureH, 0);
322
        mBufferFBO.resizeFast(surface.mWidth, surface.mHeight);
323
        mBufferFBO.setAsOutput();
324
        GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
325
        GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
326
        mM.send(mBufferFBO,halfW,halfH,halfZ);
327
        mV.send(halfW,halfH,halfZ);
328
        mF.send(halfW,halfH);
329
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
330
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
331
        GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
332
        GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
333

    
334
        Matrix.setIdentityM(mTmpMatrix, 0);
335
        Matrix.translateM(mTmpMatrix, 0, 0, 0, -surface.mDistance);
336
        Matrix.multiplyMM(mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
337

    
338
        mBufferFBO.setAsInput();
339
        mP.render(surface.mWidth, surface.mHeight, mMVPMatrix, surface);
340
        }
341
      }
342

    
343
    /// DEBUG ONLY //////
344
    // displayBoundingRect(halfInputW, halfInputH, halfZ, df, mM.getMVP(), mesh.getBoundingVertices() );
345
    /// END DEBUG ///////
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349
   
350
  static void blitPriv(DistortedOutputSurface projection)
351
    {
352
    GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight);
353

    
354
    mBlitProgram.useProgram();
355

    
356
    Matrix.setIdentityM(mTmpMatrix, 0);
357
    Matrix.translateM(mTmpMatrix, 0, 0, 0, -projection.mDistance);
358
    Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mTmpMatrix, 0);
359

    
360
    GLES30.glUniform1i(mBlitTextureH, 0);
361
    GLES30.glUniform2f( mBlitObjDH , projection.mWidth/2, projection.mHeight/2);
362
    GLES30.glUniformMatrix4fv(mBlitMVPMatrixH, 1, false, mMVPMatrix, 0);
363
    GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
364
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
365
    }
366
    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
   
369
  private void releasePriv()
370
    {
371
    if( !matrixCloned     ) mM.abortAll(false);
372
    if( !vertexCloned     ) mV.abortAll(false);
373
    if( !fragmentCloned   ) mF.abortAll(false);
374
    if( !postprocessCloned) mP.abortAll(false);
375

    
376
    mM = null;
377
    mV = null;
378
    mF = null;
379
    mP = null;
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  static void onDestroy()
385
    {
386
    mNextID = 0;
387

    
388
    int len = EffectNames.size();
389

    
390
    for(int i=0; i<len; i++)
391
      {
392
      mEffectEnabled[i] = false;
393
      }
394
    }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
// PUBLIC API
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399
/**
400
 * Create empty effect queue.
401
 */
402
  public DistortedEffects()
403
    {
404
    mID = ++mNextID;
405
    initializeEffectLists(this,0);
406
    }
407

    
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409
/**
410
 * Copy constructor.
411
 * <p>
412
 * Whatever we do not clone gets created just like in the default constructor.
413
 *
414
 * @param dc    Source object to create our object from
415
 * @param flags A bitmask of values specifying what to copy.
416
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
417
 */
418
  public DistortedEffects(DistortedEffects dc, int flags)
419
    {
420
    mID = ++mNextID;
421
    initializeEffectLists(dc,flags);
422
    }
423

    
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425
/**
426
 * Releases all resources. After this call, the queue should not be used anymore.
427
 */
428
  public synchronized void delete()
429
    {
430
    releasePriv();
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434
/**
435
 * Returns unique ID of this instance.
436
 *
437
 * @return ID of the object.
438
 */
439
  public long getID()
440
      {
441
      return mID;
442
      }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445
/**
446
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
447
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
448
 * 
449
 * @param el A class implementing the EffectListener interface that wants to get notifications.
450
 */
451
  public void registerForMessages(EffectListener el)
452
    {
453
    mV.registerForMessages(el);
454
    mF.registerForMessages(el);
455
    mM.registerForMessages(el);
456
    mP.registerForMessages(el);
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
/**
461
 * Removes the calling class from the list of Listeners.
462
 * 
463
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
464
 */
465
  public void deregisterForMessages(EffectListener el)
466
    {
467
    mV.deregisterForMessages(el);
468
    mF.deregisterForMessages(el);
469
    mM.deregisterForMessages(el);
470
    mP.deregisterForMessages(el);
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474
/**
475
 * Aborts all Effects.
476
 * @return Number of effects aborted.
477
 */
478
  public int abortAllEffects()
479
      {
480
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
481
      }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484
/**
485
 * Aborts all Effects of a given type, for example all MATRIX Effects.
486
 * 
487
 * @param type one of the constants defined in {@link EffectTypes}
488
 * @return Number of effects aborted.
489
 */
490
  public int abortEffects(EffectTypes type)
491
    {
492
    switch(type)
493
      {
494
      case MATRIX     : return mM.abortAll(true);
495
      case VERTEX     : return mV.abortAll(true);
496
      case FRAGMENT   : return mF.abortAll(true);
497
      case POSTPROCESS: return mP.abortAll(true);
498
      default         : return 0;
499
      }
500
    }
501
    
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503
/**
504
 * Aborts a single Effect.
505
 * 
506
 * @param id ID of the Effect we want to abort.
507
 * @return number of Effects aborted. Always either 0 or 1.
508
 */
509
  public int abortEffect(long id)
510
    {
511
    int type = (int)(id&EffectTypes.MASK);
512

    
513
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
514
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
515
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
516
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
517

    
518
    return 0;
519
    }
520

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522
/**
523
 * Abort all Effects of a given name, for example all rotations.
524
 * 
525
 * @param name one of the constants defined in {@link EffectNames}
526
 * @return number of Effects aborted.
527
 */
528
  public int abortEffects(EffectNames name)
529
    {
530
    switch(name.getType())
531
      {
532
      case MATRIX     : return mM.removeByType(name);
533
      case VERTEX     : return mV.removeByType(name);
534
      case FRAGMENT   : return mF.removeByType(name);
535
      case POSTPROCESS: return mP.removeByType(name);
536
      default         : return 0;
537
      }
538
    }
539
    
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541
/**
542
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
543
 * 
544
 * @param id Effect ID we want to print info about
545
 * @return <code>true</code> if a single Effect of type effectType has been found.
546
 */
547
    
548
  public boolean printEffect(long id)
549
    {
550
    int type = (int)(id&EffectTypes.MASK);
551

    
552
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
553
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
554
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
555
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
556

    
557
    return false;
558
    }
559

    
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561
/**
562
 * Enables a given Effect.
563
 * <p>
564
 * By default, all effects are disabled. One has to explicitly enable each effect one intends to use.
565
 * This needs to be called BEFORE shaders get compiled, i.e. before the call to Distorted.onCreate().
566
 * The point: by enabling only the effects we need, we can optimize the shaders.
567
 *
568
 * @param name Name of the Effect to enable.
569
 */
570
  public static void enableEffect(EffectNames name)
571
    {
572
    mEffectEnabled[name.ordinal()] = true;
573
    }
574

    
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
/**
577
 * Returns the maximum number of Matrix effects.
578
 *
579
 * @return The maximum number of Matrix effects
580
 */
581
  public static int getMaxMatrix()
582
    {
583
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
584
    }
585

    
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587
/**
588
 * Returns the maximum number of Vertex effects.
589
 *
590
 * @return The maximum number of Vertex effects
591
 */
592
  public static int getMaxVertex()
593
    {
594
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
595
    }
596

    
597
///////////////////////////////////////////////////////////////////////////////////////////////////
598
/**
599
 * Returns the maximum number of Fragment effects.
600
 *
601
 * @return The maximum number of Fragment effects
602
 */
603
  public static int getMaxFragment()
604
    {
605
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
606
    }
607

    
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609
/**
610
 * Returns the maximum number of Postprocess effects.
611
 *
612
 * @return The maximum number of Postprocess effects
613
 */
614
  public static int getMaxPostprocess()
615
    {
616
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
617
    }
618

    
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620
/**
621
 * Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
622
 * This can fail if:
623
 * <ul>
624
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
625
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
626
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
627
 *     time only decreasing the value of 'max' is permitted.
628
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
629
 * </ul>
630
 *
631
 * @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
632
 *            than Byte.MAX_VALUE
633
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
634
 */
635
  public static boolean setMaxMatrix(int max)
636
    {
637
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
638
    }
639

    
640
///////////////////////////////////////////////////////////////////////////////////////////////////
641
/**
642
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
643
 * This can fail if:
644
 * <ul>
645
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
646
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
647
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
648
 *     time only decreasing the value of 'max' is permitted.
649
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
650
 * </ul>
651
 *
652
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
653
 *            than Byte.MAX_VALUE
654
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
655
 */
656
  public static boolean setMaxVertex(int max)
657
    {
658
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
659
    }
660

    
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662
/**
663
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
664
 * This can fail if:
665
 * <ul>
666
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
667
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
668
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
669
 *     time only decreasing the value of 'max' is permitted.
670
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
671
 * </ul>
672
 *
673
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
674
 *            than Byte.MAX_VALUE
675
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
676
 */
677
  public static boolean setMaxFragment(int max)
678
    {
679
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
680
    }
681

    
682
///////////////////////////////////////////////////////////////////////////////////////////////////
683
/**
684
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
685
 * This can fail if:
686
 * <ul>
687
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
688
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
689
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
690
 *     time only decreasing the value of 'max' is permitted.
691
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
692
 * </ul>
693
 *
694
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
695
 *            than Byte.MAX_VALUE
696
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
697
 */
698
  public static boolean setMaxPostprocess(int max)
699
    {
700
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
701
    }
702

    
703
///////////////////////////////////////////////////////////////////////////////////////////////////   
704
///////////////////////////////////////////////////////////////////////////////////////////////////
705
// Individual effect functions.
706
///////////////////////////////////////////////////////////////////////////////////////////////////
707
// Matrix-based effects
708
///////////////////////////////////////////////////////////////////////////////////////////////////
709
/**
710
 * Moves the Object by a (possibly changing in time) vector.
711
 * 
712
 * @param vector 3-dimensional Data which at any given time will return a Static3D
713
 *               representing the current coordinates of the vector we want to move the Object with.
714
 * @return       ID of the effect added, or -1 if we failed to add one.
715
 */
716
  public long move(Data3D vector)
717
    {   
718
    return mM.add(EffectNames.MOVE,vector);
719
    }
720

    
721
///////////////////////////////////////////////////////////////////////////////////////////////////
722
/**
723
 * Scales the Object by (possibly changing in time) 3D scale factors.
724
 * 
725
 * @param scale 3-dimensional Data which at any given time returns a Static3D
726
 *              representing the current x- , y- and z- scale factors.
727
 * @return      ID of the effect added, or -1 if we failed to add one.
728
 */
729
  public long scale(Data3D scale)
730
    {   
731
    return mM.add(EffectNames.SCALE,scale);
732
    }
733

    
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735
/**
736
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
737
 *
738
 * @param scale The factor to scale all 3 dimensions with.
739
 * @return      ID of the effect added, or -1 if we failed to add one.
740
 */
741
  public long scale(float scale)
742
    {
743
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
744
    }
745

    
746
///////////////////////////////////////////////////////////////////////////////////////////////////
747
/**
748
 * Rotates the Object by 'angle' degrees around the center.
749
 * Static axis of rotation is given by the last parameter.
750
 *
751
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
752
 * @param axis   Axis of rotation
753
 * @param center Coordinates of the Point we are rotating around.
754
 * @return       ID of the effect added, or -1 if we failed to add one.
755
 */
756
  public long rotate(Data1D angle, Static3D axis, Data3D center )
757
    {   
758
    return mM.add(EffectNames.ROTATE, angle, axis, center);
759
    }
760

    
761
///////////////////////////////////////////////////////////////////////////////////////////////////
762
/**
763
 * Rotates the Object by 'angle' degrees around the center.
764
 * Here both angle and axis can dynamically change.
765
 *
766
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
767
 * @param center    Coordinates of the Point we are rotating around.
768
 * @return          ID of the effect added, or -1 if we failed to add one.
769
 */
770
  public long rotate(Data4D angleaxis, Data3D center)
771
    {
772
    return mM.add(EffectNames.ROTATE, angleaxis, center);
773
    }
774

    
775
///////////////////////////////////////////////////////////////////////////////////////////////////
776
/**
777
 * Rotates the Object by quaternion.
778
 *
779
 * @param quaternion The quaternion describing the rotation.
780
 * @param center     Coordinates of the Point we are rotating around.
781
 * @return           ID of the effect added, or -1 if we failed to add one.
782
 */
783
  public long quaternion(Data4D quaternion, Data3D center )
784
    {
785
    return mM.add(EffectNames.QUATERNION,quaternion,center);
786
    }
787

    
788
///////////////////////////////////////////////////////////////////////////////////////////////////
789
/**
790
 * Shears the Object.
791
 *
792
 * @param shear   The 3-tuple of shear factors. The first controls level
793
 *                of shearing in the X-axis, second - Y-axis and the third -
794
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
795
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
796
 * @param center  Center of shearing, i.e. the point which stays unmoved.
797
 * @return        ID of the effect added, or -1 if we failed to add one.
798
 */
799
  public long shear(Data3D shear, Data3D center)
800
    {
801
    return mM.add(EffectNames.SHEAR, shear, center);
802
    }
803

    
804
///////////////////////////////////////////////////////////////////////////////////////////////////
805
// Fragment-based effects  
806
///////////////////////////////////////////////////////////////////////////////////////////////////
807
/**
808
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
809
 *        
810
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
811
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
812
 *               Valid range: <0,1>
813
 * @param color  Color to mix. (1,0,0) is RED.
814
 * @param region Region this Effect is limited to.
815
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
816
 * @return       ID of the effect added, or -1 if we failed to add one.
817
 */
818
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
819
    {
820
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
821
    }
822

    
823
///////////////////////////////////////////////////////////////////////////////////////////////////
824
/**
825
 * Makes the whole Object smoothly change all three of its RGB components.
826
 *
827
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
828
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
829
 *               Valid range: <0,1>
830
 * @param color  Color to mix. (1,0,0) is RED.
831
 * @return       ID of the effect added, or -1 if we failed to add one.
832
 */
833
  public long chroma(Data1D blend, Data3D color)
834
    {
835
    return mF.add(EffectNames.CHROMA, blend, color);
836
    }
837

    
838
///////////////////////////////////////////////////////////////////////////////////////////////////
839
/**
840
 * Makes a certain sub-region of the Object smoothly change its transparency level.
841
 *        
842
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
843
 *               moment: pixel.a *= alpha.
844
 *               Valid range: <0,1>
845
 * @param region Region this Effect is limited to. 
846
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
847
 * @return       ID of the effect added, or -1 if we failed to add one. 
848
 */
849
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
850
    {
851
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
852
    }
853

    
854
///////////////////////////////////////////////////////////////////////////////////////////////////
855
/**
856
 * Makes the whole Object smoothly change its transparency level.
857
 *
858
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
859
 *               given moment: pixel.a *= alpha.
860
 *               Valid range: <0,1>
861
 * @return       ID of the effect added, or -1 if we failed to add one.
862
 */
863
  public long alpha(Data1D alpha)
864
    {
865
    return mF.add(EffectNames.ALPHA, alpha);
866
    }
867

    
868
///////////////////////////////////////////////////////////////////////////////////////////////////
869
/**
870
 * Makes a certain sub-region of the Object smoothly change its brightness level.
871
 *        
872
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
873
 *                   at any given moment. Valid range: <0,infinity)
874
 * @param region     Region this Effect is limited to.
875
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
876
 * @return           ID of the effect added, or -1 if we failed to add one.
877
 */
878
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
879
    {
880
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
881
    }
882

    
883
///////////////////////////////////////////////////////////////////////////////////////////////////
884
/**
885
 * Makes the whole Object smoothly change its brightness level.
886
 *
887
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
888
 *                   at any given moment. Valid range: <0,infinity)
889
 * @return           ID of the effect added, or -1 if we failed to add one.
890
 */
891
  public long brightness(Data1D brightness)
892
    {
893
    return mF.add(EffectNames.BRIGHTNESS, brightness);
894
    }
895

    
896
///////////////////////////////////////////////////////////////////////////////////////////////////
897
/**
898
 * Makes a certain sub-region of the Object smoothly change its contrast level.
899
 *        
900
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
901
 *                 at any given moment. Valid range: <0,infinity)
902
 * @param region   Region this Effect is limited to.
903
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
904
 * @return         ID of the effect added, or -1 if we failed to add one.
905
 */
906
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
907
    {
908
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
909
    }
910

    
911
///////////////////////////////////////////////////////////////////////////////////////////////////
912
/**
913
 * Makes the whole Object smoothly change its contrast level.
914
 *
915
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
916
 *                 at any given moment. Valid range: <0,infinity)
917
 * @return         ID of the effect added, or -1 if we failed to add one.
918
 */
919
  public long contrast(Data1D contrast)
920
    {
921
    return mF.add(EffectNames.CONTRAST, contrast);
922
    }
923

    
924
///////////////////////////////////////////////////////////////////////////////////////////////////
925
/**
926
 * Makes a certain sub-region of the Object smoothly change its saturation level.
927
 *        
928
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
929
 *                   at any given moment. Valid range: <0,infinity)
930
 * @param region     Region this Effect is limited to.
931
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
932
 * @return           ID of the effect added, or -1 if we failed to add one.
933
 */
934
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
935
    {
936
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
937
    }
938

    
939
///////////////////////////////////////////////////////////////////////////////////////////////////
940
/**
941
 * Makes the whole Object smoothly change its saturation level.
942
 *
943
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
944
 *                   at any given moment. Valid range: <0,infinity)
945
 * @return           ID of the effect added, or -1 if we failed to add one.
946
 */
947
  public long saturation(Data1D saturation)
948
    {
949
    return mF.add(EffectNames.SATURATION, saturation);
950
    }
951

    
952
///////////////////////////////////////////////////////////////////////////////////////////////////
953
// Vertex-based effects  
954
///////////////////////////////////////////////////////////////////////////////////////////////////
955
/**
956
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
957
 *
958
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
959
 *               currently being dragged with.
960
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
961
 * @param region Region that masks the Effect.
962
 * @return       ID of the effect added, or -1 if we failed to add one.
963
 */
964
  public long distort(Data3D vector, Data3D center, Data4D region)
965
    {  
966
    return mV.add(EffectNames.DISTORT, vector, center, region);
967
    }
968

    
969
///////////////////////////////////////////////////////////////////////////////////////////////////
970
/**
971
 * Distort the whole Object by a (possibly changing in time) vector of force.
972
 *
973
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
974
 *               currently being dragged with.
975
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
976
 * @return       ID of the effect added, or -1 if we failed to add one.
977
 */
978
  public long distort(Data3D vector, Data3D center)
979
    {
980
    return mV.add(EffectNames.DISTORT, vector, center, null);
981
    }
982

    
983
///////////////////////////////////////////////////////////////////////////////////////////////////
984
/**
985
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
986
 * a (possibly changing in time) point on the Object.
987
 *
988
 * @param vector Vector of force that deforms the shape of the whole Object.
989
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
990
 * @param region Region that masks the Effect.
991
 * @return       ID of the effect added, or -1 if we failed to add one.
992
 */
993
  public long deform(Data3D vector, Data3D center, Data4D region)
994
    {
995
    return mV.add(EffectNames.DEFORM, vector, center, region);
996
    }
997

    
998
///////////////////////////////////////////////////////////////////////////////////////////////////
999
/**
1000
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
1001
 * a (possibly changing in time) point on the Object.
1002
 *     
1003
 * @param vector Vector of force that deforms the shape of the whole Object.
1004
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1005
 * @return       ID of the effect added, or -1 if we failed to add one.
1006
 */
1007
  public long deform(Data3D vector, Data3D center)
1008
    {  
1009
    return mV.add(EffectNames.DEFORM, vector, center, null);
1010
    }
1011

    
1012
///////////////////////////////////////////////////////////////////////////////////////////////////  
1013
/**
1014
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
1015
 * away from the center (degree<=1)
1016
 *
1017
 * @param sink   The current degree of the Effect.
1018
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1019
 * @param region Region that masks the Effect.
1020
 * @return       ID of the effect added, or -1 if we failed to add one.
1021
 */
1022
  public long sink(Data1D sink, Data3D center, Data4D region)
1023
    {
1024
    return mV.add(EffectNames.SINK, sink, center, region);
1025
    }
1026

    
1027
///////////////////////////////////////////////////////////////////////////////////////////////////
1028
/**
1029
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
1030
 * away from the center (degree<=1)
1031
 *
1032
 * @param sink   The current degree of the Effect.
1033
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1034
 * @return       ID of the effect added, or -1 if we failed to add one.
1035
 */
1036
  public long sink(Data1D sink, Data3D center)
1037
    {
1038
    return mV.add(EffectNames.SINK, sink, center);
1039
    }
1040

    
1041
///////////////////////////////////////////////////////////////////////////////////////////////////
1042
/**
1043
 * Pull all points around the center of the Effect towards a line passing through the center
1044
 * (that's if degree>=1) or push them away from the line (degree<=1)
1045
 *
1046
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1047
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1048
 * @param region Region that masks the Effect.
1049
 * @return       ID of the effect added, or -1 if we failed to add one.
1050
 */
1051
  public long pinch(Data2D pinch, Data3D center, Data4D region)
1052
    {
1053
    return mV.add(EffectNames.PINCH, pinch, center, region);
1054
    }
1055

    
1056
///////////////////////////////////////////////////////////////////////////////////////////////////
1057
/**
1058
 * Pull all points around the center of the Effect towards a line passing through the center
1059
 * (that's if degree>=1) or push them away from the line (degree<=1)
1060
 *
1061
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1062
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1063
 * @return       ID of the effect added, or -1 if we failed to add one.
1064
 */
1065
  public long pinch(Data2D pinch, Data3D center)
1066
    {
1067
    return mV.add(EffectNames.PINCH, pinch, center);
1068
    }
1069

    
1070
///////////////////////////////////////////////////////////////////////////////////////////////////  
1071
/**
1072
 * Rotate part of the Object around the Center of the Effect by a certain angle.
1073
 *
1074
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1075
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1076
 * @param region Region that masks the Effect.
1077
 * @return       ID of the effect added, or -1 if we failed to add one.
1078
 */
1079
  public long swirl(Data1D swirl, Data3D center, Data4D region)
1080
    {    
1081
    return mV.add(EffectNames.SWIRL, swirl, center, region);
1082
    }
1083

    
1084
///////////////////////////////////////////////////////////////////////////////////////////////////
1085
/**
1086
 * Rotate the whole Object around the Center of the Effect by a certain angle.
1087
 *
1088
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1089
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1090
 * @return       ID of the effect added, or -1 if we failed to add one.
1091
 */
1092
  public long swirl(Data1D swirl, Data3D center)
1093
    {
1094
    return mV.add(EffectNames.SWIRL, swirl, center);
1095
    }
1096

    
1097
///////////////////////////////////////////////////////////////////////////////////////////////////
1098
/**
1099
 * Directional, sinusoidal wave effect.
1100
 *
1101
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
1102
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
1103
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
1104
 *               describe the 'direction' of the wave.
1105
 *               <p>
1106
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
1107
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
1108
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
1109
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
1110
 *               <p>
1111
 *               <p>
1112
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
1113
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
1114
 *               will be sine shapes.
1115
 *               <p>
1116
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
1117
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
1118
 *               YZ-plane with be sine shapes.
1119
 *               <p>
1120
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
1121
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
1122
 *               value if sin at this point.
1123
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1124
 * @return       ID of the effect added, or -1 if we failed to add one.
1125
 */
1126
  public long wave(Data5D wave, Data3D center)
1127
    {
1128
    return mV.add(EffectNames.WAVE, wave, center, null);
1129
    }
1130

    
1131
///////////////////////////////////////////////////////////////////////////////////////////////////
1132
/**
1133
 * Directional, sinusoidal wave effect.
1134
 *
1135
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
1136
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1137
 * @param region Region that masks the Effect.
1138
 * @return       ID of the effect added, or -1 if we failed to add one.
1139
 */
1140
  public long wave(Data5D wave, Data3D center, Data4D region)
1141
    {
1142
    return mV.add(EffectNames.WAVE, wave, center, region);
1143
    }
1144

    
1145
///////////////////////////////////////////////////////////////////////////////////////////////////
1146
// Postprocess-based effects
1147
///////////////////////////////////////////////////////////////////////////////////////////////////
1148
/**
1149
 * Blur the object.
1150
 *
1151
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
1152
 *               take into account 10 pixels in each direction.
1153
 * @return ID of the effect added, or -1 if we failed to add one.
1154
 */
1155
  public long blur(Data1D radius)
1156
    {
1157
    return mP.add(EffectNames.BLUR, radius);
1158
    }
1159
  }
(4-4/23)