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