Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 79921db2

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.Buffer;
42
import java.nio.ByteBuffer;
43
import java.nio.ByteOrder;
44
import java.nio.FloatBuffer;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
/**
48
 * Class containing Matrix,Vertex and Fragment effect queues. Postprocessing queue is held in a separate
49
 * class.
50
 * <p>
51
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
52
 */
53
public class DistortedEffects
54
  {
55
  // THIS IS FOR MAIN AND FEEDBACK PROGRAMS ///
56
  private static boolean[] mEffectEnabled = new boolean[EffectNames.size()];
57

    
58
  static
59
    {
60
    int len = EffectNames.size();
61

    
62
    for(int i=0; i<len; i++)
63
      {
64
      mEffectEnabled[i] = false;
65
      }
66
    }
67

    
68
  /// MAIN PROGRAM ///
69
  private static DistortedProgram mMainProgram;
70
  private static int mMainTextureH;
71

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

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

    
85
  /// DEBUG PROGRAM /////
86
  private static DistortedProgram mDebugProgram;
87

    
88
  private static int mDebugObjDH;
89
  private static int mDebugMVPMatrixH;
90

    
91
  private static float[] mMVPMatrix = new float[16];
92
  private static float[] mTmpMatrix = new float[16];
93

    
94
  private static long mNextID =0;
95
  private long mID;
96

    
97
  private EffectQueueMatrix      mM;
98
  private EffectQueueFragment    mF;
99
  private EffectQueueVertex      mV;
100

    
101
  private boolean matrixCloned, vertexCloned, fragmentCloned;
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  static void createProgram(Resources resources)
106
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
107
    {
108
    //// BOTH MAIN AND FEEDBACK PROGRAMS ///////
109
    String mainVertHeader= Distorted.GLSL_VERSION;
110
    String mainFragHeader= Distorted.GLSL_VERSION;
111

    
112
    EffectNames name;
113
    EffectTypes type;
114
    boolean foundF = false;
115
    boolean foundV = false;
116

    
117
    for(int i=0; i<mEffectEnabled.length; i++)
118
      {
119
      if( mEffectEnabled[i] )
120
        {
121
        name = EffectNames.getName(i);
122
        type = EffectNames.getType(i);
123

    
124
        if( type == EffectTypes.VERTEX )
125
          {
126
          mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
127
          foundV = true;
128
          }
129
        else if( type == EffectTypes.FRAGMENT )
130
          {
131
          mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
132
          foundF = true;
133
          }
134
        }
135
      }
136

    
137
    mainVertHeader += ("#define NUM_VERTEX "   + ( foundV ? getMaxVertex()   : 0 ) + "\n");
138
    mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMaxFragment() : 0 ) + "\n");
139

    
140
    //android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
141
    //android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
142

    
143
    //////////////////////////////////////////////////////////////////////////////////////
144
    ////////// MAIN PROGRAM //////////////////////////////////////////////////////////////
145
    //////////////////////////////////////////////////////////////////////////////////////
146
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
147
    final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
148

    
149
    String[] feedback = { "v_Position", "v_Normal" };
150

    
151
    mMainProgram = new DistortedProgram(mainVertStream,mainFragStream, mainVertHeader, mainFragHeader, Distorted.GLSL, feedback);
152

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

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

    
165
    String blitVertHeader= (Distorted.GLSL_VERSION + "#define NUM_VERTEX 0\n"  );
166
    String blitFragHeader= (Distorted.GLSL_VERSION + "#define NUM_FRAGMENT 0\n");
167

    
168
    try
169
      {
170
      mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
171
      }
172
    catch(Exception e)
173
      {
174
      android.util.Log.e("EFFECTS", "exception trying to compile BLIT program: "+e.getMessage());
175
      throw new RuntimeException(e.getMessage());
176
      }
177

    
178
    int blitProgramH = mBlitProgram.getProgramHandle();
179
    mBlitTextureH  = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
180
    mBlitDepthH    = GLES30.glGetUniformLocation( blitProgramH, "u_Depth");
181

    
182
    //////////////////////////////////////////////////////////////////////////////////////
183
    ////////// DEBUG PROGRAM /////////////////////////////////////////////////////////////
184
    //////////////////////////////////////////////////////////////////////////////////////
185
    final InputStream debugVertexStream   = resources.openRawResource(R.raw.test_vertex_shader);
186
    final InputStream debugFragmentStream = resources.openRawResource(R.raw.test_fragment_shader);
187

    
188
    try
189
      {
190
      mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, Distorted.GLSL_VERSION, Distorted.GLSL_VERSION, Distorted.GLSL);
191
      }
192
    catch(Exception e)
193
      {
194
      android.util.Log.e("EFFECTS", "exception trying to compile DEBUG program: "+e.getMessage());
195
      throw new RuntimeException(e.getMessage());
196
      }
197

    
198
    int debugProgramH = mDebugProgram.getProgramHandle();
199
    mDebugObjDH = GLES30.glGetUniformLocation( debugProgramH, "u_objD");
200
    mDebugMVPMatrixH = GLES30.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  private void initializeEffectLists(DistortedEffects d, int flags)
206
    {
207
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
208
      {
209
      mM = d.mM;
210
      matrixCloned = true;
211
      }
212
    else
213
      {
214
      mM = new EffectQueueMatrix(mID);
215
      matrixCloned = false;
216
      }
217
    
218
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
219
      {
220
      mV = d.mV;
221
      vertexCloned = true;
222
      }
223
    else
224
      {
225
      mV = new EffectQueueVertex(mID);
226
      vertexCloned = false;
227
      }
228
    
229
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
230
      {
231
      mF = d.mF;
232
      fragmentCloned = true;
233
      }
234
    else
235
      {
236
      mF = new EffectQueueFragment(mID);
237
      fragmentCloned = false;
238
      }
239
    }
240

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242
// DEBUG ONLY
243

    
244
  @SuppressWarnings("unused")
245
  private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedOutputSurface surface, float[] mvp, float[] vertices, long currTime)
246
    {
247
    int len  = vertices.length/3;
248
    int minx = Integer.MAX_VALUE;
249
    int maxx = Integer.MIN_VALUE;
250
    int miny = Integer.MAX_VALUE;
251
    int maxy = Integer.MIN_VALUE;
252
    int wx,wy;
253

    
254
    float x,y,z, X,Y,W, ndcX,ndcY;
255

    
256
    for(int i=0; i<len; i++)
257
      {
258
      x = 2*halfX*vertices[3*i  ];
259
      y = 2*halfY*vertices[3*i+1];
260
      z = 2*halfZ*vertices[3*i+2];
261

    
262
      X = mvp[ 0]*x + mvp[ 4]*y + mvp[ 8]*z + mvp[12];
263
      Y = mvp[ 1]*x + mvp[ 5]*y + mvp[ 9]*z + mvp[13];
264
      W = mvp[ 3]*x + mvp[ 7]*y + mvp[11]*z + mvp[15];
265

    
266
      ndcX = X/W;
267
      ndcY = Y/W;
268

    
269
      wx = (int)(surface.mWidth *(ndcX+1)/2);
270
      wy = (int)(surface.mHeight*(ndcY+1)/2);
271

    
272
      if( wx<minx ) minx = wx;
273
      if( wx>maxx ) maxx = wx;
274
      if( wy<miny ) miny = wy;
275
      if( wy>maxy ) maxy = wy;
276
      }
277

    
278
    mDebugProgram.useProgram();
279
    surface.setAsOutput(currTime);
280

    
281
    Matrix.setIdentityM( mTmpMatrix, 0);
282
    Matrix.translateM  ( mTmpMatrix, 0, minx-surface.mWidth/2, maxy-surface.mHeight/2, -surface.mDistance);
283
    Matrix.scaleM      ( mTmpMatrix, 0, (float)(maxx-minx)/(2*halfX), (float)(maxy-miny)/(2*halfY), 1.0f);
284
    Matrix.translateM  ( mTmpMatrix, 0, halfX,-halfY, 0);
285
    Matrix.multiplyMM  ( mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
286

    
287
    GLES30.glUniform2f(mDebugObjDH, 2*halfX, 2*halfY);
288
    GLES30.glUniformMatrix4fv(mDebugMVPMatrixH, 1, false, mMVPMatrix , 0);
289

    
290
    GLES30.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
291
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
292
    }
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294

    
295
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
296
    {
297
    mM.compute(currTime);
298
    mV.compute(currTime);
299
    mF.compute(currTime);
300

    
301
    float halfZ = halfW*mesh.zFactor;
302

    
303
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
304

    
305
    mMainProgram.useProgram();
306
    GLES30.glUniform1i(mMainTextureH, 0);
307
    surface.setAsOutput(currTime);
308
    mM.send(surface,halfW,halfH,halfZ);
309
    mV.send(halfW,halfH,halfZ);
310
    mF.send(halfW,halfH);
311

    
312
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mPosVBO[0]);
313
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
314
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mNorVBO[0]);
315
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, 0);
316
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mTexVBO[0]);
317
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, 0);
318

    
319
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
320
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0 );
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

    
325
  void drawPrivFeedback(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
326
    {
327
    int error;
328

    
329
    mM.compute(currTime);
330
    mV.compute(currTime);
331
    mF.compute(currTime);
332

    
333
    float halfZ = halfW*mesh.zFactor;
334

    
335
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
336

    
337
    mMainProgram.useProgram();
338

    
339
    mM.send(surface,halfW,halfH,halfZ);
340
    mV.send(halfW,halfH,halfZ);
341

    
342
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mPosVBO[0]);
343
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
344
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mNorVBO[0]);
345
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, 0);
346
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mTexVBO[0]);
347
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, 0);
348

    
349
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mesh.mPosTBO[0]);
350
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 1, mesh.mNorTBO[0]);
351
    GLES30.glEnable(GLES30.GL_RASTERIZER_DISCARD);
352
    GLES30.glBeginTransformFeedback(GLES30.GL_POINTS);
353
    GLES30.glDrawArrays(GLES30.GL_POINTS, 0, mesh.dataLength);
354

    
355
    error = GLES30.glGetError();
356
    if (error != GLES30.GL_NO_ERROR)
357
      {
358
      throw new RuntimeException("2 glError 0x" + Integer.toHexString(error));
359
      }
360

    
361
    GLES30.glEndTransformFeedback();
362
    GLES30.glDisable(GLES30.GL_RASTERIZER_DISCARD);
363
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0 );
364
/*
365
int len = mesh.dataLength*MeshObject.BYTES_PER_FLOAT*MeshObject.POSITION_DATA_SIZE;
366

    
367
Buffer mappedBuffer =  GLES30.glMapBufferRange(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, len, GLES30.GL_MAP_READ_BIT);
368
FloatBuffer fb = ((ByteBuffer) mappedBuffer).order(ByteOrder.nativeOrder()).asFloatBuffer();
369
FloatBuffer bb = mesh.mMeshNormals;
370

    
371
String msgB = "";
372
for(int d=0; d<mesh.dataLength; d++)
373
  {
374
  msgB+="("+(2*halfW*bb.get(3*d+0))+","+(2*halfH*bb.get(3*d+1))+","+(bb.get(3*d+2))+")";
375
  }
376
android.util.Log.d( "Feedback", msgB);
377

    
378
String msgA = "";
379
for(int d=0; d<mesh.dataLength; d++)
380
  {
381
  msgA+="("+fb.get(3*d+0)+","+fb.get(3*d+1)+","+fb.get(3*d+2)+")";
382
  }
383
android.util.Log.d( "Feedback", msgA);
384

    
385
android.util.Log.e( "Feedback",msgA.equalsIgnoreCase(msgB) ? "identical":"not identical");
386

    
387
GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER);
388
*/
389

    
390
    /// DEBUG ONLY //////
391
    // displayBoundingRect(halfW, halfH, halfZ, surface, mM.getMVP(), fb, currTime );
392
    /// END DEBUG ///////
393

    
394
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
395
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 1, 0);
396

    
397
    surface.setAsOutput(currTime);
398
    GLES30.glUniform1i(mMainTextureH, 0);
399
    mM.sendZero();
400
    mV.sendZero();
401
    mF.send(halfW,halfH);
402

    
403
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mPosTBO[0]);
404
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
405
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mNorVBO[0]);
406
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, 0);
407
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mTexVBO[0]);
408
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, 0);
409

    
410
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
411
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0 );
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415
   
416
  static void blitPriv(DistortedOutputSurface surface)
417
    {
418
    mBlitProgram.useProgram();
419

    
420
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
421
    GLES30.glUniform1i(mBlitTextureH, 0);
422
    GLES30.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
423
    GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
424
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
425
    }
426
    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
   
429
  private void releasePriv()
430
    {
431
    if( !matrixCloned     ) mM.abortAll(false);
432
    if( !vertexCloned     ) mV.abortAll(false);
433
    if( !fragmentCloned   ) mF.abortAll(false);
434

    
435
    mM = null;
436
    mV = null;
437
    mF = null;
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

    
442
  static void onDestroy()
443
    {
444
    mNextID = 0;
445

    
446
    int len = EffectNames.size();
447

    
448
    for(int i=0; i<len; i++)
449
      {
450
      mEffectEnabled[i] = false;
451
      }
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455
// PUBLIC API
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457
/**
458
 * Create empty effect queue.
459
 */
460
  public DistortedEffects()
461
    {
462
    mID = ++mNextID;
463
    initializeEffectLists(this,0);
464
    }
465

    
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467
/**
468
 * Copy constructor.
469
 * <p>
470
 * Whatever we do not clone gets created just like in the default constructor.
471
 *
472
 * @param dc    Source object to create our object from
473
 * @param flags A bitmask of values specifying what to copy.
474
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
475
 */
476
  public DistortedEffects(DistortedEffects dc, int flags)
477
    {
478
    mID = ++mNextID;
479
    initializeEffectLists(dc,flags);
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483
/**
484
 * Releases all resources. After this call, the queue should not be used anymore.
485
 */
486
  @SuppressWarnings("unused")
487
  public synchronized void delete()
488
    {
489
    releasePriv();
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493
/**
494
 * Returns unique ID of this instance.
495
 *
496
 * @return ID of the object.
497
 */
498
  public long getID()
499
      {
500
      return mID;
501
      }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504
/**
505
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
506
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
507
 * 
508
 * @param el A class implementing the EffectListener interface that wants to get notifications.
509
 */
510
  @SuppressWarnings("unused")
511
  public void registerForMessages(EffectListener el)
512
    {
513
    mV.registerForMessages(el);
514
    mF.registerForMessages(el);
515
    mM.registerForMessages(el);
516
    }
517

    
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519
/**
520
 * Removes the calling class from the list of Listeners.
521
 * 
522
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
523
 */
524
  @SuppressWarnings("unused")
525
  public void deregisterForMessages(EffectListener el)
526
    {
527
    mV.deregisterForMessages(el);
528
    mF.deregisterForMessages(el);
529
    mM.deregisterForMessages(el);
530
    }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
/**
534
 * Aborts all Effects.
535
 * @return Number of effects aborted.
536
 */
537
  public int abortAllEffects()
538
    {
539
    return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
540
    }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543
/**
544
 * Aborts all Effects of a given type, for example all MATRIX Effects.
545
 * 
546
 * @param type one of the constants defined in {@link EffectTypes}
547
 * @return Number of effects aborted.
548
 */
549
  public int abortEffects(EffectTypes type)
550
    {
551
    switch(type)
552
      {
553
      case MATRIX     : return mM.abortAll(true);
554
      case VERTEX     : return mV.abortAll(true);
555
      case FRAGMENT   : return mF.abortAll(true);
556
      default         : return 0;
557
      }
558
    }
559
    
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561
/**
562
 * Aborts a single Effect.
563
 * 
564
 * @param id ID of the Effect we want to abort.
565
 * @return number of Effects aborted. Always either 0 or 1.
566
 */
567
  public int abortEffect(long id)
568
    {
569
    int type = (int)(id&EffectTypes.MASK);
570

    
571
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
572
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
573
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
574

    
575
    return 0;
576
    }
577

    
578
///////////////////////////////////////////////////////////////////////////////////////////////////
579
/**
580
 * Abort all Effects of a given name, for example all rotations.
581
 * 
582
 * @param name one of the constants defined in {@link EffectNames}
583
 * @return number of Effects aborted.
584
 */
585
  public int abortEffects(EffectNames name)
586
    {
587
    switch(name.getType())
588
      {
589
      case MATRIX     : return mM.removeByType(name);
590
      case VERTEX     : return mV.removeByType(name);
591
      case FRAGMENT   : return mF.removeByType(name);
592
      default         : return 0;
593
      }
594
    }
595
    
596
///////////////////////////////////////////////////////////////////////////////////////////////////
597
/**
598
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
599
 * 
600
 * @param id Effect ID we want to print info about
601
 * @return <code>true</code> if a single Effect of type effectType has been found.
602
 */
603
  @SuppressWarnings("unused")
604
  public boolean printEffect(long id)
605
    {
606
    int type = (int)(id&EffectTypes.MASK);
607

    
608
    if( type==EffectTypes.MATRIX.type  )  return mM.printByID(id>>EffectTypes.LENGTH);
609
    if( type==EffectTypes.VERTEX.type  )  return mV.printByID(id>>EffectTypes.LENGTH);
610
    if( type==EffectTypes.FRAGMENT.type)  return mF.printByID(id>>EffectTypes.LENGTH);
611

    
612
    return false;
613
    }
614

    
615
///////////////////////////////////////////////////////////////////////////////////////////////////
616
/**
617
 * Enables a given Effect.
618
 * <p>
619
 * By default, all effects are disabled. One has to explicitly enable each effect one intends to use.
620
 * This needs to be called BEFORE shaders get compiled, i.e. before the call to Distorted.onCreate().
621
 * The point: by enabling only the effects we need, we can optimize the shaders.
622
 *
623
 * @param name Name of the Effect to enable.
624
 */
625
  public static void enableEffect(EffectNames name)
626
    {
627
    mEffectEnabled[name.ordinal()] = true;
628
    }
629

    
630
///////////////////////////////////////////////////////////////////////////////////////////////////
631
/**
632
 * Returns the maximum number of Matrix effects.
633
 *
634
 * @return The maximum number of Matrix effects
635
 */
636
  @SuppressWarnings("unused")
637
  public static int getMaxMatrix()
638
    {
639
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
640
    }
641

    
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643
/**
644
 * Returns the maximum number of Vertex effects.
645
 *
646
 * @return The maximum number of Vertex effects
647
 */
648
  @SuppressWarnings("unused")
649
  public static int getMaxVertex()
650
    {
651
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
652
    }
653

    
654
///////////////////////////////////////////////////////////////////////////////////////////////////
655
/**
656
 * Returns the maximum number of Fragment effects.
657
 *
658
 * @return The maximum number of Fragment effects
659
 */
660
  @SuppressWarnings("unused")
661
  public static int getMaxFragment()
662
    {
663
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
664
    }
665

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

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

    
710
///////////////////////////////////////////////////////////////////////////////////////////////////
711
/**
712
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
713
 * This can fail if:
714
 * <ul>
715
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
716
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
717
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
718
 *     time only decreasing the value of 'max' is permitted.
719
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
720
 * </ul>
721
 *
722
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
723
 *            than Byte.MAX_VALUE
724
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
725
 */
726
  @SuppressWarnings("unused")
727
  public static boolean setMaxFragment(int max)
728
    {
729
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
730
    }
731

    
732
///////////////////////////////////////////////////////////////////////////////////////////////////   
733
///////////////////////////////////////////////////////////////////////////////////////////////////
734
// Individual effect functions.
735
///////////////////////////////////////////////////////////////////////////////////////////////////
736
// Matrix-based effects
737
///////////////////////////////////////////////////////////////////////////////////////////////////
738
/**
739
 * Moves the Object by a (possibly changing in time) vector.
740
 * 
741
 * @param vector 3-dimensional Data which at any given time will return a Static3D
742
 *               representing the current coordinates of the vector we want to move the Object with.
743
 * @return       ID of the effect added, or -1 if we failed to add one.
744
 */
745
  public long move(Data3D vector)
746
    {   
747
    return mM.add(EffectNames.MOVE,vector);
748
    }
749

    
750
///////////////////////////////////////////////////////////////////////////////////////////////////
751
/**
752
 * Scales the Object by (possibly changing in time) 3D scale factors.
753
 * 
754
 * @param scale 3-dimensional Data which at any given time returns a Static3D
755
 *              representing the current x- , y- and z- scale factors.
756
 * @return      ID of the effect added, or -1 if we failed to add one.
757
 */
758
  public long scale(Data3D scale)
759
    {   
760
    return mM.add(EffectNames.SCALE,scale);
761
    }
762

    
763
///////////////////////////////////////////////////////////////////////////////////////////////////
764
/**
765
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
766
 *
767
 * @param scale The factor to scale all 3 dimensions with.
768
 * @return      ID of the effect added, or -1 if we failed to add one.
769
 */
770
  public long scale(float scale)
771
    {
772
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
773
    }
774

    
775
///////////////////////////////////////////////////////////////////////////////////////////////////
776
/**
777
 * Rotates the Object by 'angle' degrees around the center.
778
 * Static axis of rotation is given by the last parameter.
779
 *
780
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
781
 * @param axis   Axis of rotation
782
 * @param center Coordinates of the Point we are rotating around.
783
 * @return       ID of the effect added, or -1 if we failed to add one.
784
 */
785
  public long rotate(Data1D angle, Static3D axis, Data3D center )
786
    {   
787
    return mM.add(EffectNames.ROTATE, angle, axis, center);
788
    }
789

    
790
///////////////////////////////////////////////////////////////////////////////////////////////////
791
/**
792
 * Rotates the Object by 'angle' degrees around the center.
793
 * Here both angle and axis can dynamically change.
794
 *
795
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
796
 * @param center    Coordinates of the Point we are rotating around.
797
 * @return          ID of the effect added, or -1 if we failed to add one.
798
 */
799
  public long rotate(Data4D angleaxis, Data3D center)
800
    {
801
    return mM.add(EffectNames.ROTATE, angleaxis, center);
802
    }
803

    
804
///////////////////////////////////////////////////////////////////////////////////////////////////
805
/**
806
 * Rotates the Object by quaternion.
807
 *
808
 * @param quaternion The quaternion describing the rotation.
809
 * @param center     Coordinates of the Point we are rotating around.
810
 * @return           ID of the effect added, or -1 if we failed to add one.
811
 */
812
  public long quaternion(Data4D quaternion, Data3D center )
813
    {
814
    return mM.add(EffectNames.QUATERNION,quaternion,center);
815
    }
816

    
817
///////////////////////////////////////////////////////////////////////////////////////////////////
818
/**
819
 * Shears the Object.
820
 *
821
 * @param shear   The 3-tuple of shear factors. The first controls level
822
 *                of shearing in the X-axis, second - Y-axis and the third -
823
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
824
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
825
 * @param center  Center of shearing, i.e. the point which stays unmoved.
826
 * @return        ID of the effect added, or -1 if we failed to add one.
827
 */
828
  public long shear(Data3D shear, Data3D center)
829
    {
830
    return mM.add(EffectNames.SHEAR, shear, center);
831
    }
832

    
833
///////////////////////////////////////////////////////////////////////////////////////////////////
834
// Fragment-based effects  
835
///////////////////////////////////////////////////////////////////////////////////////////////////
836
/**
837
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
838
 *        
839
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
840
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
841
 *               Valid range: <0,1>
842
 * @param color  Color to mix. (1,0,0) is RED.
843
 * @param region Region this Effect is limited to.
844
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
845
 * @return       ID of the effect added, or -1 if we failed to add one.
846
 */
847
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
848
    {
849
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
850
    }
851

    
852
///////////////////////////////////////////////////////////////////////////////////////////////////
853
/**
854
 * Makes the whole Object smoothly change all three of its RGB components.
855
 *
856
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
857
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
858
 *               Valid range: <0,1>
859
 * @param color  Color to mix. (1,0,0) is RED.
860
 * @return       ID of the effect added, or -1 if we failed to add one.
861
 */
862
  public long chroma(Data1D blend, Data3D color)
863
    {
864
    return mF.add(EffectNames.CHROMA, blend, color);
865
    }
866

    
867
///////////////////////////////////////////////////////////////////////////////////////////////////
868
/**
869
 * Makes a certain sub-region of the Object smoothly change its transparency level.
870
 *        
871
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
872
 *               moment: pixel.a *= alpha.
873
 *               Valid range: <0,1>
874
 * @param region Region this Effect is limited to. 
875
 * @param smooth If true, the level of 'alpha' 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 alpha(Data1D alpha, Data4D region, boolean smooth)
879
    {
880
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
881
    }
882

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

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

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

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

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

    
953
///////////////////////////////////////////////////////////////////////////////////////////////////
954
/**
955
 * Makes a certain sub-region of the Object smoothly change its saturation level.
956
 *        
957
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
958
 *                   at any given moment. Valid range: <0,infinity)
959
 * @param region     Region this Effect is limited to.
960
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
961
 * @return           ID of the effect added, or -1 if we failed to add one.
962
 */
963
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
964
    {
965
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
966
    }
967

    
968
///////////////////////////////////////////////////////////////////////////////////////////////////
969
/**
970
 * Makes the whole Object smoothly change its saturation level.
971
 *
972
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
973
 *                   at any given moment. Valid range: <0,infinity)
974
 * @return           ID of the effect added, or -1 if we failed to add one.
975
 */
976
  public long saturation(Data1D saturation)
977
    {
978
    return mF.add(EffectNames.SATURATION, saturation);
979
    }
980

    
981
///////////////////////////////////////////////////////////////////////////////////////////////////
982
// Vertex-based effects  
983
///////////////////////////////////////////////////////////////////////////////////////////////////
984
/**
985
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
986
 *
987
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
988
 *               currently being dragged with.
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 distort(Data3D vector, Data3D center, Data4D region)
994
    {  
995
    return mV.add(EffectNames.DISTORT, vector, center, region);
996
    }
997

    
998
///////////////////////////////////////////////////////////////////////////////////////////////////
999
/**
1000
 * Distort the whole Object by a (possibly changing in time) vector of force.
1001
 *
1002
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
1003
 *               currently being dragged with.
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 distort(Data3D vector, Data3D center)
1008
    {
1009
    return mV.add(EffectNames.DISTORT, vector, center, null);
1010
    }
1011

    
1012
///////////////////////////////////////////////////////////////////////////////////////////////////
1013
/**
1014
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
1015
 * a (possibly changing in time) point on the Object.
1016
 *
1017
 * @param vector Vector of force that deforms the shape of the whole Object.
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 deform(Data3D vector, Data3D center, Data4D region)
1023
    {
1024
    return mV.add(EffectNames.DEFORM, vector, center, region);
1025
    }
1026

    
1027
///////////////////////////////////////////////////////////////////////////////////////////////////
1028
/**
1029
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
1030
 * a (possibly changing in time) point on the Object.
1031
 *     
1032
 * @param vector Vector of force that deforms the shape of the whole Object.
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 deform(Data3D vector, Data3D center)
1037
    {  
1038
    return mV.add(EffectNames.DEFORM, vector, center, null);
1039
    }
1040

    
1041
///////////////////////////////////////////////////////////////////////////////////////////////////  
1042
/**
1043
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
1044
 * away from the center (degree<=1)
1045
 *
1046
 * @param sink   The current degree of the Effect.
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 sink(Data1D sink, Data3D center, Data4D region)
1052
    {
1053
    return mV.add(EffectNames.SINK, sink, center, region);
1054
    }
1055

    
1056
///////////////////////////////////////////////////////////////////////////////////////////////////
1057
/**
1058
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
1059
 * away from the center (degree<=1)
1060
 *
1061
 * @param sink   The current degree of the Effect.
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 sink(Data1D sink, Data3D center)
1066
    {
1067
    return mV.add(EffectNames.SINK, sink, center);
1068
    }
1069

    
1070
///////////////////////////////////////////////////////////////////////////////////////////////////
1071
/**
1072
 * Pull all points around the center of the Effect towards a line passing through the center
1073
 * (that's if degree>=1) or push them away from the line (degree<=1)
1074
 *
1075
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1076
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1077
 * @param region Region that masks the Effect.
1078
 * @return       ID of the effect added, or -1 if we failed to add one.
1079
 */
1080
  public long pinch(Data2D pinch, Data3D center, Data4D region)
1081
    {
1082
    return mV.add(EffectNames.PINCH, pinch, center, region);
1083
    }
1084

    
1085
///////////////////////////////////////////////////////////////////////////////////////////////////
1086
/**
1087
 * Pull all points around the center of the Effect towards a line passing through the center
1088
 * (that's if degree>=1) or push them away from the line (degree<=1)
1089
 *
1090
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1091
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1092
 * @return       ID of the effect added, or -1 if we failed to add one.
1093
 */
1094
  public long pinch(Data2D pinch, Data3D center)
1095
    {
1096
    return mV.add(EffectNames.PINCH, pinch, center);
1097
    }
1098

    
1099
///////////////////////////////////////////////////////////////////////////////////////////////////  
1100
/**
1101
 * Rotate part of the Object around the Center of the Effect by a certain angle.
1102
 *
1103
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1104
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1105
 * @param region Region that masks the Effect.
1106
 * @return       ID of the effect added, or -1 if we failed to add one.
1107
 */
1108
  public long swirl(Data1D swirl, Data3D center, Data4D region)
1109
    {    
1110
    return mV.add(EffectNames.SWIRL, swirl, center, region);
1111
    }
1112

    
1113
///////////////////////////////////////////////////////////////////////////////////////////////////
1114
/**
1115
 * Rotate the whole Object around the Center of the Effect by a certain angle.
1116
 *
1117
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1118
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1119
 * @return       ID of the effect added, or -1 if we failed to add one.
1120
 */
1121
  public long swirl(Data1D swirl, Data3D center)
1122
    {
1123
    return mV.add(EffectNames.SWIRL, swirl, center);
1124
    }
1125

    
1126
///////////////////////////////////////////////////////////////////////////////////////////////////
1127
/**
1128
 * Directional, sinusoidal wave effect.
1129
 *
1130
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
1131
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
1132
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
1133
 *               describe the 'direction' of the wave.
1134
 *               <p>
1135
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
1136
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
1137
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
1138
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
1139
 *               <p>
1140
 *               <p>
1141
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
1142
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
1143
 *               will be sine shapes.
1144
 *               <p>
1145
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
1146
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
1147
 *               YZ-plane with be sine shapes.
1148
 *               <p>
1149
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
1150
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
1151
 *               value if sin at this point.
1152
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1153
 * @return       ID of the effect added, or -1 if we failed to add one.
1154
 */
1155
  public long wave(Data5D wave, Data3D center)
1156
    {
1157
    return mV.add(EffectNames.WAVE, wave, center, null);
1158
    }
1159

    
1160
///////////////////////////////////////////////////////////////////////////////////////////////////
1161
/**
1162
 * Directional, sinusoidal wave effect.
1163
 *
1164
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
1165
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1166
 * @param region Region that masks the Effect.
1167
 * @return       ID of the effect added, or -1 if we failed to add one.
1168
 */
1169
  public long wave(Data5D wave, Data3D center, Data4D region)
1170
    {
1171
    return mV.add(EffectNames.WAVE, wave, center, region);
1172
    }
1173
  }
(2-2/26)