Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ a56bc359

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.graphics.Bitmap;
23 985ea9c5 Leszek Koltunski
import android.graphics.Matrix;
24 6a06a912 Leszek Koltunski
import android.opengl.GLES20;
25
import android.opengl.GLUtils;
26
27 e458a4ba Leszek Koltunski
import org.distorted.library.message.EffectListener;
28 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data1D;
29 f2fe7e28 Leszek Koltunski
import org.distorted.library.type.Data2D;
30 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data3D;
31
import org.distorted.library.type.Data4D;
32 350cc2f5 Leszek Koltunski
import org.distorted.library.type.Data5D;
33 568b29d8 Leszek Koltunski
import org.distorted.library.type.Static3D;
34 a4835695 Leszek Koltunski
35 8e34674e Leszek Koltunski
import java.util.HashMap;
36
37 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
38 b329f352 Leszek Koltunski
/**
39 437bc43e Leszek Koltunski
 * All Objects to which Distorted Graphics effects can be applied need to be extended from here.
40 b73dcaa7 Leszek Koltunski
 * <p>
41
 * General idea is as follows:
42
 * <ul>
43
 * <li> Create an instance of (some class descended from) DistortedObject
44
 * <li> Paint something onto the Bitmap that's backing it up
45
 * <li> Apply some effects
46
 * <li> Draw it!
47
 * </ul>
48
 * <p>
49
 * The effects we can apply fall into three general categories:
50
 * <ul>
51
 * <li> Matrix Effects, i.e. ones that change the Bitmap's ModelView Matrix (moves, scales, rotations)
52
 * <li> Vertex Effects, i.e. effects that are implemented in the Vertex Shader. Those typically change
53
 *      the shape of (some sub-Region of) the Bitmap in some way (deforms, distortions, sinks)
54
 * <li> Fragment Effects, i.e. effects that change (some of) the pixels of the Bitmap (transparency, macroblock)
55
 * </ul>
56
 * <p>
57 8e34674e Leszek Koltunski
 * Just like in DistortedNode and DistortedFramebuffer, we need to have a static list of all
58
 * DistortedObjects currently created by the application so that we can implement the 'mark for
59
 * deletion now - actually delete on next render' thing.
60
 * We need to be able to quickly retrieve an Object by its ID, thus a HashMap.
61 b329f352 Leszek Koltunski
 */
62 a56bc359 Leszek Koltunski
public class DistortedObject
63 d425545a Leszek Koltunski
  {
64 8e34674e Leszek Koltunski
  private static long mNextID =0;
65
  private static HashMap<Long,DistortedObject> mObjects = new HashMap<>();
66
67 3d590d8d Leszek Koltunski
  private EffectQueueMatrix    mM;
68
  private EffectQueueFragment  mF;
69
  private EffectQueueVertex    mV;
70
71
  private boolean matrixCloned, vertexCloned, fragmentCloned;
72
  private long mID;
73
  private int mSizeX, mSizeY, mSizeZ; // in screen space
74 0a046359 Leszek Koltunski
  private int mHalfX, mHalfY, mHalfZ; // halfs of the above
75 6a06a912 Leszek Koltunski
76 3d590d8d Leszek Koltunski
  private Bitmap[] mBmp= null; //
77
  int[] mTextureDataH;         // have to be shared among all the cloned Objects
78
  boolean[] mBitmapSet;        //
79 9361b337 Leszek Koltunski
80 985ea9c5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
81
// We have to flip vertically every single Bitmap that we get fed with.
82
//
83
// Reason: textures read from files are the only objects in OpenGL which have their origins at the
84
// upper-left corner. Everywhere else the origin is in the lower-left corner. Thus we have to flip.
85
// The alternative solution, namely inverting the y-coordinate of the TexCoord does not really work-
86
// i.e. it works only in case of rendering directly to the screen, but if we render to an FBO and
87
// then take the FBO and render to screen, (DistortedNode does so!) things get inverted as textures
88
// created from FBO have their origins in the lower-left... Mindfuck!
89
90
  private static Bitmap flipBitmap(Bitmap src)
91
    {
92
    Matrix matrix = new Matrix();
93
    matrix.preScale(1.0f,-1.0f);
94
95
    return Bitmap.createBitmap(src,0,0,src.getWidth(),src.getHeight(), matrix,true);
96
    }
97
98 9361b337 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
99
100 a56bc359 Leszek Koltunski
  private void initializeData(int x, int y, int z)
101 d425545a Leszek Koltunski
    {
102 0a046359 Leszek Koltunski
    mSizeX= x; mHalfX = x/2;
103
    mSizeY= y; mHalfY = y/2;
104
    mSizeZ= z; mHalfZ = z/2;
105 3d590d8d Leszek Koltunski
106 8e34674e Leszek Koltunski
    mID = mNextID++;
107
    mObjects.put(mID,this);
108
109 d425545a Leszek Koltunski
    mTextureDataH   = new int[1];
110
    mTextureDataH[0]= 0;
111
    mBmp            = new Bitmap[1];
112
    mBmp[0]         = null;
113
    mBitmapSet      = new boolean[1];
114
    mBitmapSet[0]   = false;
115 6a06a912 Leszek Koltunski
      
116 d425545a Leszek Koltunski
    initializeEffectLists(this,0);
117 6a06a912 Leszek Koltunski
      
118 d425545a Leszek Koltunski
    if( Distorted.isInitialized() ) resetTexture();
119
    }
120 6a06a912 Leszek Koltunski
    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
    
123 3d590d8d Leszek Koltunski
  private void initializeEffectLists(DistortedObject d, int flags)
124 d425545a Leszek Koltunski
    {
125 0a046359 Leszek Koltunski
    long objID = d.getID();
126
127 015642fb Leszek Koltunski
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
128 6a06a912 Leszek Koltunski
      {
129 d425545a Leszek Koltunski
      mM = d.mM;
130
      matrixCloned = true;
131
      }
132
    else
133
      {
134 0a046359 Leszek Koltunski
      mM = new EffectQueueMatrix(objID);
135 d425545a Leszek Koltunski
      matrixCloned = false;
136
      }
137 6a06a912 Leszek Koltunski
    
138 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
139
      {
140
      mV = d.mV;
141
      vertexCloned = true;
142
      }
143
    else
144
      {
145 0a046359 Leszek Koltunski
      mV = new EffectQueueVertex(objID);
146 d425545a Leszek Koltunski
      vertexCloned = false;
147
      }
148 6a06a912 Leszek Koltunski
    
149 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
150
      {
151
      mF = d.mF;
152
      fragmentCloned = true;
153 6a06a912 Leszek Koltunski
      }
154 d425545a Leszek Koltunski
    else
155
      {
156 0a046359 Leszek Koltunski
      mF = new EffectQueueFragment(objID);
157 d425545a Leszek Koltunski
      fragmentCloned = false;
158
      }
159
    }
160 6a06a912 Leszek Koltunski
    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162
// this will be called on startup and every time OpenGL context has been lost
163
// also call this from the constructor if the OpenGL context has been created already.
164
    
165 8e34674e Leszek Koltunski
  private void resetTexture()
166 d425545a Leszek Koltunski
    {
167
    if( mTextureDataH!=null )
168 6a06a912 Leszek Koltunski
      {
169 d425545a Leszek Koltunski
      if( mTextureDataH[0]==0 ) GLES20.glGenTextures(1, mTextureDataH, 0);
170 6a06a912 Leszek Koltunski
171 d425545a Leszek Koltunski
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
172
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR );
173
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR );
174
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
175
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
176 6a06a912 Leszek Koltunski
       
177 d425545a Leszek Koltunski
      if( mBmp!=null && mBmp[0]!=null)
178
        {
179 985ea9c5 Leszek Koltunski
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp[0]), 0);
180 d425545a Leszek Koltunski
        mBmp[0] = null;
181 6a06a912 Leszek Koltunski
        }
182
      }
183 d425545a Leszek Koltunski
    }
184 6a06a912 Leszek Koltunski
  
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186
   
187 a56bc359 Leszek Koltunski
  void drawPriv(long currTime, DistortedObjectGrid grid, DistortedFramebuffer df)
188 d425545a Leszek Koltunski
    {
189 8e34674e Leszek Koltunski
    DistortedFramebuffer.deleteAllMarked();
190 16d8b8f3 Leszek Koltunski
191 ed13a5de Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
192 0a046359 Leszek Koltunski
193 d425545a Leszek Koltunski
    mM.compute(currTime);
194 0a046359 Leszek Koltunski
    mM.send(df,mHalfX,mHalfY,mHalfZ);
195 6a06a912 Leszek Koltunski
      
196 d425545a Leszek Koltunski
    mV.compute(currTime);
197 0a046359 Leszek Koltunski
    mV.send(mHalfX,mHalfY,mHalfZ);
198 6a06a912 Leszek Koltunski
        
199 d425545a Leszek Koltunski
    mF.compute(currTime);
200 0a046359 Leszek Koltunski
    mF.send(mHalfX,mHalfY);
201 a56bc359 Leszek Koltunski
202
    grid.draw();
203 d425545a Leszek Koltunski
    }
204 6a06a912 Leszek Koltunski
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206
   
207 a56bc359 Leszek Koltunski
  void drawNoEffectsPriv(DistortedObjectGrid grid, DistortedFramebuffer df)
208 d425545a Leszek Koltunski
    {
209 ed13a5de Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
210 0a046359 Leszek Koltunski
211
    mM.sendZero(df,mHalfX,mHalfY,mHalfZ);
212 d425545a Leszek Koltunski
    mV.sendZero();
213
    mF.sendZero();
214 a56bc359 Leszek Koltunski
215
    grid.draw();
216 d425545a Leszek Koltunski
    }
217 6a06a912 Leszek Koltunski
    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
   
220 8e34674e Leszek Koltunski
  private void releasePriv()
221 d425545a Leszek Koltunski
    {
222 8e34674e Leszek Koltunski
    if( !matrixCloned  ) mM.abortAll(false);
223
    if( !vertexCloned  ) mV.abortAll(false);
224
    if( !fragmentCloned) mF.abortAll(false);
225 d425545a Leszek Koltunski
226
    mBmp          = null;
227
    mM            = null;
228
    mV            = null;
229
    mF            = null;
230
    mTextureDataH = null;
231
    }
232 6a06a912 Leszek Koltunski
 
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234
235 d425545a Leszek Koltunski
  long getBitmapID()
236 8e34674e Leszek Koltunski
    {
237
    return mBmp==null ? 0 : mBmp.hashCode();
238
    }
239
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
242
  static synchronized void reset()
243
    {
244
    for(long id: mObjects.keySet())
245 6a06a912 Leszek Koltunski
      {
246 8e34674e Leszek Koltunski
      mObjects.get(id).resetTexture();
247
      }
248
    }
249
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251
252
  static synchronized void release()
253
    {
254
    for(long id: mObjects.keySet())
255
      {
256
      mObjects.get(id).releasePriv();
257 6a06a912 Leszek Koltunski
      }
258
259 8e34674e Leszek Koltunski
    mObjects.clear();
260
    mNextID = 0;
261
    }
262
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264
// PUBLIC API
265 ada90d33 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
266 d425545a Leszek Koltunski
/**
267 a56bc359 Leszek Koltunski
 * Create empty effect queue with no Bitmap.
268 d425545a Leszek Koltunski
 */
269 a56bc359 Leszek Koltunski
  public DistortedObject(int width, int height, int depth)
270 d425545a Leszek Koltunski
    {
271 a56bc359 Leszek Koltunski
    initializeData(width,height,depth);
272 d425545a Leszek Koltunski
    }
273 ada90d33 Leszek Koltunski
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275 d425545a Leszek Koltunski
/**
276
 * Copy constructor used to create a DistortedObject based on various parts of another object.
277
 * <p>
278
 * Whatever we do not clone gets created just like in the default constructor.
279
 * We only call this from the descendant's classes' constructors where we have to pay attention
280
 * to give it the appropriate type of a DistortedObject!
281
 *
282
 * @param dc    Source object to create our object from
283
 * @param flags A bitmask of values specifying what to copy.
284
 *              For example, CLONE_BITMAP | CLONE_MATRIX.
285
 */
286
  public DistortedObject(DistortedObject dc, int flags)
287
    {
288
    initializeEffectLists(dc,flags);
289 ada90d33 Leszek Koltunski
290 8e34674e Leszek Koltunski
    mID = mNextID++;
291
    mObjects.put(mID,this);
292 ada90d33 Leszek Koltunski
293 d425545a Leszek Koltunski
    mSizeX = dc.mSizeX;
294
    mSizeY = dc.mSizeY;
295
    mSizeZ = dc.mSizeZ;
296 0a046359 Leszek Koltunski
    mHalfX = dc.mHalfX;
297
    mHalfY = dc.mHalfY;
298
    mHalfZ = dc.mHalfZ;
299 ada90d33 Leszek Koltunski
300 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_BITMAP) != 0 )
301
      {
302
      mTextureDataH = dc.mTextureDataH;
303
      mBmp          = dc.mBmp;
304
      mBitmapSet    = dc.mBitmapSet;
305 ada90d33 Leszek Koltunski
      }
306 d425545a Leszek Koltunski
    else
307
      {
308
      mTextureDataH   = new int[1];
309
      mTextureDataH[0]= 0;
310
      mBitmapSet      = new boolean[1];
311
      mBitmapSet[0]   = false;
312
      mBmp            = new Bitmap[1];
313
      mBmp[0]         = null;
314
315
      if( Distorted.isInitialized() ) resetTexture();
316
      }
317
    }
318 ada90d33 Leszek Koltunski
319 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
320
/**
321
 * Draw the DistortedObject to the location specified by current Matrix effects.    
322
 *     
323 d1e740c5 Leszek Koltunski
 * @param currTime current time, in milliseconds.
324 5d923c17 Leszek Koltunski
 *        This gets passed on to Dynamics inside the Effects that are currently applied to the
325 6a06a912 Leszek Koltunski
 *        Object.
326
 */
327 a56bc359 Leszek Koltunski
  public void draw(long currTime, DistortedObjectGrid grid)
328 d425545a Leszek Koltunski
    {
329
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
330
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
331 a56bc359 Leszek Koltunski
    drawPriv(currTime, grid, Distorted.mFramebuffer);
332 d425545a Leszek Koltunski
    }
333 d1e740c5 Leszek Koltunski
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335
/**
336
 * Draw the DistortedObject to the Framebuffer passed.
337
 *
338
 * @param currTime Current time, in milliseconds.
339
 * @param df       Framebuffer to render this to.
340
 */
341 a56bc359 Leszek Koltunski
  public void draw(long currTime, DistortedObjectGrid grid, DistortedFramebuffer df)
342 d1e740c5 Leszek Koltunski
    {
343
    df.setAsOutput();
344
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
345 a56bc359 Leszek Koltunski
    drawPriv(currTime,grid, df);
346 d1e740c5 Leszek Koltunski
    }
347
348 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
349
/**
350
 * Releases all resources.
351
 */
352 8e34674e Leszek Koltunski
  public synchronized void delete()
353 d425545a Leszek Koltunski
    {
354
    releasePriv();
355 8e34674e Leszek Koltunski
    mObjects.remove(this);
356 d425545a Leszek Koltunski
    }
357 6a06a912 Leszek Koltunski
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359
/**
360
 * Sets the underlying android.graphics.Bitmap object and uploads it to the GPU. 
361
 * <p>
362
 * You can only recycle() the passed Bitmap once the OpenGL context gets created (i.e. after call 
363
 * to onSurfaceCreated) because only after this point can the Library upload it to the GPU!
364
 * 
365
 * @param bmp The android.graphics.Bitmap object to apply effects to and display.
366
 */
367
   
368 a56bc359 Leszek Koltunski
  public void setTexture(Bitmap bmp)
369 d425545a Leszek Koltunski
    {
370
    mBitmapSet[0] = true;
371 0a046359 Leszek Koltunski
372
    mSizeX= bmp.getWidth() ; mHalfX = mSizeX/2;
373
    mSizeY= bmp.getHeight(); mHalfY = mSizeY/2;
374
375 d425545a Leszek Koltunski
    if( Distorted.isInitialized() )
376
      {
377
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
378
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
379 985ea9c5 Leszek Koltunski
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(bmp), 0);
380 d425545a Leszek Koltunski
      }
381
    else
382
      {
383
      mBmp[0] = bmp;
384
      }
385
    }
386 6a06a912 Leszek Koltunski
    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388
/**
389
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
390 9351ad55 Leszek Koltunski
 * to one of the Effects that are currently applied to the DistortedObject.
391 6a06a912 Leszek Koltunski
 * 
392
 * @param el A class implementing the EffectListener interface that wants to get notifications.
393
 */
394 d425545a Leszek Koltunski
  public void addEventListener(EffectListener el)
395
    {
396
    mV.addListener(el);
397
    mF.addListener(el);
398
    mM.addListener(el);
399
    }
400 6a06a912 Leszek Koltunski
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402
/**
403
 * Removes the calling class from the list of Listeners.
404
 * 
405
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
406
 */
407 d425545a Leszek Koltunski
  public void removeEventListener(EffectListener el)
408
    {
409
    mV.removeListener(el);
410
    mF.removeListener(el);
411
    mM.removeListener(el);
412
    }
413 6a06a912 Leszek Koltunski
   
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415
/**
416
 * Returns the height of the DistortedObject.
417
 *    
418
 * @return height of the object, in pixels.
419
 */
420 d425545a Leszek Koltunski
  public int getWidth()
421 6a06a912 Leszek Koltunski
     {
422
     return mSizeX;   
423
     }
424
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426
/**
427
 * Returns the width of the DistortedObject.
428
 * 
429
 * @return width of the Object, in pixels.
430
 */
431 d425545a Leszek Koltunski
  public int getHeight()
432 6a06a912 Leszek Koltunski
      {
433
      return mSizeY;  
434
      }
435
    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437
/**
438
 * Returns the depth of the DistortedObject.
439
 * 
440
 * @return depth of the Object, in pixels.
441
 */
442 d425545a Leszek Koltunski
  public int getDepth()
443 6a06a912 Leszek Koltunski
      {
444
      return mSizeZ;  
445
      }
446
        
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448
/**
449
 * Returns unique ID of this instance.
450
 * 
451
 * @return ID of the object.
452
 */
453 d425545a Leszek Koltunski
  public long getID()
454 6a06a912 Leszek Koltunski
      {
455
      return mID;  
456
      }
457
    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459
/**
460 d07f2950 Leszek Koltunski
 * Aborts all Effects.
461
 * @return Number of effects aborted.
462 6a06a912 Leszek Koltunski
 */
463 d425545a Leszek Koltunski
  public int abortAllEffects()
464 6a06a912 Leszek Koltunski
      {
465 0df17fad Leszek Koltunski
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
466 6a06a912 Leszek Koltunski
      }
467
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469
/**
470 d07f2950 Leszek Koltunski
 * Aborts all Effects of a given type, for example all MATRIX Effects.
471 6a06a912 Leszek Koltunski
 * 
472 d07f2950 Leszek Koltunski
 * @param type one of the constants defined in {@link EffectTypes}
473
 * @return Number of effects aborted.
474 6a06a912 Leszek Koltunski
 */
475 d425545a Leszek Koltunski
  public int abortEffects(EffectTypes type)
476
    {
477
    switch(type)
478 6a06a912 Leszek Koltunski
      {
479 0df17fad Leszek Koltunski
      case MATRIX  : return mM.abortAll(true);
480
      case VERTEX  : return mV.abortAll(true);
481
      case FRAGMENT: return mF.abortAll(true);
482 d425545a Leszek Koltunski
      default      : return 0;
483 6a06a912 Leszek Koltunski
      }
484 d425545a Leszek Koltunski
    }
485 6a06a912 Leszek Koltunski
    
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487
/**
488
 * Aborts a single Effect.
489
 * 
490
 * @param id ID of the Effect we want to abort.
491 476bbc81 Leszek Koltunski
 * @return number of Effects aborted. Always either 0 or 1.
492 6a06a912 Leszek Koltunski
 */
493 d425545a Leszek Koltunski
  public int abortEffect(long id)
494
    {
495
    int type = (int)(id&EffectTypes.MASK);
496 1e438fc7 Leszek Koltunski
497 d425545a Leszek Koltunski
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
498
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
499
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
500 1e438fc7 Leszek Koltunski
501 d425545a Leszek Koltunski
    return 0;
502
    }
503 6a06a912 Leszek Koltunski
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505
/**
506 e8c81a8e Leszek Koltunski
 * Abort all Effects of a given name, for example all rotations.
507 6a06a912 Leszek Koltunski
 * 
508 d07f2950 Leszek Koltunski
 * @param name one of the constants defined in {@link EffectNames}
509 476bbc81 Leszek Koltunski
 * @return number of Effects aborted.
510 6a06a912 Leszek Koltunski
 */
511 d425545a Leszek Koltunski
  public int abortEffects(EffectNames name)
512
    {
513
    switch(name.getType())
514 6a06a912 Leszek Koltunski
      {
515 d425545a Leszek Koltunski
      case MATRIX  : return mM.removeByType(name);
516
      case VERTEX  : return mV.removeByType(name);
517
      case FRAGMENT: return mF.removeByType(name);
518
      default      : return 0;
519 6a06a912 Leszek Koltunski
      }
520 d425545a Leszek Koltunski
    }
521 6a06a912 Leszek Koltunski
    
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523
/**
524
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
525
 * 
526
 * @param id Effect ID we want to print info about
527
 * @return <code>true</code> if a single Effect of type effectType has been found.
528
 */
529
    
530 d425545a Leszek Koltunski
  public boolean printEffect(long id)
531
    {
532
    int type = (int)(id&EffectTypes.MASK);
533 1e438fc7 Leszek Koltunski
534 d425545a Leszek Koltunski
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
535
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
536
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
537 1e438fc7 Leszek Koltunski
538 d425545a Leszek Koltunski
    return false;
539
    }
540 6a06a912 Leszek Koltunski
   
541
///////////////////////////////////////////////////////////////////////////////////////////////////   
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543
// Individual effect functions.
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545
// Matrix-based effects
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547
/**
548 e8c81a8e Leszek Koltunski
 * Moves the Object by a (possibly changing in time) vector.
549 6a06a912 Leszek Koltunski
 * 
550 568b29d8 Leszek Koltunski
 * @param vector 3-dimensional Data which at any given time will return a Static3D
551 e0a16874 Leszek Koltunski
 *               representing the current coordinates of the vector we want to move the Object with.
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 move(Data3D vector)
555 6a06a912 Leszek Koltunski
    {   
556 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.MOVE,vector);
557 6a06a912 Leszek Koltunski
    }
558
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560
/**
561 e8c81a8e Leszek Koltunski
 * Scales the Object by (possibly changing in time) 3D scale factors.
562 6a06a912 Leszek Koltunski
 * 
563 d1e740c5 Leszek Koltunski
 * @param scale 3-dimensional Data which at any given time returns a Static3D
564 e0a16874 Leszek Koltunski
 *              representing the current x- , y- and z- scale factors.
565
 * @return      ID of the effect added, or -1 if we failed to add one.
566 6a06a912 Leszek Koltunski
 */
567 568b29d8 Leszek Koltunski
  public long scale(Data3D scale)
568 6a06a912 Leszek Koltunski
    {   
569 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.SCALE,scale);
570 6a06a912 Leszek Koltunski
    }
571
572 2fce34f4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
573
/**
574 e8c81a8e Leszek Koltunski
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
575 2fce34f4 Leszek Koltunski
 *
576
 * @param scale The factor to scale all 3 dimensions with.
577
 * @return      ID of the effect added, or -1 if we failed to add one.
578
 */
579 d425545a Leszek Koltunski
  public long scale(float scale)
580
    {
581
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
582
    }
583 2fce34f4 Leszek Koltunski
584 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
585
/**
586 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
587
 * Static axis of rotation is given by the last parameter.
588
 *
589 9351ad55 Leszek Koltunski
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
590 568b29d8 Leszek Koltunski
 * @param axis   Axis of rotation
591 0df17fad Leszek Koltunski
 * @param center Coordinates of the Point we are rotating around.
592 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
593
 */
594 0df17fad Leszek Koltunski
  public long rotate(Data1D angle, Static3D axis, Data3D center )
595 6a06a912 Leszek Koltunski
    {   
596 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angle, axis, center);
597 6a06a912 Leszek Koltunski
    }
598
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600
/**
601 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
602 2fce34f4 Leszek Koltunski
 * Here both angle and axis can dynamically change.
603 568b29d8 Leszek Koltunski
 *
604
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
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 e0a16874 Leszek Koltunski
 */
608 0df17fad Leszek Koltunski
  public long rotate(Data4D angleaxis, Data3D center)
609 568b29d8 Leszek Koltunski
    {
610 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angleaxis, center);
611 6a06a912 Leszek Koltunski
    }
612
613
///////////////////////////////////////////////////////////////////////////////////////////////////
614
/**
615 568b29d8 Leszek Koltunski
 * Rotates the Object by quaternion.
616 0df17fad Leszek Koltunski
 *
617 568b29d8 Leszek Koltunski
 * @param quaternion The quaternion describing the rotation.
618 0df17fad Leszek Koltunski
 * @param center     Coordinates of the Point we are rotating around.
619 568b29d8 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
620 6a06a912 Leszek Koltunski
 */
621 0df17fad Leszek Koltunski
  public long quaternion(Data4D quaternion, Data3D center )
622 568b29d8 Leszek Koltunski
    {
623 0df17fad Leszek Koltunski
    return mM.add(EffectNames.QUATERNION,quaternion,center);
624 6a06a912 Leszek Koltunski
    }
625
626
///////////////////////////////////////////////////////////////////////////////////////////////////
627
/**
628 568b29d8 Leszek Koltunski
 * Shears the Object.
629 6a06a912 Leszek Koltunski
 *
630 8c3cdec5 Leszek Koltunski
 * @param shear   The 3-tuple of shear factors. The first controls level
631
 *                of shearing in the X-axis, second - Y-axis and the third -
632
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
633
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
634 0df17fad Leszek Koltunski
 * @param center  Center of shearing, i.e. the point which stays unmoved.
635 e0a16874 Leszek Koltunski
 * @return        ID of the effect added, or -1 if we failed to add one.
636 6a06a912 Leszek Koltunski
 */
637 0df17fad Leszek Koltunski
  public long shear(Data3D shear, Data3D center)
638 6a06a912 Leszek Koltunski
    {
639 0df17fad Leszek Koltunski
    return mM.add(EffectNames.SHEAR, shear, center);
640 6a06a912 Leszek Koltunski
    }
641
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643
// Fragment-based effects  
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645
/**
646 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
647 6a06a912 Leszek Koltunski
 *        
648 2fce34f4 Leszek Koltunski
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
649 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
650
 *               Valid range: <0,1>
651 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
652 2fce34f4 Leszek Koltunski
 * @param region Region this Effect is limited to.
653
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
654
 * @return       ID of the effect added, or -1 if we failed to add one.
655 6a06a912 Leszek Koltunski
 */
656 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
657 6a06a912 Leszek Koltunski
    {
658 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
659 6a06a912 Leszek Koltunski
    }
660
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662
/**
663 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change all three of its RGB components.
664
 *
665
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
666 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
667
 *               Valid range: <0,1>
668 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
669 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
670 6a06a912 Leszek Koltunski
 */
671 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color)
672 6a06a912 Leszek Koltunski
    {
673 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CHROMA, blend, color);
674 6a06a912 Leszek Koltunski
    }
675
676
///////////////////////////////////////////////////////////////////////////////////////////////////
677
/**
678 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its transparency level.
679 6a06a912 Leszek Koltunski
 *        
680 2fce34f4 Leszek Koltunski
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
681 e4878781 Leszek Koltunski
 *               moment: pixel.a *= alpha.
682
 *               Valid range: <0,1>
683 d7bbef2f Leszek Koltunski
 * @param region Region this Effect is limited to. 
684 2fce34f4 Leszek Koltunski
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
685 d7bbef2f Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one. 
686 6a06a912 Leszek Koltunski
 */
687 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
688 6a06a912 Leszek Koltunski
    {
689 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
690 6a06a912 Leszek Koltunski
    }
691
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693
/**
694 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its transparency level.
695
 *
696
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
697 e4878781 Leszek Koltunski
 *               given moment: pixel.a *= alpha.
698
 *               Valid range: <0,1>
699 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
700 6a06a912 Leszek Koltunski
 */
701 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha)
702 6a06a912 Leszek Koltunski
    {
703 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.ALPHA, alpha);
704 6a06a912 Leszek Koltunski
    }
705
706
///////////////////////////////////////////////////////////////////////////////////////////////////
707
/**
708 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its brightness level.
709 6a06a912 Leszek Koltunski
 *        
710 2fce34f4 Leszek Koltunski
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
711 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
712 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
713 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
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, Data4D region, boolean smooth)
717 6a06a912 Leszek Koltunski
    {
718 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
719 6a06a912 Leszek Koltunski
    }
720
721
///////////////////////////////////////////////////////////////////////////////////////////////////
722
/**
723 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its brightness level.
724
 *
725
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
726 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
727 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
728 6a06a912 Leszek Koltunski
 */
729 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness)
730 6a06a912 Leszek Koltunski
    {
731 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.BRIGHTNESS, brightness);
732 6a06a912 Leszek Koltunski
    }
733
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735
/**
736 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its contrast level.
737 6a06a912 Leszek Koltunski
 *        
738 2fce34f4 Leszek Koltunski
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
739 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
740 e0a16874 Leszek Koltunski
 * @param region   Region this Effect is limited to.
741 2fce34f4 Leszek Koltunski
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
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, Data4D region, boolean smooth)
745 6a06a912 Leszek Koltunski
    {
746 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
747 6a06a912 Leszek Koltunski
    }
748
749
///////////////////////////////////////////////////////////////////////////////////////////////////
750
/**
751 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its contrast level.
752
 *
753
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
754 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
755 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
756 6a06a912 Leszek Koltunski
 */
757 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast)
758 6a06a912 Leszek Koltunski
    {
759 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CONTRAST, contrast);
760 6a06a912 Leszek Koltunski
    }
761
762
///////////////////////////////////////////////////////////////////////////////////////////////////
763
/**
764 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its saturation level.
765 6a06a912 Leszek Koltunski
 *        
766 2fce34f4 Leszek Koltunski
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
767 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
768 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
769 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
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, Data4D region, boolean smooth)
773 6a06a912 Leszek Koltunski
    {
774 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
775 6a06a912 Leszek Koltunski
    }
776
777
///////////////////////////////////////////////////////////////////////////////////////////////////
778
/**
779 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its saturation level.
780
 *
781
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
782 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
783 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
784 6a06a912 Leszek Koltunski
 */
785 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation)
786 6a06a912 Leszek Koltunski
    {
787 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.SATURATION, saturation);
788 6a06a912 Leszek Koltunski
    }
789
790
///////////////////////////////////////////////////////////////////////////////////////////////////
791
// Vertex-based effects  
792
///////////////////////////////////////////////////////////////////////////////////////////////////
793
/**
794 e0a16874 Leszek Koltunski
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
795 f2fe7e28 Leszek Koltunski
 *
796
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
797
 *               currently being dragged with.
798 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
799 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
800
 * @return       ID of the effect added, or -1 if we failed to add one.
801 6a06a912 Leszek Koltunski
 */
802 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center, Data4D region)
803 6a06a912 Leszek Koltunski
    {  
804 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, region);
805 6a06a912 Leszek Koltunski
    }
806
807
///////////////////////////////////////////////////////////////////////////////////////////////////
808
/**
809 e0a16874 Leszek Koltunski
 * Distort the whole Object by a (possibly changing in time) vector of force.
810 f2fe7e28 Leszek Koltunski
 *
811
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
812
 *               currently being dragged with.
813 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
814 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
815 6a06a912 Leszek Koltunski
 */
816 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center)
817 d425545a Leszek Koltunski
    {
818 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, null);
819 d425545a Leszek Koltunski
    }
820 6a06a912 Leszek Koltunski
821 6ebdbbf1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
822
/**
823
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
824
 * a (possibly changing in time) point on the Object.
825
 *
826
 * @param vector Vector of force that deforms the shape of the whole Object.
827
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
828
 * @param region Region that masks the Effect.
829
 * @return       ID of the effect added, or -1 if we failed to add one.
830
 */
831
  public long deform(Data3D vector, Data3D center, Data4D region)
832
    {
833
    return mV.add(EffectNames.DEFORM, vector, center, region);
834
    }
835
836 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
837
/**
838 e0a16874 Leszek Koltunski
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
839 9351ad55 Leszek Koltunski
 * a (possibly changing in time) point on the Object.
840 6a06a912 Leszek Koltunski
 *     
841 f2fe7e28 Leszek Koltunski
 * @param vector Vector of force that deforms the shape of the whole Object.
842 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
843 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
844 6a06a912 Leszek Koltunski
 */
845 fa6c352d Leszek Koltunski
  public long deform(Data3D vector, Data3D center)
846 6a06a912 Leszek Koltunski
    {  
847 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DEFORM, vector, center, null);
848 6a06a912 Leszek Koltunski
    }
849
850
///////////////////////////////////////////////////////////////////////////////////////////////////  
851
/**
852 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
853 6a06a912 Leszek Koltunski
 * away from the center (degree<=1)
854 f2fe7e28 Leszek Koltunski
 *
855
 * @param sink   The current degree of the Effect.
856 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
857 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
858
 * @return       ID of the effect added, or -1 if we failed to add one.
859 6a06a912 Leszek Koltunski
 */
860 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center, Data4D region)
861 6a06a912 Leszek Koltunski
    {
862 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SINK, sink, center, region);
863 6a06a912 Leszek Koltunski
    }
864
865
///////////////////////////////////////////////////////////////////////////////////////////////////
866
/**
867 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
868
 * away from the center (degree<=1)
869
 *
870
 * @param sink   The current degree of the Effect.
871 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
872 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
873 6a06a912 Leszek Koltunski
 */
874 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center)
875 d425545a Leszek Koltunski
    {
876
    return mV.add(EffectNames.SINK, sink, center);
877
    }
878 6a06a912 Leszek Koltunski
879 82ee855a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
880
/**
881
 * Pull all points around the center of the Effect towards a line passing through the center
882
 * (that's if degree>=1) or push them away from the line (degree<=1)
883
 *
884
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
885
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
886
 * @param region Region that masks the Effect.
887
 * @return       ID of the effect added, or -1 if we failed to add one.
888
 */
889
  public long pinch(Data2D pinch, Data3D center, Data4D region)
890
    {
891
    return mV.add(EffectNames.PINCH, pinch, center, region);
892
    }
893
894
///////////////////////////////////////////////////////////////////////////////////////////////////
895
/**
896
 * Pull all points around the center of the Effect towards a line passing through the center
897
 * (that's if degree>=1) or push them away from the line (degree<=1)
898
 *
899
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
900
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
901
 * @return       ID of the effect added, or -1 if we failed to add one.
902
 */
903
  public long pinch(Data2D pinch, Data3D center)
904
    {
905
    return mV.add(EffectNames.PINCH, pinch, center);
906
    }
907
908 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////  
909
/**
910 f2fe7e28 Leszek Koltunski
 * Rotate part of the Object around the Center of the Effect by a certain angle.
911
 *
912 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
913 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
914 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
915
 * @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, Data4D region)
918 6a06a912 Leszek Koltunski
    {    
919 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SWIRL, swirl, center, region);
920 6a06a912 Leszek Koltunski
    }
921
922
///////////////////////////////////////////////////////////////////////////////////////////////////
923
/**
924 f2fe7e28 Leszek Koltunski
 * Rotate the whole Object around the Center of the Effect by a certain angle.
925
 *
926 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
927 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
928 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
929 6a06a912 Leszek Koltunski
 */
930 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center)
931 d425545a Leszek Koltunski
    {
932
    return mV.add(EffectNames.SWIRL, swirl, center);
933
    }
934 4fde55a0 Leszek Koltunski
935
///////////////////////////////////////////////////////////////////////////////////////////////////
936
/**
937
 * Directional, sinusoidal wave effect.
938
 *
939 350cc2f5 Leszek Koltunski
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
940 ea16dc89 Leszek Koltunski
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
941 350cc2f5 Leszek Koltunski
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
942
 *               describe the 'direction' of the wave.
943 3695d6fa Leszek Koltunski
 *               <p>
944 d0c902b8 Leszek Koltunski
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
945
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
946
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
947
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
948 3695d6fa Leszek Koltunski
 *               <p>
949
 *               <p>
950 d0c902b8 Leszek Koltunski
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
951
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
952
 *               will be sine shapes.
953 3695d6fa Leszek Koltunski
 *               <p>
954 d0c902b8 Leszek Koltunski
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
955
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
956
 *               YZ-plane with be sine shapes.
957 3695d6fa Leszek Koltunski
 *               <p>
958 d0c902b8 Leszek Koltunski
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
959 350cc2f5 Leszek Koltunski
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
960
 *               value if sin at this point.
961 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
962 4fde55a0 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
963
 */
964 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center)
965 4fde55a0 Leszek Koltunski
    {
966 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.WAVE, wave, center, null);
967 4fde55a0 Leszek Koltunski
    }
968
969
///////////////////////////////////////////////////////////////////////////////////////////////////
970
/**
971
 * Directional, sinusoidal wave effect.
972
 *
973 3d590d8d Leszek Koltunski
 * @param wave   see {@link DistortedObject#wave(Data5D,Data3D)}
974 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
975 4fde55a0 Leszek Koltunski
 * @param region Region that masks the Effect.
976
 * @return       ID of the effect added, or -1 if we failed to add one.
977
 */
978 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center, Data4D region)
979 4fde55a0 Leszek Koltunski
    {
980
    return mV.add(EffectNames.WAVE, wave, center, region);
981
    }
982 f2fe7e28 Leszek Koltunski
  }