Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffectQueues.java @ 3ef3364d

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 6a06a912 Leszek Koltunski
package org.distorted.library;
21
22
import android.opengl.GLES20;
23
24 e458a4ba Leszek Koltunski
import org.distorted.library.message.EffectListener;
25 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data1D;
26 f2fe7e28 Leszek Koltunski
import org.distorted.library.type.Data2D;
27 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data3D;
28
import org.distorted.library.type.Data4D;
29 350cc2f5 Leszek Koltunski
import org.distorted.library.type.Data5D;
30 568b29d8 Leszek Koltunski
import org.distorted.library.type.Static3D;
31 a4835695 Leszek Koltunski
32 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
33 b329f352 Leszek Koltunski
/**
34 4e2382f3 Leszek Koltunski
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
35 b73dcaa7 Leszek Koltunski
 * <p>
36 4e2382f3 Leszek Koltunski
 * The queues hold actual effects to be applied to a given (DistortedTexture,GridObject) combo.
37 b329f352 Leszek Koltunski
 */
38 4e2382f3 Leszek Koltunski
public class DistortedEffectQueues
39 d425545a Leszek Koltunski
  {
40 8e34674e Leszek Koltunski
  private static long mNextID =0;
41 4e2382f3 Leszek Koltunski
  private long mID;
42 8e34674e Leszek Koltunski
43 3d590d8d Leszek Koltunski
  private EffectQueueMatrix    mM;
44
  private EffectQueueFragment  mF;
45
  private EffectQueueVertex    mV;
46
47
  private boolean matrixCloned, vertexCloned, fragmentCloned;
48 985ea9c5 Leszek Koltunski
49 9361b337 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
50 6a06a912 Leszek Koltunski
    
51 4e2382f3 Leszek Koltunski
  private void initializeEffectLists(DistortedEffectQueues d, int flags)
52 d425545a Leszek Koltunski
    {
53 015642fb Leszek Koltunski
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
54 6a06a912 Leszek Koltunski
      {
55 d425545a Leszek Koltunski
      mM = d.mM;
56
      matrixCloned = true;
57
      }
58
    else
59
      {
60 4e2382f3 Leszek Koltunski
      mM = new EffectQueueMatrix(mID);
61 d425545a Leszek Koltunski
      matrixCloned = false;
62
      }
63 6a06a912 Leszek Koltunski
    
64 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
65
      {
66
      mV = d.mV;
67
      vertexCloned = true;
68
      }
69
    else
70
      {
71 4e2382f3 Leszek Koltunski
      mV = new EffectQueueVertex(mID);
72 d425545a Leszek Koltunski
      vertexCloned = false;
73
      }
74 6a06a912 Leszek Koltunski
    
75 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
76
      {
77
      mF = d.mF;
78
      fragmentCloned = true;
79 6a06a912 Leszek Koltunski
      }
80 d425545a Leszek Koltunski
    else
81
      {
82 4e2382f3 Leszek Koltunski
      mF = new EffectQueueFragment(mID);
83 d425545a Leszek Koltunski
      fragmentCloned = false;
84
      }
85
    }
86 6a06a912 Leszek Koltunski
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
   
89 4e2382f3 Leszek Koltunski
  void drawPriv(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
90 d425545a Leszek Koltunski
    {
91 8e34674e Leszek Koltunski
    DistortedFramebuffer.deleteAllMarked();
92 16d8b8f3 Leszek Koltunski
93 ed13a5de Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
94 0a046359 Leszek Koltunski
95 3ef3364d Leszek Koltunski
    float halfZ = tex.mHalfX*grid.zFactor;
96
97 d425545a Leszek Koltunski
    mM.compute(currTime);
98 3ef3364d Leszek Koltunski
    mM.send(df,tex.mHalfX,tex.mHalfY,halfZ);
99 6a06a912 Leszek Koltunski
      
100 d425545a Leszek Koltunski
    mV.compute(currTime);
101 3ef3364d Leszek Koltunski
    mV.send(tex.mHalfX,tex.mHalfY,halfZ);
102 6a06a912 Leszek Koltunski
        
103 d425545a Leszek Koltunski
    mF.compute(currTime);
104 4e2382f3 Leszek Koltunski
    mF.send(tex.mHalfX,tex.mHalfY);
105 a56bc359 Leszek Koltunski
106
    grid.draw();
107 d425545a Leszek Koltunski
    }
108 6a06a912 Leszek Koltunski
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
   
111 4e2382f3 Leszek Koltunski
  void drawNoEffectsPriv(DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
112 d425545a Leszek Koltunski
    {
113 ed13a5de Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
114 0a046359 Leszek Koltunski
115 3ef3364d Leszek Koltunski
    mM.sendZero(df,tex.mHalfX,tex.mHalfY,tex.mHalfX*grid.zFactor);
116 d425545a Leszek Koltunski
    mV.sendZero();
117
    mF.sendZero();
118 a56bc359 Leszek Koltunski
119
    grid.draw();
120 d425545a Leszek Koltunski
    }
121 6a06a912 Leszek Koltunski
    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123
   
124 8e34674e Leszek Koltunski
  private void releasePriv()
125 d425545a Leszek Koltunski
    {
126 8e34674e Leszek Koltunski
    if( !matrixCloned  ) mM.abortAll(false);
127
    if( !vertexCloned  ) mV.abortAll(false);
128
    if( !fragmentCloned) mF.abortAll(false);
129 d425545a Leszek Koltunski
130 4e2382f3 Leszek Koltunski
    mM = null;
131
    mV = null;
132
    mF = null;
133 8e34674e Leszek Koltunski
    }
134
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
// PUBLIC API
137 ada90d33 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
138 d425545a Leszek Koltunski
/**
139 4e2382f3 Leszek Koltunski
 * Create empty effect queue.
140 d425545a Leszek Koltunski
 */
141 4e2382f3 Leszek Koltunski
  public DistortedEffectQueues()
142 d425545a Leszek Koltunski
    {
143 4e2382f3 Leszek Koltunski
    mID = mNextID++;
144
    initializeEffectLists(this,0);
145 d425545a Leszek Koltunski
    }
146 ada90d33 Leszek Koltunski
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148 d425545a Leszek Koltunski
/**
149 4e2382f3 Leszek Koltunski
 * Copy constructor.
150 d425545a Leszek Koltunski
 * <p>
151
 * Whatever we do not clone gets created just like in the default constructor.
152
 * We only call this from the descendant's classes' constructors where we have to pay attention
153
 * to give it the appropriate type of a DistortedObject!
154
 *
155
 * @param dc    Source object to create our object from
156
 * @param flags A bitmask of values specifying what to copy.
157 e6ab30eb Leszek Koltunski
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
158 d425545a Leszek Koltunski
 */
159 4e2382f3 Leszek Koltunski
  public DistortedEffectQueues(DistortedEffectQueues dc, int flags)
160 d425545a Leszek Koltunski
    {
161 8e34674e Leszek Koltunski
    mID = mNextID++;
162 4e2382f3 Leszek Koltunski
    initializeEffectLists(dc,flags);
163 d425545a Leszek Koltunski
    }
164 ada90d33 Leszek Koltunski
165 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
166
/**
167
 * Draw the DistortedObject to the location specified by current Matrix effects.    
168
 *     
169 d1e740c5 Leszek Koltunski
 * @param currTime current time, in milliseconds.
170 5d923c17 Leszek Koltunski
 *        This gets passed on to Dynamics inside the Effects that are currently applied to the
171 6a06a912 Leszek Koltunski
 *        Object.
172
 */
173 4e2382f3 Leszek Koltunski
  public void draw(long currTime, DistortedTexture tex, GridObject grid)
174 d425545a Leszek Koltunski
    {
175
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
176 4e2382f3 Leszek Koltunski
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
177
    drawPriv(currTime, tex, grid, Distorted.mFramebuffer);
178 d425545a Leszek Koltunski
    }
179 d1e740c5 Leszek Koltunski
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
/**
182
 * Draw the DistortedObject to the Framebuffer passed.
183
 *
184
 * @param currTime Current time, in milliseconds.
185
 * @param df       Framebuffer to render this to.
186
 */
187 4e2382f3 Leszek Koltunski
  public void draw(long currTime, DistortedTexture tex, GridObject grid, DistortedFramebuffer df)
188 d1e740c5 Leszek Koltunski
    {
189
    df.setAsOutput();
190 4e2382f3 Leszek Koltunski
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex.mTextureDataH[0]);
191
    drawPriv(currTime, tex, grid, df);
192 d1e740c5 Leszek Koltunski
    }
193
194 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
195
/**
196
 * Releases all resources.
197
 */
198 8e34674e Leszek Koltunski
  public synchronized void delete()
199 d425545a Leszek Koltunski
    {
200
    releasePriv();
201
    }
202 6a06a912 Leszek Koltunski
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204
/**
205 4e2382f3 Leszek Koltunski
 * Returns unique ID of this instance.
206
 *
207
 * @return ID of the object.
208 6a06a912 Leszek Koltunski
 */
209 4e2382f3 Leszek Koltunski
  public long getID()
210 d425545a Leszek Koltunski
      {
211 4e2382f3 Leszek Koltunski
      return mID;
212 d425545a Leszek Koltunski
      }
213 4e2382f3 Leszek Koltunski
214 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
215
/**
216
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
217 9351ad55 Leszek Koltunski
 * to one of the Effects that are currently applied to the DistortedObject.
218 6a06a912 Leszek Koltunski
 * 
219
 * @param el A class implementing the EffectListener interface that wants to get notifications.
220
 */
221 d425545a Leszek Koltunski
  public void addEventListener(EffectListener el)
222
    {
223
    mV.addListener(el);
224
    mF.addListener(el);
225
    mM.addListener(el);
226
    }
227 6a06a912 Leszek Koltunski
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
/**
230
 * Removes the calling class from the list of Listeners.
231
 * 
232
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
233
 */
234 d425545a Leszek Koltunski
  public void removeEventListener(EffectListener el)
235
    {
236
    mV.removeListener(el);
237
    mF.removeListener(el);
238
    mM.removeListener(el);
239
    }
240 6a06a912 Leszek Koltunski
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242
/**
243 d07f2950 Leszek Koltunski
 * Aborts all Effects.
244
 * @return Number of effects aborted.
245 6a06a912 Leszek Koltunski
 */
246 d425545a Leszek Koltunski
  public int abortAllEffects()
247 6a06a912 Leszek Koltunski
      {
248 0df17fad Leszek Koltunski
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
249 6a06a912 Leszek Koltunski
      }
250
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252
/**
253 d07f2950 Leszek Koltunski
 * Aborts all Effects of a given type, for example all MATRIX Effects.
254 6a06a912 Leszek Koltunski
 * 
255 d07f2950 Leszek Koltunski
 * @param type one of the constants defined in {@link EffectTypes}
256
 * @return Number of effects aborted.
257 6a06a912 Leszek Koltunski
 */
258 d425545a Leszek Koltunski
  public int abortEffects(EffectTypes type)
259
    {
260
    switch(type)
261 6a06a912 Leszek Koltunski
      {
262 0df17fad Leszek Koltunski
      case MATRIX  : return mM.abortAll(true);
263
      case VERTEX  : return mV.abortAll(true);
264
      case FRAGMENT: return mF.abortAll(true);
265 d425545a Leszek Koltunski
      default      : return 0;
266 6a06a912 Leszek Koltunski
      }
267 d425545a Leszek Koltunski
    }
268 6a06a912 Leszek Koltunski
    
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
/**
271
 * Aborts a single Effect.
272
 * 
273
 * @param id ID of the Effect we want to abort.
274 476bbc81 Leszek Koltunski
 * @return number of Effects aborted. Always either 0 or 1.
275 6a06a912 Leszek Koltunski
 */
276 d425545a Leszek Koltunski
  public int abortEffect(long id)
277
    {
278
    int type = (int)(id&EffectTypes.MASK);
279 1e438fc7 Leszek Koltunski
280 d425545a Leszek Koltunski
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
281
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
282
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
283 1e438fc7 Leszek Koltunski
284 d425545a Leszek Koltunski
    return 0;
285
    }
286 6a06a912 Leszek Koltunski
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288
/**
289 e8c81a8e Leszek Koltunski
 * Abort all Effects of a given name, for example all rotations.
290 6a06a912 Leszek Koltunski
 * 
291 d07f2950 Leszek Koltunski
 * @param name one of the constants defined in {@link EffectNames}
292 476bbc81 Leszek Koltunski
 * @return number of Effects aborted.
293 6a06a912 Leszek Koltunski
 */
294 d425545a Leszek Koltunski
  public int abortEffects(EffectNames name)
295
    {
296
    switch(name.getType())
297 6a06a912 Leszek Koltunski
      {
298 d425545a Leszek Koltunski
      case MATRIX  : return mM.removeByType(name);
299
      case VERTEX  : return mV.removeByType(name);
300
      case FRAGMENT: return mF.removeByType(name);
301
      default      : return 0;
302 6a06a912 Leszek Koltunski
      }
303 d425545a Leszek Koltunski
    }
304 6a06a912 Leszek Koltunski
    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306
/**
307
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
308
 * 
309
 * @param id Effect ID we want to print info about
310
 * @return <code>true</code> if a single Effect of type effectType has been found.
311
 */
312
    
313 d425545a Leszek Koltunski
  public boolean printEffect(long id)
314
    {
315
    int type = (int)(id&EffectTypes.MASK);
316 1e438fc7 Leszek Koltunski
317 d425545a Leszek Koltunski
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
318
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
319
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
320 1e438fc7 Leszek Koltunski
321 d425545a Leszek Koltunski
    return false;
322
    }
323 6a06a912 Leszek Koltunski
   
324
///////////////////////////////////////////////////////////////////////////////////////////////////   
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326
// Individual effect functions.
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328
// Matrix-based effects
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
/**
331 e8c81a8e Leszek Koltunski
 * Moves the Object by a (possibly changing in time) vector.
332 6a06a912 Leszek Koltunski
 * 
333 568b29d8 Leszek Koltunski
 * @param vector 3-dimensional Data which at any given time will return a Static3D
334 e0a16874 Leszek Koltunski
 *               representing the current coordinates of the vector we want to move the Object with.
335
 * @return       ID of the effect added, or -1 if we failed to add one.
336 6a06a912 Leszek Koltunski
 */
337 568b29d8 Leszek Koltunski
  public long move(Data3D vector)
338 6a06a912 Leszek Koltunski
    {   
339 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.MOVE,vector);
340 6a06a912 Leszek Koltunski
    }
341
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
/**
344 e8c81a8e Leszek Koltunski
 * Scales the Object by (possibly changing in time) 3D scale factors.
345 6a06a912 Leszek Koltunski
 * 
346 d1e740c5 Leszek Koltunski
 * @param scale 3-dimensional Data which at any given time returns a Static3D
347 e0a16874 Leszek Koltunski
 *              representing the current x- , y- and z- scale factors.
348
 * @return      ID of the effect added, or -1 if we failed to add one.
349 6a06a912 Leszek Koltunski
 */
350 568b29d8 Leszek Koltunski
  public long scale(Data3D scale)
351 6a06a912 Leszek Koltunski
    {   
352 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.SCALE,scale);
353 6a06a912 Leszek Koltunski
    }
354
355 2fce34f4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
356
/**
357 e8c81a8e Leszek Koltunski
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
358 2fce34f4 Leszek Koltunski
 *
359
 * @param scale The factor to scale all 3 dimensions with.
360
 * @return      ID of the effect added, or -1 if we failed to add one.
361
 */
362 d425545a Leszek Koltunski
  public long scale(float scale)
363
    {
364
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
365
    }
366 2fce34f4 Leszek Koltunski
367 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
368
/**
369 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
370
 * Static axis of rotation is given by the last parameter.
371
 *
372 9351ad55 Leszek Koltunski
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
373 568b29d8 Leszek Koltunski
 * @param axis   Axis of rotation
374 0df17fad Leszek Koltunski
 * @param center Coordinates of the Point we are rotating around.
375 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
376
 */
377 0df17fad Leszek Koltunski
  public long rotate(Data1D angle, Static3D axis, Data3D center )
378 6a06a912 Leszek Koltunski
    {   
379 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angle, axis, center);
380 6a06a912 Leszek Koltunski
    }
381
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383
/**
384 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
385 2fce34f4 Leszek Koltunski
 * Here both angle and axis can dynamically change.
386 568b29d8 Leszek Koltunski
 *
387
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
388 0df17fad Leszek Koltunski
 * @param center    Coordinates of the Point we are rotating around.
389 568b29d8 Leszek Koltunski
 * @return          ID of the effect added, or -1 if we failed to add one.
390 e0a16874 Leszek Koltunski
 */
391 0df17fad Leszek Koltunski
  public long rotate(Data4D angleaxis, Data3D center)
392 568b29d8 Leszek Koltunski
    {
393 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angleaxis, center);
394 6a06a912 Leszek Koltunski
    }
395
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
/**
398 568b29d8 Leszek Koltunski
 * Rotates the Object by quaternion.
399 0df17fad Leszek Koltunski
 *
400 568b29d8 Leszek Koltunski
 * @param quaternion The quaternion describing the rotation.
401 0df17fad Leszek Koltunski
 * @param center     Coordinates of the Point we are rotating around.
402 568b29d8 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
403 6a06a912 Leszek Koltunski
 */
404 0df17fad Leszek Koltunski
  public long quaternion(Data4D quaternion, Data3D center )
405 568b29d8 Leszek Koltunski
    {
406 0df17fad Leszek Koltunski
    return mM.add(EffectNames.QUATERNION,quaternion,center);
407 6a06a912 Leszek Koltunski
    }
408
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410
/**
411 568b29d8 Leszek Koltunski
 * Shears the Object.
412 6a06a912 Leszek Koltunski
 *
413 8c3cdec5 Leszek Koltunski
 * @param shear   The 3-tuple of shear factors. The first controls level
414
 *                of shearing in the X-axis, second - Y-axis and the third -
415
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
416
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
417 0df17fad Leszek Koltunski
 * @param center  Center of shearing, i.e. the point which stays unmoved.
418 e0a16874 Leszek Koltunski
 * @return        ID of the effect added, or -1 if we failed to add one.
419 6a06a912 Leszek Koltunski
 */
420 0df17fad Leszek Koltunski
  public long shear(Data3D shear, Data3D center)
421 6a06a912 Leszek Koltunski
    {
422 0df17fad Leszek Koltunski
    return mM.add(EffectNames.SHEAR, shear, center);
423 6a06a912 Leszek Koltunski
    }
424
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426
// Fragment-based effects  
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
/**
429 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
430 6a06a912 Leszek Koltunski
 *        
431 2fce34f4 Leszek Koltunski
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
432 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
433
 *               Valid range: <0,1>
434 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
435 2fce34f4 Leszek Koltunski
 * @param region Region this Effect is limited to.
436
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
437
 * @return       ID of the effect added, or -1 if we failed to add one.
438 6a06a912 Leszek Koltunski
 */
439 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
440 6a06a912 Leszek Koltunski
    {
441 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
442 6a06a912 Leszek Koltunski
    }
443
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445
/**
446 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change all three of its RGB components.
447
 *
448
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
449 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
450
 *               Valid range: <0,1>
451 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
452 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
453 6a06a912 Leszek Koltunski
 */
454 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color)
455 6a06a912 Leszek Koltunski
    {
456 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CHROMA, blend, color);
457 6a06a912 Leszek Koltunski
    }
458
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
/**
461 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its transparency level.
462 6a06a912 Leszek Koltunski
 *        
463 2fce34f4 Leszek Koltunski
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
464 e4878781 Leszek Koltunski
 *               moment: pixel.a *= alpha.
465
 *               Valid range: <0,1>
466 d7bbef2f Leszek Koltunski
 * @param region Region this Effect is limited to. 
467 2fce34f4 Leszek Koltunski
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
468 d7bbef2f Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one. 
469 6a06a912 Leszek Koltunski
 */
470 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
471 6a06a912 Leszek Koltunski
    {
472 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
473 6a06a912 Leszek Koltunski
    }
474
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476
/**
477 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its transparency level.
478
 *
479
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
480 e4878781 Leszek Koltunski
 *               given moment: pixel.a *= alpha.
481
 *               Valid range: <0,1>
482 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
483 6a06a912 Leszek Koltunski
 */
484 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha)
485 6a06a912 Leszek Koltunski
    {
486 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.ALPHA, alpha);
487 6a06a912 Leszek Koltunski
    }
488
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490
/**
491 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its brightness level.
492 6a06a912 Leszek Koltunski
 *        
493 2fce34f4 Leszek Koltunski
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
494 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
495 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
496 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
497 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
498 6a06a912 Leszek Koltunski
 */
499 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
500 6a06a912 Leszek Koltunski
    {
501 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
502 6a06a912 Leszek Koltunski
    }
503
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505
/**
506 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its brightness level.
507
 *
508
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
509 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
510 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
511 6a06a912 Leszek Koltunski
 */
512 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness)
513 6a06a912 Leszek Koltunski
    {
514 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.BRIGHTNESS, brightness);
515 6a06a912 Leszek Koltunski
    }
516
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518
/**
519 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its contrast level.
520 6a06a912 Leszek Koltunski
 *        
521 2fce34f4 Leszek Koltunski
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
522 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
523 e0a16874 Leszek Koltunski
 * @param region   Region this Effect is limited to.
524 2fce34f4 Leszek Koltunski
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
525 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
526 6a06a912 Leszek Koltunski
 */
527 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
528 6a06a912 Leszek Koltunski
    {
529 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
530 6a06a912 Leszek Koltunski
    }
531
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
/**
534 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its contrast level.
535
 *
536
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
537 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
538 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
539 6a06a912 Leszek Koltunski
 */
540 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast)
541 6a06a912 Leszek Koltunski
    {
542 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CONTRAST, contrast);
543 6a06a912 Leszek Koltunski
    }
544
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546
/**
547 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its saturation level.
548 6a06a912 Leszek Koltunski
 *        
549 2fce34f4 Leszek Koltunski
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
550 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
551 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
552 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
553 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
554 6a06a912 Leszek Koltunski
 */
555 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
556 6a06a912 Leszek Koltunski
    {
557 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
558 6a06a912 Leszek Koltunski
    }
559
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561
/**
562 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its saturation level.
563
 *
564
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
565 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
566 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
567 6a06a912 Leszek Koltunski
 */
568 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation)
569 6a06a912 Leszek Koltunski
    {
570 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.SATURATION, saturation);
571 6a06a912 Leszek Koltunski
    }
572
573
///////////////////////////////////////////////////////////////////////////////////////////////////
574
// Vertex-based effects  
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
/**
577 e0a16874 Leszek Koltunski
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
578 f2fe7e28 Leszek Koltunski
 *
579
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
580
 *               currently being dragged with.
581 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
582 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
583
 * @return       ID of the effect added, or -1 if we failed to add one.
584 6a06a912 Leszek Koltunski
 */
585 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center, Data4D region)
586 6a06a912 Leszek Koltunski
    {  
587 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, region);
588 6a06a912 Leszek Koltunski
    }
589
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591
/**
592 e0a16874 Leszek Koltunski
 * Distort the whole Object by a (possibly changing in time) vector of force.
593 f2fe7e28 Leszek Koltunski
 *
594
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
595
 *               currently being dragged with.
596 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
597 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
598 6a06a912 Leszek Koltunski
 */
599 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center)
600 d425545a Leszek Koltunski
    {
601 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, null);
602 d425545a Leszek Koltunski
    }
603 6a06a912 Leszek Koltunski
604 6ebdbbf1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
605
/**
606
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
607
 * a (possibly changing in time) point on the Object.
608
 *
609
 * @param vector Vector of force that deforms the shape of the whole Object.
610
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
611
 * @param region Region that masks the Effect.
612
 * @return       ID of the effect added, or -1 if we failed to add one.
613
 */
614
  public long deform(Data3D vector, Data3D center, Data4D region)
615
    {
616
    return mV.add(EffectNames.DEFORM, vector, center, region);
617
    }
618
619 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
620
/**
621 e0a16874 Leszek Koltunski
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
622 9351ad55 Leszek Koltunski
 * a (possibly changing in time) point on the Object.
623 6a06a912 Leszek Koltunski
 *     
624 f2fe7e28 Leszek Koltunski
 * @param vector Vector of force that deforms the shape of the whole Object.
625 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
626 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
627 6a06a912 Leszek Koltunski
 */
628 fa6c352d Leszek Koltunski
  public long deform(Data3D vector, Data3D center)
629 6a06a912 Leszek Koltunski
    {  
630 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DEFORM, vector, center, null);
631 6a06a912 Leszek Koltunski
    }
632
633
///////////////////////////////////////////////////////////////////////////////////////////////////  
634
/**
635 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
636 6a06a912 Leszek Koltunski
 * away from the center (degree<=1)
637 f2fe7e28 Leszek Koltunski
 *
638
 * @param sink   The current degree of the Effect.
639 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
640 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
641
 * @return       ID of the effect added, or -1 if we failed to add one.
642 6a06a912 Leszek Koltunski
 */
643 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center, Data4D region)
644 6a06a912 Leszek Koltunski
    {
645 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SINK, sink, center, region);
646 6a06a912 Leszek Koltunski
    }
647
648
///////////////////////////////////////////////////////////////////////////////////////////////////
649
/**
650 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
651
 * away from the center (degree<=1)
652
 *
653
 * @param sink   The current degree of the Effect.
654 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
655 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
656 6a06a912 Leszek Koltunski
 */
657 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center)
658 d425545a Leszek Koltunski
    {
659
    return mV.add(EffectNames.SINK, sink, center);
660
    }
661 6a06a912 Leszek Koltunski
662 82ee855a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
663
/**
664
 * Pull all points around the center of the Effect towards a line passing through the center
665
 * (that's if degree>=1) or push them away from the line (degree<=1)
666
 *
667
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
668
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
669
 * @param region Region that masks the Effect.
670
 * @return       ID of the effect added, or -1 if we failed to add one.
671
 */
672
  public long pinch(Data2D pinch, Data3D center, Data4D region)
673
    {
674
    return mV.add(EffectNames.PINCH, pinch, center, region);
675
    }
676
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678
/**
679
 * Pull all points around the center of the Effect towards a line passing through the center
680
 * (that's if degree>=1) or push them away from the line (degree<=1)
681
 *
682
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
683
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
684
 * @return       ID of the effect added, or -1 if we failed to add one.
685
 */
686
  public long pinch(Data2D pinch, Data3D center)
687
    {
688
    return mV.add(EffectNames.PINCH, pinch, center);
689
    }
690
691 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////  
692
/**
693 f2fe7e28 Leszek Koltunski
 * Rotate part of the Object around the Center of the Effect by a certain angle.
694
 *
695 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
696 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
697 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
698
 * @return       ID of the effect added, or -1 if we failed to add one.
699 6a06a912 Leszek Koltunski
 */
700 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center, Data4D region)
701 6a06a912 Leszek Koltunski
    {    
702 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SWIRL, swirl, center, region);
703 6a06a912 Leszek Koltunski
    }
704
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706
/**
707 f2fe7e28 Leszek Koltunski
 * Rotate the whole Object around the Center of the Effect by a certain angle.
708
 *
709 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
710 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
711 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
712 6a06a912 Leszek Koltunski
 */
713 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center)
714 d425545a Leszek Koltunski
    {
715
    return mV.add(EffectNames.SWIRL, swirl, center);
716
    }
717 4fde55a0 Leszek Koltunski
718
///////////////////////////////////////////////////////////////////////////////////////////////////
719
/**
720
 * Directional, sinusoidal wave effect.
721
 *
722 350cc2f5 Leszek Koltunski
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
723 ea16dc89 Leszek Koltunski
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
724 350cc2f5 Leszek Koltunski
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
725
 *               describe the 'direction' of the wave.
726 3695d6fa Leszek Koltunski
 *               <p>
727 d0c902b8 Leszek Koltunski
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
728
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
729
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
730
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
731 3695d6fa Leszek Koltunski
 *               <p>
732
 *               <p>
733 d0c902b8 Leszek Koltunski
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
734
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
735
 *               will be sine shapes.
736 3695d6fa Leszek Koltunski
 *               <p>
737 d0c902b8 Leszek Koltunski
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
738
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
739
 *               YZ-plane with be sine shapes.
740 3695d6fa Leszek Koltunski
 *               <p>
741 d0c902b8 Leszek Koltunski
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
742 350cc2f5 Leszek Koltunski
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
743
 *               value if sin at this point.
744 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
745 4fde55a0 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
746
 */
747 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center)
748 4fde55a0 Leszek Koltunski
    {
749 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.WAVE, wave, center, null);
750 4fde55a0 Leszek Koltunski
    }
751
752
///////////////////////////////////////////////////////////////////////////////////////////////////
753
/**
754
 * Directional, sinusoidal wave effect.
755
 *
756 3ef3364d Leszek Koltunski
 * @param wave   see {@link DistortedEffectQueues#wave(Data5D,Data3D)}
757 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
758 4fde55a0 Leszek Koltunski
 * @param region Region that masks the Effect.
759
 * @return       ID of the effect added, or -1 if we failed to add one.
760
 */
761 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center, Data4D region)
762 4fde55a0 Leszek Koltunski
    {
763
    return mV.add(EffectNames.WAVE, wave, center, region);
764
    }
765 f2fe7e28 Leszek Koltunski
  }