Project

General

Profile

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

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

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