Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 1a940548

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