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