Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 8fa96e69

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