Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 0a046359

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