Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 5fd28c26

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