Project

General

Profile

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

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

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