Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedObject.java @ 77fcb24d

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