Revision cacc63de
Added by Leszek Koltunski about 8 years ago
src/main/java/org/distorted/library/Distorted.java | ||
---|---|---|
37 | 37 |
public class Distorted |
38 | 38 |
{ |
39 | 39 |
/** |
40 |
* When creating an instance of a DistortedObject from another instance, do not clone anything.
|
|
40 |
* When creating an instance of a DistortedTexture (or Tree) from another instance, do not clone anything.
|
|
41 | 41 |
* Used in the copy constructor. |
42 | 42 |
*/ |
43 | 43 |
public static final int CLONE_NOTHING = 0x0; |
44 | 44 |
/** |
45 |
* When creating an instance of a DistortedObject from another instance, clone the Bitmap that's
|
|
46 |
* backing up our DistortedObject.
|
|
45 |
* When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
|
|
46 |
* backing up our DistortedTexture.
|
|
47 | 47 |
* <p> |
48 |
* This way we can have two DistortedObjects, both backed up by the same Bitmap, to which we can
|
|
48 |
* This way we can have two DistortedTextures, both backed up by the same Bitmap, to which we can
|
|
49 | 49 |
* apply different effects. Used in the copy constructor. |
50 | 50 |
*/ |
51 | 51 |
public static final int CLONE_BITMAP = 0x1; |
52 | 52 |
/** |
53 |
* When creating an instance of a DistortedObject from another instance, clone the Matrix Effects.
|
|
53 |
* When creating an instance of a DistortedEffects from another instance, clone the Matrix Effects.
|
|
54 | 54 |
* <p> |
55 |
* This way we can have two different DistortedObjects with different Bitmaps behind them, both |
|
56 |
* always displayed in exactly the same place on the screen. Applying any matrix-based effect to |
|
57 |
* one of them automatically applies the effect to the other. Used in the copy constructor. |
|
55 |
* This way we can have two different DistortedEffects sharing the MATRIX queue. |
|
58 | 56 |
*/ |
59 | 57 |
public static final int CLONE_MATRIX = 0x2; |
60 | 58 |
/** |
61 |
* When creating an instance of a DistortedObject from another instance, clone the Vertex Effects.
|
|
59 |
* When creating an instance of a DistortedEffects from another instance, clone the Vertex Effects.
|
|
62 | 60 |
* <p> |
63 |
* This way we can have two different DistortedObjects with different Bitmaps behind them, both |
|
64 |
* always with the same Vertex effects. Applying any vertex-based effect to one of them automatically |
|
65 |
* applies the effect to the other. Used in the copy constructor. |
|
61 |
* This way we can have two different DistortedEffects sharing the VERTEX queue. |
|
66 | 62 |
*/ |
67 | 63 |
public static final int CLONE_VERTEX = 0x4; |
68 | 64 |
/** |
69 |
* When creating an instance of a DistortedObject from another instance, clone the Fragment Effects.
|
|
65 |
* When creating an instance of a DistortedEffects from another instance, clone the Fragment Effects.
|
|
70 | 66 |
* <p> |
71 |
* This way we can have two different DistortedObjects with different Bitmaps behind them, both |
|
72 |
* always with the same Fragment effects. Applying any fragment-based effect to one of them automatically |
|
73 |
* applies the effect to the other. Used in the copy constructor. |
|
67 |
* This way we can have two different DistortedEffects sharing the FRAGMENT queue. |
|
74 | 68 |
*/ |
75 | 69 |
public static final int CLONE_FRAGMENT= 0x8; |
76 | 70 |
/** |
77 | 71 |
* When creating an instance of a DistortedTree from another instance, clone the children Nodes. |
78 | 72 |
* <p> |
79 |
* This is mainly useful for creating many similar sub-trees of Bitmaps and rendering then at different places
|
|
80 |
* on the screen, with (optionally) different effects of the top-level root Bitmap.
|
|
73 |
* This is mainly useful for creating many similar sub-trees and rendering then at different places |
|
74 |
* on the screen with (optionally) different Effects.
|
|
81 | 75 |
*/ |
82 | 76 |
public static final int CLONE_CHILDREN= 0x10; |
83 | 77 |
|
... | ... | |
391 | 385 |
|
392 | 386 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
393 | 387 |
/** |
394 |
* Sets the maximum number of Matrix effects that can be applied to a single DistortedObject at one time.
|
|
388 |
* Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
|
|
395 | 389 |
* This can fail if: |
396 | 390 |
* <ul> |
397 | 391 |
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE) |
398 | 392 |
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called |
399 | 393 |
* before the Vertex Shader gets compiled, i.e. before the call to {@link #onSurfaceCreated}. After this |
400 | 394 |
* time only decreasing the value of 'max' is permitted. |
401 |
* <li>Furthermore, this needs to be called before any DistortedObject gets created.
|
|
395 |
* <li>Furthermore, this needs to be called before any DistortedEffects gets created.
|
|
402 | 396 |
* </ul> |
403 | 397 |
* |
404 | 398 |
* @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater |
... | ... | |
412 | 406 |
|
413 | 407 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
414 | 408 |
/** |
415 |
* Sets the maximum number of Vertex effects that can be applied to a single DistortedObject at one time.
|
|
409 |
* Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
|
|
416 | 410 |
* This can fail if: |
417 | 411 |
* <ul> |
418 | 412 |
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE) |
419 | 413 |
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called |
420 | 414 |
* before the Vertex Shader gets compiled, i.e. before the call to {@link #onSurfaceCreated}. After this |
421 | 415 |
* time only decreasing the value of 'max' is permitted. |
422 |
* <li>Furthermore, this needs to be called before any DistortedObject gets created.
|
|
416 |
* <li>Furthermore, this needs to be called before any DistortedEffects get created.
|
|
423 | 417 |
* </ul> |
424 | 418 |
* |
425 | 419 |
* @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater |
... | ... | |
433 | 427 |
|
434 | 428 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
435 | 429 |
/** |
436 |
* Sets the maximum number of Fragment effects that can be applied to a single DistortedObject at one time.
|
|
430 |
* Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
|
|
437 | 431 |
* This can fail if: |
438 | 432 |
* <ul> |
439 | 433 |
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE) |
440 | 434 |
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called |
441 | 435 |
* before the Fragment Shader gets compiled, i.e. before the call to {@link #onSurfaceCreated}. After this |
442 | 436 |
* time only decreasing the value of 'max' is permitted. |
443 |
* <li>Furthermore, this needs to be called before any DistortedObject gets created.
|
|
437 |
* <li>Furthermore, this needs to be called before any DistortedEffects get created.
|
|
444 | 438 |
* </ul> |
445 | 439 |
* |
446 | 440 |
* @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater |
src/main/java/org/distorted/library/EffectMessageSender.java | ||
---|---|---|
35 | 35 |
long mEffectID; |
36 | 36 |
int mEffectName; |
37 | 37 |
long mBitmapID; |
38 |
String mStr; |
|
39 | 38 |
|
40 |
Message(EffectListener l, EffectMessage m, long id, int name, long bmpID, String str)
|
|
39 |
Message(EffectListener l, EffectMessage m, long id, int name, long bmpID) |
|
41 | 40 |
{ |
42 | 41 |
mListener = l; |
43 | 42 |
mMessage = m; |
44 | 43 |
mEffectID = id; |
45 | 44 |
mEffectName = name; |
46 | 45 |
mBitmapID = bmpID; |
47 |
mStr = str; |
|
48 | 46 |
} |
49 | 47 |
} |
50 | 48 |
|
... | ... | |
108 | 106 |
while( mList.size()>0 ) |
109 | 107 |
{ |
110 | 108 |
tmp = mList.remove(0); |
111 |
tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, EffectNames.getName(tmp.mEffectName), |
|
112 |
tmp.mBitmapID, tmp.mStr); |
|
109 |
tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, EffectNames.getName(tmp.mEffectName),tmp.mBitmapID); |
|
113 | 110 |
} |
114 | 111 |
|
115 | 112 |
synchronized(mThis) |
... | ... | |
131 | 128 |
|
132 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
133 | 130 |
|
134 |
static void newMessage(EffectListener l, EffectMessage m, long id, int name, long bmpID, String str)
|
|
131 |
static void newMessage(EffectListener l, EffectMessage m, long id, int name, long bmpID) |
|
135 | 132 |
{ |
136 |
Message msg = mThis.new Message(l,m,id,name,bmpID,str);
|
|
133 |
Message msg = mThis.new Message(l,m,id,name,bmpID); |
|
137 | 134 |
mList.add(msg); |
138 | 135 |
|
139 | 136 |
synchronized(mThis) |
src/main/java/org/distorted/library/EffectNames.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
/** |
24 |
* Names of Effects one can apply to DistortedObjects.
|
|
24 |
* Names of Effects one can add to the DistortedEffects queues.
|
|
25 | 25 |
* <p> |
26 | 26 |
* Effect's 'Type' is one of the constants defined in {@link EffectTypes}. |
27 | 27 |
* </p> |
... | ... | |
144 | 144 |
SWIRL ( EffectTypes.VERTEX , new float[] {0.0f} , 1, true, true ), |
145 | 145 |
/** |
146 | 146 |
* Directional sinusoidal wave effect. The direction of the wave is given by the 'angle' |
147 |
* parameters. Details: {@link DistortedObject#wave(org.distorted.library.type.Data5D,org.distorted.library.type.Data3D)}
|
|
147 |
* parameters. Details: {@link DistortedEffects#wave(org.distorted.library.type.Data5D,org.distorted.library.type.Data3D)}
|
|
148 | 148 |
* <p> |
149 | 149 |
* Uniforms: (amplitude,length,phase,angleAlpha, |
150 | 150 |
* angleBeta, centerX,centerY,centerZ, |
src/main/java/org/distorted/library/EffectQueue.java | ||
---|---|---|
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
95 |
// Only max Byte.MAX_VALUE concurrent effects per DistortedObject.
|
|
95 |
// Only max Byte.MAX_VALUE concurrent effects per DistortedEffects object.
|
|
96 | 96 |
// If you want more, change type of the mNumEffects, mIDIndex and mFreeIndexes variables to shorts. |
97 |
// (although probably this many uniforms will not fit in the shaders anyway!) |
|
97 | 98 |
|
98 | 99 |
static boolean setMax(int index, int m) |
99 | 100 |
{ |
... | ... | |
216 | 217 |
EffectMessage.EFFECT_REMOVED, |
217 | 218 |
(removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedName).type, |
218 | 219 |
removedName, |
219 |
mObjectID, |
|
220 |
null); |
|
220 |
mObjectID); |
|
221 | 221 |
} |
222 | 222 |
} |
223 | 223 |
|
... | ... | |
266 | 266 |
EffectMessage.EFFECT_REMOVED, |
267 | 267 |
(removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedName).type, |
268 | 268 |
removedName, |
269 |
mObjectID, |
|
270 |
null); |
|
269 |
mObjectID); |
|
271 | 270 |
} |
272 | 271 |
|
273 | 272 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/EffectQueueFragment.java | ||
---|---|---|
76 | 76 |
EffectMessage.EFFECT_FINISHED, |
77 | 77 |
(mID[i]<<EffectTypes.LENGTH)+EffectTypes.FRAGMENT.type, |
78 | 78 |
mName[i], |
79 |
mObjectID, |
|
80 |
null); |
|
79 |
mObjectID); |
|
81 | 80 |
|
82 | 81 |
if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) ) |
83 | 82 |
{ |
src/main/java/org/distorted/library/EffectQueueMatrix.java | ||
---|---|---|
115 | 115 |
EffectMessage.EFFECT_FINISHED, |
116 | 116 |
(mID[i]<<EffectTypes.LENGTH)+EffectTypes.MATRIX.type, |
117 | 117 |
mName[i], |
118 |
mObjectID, |
|
119 |
null); |
|
118 |
mObjectID); |
|
120 | 119 |
|
121 | 120 |
if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) ) |
122 | 121 |
{ |
src/main/java/org/distorted/library/EffectQueueVertex.java | ||
---|---|---|
86 | 86 |
EffectMessage.EFFECT_FINISHED, |
87 | 87 |
(mID[i]<<EffectTypes.LENGTH)+EffectTypes.VERTEX.type, |
88 | 88 |
mName[i], |
89 |
mObjectID, |
|
90 |
null); |
|
89 |
mObjectID); |
|
91 | 90 |
|
92 | 91 |
if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) ) |
93 | 92 |
{ |
src/main/java/org/distorted/library/EffectTypes.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
/** |
24 |
* Types of Effects one can apply to DistortedObjects.
|
|
24 |
* Types of Effects one can add to the DistortedEffects queues.
|
|
25 | 25 |
* <p> |
26 | 26 |
* Each effect type goes to an independent queue; the queues get executed one-by-one |
27 | 27 |
* and are each a class descendant from EffectQueue. |
src/main/java/org/distorted/library/GridCubes.java | ||
---|---|---|
162 | 162 |
} |
163 | 163 |
*/ |
164 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
165 |
// desc is guaranteed to be padded with 0s in the end (DistortedCubes constructor does it) |
|
166 | 165 |
|
167 | 166 |
private void prepareDataStructures(int cols, String desc, boolean frontOnly) |
168 | 167 |
{ |
src/main/java/org/distorted/library/GridFlat.java | ||
---|---|---|
30 | 30 |
private int remainingVert; |
31 | 31 |
|
32 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 |
// Create a flat, full grid. cols and rows is guaranteed (by DistortedBitmap constructor) |
|
34 |
// to be in 1,2,...,256. |
|
33 |
// Create a flat, full grid. |
|
35 | 34 |
|
36 | 35 |
private void computeNumberOfVertices(int cols, int rows) |
37 | 36 |
{ |
src/main/java/org/distorted/library/message/EffectListener.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
/** |
27 | 27 |
* This interface lets users of the Distorted library get notified when something happens to one of the effects. |
28 |
* To receive the notifications, we first have to register with a call to {@link org.distorted.library.DistortedObject#addEventListener(EffectListener)}.
|
|
28 |
* To receive the notifications, we first have to register with a call to {@link org.distorted.library.DistortedEffects#registerForMessages(EffectListener)}.
|
|
29 | 29 |
* List of all possible events that can happen is defined in {@link EffectMessage} |
30 | 30 |
*/ |
31 | 31 |
|
... | ... | |
36 | 36 |
* |
37 | 37 |
* @param eventType Type of event that happened. |
38 | 38 |
* @param effectID ID of the effect the event happened to. This ID must have been previously returned by one |
39 |
* of the DistortedObject.{deform,distort,move,...} functions.
|
|
39 |
* of the DistortedEffects.{deform,distort,move,...} functions.
|
|
40 | 40 |
* @param effectName Name of the effect as defined by EffectNames. |
41 |
* @param objectID the ID of the DistortedObject object, as returned by {@link org.distorted.library.DistortedObject#getID()}, |
|
42 |
* this event happened to. If the Object has been created using a copy constructor |
|
43 |
* from another instance of DistortedObject, the ID here will be the one of the original object. |
|
44 |
* @param message Any message string associated with it. 'Failed' event types have one. |
|
41 |
* @param objectID the ID of the DistortedEffects object, as returned by {@link org.distorted.library.DistortedEffects#getID()}, |
|
42 |
* this event happened to. |
|
45 | 43 |
* @see EffectMessage |
46 | 44 |
* @see EffectNames |
47 | 45 |
*/ |
48 | 46 |
|
49 |
void effectMessage(final EffectMessage eventType, final long effectID, final EffectNames effectName, final long objectID, final String message);
|
|
47 |
void effectMessage(final EffectMessage eventType, final long effectID, final EffectNames effectName, final long objectID); |
|
50 | 48 |
} |
51 | 49 |
|
52 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/message/EffectMessage.java | ||
---|---|---|
30 | 30 |
/** |
31 | 31 |
* The effect has been removed. This can happen if: |
32 | 32 |
* <ul> |
33 |
* <li> someone explicitly removed the effect with a call to {@link org.distorted.library.DistortedObject#abortEffect(long)}
|
|
33 |
* <li> someone explicitly removed the effect with a call to {@link org.distorted.library.DistortedEffects#abortEffect(long)}
|
|
34 | 34 |
* (or one of the other 'abort' methods) |
35 | 35 |
* <li> the interpolation of the effect has finished and the end result is equal to the effect's unity. |
36 | 36 |
* </ul> |
... | ... | |
49 | 49 |
* If then the end effect is equal to the effect's unity, then immediately after this message you |
50 | 50 |
* will also get a EFFECT_REMOVED message. |
51 | 51 |
*/ |
52 |
EFFECT_FINISHED, |
|
53 |
|
|
54 |
/** |
|
55 |
* The effect has failed to properly execute. |
|
56 |
* <p> |
|
57 |
* Currently only OTHER effects (saving to PNG file and to a MP4 movie) can fail. |
|
58 |
*/ |
|
59 |
EFFECT_FAILED |
|
52 |
EFFECT_FINISHED |
|
60 | 53 |
} |
61 | 54 |
|
62 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/type/Dynamic3D.java | ||
---|---|---|
31 | 31 |
{ |
32 | 32 |
private Vector<Static3D> vv; |
33 | 33 |
private Static3D prev, curr, next; |
34 |
/* |
|
35 |
private float a0,a1,a2; |
|
36 |
private float f0, f1; |
|
37 |
private float b00,b01,b02; |
|
38 |
private float b10,b11,b12; |
|
39 |
private float b20,b21,b22; |
|
40 |
private float oldTime; |
|
41 |
*/ |
|
34 |
|
|
42 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
43 | 36 |
// no array bounds checking! |
44 | 37 |
|
src/main/java/org/distorted/library/type/DynamicQuat.java | ||
---|---|---|
37 | 37 |
// omega, sinOmega, cosOmega - angle between pair of quaternions, its sinus and cosinus. |
38 | 38 |
// |
39 | 39 |
// (vx,vy,vz,vw) is the original vector from vv (copied here so when interpolating we can see if it is |
40 |
// still valid and if not - rebuild the Cache |
|
40 |
// still valid and if not - rebuild the Cache.
|
|
41 | 41 |
|
42 | 42 |
private class VectorCacheQuat |
43 | 43 |
{ |
... | ... | |
398 | 398 |
} |
399 | 399 |
|
400 | 400 |
} |
401 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
402 |
// |
src/main/java/org/distorted/library/type/Static1D.java | ||
---|---|---|
22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
/** |
24 | 24 |
* A 1-dimensional data structure containing a single float. The float has no particular meaning; |
25 |
* when this data structure is used in Interpolators, we can think of it as a 1-dimensional Point
|
|
25 |
* when this data structure is used in Dynamics, we can think of it as a 1-dimensional Point
|
|
26 | 26 |
* a few of which the Dynamic interpolates between. |
27 | 27 |
*/ |
28 | 28 |
|
... | ... | |
106 | 106 |
{ |
107 | 107 |
return x; |
108 | 108 |
} |
109 |
|
|
110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
111 |
// end of class |
|
109 |
|
|
112 | 110 |
} |
src/main/java/org/distorted/library/type/Static2D.java | ||
---|---|---|
22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
/** |
24 | 24 |
* A 2-dimensional data structure containing two floats. The floats have no particular meaning; |
25 |
* when this data structure is used in Interpolators, we can think of it as a 2-dimensional Point
|
|
25 |
* when this data structure is used in Dynamics, we can think of it as a 2-dimensional Point
|
|
26 | 26 |
* a few of which the Dynamic interpolates between. |
27 | 27 |
*/ |
28 | 28 |
|
... | ... | |
115 | 115 |
return y; |
116 | 116 |
} |
117 | 117 |
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
// end of class |
|
120 | 118 |
} |
src/main/java/org/distorted/library/type/Static3D.java | ||
---|---|---|
22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
/** |
24 | 24 |
* A 3-dimensional data structure containing three floats. The floats have no particular meaning; |
25 |
* when this data structure is used in Interpolators, we can think of it as a 3-dimensional Point
|
|
25 |
* when this data structure is used in Dynamics, we can think of it as a 3-dimensional Point
|
|
26 | 26 |
* a few of which the Dynamic interpolates between. |
27 | 27 |
*/ |
28 | 28 |
|
... | ... | |
120 | 120 |
{ |
121 | 121 |
return z; |
122 | 122 |
} |
123 |
|
|
124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
125 |
// end of class |
|
123 |
|
|
126 | 124 |
} |
src/main/java/org/distorted/library/type/Static4D.java | ||
---|---|---|
126 | 126 |
{ |
127 | 127 |
return w; |
128 | 128 |
} |
129 |
|
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
// end of class |
|
129 |
|
|
132 | 130 |
} |
src/main/java/org/distorted/library/type/Static5D.java | ||
---|---|---|
132 | 132 |
{ |
133 | 133 |
return v; |
134 | 134 |
} |
135 |
|
|
136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
137 |
// end of class |
|
135 |
|
|
138 | 136 |
} |
Also available in: Unified diff
Fix Lint warnings, correct a lot of comments, adjust EffectListener interface.