Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 55c14a19

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