Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 985ea9c5

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