Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 86eb00a9

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 6a06a912 Leszek Koltunski
package org.distorted.library;
21
22
import android.opengl.GLES20;
23
24 e458a4ba Leszek Koltunski
import org.distorted.library.message.EffectListener;
25 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data1D;
26 f2fe7e28 Leszek Koltunski
import org.distorted.library.type.Data2D;
27 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data3D;
28
import org.distorted.library.type.Data4D;
29 350cc2f5 Leszek Koltunski
import org.distorted.library.type.Data5D;
30 568b29d8 Leszek Koltunski
import org.distorted.library.type.Static3D;
31 a4835695 Leszek Koltunski
32 c638c1b0 Leszek Koltunski
import java.nio.ByteBuffer;
33
import java.nio.ByteOrder;
34
import java.nio.FloatBuffer;
35
36 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
37 b329f352 Leszek Koltunski
/**
38 4e2382f3 Leszek Koltunski
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
39 b73dcaa7 Leszek Koltunski
 * <p>
40 26df012c Leszek Koltunski
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
41 b329f352 Leszek Koltunski
 */
42 421c2728 Leszek Koltunski
public class DistortedEffects
43 d425545a Leszek Koltunski
  {
44 c638c1b0 Leszek Koltunski
  private static final int BYTES_PER_FLOAT   = 4; //
45
  private static final int POSITION_DATA_SIZE= 2; // Size of the position data in elements
46
  private static final int TEX_DATA_SIZE     = 2; // Size of the texture coordinate data in elements.
47
  private static final FloatBuffer mQuadPositions, mQuadTexture;
48
49 8e34674e Leszek Koltunski
  private static long mNextID =0;
50 4e2382f3 Leszek Koltunski
  private long mID;
51 8e34674e Leszek Koltunski
52 86eb00a9 Leszek Koltunski
  private static DistortedFramebuffer mBufferFBO;
53
54 d6e94c84 Leszek Koltunski
  private EffectQueueMatrix      mM;
55
  private EffectQueueFragment    mF;
56
  private EffectQueueVertex      mV;
57
  private EffectQueuePostprocess mP;
58 3d590d8d Leszek Koltunski
59 d6e94c84 Leszek Koltunski
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
60 985ea9c5 Leszek Koltunski
61 c638c1b0 Leszek Koltunski
  static
62
    {
63
    int dataLength = 4;
64
65
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
66
    float[] textureData = {  0.0f,  0.0f,   0.0f, 1.0f,  1.0f, 0.0f,  1.0f, 1.0f };
67
68
    mQuadPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
69
    mQuadPositions.put(positionData).position(0);
70
    mQuadTexture   = ByteBuffer.allocateDirect(TEX_DATA_SIZE     *dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
71
    mQuadTexture.put(textureData).position(0);
72 86eb00a9 Leszek Koltunski
73
    mBufferFBO = new DistortedFramebuffer(1,1);
74 c638c1b0 Leszek Koltunski
    }
75
76 9361b337 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
77 6a06a912 Leszek Koltunski
    
78 421c2728 Leszek Koltunski
  private void initializeEffectLists(DistortedEffects d, int flags)
79 d425545a Leszek Koltunski
    {
80 015642fb Leszek Koltunski
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
81 6a06a912 Leszek Koltunski
      {
82 d425545a Leszek Koltunski
      mM = d.mM;
83
      matrixCloned = true;
84
      }
85
    else
86
      {
87 4e2382f3 Leszek Koltunski
      mM = new EffectQueueMatrix(mID);
88 d425545a Leszek Koltunski
      matrixCloned = false;
89
      }
90 6a06a912 Leszek Koltunski
    
91 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
92
      {
93
      mV = d.mV;
94
      vertexCloned = true;
95
      }
96
    else
97
      {
98 4e2382f3 Leszek Koltunski
      mV = new EffectQueueVertex(mID);
99 d425545a Leszek Koltunski
      vertexCloned = false;
100
      }
101 6a06a912 Leszek Koltunski
    
102 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
103
      {
104
      mF = d.mF;
105
      fragmentCloned = true;
106 6a06a912 Leszek Koltunski
      }
107 d425545a Leszek Koltunski
    else
108
      {
109 4e2382f3 Leszek Koltunski
      mF = new EffectQueueFragment(mID);
110 d425545a Leszek Koltunski
      fragmentCloned = false;
111
      }
112 d6e94c84 Leszek Koltunski
113
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
114
      {
115
      mP = d.mP;
116
      postprocessCloned = true;
117
      }
118
    else
119
      {
120
      mP = new EffectQueuePostprocess(mID);
121
      postprocessCloned = false;
122
      }
123 d425545a Leszek Koltunski
    }
124 6a06a912 Leszek Koltunski
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
   
127 05403bba Leszek Koltunski
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
128 d425545a Leszek Koltunski
    {
129
    mM.compute(currTime);
130
    mV.compute(currTime);
131
    mF.compute(currTime);
132 d6e94c84 Leszek Koltunski
    mP.compute(currTime);
133 a56bc359 Leszek Koltunski
134 d6e94c84 Leszek Koltunski
    float halfZ = halfInputW*mesh.zFactor;
135
136
    GLES20.glUseProgram(Distorted.mainProgramH);
137 86eb00a9 Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
138 d6e94c84 Leszek Koltunski
139
    if( mP.mNumEffects==0 )
140
      {
141
      mM.send(df,halfInputW,halfInputH,halfZ);
142
      mV.send(halfInputW,halfInputH,halfZ);
143
      mF.send(halfInputW,halfInputH);
144
145
      mesh.draw();
146
      }
147
    else
148
      {
149 86eb00a9 Leszek Koltunski
      mBufferFBO.resizeFast(df.mWidth, df.mHeight);
150
      mBufferFBO.setAsOutput();
151 d6e94c84 Leszek Koltunski
152 86eb00a9 Leszek Koltunski
      mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
153 d6e94c84 Leszek Koltunski
      mV.send(halfInputW,halfInputH,halfZ);
154
      mF.send(halfInputW,halfInputH);
155
156
      mesh.draw();
157
158
      GLES20.glUseProgram(Distorted.postProgramH);
159 c638c1b0 Leszek Koltunski
      GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
160 86eb00a9 Leszek Koltunski
      mBufferFBO.setAsInput();
161 c638c1b0 Leszek Koltunski
      df.setAsOutput();
162
      mP.send(halfInputW,halfInputH);
163 d6e94c84 Leszek Koltunski
164 c638c1b0 Leszek Koltunski
      GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
165
      GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mQuadTexture);
166
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
167 d6e94c84 Leszek Koltunski
      }
168 d425545a Leszek Koltunski
    }
169 6a06a912 Leszek Koltunski
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
   
172 d6e94c84 Leszek Koltunski
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
173 d425545a Leszek Koltunski
    {
174 ed13a5de Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
175 0a046359 Leszek Koltunski
176 d6e94c84 Leszek Koltunski
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
177
    EffectQueueVertex.sendZero();
178
    EffectQueueFragment.sendZero();
179
    EffectQueuePostprocess.sendZero(2*halfInputW,2*halfInputH);
180 a56bc359 Leszek Koltunski
181 05403bba Leszek Koltunski
    mesh.draw();
182 d425545a Leszek Koltunski
    }
183 6a06a912 Leszek Koltunski
    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185
   
186 8e34674e Leszek Koltunski
  private void releasePriv()
187 d425545a Leszek Koltunski
    {
188 d6e94c84 Leszek Koltunski
    if( !matrixCloned     ) mM.abortAll(false);
189
    if( !vertexCloned     ) mV.abortAll(false);
190
    if( !fragmentCloned   ) mF.abortAll(false);
191
    if( !postprocessCloned) mP.abortAll(false);
192 d425545a Leszek Koltunski
193 4e2382f3 Leszek Koltunski
    mM = null;
194
    mV = null;
195
    mF = null;
196 d6e94c84 Leszek Koltunski
    mP = null;
197 8e34674e Leszek Koltunski
    }
198
199 1942537e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
200
201 7b8086eb Leszek Koltunski
  static void onDestroy()
202 1942537e Leszek Koltunski
    {
203
    mNextID = 0;
204
    }
205
206 8e34674e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
207
// PUBLIC API
208 ada90d33 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
209 d425545a Leszek Koltunski
/**
210 4e2382f3 Leszek Koltunski
 * Create empty effect queue.
211 d425545a Leszek Koltunski
 */
212 421c2728 Leszek Koltunski
  public DistortedEffects()
213 d425545a Leszek Koltunski
    {
214 4e2382f3 Leszek Koltunski
    mID = mNextID++;
215
    initializeEffectLists(this,0);
216 d425545a Leszek Koltunski
    }
217 ada90d33 Leszek Koltunski
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219 d425545a Leszek Koltunski
/**
220 4e2382f3 Leszek Koltunski
 * Copy constructor.
221 d425545a Leszek Koltunski
 * <p>
222
 * Whatever we do not clone gets created just like in the default constructor.
223
 *
224
 * @param dc    Source object to create our object from
225
 * @param flags A bitmask of values specifying what to copy.
226 e6ab30eb Leszek Koltunski
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
227 d425545a Leszek Koltunski
 */
228 421c2728 Leszek Koltunski
  public DistortedEffects(DistortedEffects dc, int flags)
229 d425545a Leszek Koltunski
    {
230 8e34674e Leszek Koltunski
    mID = mNextID++;
231 4e2382f3 Leszek Koltunski
    initializeEffectLists(dc,flags);
232 d425545a Leszek Koltunski
    }
233 ada90d33 Leszek Koltunski
234 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
235
/**
236 07305c87 Leszek Koltunski
 * Releases all resources. After this call, the queue should not be used anymore.
237 6a06a912 Leszek Koltunski
 */
238 8e34674e Leszek Koltunski
  public synchronized void delete()
239 d425545a Leszek Koltunski
    {
240
    releasePriv();
241
    }
242 6a06a912 Leszek Koltunski
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
/**
245 4e2382f3 Leszek Koltunski
 * Returns unique ID of this instance.
246
 *
247
 * @return ID of the object.
248 6a06a912 Leszek Koltunski
 */
249 4e2382f3 Leszek Koltunski
  public long getID()
250 d425545a Leszek Koltunski
      {
251 4e2382f3 Leszek Koltunski
      return mID;
252 d425545a Leszek Koltunski
      }
253 4e2382f3 Leszek Koltunski
254 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
255
/**
256
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
257 07305c87 Leszek Koltunski
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
258 6a06a912 Leszek Koltunski
 * 
259
 * @param el A class implementing the EffectListener interface that wants to get notifications.
260
 */
261 3fc994b2 Leszek Koltunski
  public void registerForMessages(EffectListener el)
262 d425545a Leszek Koltunski
    {
263 3fc994b2 Leszek Koltunski
    mV.registerForMessages(el);
264
    mF.registerForMessages(el);
265
    mM.registerForMessages(el);
266 d6e94c84 Leszek Koltunski
    mP.registerForMessages(el);
267 d425545a Leszek Koltunski
    }
268 6a06a912 Leszek Koltunski
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
/**
271
 * Removes the calling class from the list of Listeners.
272
 * 
273
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
274
 */
275 3fc994b2 Leszek Koltunski
  public void deregisterForMessages(EffectListener el)
276 d425545a Leszek Koltunski
    {
277 3fc994b2 Leszek Koltunski
    mV.deregisterForMessages(el);
278
    mF.deregisterForMessages(el);
279
    mM.deregisterForMessages(el);
280 d6e94c84 Leszek Koltunski
    mP.deregisterForMessages(el);
281 d425545a Leszek Koltunski
    }
282 6a06a912 Leszek Koltunski
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284
/**
285 d07f2950 Leszek Koltunski
 * Aborts all Effects.
286
 * @return Number of effects aborted.
287 6a06a912 Leszek Koltunski
 */
288 d425545a Leszek Koltunski
  public int abortAllEffects()
289 6a06a912 Leszek Koltunski
      {
290 d6e94c84 Leszek Koltunski
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
291 6a06a912 Leszek Koltunski
      }
292
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294
/**
295 d07f2950 Leszek Koltunski
 * Aborts all Effects of a given type, for example all MATRIX Effects.
296 6a06a912 Leszek Koltunski
 * 
297 d07f2950 Leszek Koltunski
 * @param type one of the constants defined in {@link EffectTypes}
298
 * @return Number of effects aborted.
299 6a06a912 Leszek Koltunski
 */
300 d425545a Leszek Koltunski
  public int abortEffects(EffectTypes type)
301
    {
302
    switch(type)
303 6a06a912 Leszek Koltunski
      {
304 d6e94c84 Leszek Koltunski
      case MATRIX     : return mM.abortAll(true);
305
      case VERTEX     : return mV.abortAll(true);
306
      case FRAGMENT   : return mF.abortAll(true);
307
      case POSTPROCESS: return mP.abortAll(true);
308
      default         : return 0;
309 6a06a912 Leszek Koltunski
      }
310 d425545a Leszek Koltunski
    }
311 6a06a912 Leszek Koltunski
    
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313
/**
314
 * Aborts a single Effect.
315
 * 
316
 * @param id ID of the Effect we want to abort.
317 476bbc81 Leszek Koltunski
 * @return number of Effects aborted. Always either 0 or 1.
318 6a06a912 Leszek Koltunski
 */
319 d425545a Leszek Koltunski
  public int abortEffect(long id)
320
    {
321
    int type = (int)(id&EffectTypes.MASK);
322 1e438fc7 Leszek Koltunski
323 d6e94c84 Leszek Koltunski
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
324
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
325
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
326
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
327 1e438fc7 Leszek Koltunski
328 d425545a Leszek Koltunski
    return 0;
329
    }
330 6a06a912 Leszek Koltunski
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332
/**
333 e8c81a8e Leszek Koltunski
 * Abort all Effects of a given name, for example all rotations.
334 6a06a912 Leszek Koltunski
 * 
335 d07f2950 Leszek Koltunski
 * @param name one of the constants defined in {@link EffectNames}
336 476bbc81 Leszek Koltunski
 * @return number of Effects aborted.
337 6a06a912 Leszek Koltunski
 */
338 d425545a Leszek Koltunski
  public int abortEffects(EffectNames name)
339
    {
340
    switch(name.getType())
341 6a06a912 Leszek Koltunski
      {
342 d6e94c84 Leszek Koltunski
      case MATRIX     : return mM.removeByType(name);
343
      case VERTEX     : return mV.removeByType(name);
344
      case FRAGMENT   : return mF.removeByType(name);
345
      case POSTPROCESS: return mP.removeByType(name);
346
      default         : return 0;
347 6a06a912 Leszek Koltunski
      }
348 d425545a Leszek Koltunski
    }
349 6a06a912 Leszek Koltunski
    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351
/**
352
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
353
 * 
354
 * @param id Effect ID we want to print info about
355
 * @return <code>true</code> if a single Effect of type effectType has been found.
356
 */
357
    
358 d425545a Leszek Koltunski
  public boolean printEffect(long id)
359
    {
360
    int type = (int)(id&EffectTypes.MASK);
361 1e438fc7 Leszek Koltunski
362 d6e94c84 Leszek Koltunski
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
363
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
364
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
365
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
366 1e438fc7 Leszek Koltunski
367 d425545a Leszek Koltunski
    return false;
368
    }
369 432442f9 Leszek Koltunski
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371
/**
372
 * Returns the maximum number of Matrix effects.
373
 *
374
 * @return The maximum number of Matrix effects
375
 */
376
  public static int getMaxMatrix()
377
    {
378
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
379
    }
380
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382
/**
383
 * Returns the maximum number of Vertex effects.
384
 *
385
 * @return The maximum number of Vertex effects
386
 */
387
  public static int getMaxVertex()
388
    {
389
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
390
    }
391
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393
/**
394
 * Returns the maximum number of Fragment effects.
395
 *
396
 * @return The maximum number of Fragment effects
397
 */
398
  public static int getMaxFragment()
399
    {
400
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
401
    }
402
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404
/**
405
 * Returns the maximum number of Postprocess effects.
406
 *
407
 * @return The maximum number of Postprocess effects
408
 */
409
  public static int getMaxPostprocess()
410
    {
411
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
412
    }
413
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415
/**
416
 * Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
417
 * This can fail if:
418
 * <ul>
419
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
420
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
421
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
422
 *     time only decreasing the value of 'max' is permitted.
423
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
424
 * </ul>
425
 *
426
 * @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
427
 *            than Byte.MAX_VALUE
428
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
429
 */
430
  public static boolean setMaxMatrix(int max)
431
    {
432
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
433
    }
434
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436
/**
437
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
438
 * This can fail if:
439
 * <ul>
440
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
441
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
442
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
443
 *     time only decreasing the value of 'max' is permitted.
444
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
445
 * </ul>
446
 *
447
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
448
 *            than Byte.MAX_VALUE
449
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
450
 */
451
  public static boolean setMaxVertex(int max)
452
    {
453
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
454
    }
455
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457
/**
458
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
459
 * This can fail if:
460
 * <ul>
461
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
462
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
463
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
464
 *     time only decreasing the value of 'max' is permitted.
465
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
466
 * </ul>
467
 *
468
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
469
 *            than Byte.MAX_VALUE
470
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
471
 */
472
  public static boolean setMaxFragment(int max)
473
    {
474
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
475
    }
476
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478
/**
479
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
480
 * This can fail if:
481
 * <ul>
482
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
483
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
484
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
485
 *     time only decreasing the value of 'max' is permitted.
486
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
487
 * </ul>
488
 *
489
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
490
 *            than Byte.MAX_VALUE
491
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
492
 */
493
  public static boolean setMaxPostprocess(int max)
494
    {
495
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
496
    }
497
498 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////   
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500
// Individual effect functions.
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502
// Matrix-based effects
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504
/**
505 e8c81a8e Leszek Koltunski
 * Moves the Object by a (possibly changing in time) vector.
506 6a06a912 Leszek Koltunski
 * 
507 568b29d8 Leszek Koltunski
 * @param vector 3-dimensional Data which at any given time will return a Static3D
508 e0a16874 Leszek Koltunski
 *               representing the current coordinates of the vector we want to move the Object with.
509
 * @return       ID of the effect added, or -1 if we failed to add one.
510 6a06a912 Leszek Koltunski
 */
511 568b29d8 Leszek Koltunski
  public long move(Data3D vector)
512 6a06a912 Leszek Koltunski
    {   
513 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.MOVE,vector);
514 6a06a912 Leszek Koltunski
    }
515
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
/**
518 e8c81a8e Leszek Koltunski
 * Scales the Object by (possibly changing in time) 3D scale factors.
519 6a06a912 Leszek Koltunski
 * 
520 d1e740c5 Leszek Koltunski
 * @param scale 3-dimensional Data which at any given time returns a Static3D
521 e0a16874 Leszek Koltunski
 *              representing the current x- , y- and z- scale factors.
522
 * @return      ID of the effect added, or -1 if we failed to add one.
523 6a06a912 Leszek Koltunski
 */
524 568b29d8 Leszek Koltunski
  public long scale(Data3D scale)
525 6a06a912 Leszek Koltunski
    {   
526 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.SCALE,scale);
527 6a06a912 Leszek Koltunski
    }
528
529 2fce34f4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
530
/**
531 e8c81a8e Leszek Koltunski
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
532 2fce34f4 Leszek Koltunski
 *
533
 * @param scale The factor to scale all 3 dimensions with.
534
 * @return      ID of the effect added, or -1 if we failed to add one.
535
 */
536 d425545a Leszek Koltunski
  public long scale(float scale)
537
    {
538
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
539
    }
540 2fce34f4 Leszek Koltunski
541 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
542
/**
543 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
544
 * Static axis of rotation is given by the last parameter.
545
 *
546 9351ad55 Leszek Koltunski
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
547 568b29d8 Leszek Koltunski
 * @param axis   Axis of rotation
548 0df17fad Leszek Koltunski
 * @param center Coordinates of the Point we are rotating around.
549 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
550
 */
551 0df17fad Leszek Koltunski
  public long rotate(Data1D angle, Static3D axis, Data3D center )
552 6a06a912 Leszek Koltunski
    {   
553 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angle, axis, center);
554 6a06a912 Leszek Koltunski
    }
555
556
///////////////////////////////////////////////////////////////////////////////////////////////////
557
/**
558 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
559 2fce34f4 Leszek Koltunski
 * Here both angle and axis can dynamically change.
560 568b29d8 Leszek Koltunski
 *
561
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
562 0df17fad Leszek Koltunski
 * @param center    Coordinates of the Point we are rotating around.
563 568b29d8 Leszek Koltunski
 * @return          ID of the effect added, or -1 if we failed to add one.
564 e0a16874 Leszek Koltunski
 */
565 0df17fad Leszek Koltunski
  public long rotate(Data4D angleaxis, Data3D center)
566 568b29d8 Leszek Koltunski
    {
567 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angleaxis, center);
568 6a06a912 Leszek Koltunski
    }
569
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571
/**
572 568b29d8 Leszek Koltunski
 * Rotates the Object by quaternion.
573 0df17fad Leszek Koltunski
 *
574 568b29d8 Leszek Koltunski
 * @param quaternion The quaternion describing the rotation.
575 0df17fad Leszek Koltunski
 * @param center     Coordinates of the Point we are rotating around.
576 568b29d8 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
577 6a06a912 Leszek Koltunski
 */
578 0df17fad Leszek Koltunski
  public long quaternion(Data4D quaternion, Data3D center )
579 568b29d8 Leszek Koltunski
    {
580 0df17fad Leszek Koltunski
    return mM.add(EffectNames.QUATERNION,quaternion,center);
581 6a06a912 Leszek Koltunski
    }
582
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584
/**
585 568b29d8 Leszek Koltunski
 * Shears the Object.
586 6a06a912 Leszek Koltunski
 *
587 8c3cdec5 Leszek Koltunski
 * @param shear   The 3-tuple of shear factors. The first controls level
588
 *                of shearing in the X-axis, second - Y-axis and the third -
589
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
590
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
591 0df17fad Leszek Koltunski
 * @param center  Center of shearing, i.e. the point which stays unmoved.
592 e0a16874 Leszek Koltunski
 * @return        ID of the effect added, or -1 if we failed to add one.
593 6a06a912 Leszek Koltunski
 */
594 0df17fad Leszek Koltunski
  public long shear(Data3D shear, Data3D center)
595 6a06a912 Leszek Koltunski
    {
596 0df17fad Leszek Koltunski
    return mM.add(EffectNames.SHEAR, shear, center);
597 6a06a912 Leszek Koltunski
    }
598
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600
// Fragment-based effects  
601
///////////////////////////////////////////////////////////////////////////////////////////////////
602
/**
603 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
604 6a06a912 Leszek Koltunski
 *        
605 2fce34f4 Leszek Koltunski
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
606 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
607
 *               Valid range: <0,1>
608 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
609 2fce34f4 Leszek Koltunski
 * @param region Region this Effect is limited to.
610
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
611
 * @return       ID of the effect added, or -1 if we failed to add one.
612 6a06a912 Leszek Koltunski
 */
613 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
614 6a06a912 Leszek Koltunski
    {
615 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
616 6a06a912 Leszek Koltunski
    }
617
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619
/**
620 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change all three of its RGB components.
621
 *
622
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
623 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
624
 *               Valid range: <0,1>
625 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
626 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
627 6a06a912 Leszek Koltunski
 */
628 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color)
629 6a06a912 Leszek Koltunski
    {
630 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CHROMA, blend, color);
631 6a06a912 Leszek Koltunski
    }
632
633
///////////////////////////////////////////////////////////////////////////////////////////////////
634
/**
635 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its transparency level.
636 6a06a912 Leszek Koltunski
 *        
637 2fce34f4 Leszek Koltunski
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
638 e4878781 Leszek Koltunski
 *               moment: pixel.a *= alpha.
639
 *               Valid range: <0,1>
640 d7bbef2f Leszek Koltunski
 * @param region Region this Effect is limited to. 
641 2fce34f4 Leszek Koltunski
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
642 d7bbef2f Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one. 
643 6a06a912 Leszek Koltunski
 */
644 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
645 6a06a912 Leszek Koltunski
    {
646 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
647 6a06a912 Leszek Koltunski
    }
648
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650
/**
651 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its transparency level.
652
 *
653
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
654 e4878781 Leszek Koltunski
 *               given moment: pixel.a *= alpha.
655
 *               Valid range: <0,1>
656 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
657 6a06a912 Leszek Koltunski
 */
658 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha)
659 6a06a912 Leszek Koltunski
    {
660 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.ALPHA, alpha);
661 6a06a912 Leszek Koltunski
    }
662
663
///////////////////////////////////////////////////////////////////////////////////////////////////
664
/**
665 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its brightness level.
666 6a06a912 Leszek Koltunski
 *        
667 2fce34f4 Leszek Koltunski
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
668 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
669 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
670 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
671 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
672 6a06a912 Leszek Koltunski
 */
673 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
674 6a06a912 Leszek Koltunski
    {
675 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
676 6a06a912 Leszek Koltunski
    }
677
678
///////////////////////////////////////////////////////////////////////////////////////////////////
679
/**
680 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its brightness level.
681
 *
682
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
683 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
684 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
685 6a06a912 Leszek Koltunski
 */
686 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness)
687 6a06a912 Leszek Koltunski
    {
688 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.BRIGHTNESS, brightness);
689 6a06a912 Leszek Koltunski
    }
690
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692
/**
693 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its contrast level.
694 6a06a912 Leszek Koltunski
 *        
695 2fce34f4 Leszek Koltunski
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
696 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
697 e0a16874 Leszek Koltunski
 * @param region   Region this Effect is limited to.
698 2fce34f4 Leszek Koltunski
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
699 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
700 6a06a912 Leszek Koltunski
 */
701 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
702 6a06a912 Leszek Koltunski
    {
703 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
704 6a06a912 Leszek Koltunski
    }
705
706
///////////////////////////////////////////////////////////////////////////////////////////////////
707
/**
708 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its contrast level.
709
 *
710
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
711 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
712 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
713 6a06a912 Leszek Koltunski
 */
714 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast)
715 6a06a912 Leszek Koltunski
    {
716 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CONTRAST, contrast);
717 6a06a912 Leszek Koltunski
    }
718
719
///////////////////////////////////////////////////////////////////////////////////////////////////
720
/**
721 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its saturation level.
722 6a06a912 Leszek Koltunski
 *        
723 2fce34f4 Leszek Koltunski
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
724 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
725 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
726 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
727 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
728 6a06a912 Leszek Koltunski
 */
729 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
730 6a06a912 Leszek Koltunski
    {
731 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
732 6a06a912 Leszek Koltunski
    }
733
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735
/**
736 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its saturation level.
737
 *
738
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
739 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
740 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
741 6a06a912 Leszek Koltunski
 */
742 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation)
743 6a06a912 Leszek Koltunski
    {
744 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.SATURATION, saturation);
745 6a06a912 Leszek Koltunski
    }
746
747
///////////////////////////////////////////////////////////////////////////////////////////////////
748
// Vertex-based effects  
749
///////////////////////////////////////////////////////////////////////////////////////////////////
750
/**
751 e0a16874 Leszek Koltunski
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
752 f2fe7e28 Leszek Koltunski
 *
753
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
754
 *               currently being dragged with.
755 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
756 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
757
 * @return       ID of the effect added, or -1 if we failed to add one.
758 6a06a912 Leszek Koltunski
 */
759 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center, Data4D region)
760 6a06a912 Leszek Koltunski
    {  
761 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, region);
762 6a06a912 Leszek Koltunski
    }
763
764
///////////////////////////////////////////////////////////////////////////////////////////////////
765
/**
766 e0a16874 Leszek Koltunski
 * Distort the whole Object by a (possibly changing in time) vector of force.
767 f2fe7e28 Leszek Koltunski
 *
768
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
769
 *               currently being dragged with.
770 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
771 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
772 6a06a912 Leszek Koltunski
 */
773 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center)
774 d425545a Leszek Koltunski
    {
775 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, null);
776 d425545a Leszek Koltunski
    }
777 6a06a912 Leszek Koltunski
778 6ebdbbf1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
779
/**
780
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
781
 * a (possibly changing in time) point on the Object.
782
 *
783
 * @param vector Vector of force that deforms the shape of the whole Object.
784
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
785
 * @param region Region that masks the Effect.
786
 * @return       ID of the effect added, or -1 if we failed to add one.
787
 */
788
  public long deform(Data3D vector, Data3D center, Data4D region)
789
    {
790
    return mV.add(EffectNames.DEFORM, vector, center, region);
791
    }
792
793 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
794
/**
795 e0a16874 Leszek Koltunski
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
796 9351ad55 Leszek Koltunski
 * a (possibly changing in time) point on the Object.
797 6a06a912 Leszek Koltunski
 *     
798 f2fe7e28 Leszek Koltunski
 * @param vector Vector of force that deforms the shape of the whole Object.
799 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
800 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
801 6a06a912 Leszek Koltunski
 */
802 fa6c352d Leszek Koltunski
  public long deform(Data3D vector, Data3D center)
803 6a06a912 Leszek Koltunski
    {  
804 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DEFORM, vector, center, null);
805 6a06a912 Leszek Koltunski
    }
806
807
///////////////////////////////////////////////////////////////////////////////////////////////////  
808
/**
809 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
810 6a06a912 Leszek Koltunski
 * away from the center (degree<=1)
811 f2fe7e28 Leszek Koltunski
 *
812
 * @param sink   The current degree of the Effect.
813 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
814 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
815
 * @return       ID of the effect added, or -1 if we failed to add one.
816 6a06a912 Leszek Koltunski
 */
817 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center, Data4D region)
818 6a06a912 Leszek Koltunski
    {
819 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SINK, sink, center, region);
820 6a06a912 Leszek Koltunski
    }
821
822
///////////////////////////////////////////////////////////////////////////////////////////////////
823
/**
824 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
825
 * away from the center (degree<=1)
826
 *
827
 * @param sink   The current degree of the Effect.
828 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
829 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
830 6a06a912 Leszek Koltunski
 */
831 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center)
832 d425545a Leszek Koltunski
    {
833
    return mV.add(EffectNames.SINK, sink, center);
834
    }
835 6a06a912 Leszek Koltunski
836 82ee855a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
837
/**
838
 * Pull all points around the center of the Effect towards a line passing through the center
839
 * (that's if degree>=1) or push them away from the line (degree<=1)
840
 *
841
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
842
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
843
 * @param region Region that masks the Effect.
844
 * @return       ID of the effect added, or -1 if we failed to add one.
845
 */
846
  public long pinch(Data2D pinch, Data3D center, Data4D region)
847
    {
848
    return mV.add(EffectNames.PINCH, pinch, center, region);
849
    }
850
851
///////////////////////////////////////////////////////////////////////////////////////////////////
852
/**
853
 * Pull all points around the center of the Effect towards a line passing through the center
854
 * (that's if degree>=1) or push them away from the line (degree<=1)
855
 *
856
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
857
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
858
 * @return       ID of the effect added, or -1 if we failed to add one.
859
 */
860
  public long pinch(Data2D pinch, Data3D center)
861
    {
862
    return mV.add(EffectNames.PINCH, pinch, center);
863
    }
864
865 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////  
866
/**
867 f2fe7e28 Leszek Koltunski
 * Rotate part of the Object around the Center of the Effect by a certain angle.
868
 *
869 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
870 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
871 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
872
 * @return       ID of the effect added, or -1 if we failed to add one.
873 6a06a912 Leszek Koltunski
 */
874 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center, Data4D region)
875 6a06a912 Leszek Koltunski
    {    
876 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SWIRL, swirl, center, region);
877 6a06a912 Leszek Koltunski
    }
878
879
///////////////////////////////////////////////////////////////////////////////////////////////////
880
/**
881 f2fe7e28 Leszek Koltunski
 * Rotate the whole Object around the Center of the Effect by a certain angle.
882
 *
883 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
884 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
885 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
886 6a06a912 Leszek Koltunski
 */
887 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center)
888 d425545a Leszek Koltunski
    {
889
    return mV.add(EffectNames.SWIRL, swirl, center);
890
    }
891 4fde55a0 Leszek Koltunski
892
///////////////////////////////////////////////////////////////////////////////////////////////////
893
/**
894
 * Directional, sinusoidal wave effect.
895
 *
896 350cc2f5 Leszek Koltunski
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
897 ea16dc89 Leszek Koltunski
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
898 350cc2f5 Leszek Koltunski
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
899
 *               describe the 'direction' of the wave.
900 3695d6fa Leszek Koltunski
 *               <p>
901 d0c902b8 Leszek Koltunski
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
902
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
903
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
904
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
905 3695d6fa Leszek Koltunski
 *               <p>
906
 *               <p>
907 d0c902b8 Leszek Koltunski
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
908
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
909
 *               will be sine shapes.
910 3695d6fa Leszek Koltunski
 *               <p>
911 d0c902b8 Leszek Koltunski
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
912
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
913
 *               YZ-plane with be sine shapes.
914 3695d6fa Leszek Koltunski
 *               <p>
915 d0c902b8 Leszek Koltunski
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
916 350cc2f5 Leszek Koltunski
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
917
 *               value if sin at this point.
918 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
919 4fde55a0 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
920
 */
921 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center)
922 4fde55a0 Leszek Koltunski
    {
923 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.WAVE, wave, center, null);
924 4fde55a0 Leszek Koltunski
    }
925
926
///////////////////////////////////////////////////////////////////////////////////////////////////
927
/**
928
 * Directional, sinusoidal wave effect.
929
 *
930 421c2728 Leszek Koltunski
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
931 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
932 4fde55a0 Leszek Koltunski
 * @param region Region that masks the Effect.
933
 * @return       ID of the effect added, or -1 if we failed to add one.
934
 */
935 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center, Data4D region)
936 4fde55a0 Leszek Koltunski
    {
937
    return mV.add(EffectNames.WAVE, wave, center, region);
938
    }
939 d6e94c84 Leszek Koltunski
940
///////////////////////////////////////////////////////////////////////////////////////////////////
941
// Postprocess-based effects
942
///////////////////////////////////////////////////////////////////////////////////////////////////
943
/**
944
 * Blur the object.
945
 *
946
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
947
 *               take into account 10 pixels in each direction.
948
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
949
 * @return ID of the effect added, or -1 if we failed to add one.
950
 */
951
  public long blur(Data1D radius, Data2D center)
952
    {
953
    return mP.add(EffectNames.BLUR, radius, center);
954
    }
955 f2fe7e28 Leszek Koltunski
  }