Project

General

Profile

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

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

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