Project

General

Profile

« Previous | Next » 

Revision d425545a

Added by Leszek Koltunski over 8 years ago

Some more progress with porting apps to new VERTEX API.

View differences:

src/main/java/org/distorted/library/DistortedObject.java
28 28
import org.distorted.library.type.Data2D;
29 29
import org.distorted.library.type.Data3D;
30 30
import org.distorted.library.type.Data4D;
31
import org.distorted.library.type.Dynamic;
32
import org.distorted.library.type.Dynamic1D;
33
import org.distorted.library.type.Dynamic2D;
34
import org.distorted.library.type.Dynamic3D;
35
import org.distorted.library.type.Dynamic4D;
36
import org.distorted.library.type.Static1D;
37 31
import org.distorted.library.type.Static2D;
38 32
import org.distorted.library.type.Static3D;
39
import org.distorted.library.type.Static4D;
40
import org.distorted.library.type.DynamicQuat;
41 33

  
42 34
///////////////////////////////////////////////////////////////////////////////////////////////////
43 35
/**
44 36
 * All Objects to which Distorted Graphics effects can be applied need to be extended from here.
45 37
 */
46 38
public abstract class DistortedObject 
47
{
48
    private static final Static2D mZero2D = new Static2D(0,0);
49
    private static final Static3D mZero3D = new Static3D(0,0,0);
50

  
51
    private static float[] mViewMatrix   = new float[16];
39
  {
40
  private static float[] mViewMatrix   = new float[16];
52 41
   
53
    protected EffectQueueMatrix    mM;
54
    protected EffectQueueFragment  mF;
55
    protected EffectQueueVertex    mV;
42
  protected EffectQueueMatrix    mM;
43
  protected EffectQueueFragment  mF;
44
  protected EffectQueueVertex    mV;
56 45

  
57
    protected boolean matrixCloned, vertexCloned, fragmentCloned;
46
  protected boolean matrixCloned, vertexCloned, fragmentCloned;
58 47
 
59
    protected DistortedObjectGrid mGrid = null;
60
    protected long mID;
61
    protected int mSizeX, mSizeY, mSizeZ, mSize; // in screen space
48
  protected DistortedObjectGrid mGrid = null;
49
  protected long mID;
50
  protected int mSizeX, mSizeY, mSizeZ, mSize; // in screen space
62 51

  
63
    protected Bitmap[] mBmp= null; // 
64
    int[] mTextureDataH;           // have to be shared among all the cloned Objects
65
    boolean[] mBitmapSet;          // 
52
  protected Bitmap[] mBmp= null; //
53
  int[] mTextureDataH;           // have to be shared among all the cloned Objects
54
  boolean[] mBitmapSet;          //
66 55

  
67 56
///////////////////////////////////////////////////////////////////////////////////////////////////
68 57

  
69
    protected abstract DistortedObject deepCopy(int flags);
58
  protected abstract DistortedObject deepCopy(int flags);
70 59

  
71 60
///////////////////////////////////////////////////////////////////////////////////////////////////
72 61

  
73
    protected void initializeData(int size)
74
      {
75
      mID             = DistortedObjectList.add(this);
76
      mSize           = size;
77
      mTextureDataH   = new int[1];
78
      mTextureDataH[0]= 0;
79
      mBmp            = new Bitmap[1];
80
      mBmp[0]         = null;
81
      mBitmapSet      = new boolean[1];
82
      mBitmapSet[0]   = false;
62
  protected void initializeData(int size)
63
    {
64
    mID             = DistortedObjectList.add(this);
65
    mSize           = size;
66
    mTextureDataH   = new int[1];
67
    mTextureDataH[0]= 0;
68
    mBmp            = new Bitmap[1];
69
    mBmp[0]         = null;
70
    mBitmapSet      = new boolean[1];
71
    mBitmapSet[0]   = false;
83 72
      
84
      initializeEffectLists(this,0);
73
    initializeEffectLists(this,0);
85 74
      
86
      if( Distorted.isInitialized() ) resetTexture();    
87
      }
75
    if( Distorted.isInitialized() ) resetTexture();
76
    }
88 77
    
89 78
///////////////////////////////////////////////////////////////////////////////////////////////////
90 79
    
91
    protected void initializeEffectLists(DistortedObject d, int flags)
80
  protected void initializeEffectLists(DistortedObject d, int flags)
81
    {
82
    if( (flags & Distorted.CLONE_PRESHADER) != 0 )
92 83
      {
93
      if( (flags & Distorted.CLONE_PRESHADER) != 0 )
94
        {
95
        mM = d.mM;
96
        matrixCloned = true;
97
        } 
98
      else
99
        {
100
        mM = new EffectQueueMatrix(d);
101
        matrixCloned = false;  
102
        }
84
      mM = d.mM;
85
      matrixCloned = true;
86
      }
87
    else
88
      {
89
      mM = new EffectQueueMatrix(d);
90
      matrixCloned = false;
91
      }
103 92
    
104
      if( (flags & Distorted.CLONE_VERTEX) != 0 )
105
        {
106
        mV = d.mV;
107
        vertexCloned = true;
108
        } 
109
      else
110
        {
111
        mV = new EffectQueueVertex(d);
112
        vertexCloned = false;  
113
        }
93
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
94
      {
95
      mV = d.mV;
96
      vertexCloned = true;
97
      }
98
    else
99
      {
100
      mV = new EffectQueueVertex(d);
101
      vertexCloned = false;
102
      }
114 103
    
115
      if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
116
        {
117
        mF = d.mF;
118
        fragmentCloned = true;
119
        } 
120
      else
121
        {
122
        mF = new EffectQueueFragment(d);
123
        fragmentCloned = false;   
124
        }
104
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
105
      {
106
      mF = d.mF;
107
      fragmentCloned = true;
125 108
      }
109
    else
110
      {
111
      mF = new EffectQueueFragment(d);
112
      fragmentCloned = false;
113
      }
114
    }
126 115
    
127 116
///////////////////////////////////////////////////////////////////////////////////////////////////
128 117
// this will be called on startup and every time OpenGL context has been lost
129 118
// also call this from the constructor if the OpenGL context has been created already.
130 119
    
131
    void resetTexture()
120
  void resetTexture()
121
    {
122
    if( mTextureDataH!=null )
132 123
      {
133
      if( mTextureDataH!=null ) 
134
        {
135
        if( mTextureDataH[0]==0 ) GLES20.glGenTextures(1, mTextureDataH, 0);
124
      if( mTextureDataH[0]==0 ) GLES20.glGenTextures(1, mTextureDataH, 0);
136 125

  
137
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);       
138
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR );
139
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR );
140
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
141
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
126
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
127
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR );
128
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR );
129
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
130
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
142 131
       
143
        if( mBmp!=null && mBmp[0]!=null)
144
          {
145
          GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, mBmp[0], 0);
146
          mBmp[0] = null;
147
          }
132
      if( mBmp!=null && mBmp[0]!=null)
133
        {
134
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, mBmp[0], 0);
135
        mBmp[0] = null;
148 136
        }
149 137
      }
138
    }
150 139
  
151 140
///////////////////////////////////////////////////////////////////////////////////////////////////
152 141
   
153
    void drawPriv(long currTime, DistortedProjection dp)
154
      {
155
      GLES20.glViewport(0, 0, dp.width, dp.height); 
142
  void drawPriv(long currTime, DistortedProjection dp)
143
    {
144
    GLES20.glViewport(0, 0, dp.width, dp.height);
156 145
      
157
      mM.compute(currTime);
158
      mM.send(mViewMatrix, dp);
146
    mM.compute(currTime);
147
    mM.send(mViewMatrix, dp);
159 148
      
160
      mV.compute(currTime);
161
      mV.postprocess();
162
      mV.send();
149
    mV.compute(currTime);
150
    mV.postprocess();
151
    mV.send();
163 152
        
164
      mF.compute(currTime);
165
      mF.postprocess(mViewMatrix);
166
      mF.send();
153
    mF.compute(currTime);
154
    mF.postprocess(mViewMatrix);
155
    mF.send();
167 156
       
168
      mGrid.draw();
169
      }
157
    mGrid.draw();
158
    }
170 159

  
171 160
///////////////////////////////////////////////////////////////////////////////////////////////////
172 161
   
173
    void drawNoEffectsPriv(DistortedProjection dp)
174
      {
175
      GLES20.glViewport(0, 0, dp.width, dp.height);
176
      mM.sendNoEffects(dp);
177
      mV.sendZero();
178
      mF.sendZero();
179
      mGrid.draw();
180
      }
162
  void drawNoEffectsPriv(DistortedProjection dp)
163
    {
164
    GLES20.glViewport(0, 0, dp.width, dp.height);
165
    mM.sendNoEffects(dp);
166
    mV.sendZero();
167
    mF.sendZero();
168
    mGrid.draw();
169
    }
181 170
    
182 171
///////////////////////////////////////////////////////////////////////////////////////////////////
183 172
   
184
    void releasePriv()
185
      {
186
      if( matrixCloned  ==false) mM.abortAll();
187
      if( vertexCloned  ==false) mV.abortAll();
188
      if( fragmentCloned==false) mF.abortAll();
189

  
190
      mBmp          = null;
191
      mGrid         = null;
192
      mM            = null;
193
      mV            = null;
194
      mF            = null;
195
      mTextureDataH = null;
196
      }
173
  void releasePriv()
174
    {
175
    if( matrixCloned  ==false) mM.abortAll();
176
    if( vertexCloned  ==false) mV.abortAll();
177
    if( fragmentCloned==false) mF.abortAll();
178

  
179
    mBmp          = null;
180
    mGrid         = null;
181
    mM            = null;
182
    mV            = null;
183
    mF            = null;
184
    mTextureDataH = null;
185
    }
197 186
 
198 187
///////////////////////////////////////////////////////////////////////////////////////////////////
199 188

  
200
    long getBitmapID()
189
  long getBitmapID()
201 190
      {
202 191
      return mBmp==null ? 0 : mBmp.hashCode();
203 192
      }
204 193

  
205 194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
/**
196
 * Default empty constructor so that derived classes can call it
197
 */
198
  public DistortedObject()
199
    {
206 200

  
207
  /**
208
   * Default empty constructor so that derived classes can call it
209
   */
210
    public DistortedObject()
211
      {
212

  
213
      }
201
    }
214 202

  
215 203
///////////////////////////////////////////////////////////////////////////////////////////////////
216
  /**
217
   * Copy constructor used to create a DistortedObject based on various parts of another object.
218
   * <p>
219
   * Whatever we do not clone gets created just like in the default constructor.
220
   * We only call this from the descendant's classes' constructors where we have to pay attention
221
   * to give it the appropriate type of a DistortedObject!
222
   *
223
   * @param dc    Source object to create our object from
224
   * @param flags A bitmask of values specifying what to copy.
225
   *              For example, CLONE_BITMAP | CLONE_MATRIX.
226
   */
227
    public DistortedObject(DistortedObject dc, int flags)
228
      {
229
      initializeEffectLists(dc,flags);
204
/**
205
 * Copy constructor used to create a DistortedObject based on various parts of another object.
206
 * <p>
207
 * Whatever we do not clone gets created just like in the default constructor.
208
 * We only call this from the descendant's classes' constructors where we have to pay attention
209
 * to give it the appropriate type of a DistortedObject!
210
 *
211
 * @param dc    Source object to create our object from
212
 * @param flags A bitmask of values specifying what to copy.
213
 *              For example, CLONE_BITMAP | CLONE_MATRIX.
214
 */
215
  public DistortedObject(DistortedObject dc, int flags)
216
    {
217
    initializeEffectLists(dc,flags);
230 218

  
231
      mID = DistortedObjectList.add(this);
219
    mID = DistortedObjectList.add(this);
232 220

  
233
      mSizeX = dc.mSizeX;
234
      mSizeY = dc.mSizeY;
235
      mSizeZ = dc.mSizeZ;
236
      mSize  = dc.mSize;
237
      mGrid  = dc.mGrid;
221
    mSizeX = dc.mSizeX;
222
    mSizeY = dc.mSizeY;
223
    mSizeZ = dc.mSizeZ;
224
    mSize  = dc.mSize;
225
    mGrid  = dc.mGrid;
238 226

  
239
      if( (flags & Distorted.CLONE_BITMAP) != 0 )
240
        {
241
        mTextureDataH = dc.mTextureDataH;
242
        mBmp          = dc.mBmp;
243
        mBitmapSet    = dc.mBitmapSet;
244
        }
245
      else
246
        {
247
        mTextureDataH   = new int[1];
248
        mTextureDataH[0]= 0;
249
        mBitmapSet      = new boolean[1];
250
        mBitmapSet[0]   = false;
251
        mBmp            = new Bitmap[1];
252
        mBmp[0]         = null;
253

  
254
        if( Distorted.isInitialized() ) resetTexture();
255
        }
227
    if( (flags & Distorted.CLONE_BITMAP) != 0 )
228
      {
229
      mTextureDataH = dc.mTextureDataH;
230
      mBmp          = dc.mBmp;
231
      mBitmapSet    = dc.mBitmapSet;
256 232
      }
233
    else
234
      {
235
      mTextureDataH   = new int[1];
236
      mTextureDataH[0]= 0;
237
      mBitmapSet      = new boolean[1];
238
      mBitmapSet[0]   = false;
239
      mBmp            = new Bitmap[1];
240
      mBmp[0]         = null;
241

  
242
      if( Distorted.isInitialized() ) resetTexture();
243
      }
244
    }
257 245

  
258 246
///////////////////////////////////////////////////////////////////////////////////////////////////
259 247
/**
......
263 251
 *        This gets passed on to Interpolators inside the Effects that are currently applied to the 
264 252
 *        Object.
265 253
 */
266
   public void draw(long currTime)
267
     {
268
     GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
269
     GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
270
     GLES20.glUniform1i(Distorted.mTextureUniformH, 0);  
271
     GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]); 
254
  public void draw(long currTime)
255
    {
256
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
257
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
258
    GLES20.glUniform1i(Distorted.mTextureUniformH, 0);
259
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
272 260
      
273
     drawPriv(currTime, Distorted.mProjection);
274
     }
261
    drawPriv(currTime, Distorted.mProjection);
262
    }
275 263
 
276 264
///////////////////////////////////////////////////////////////////////////////////////////////////
277 265
/**
278 266
 * Releases all resources.
279 267
 */
280
   public synchronized void release()
281
     {
282
     releasePriv();  
283
     DistortedObjectList.remove(this);
284
     }
268
  public synchronized void release()
269
    {
270
    releasePriv();
271
    DistortedObjectList.remove(this);
272
    }
285 273

  
286 274
///////////////////////////////////////////////////////////////////////////////////////////////////
287 275
/**
......
293 281
 * @param bmp The android.graphics.Bitmap object to apply effects to and display.
294 282
 */
295 283
   
296
   public void setBitmap(Bitmap bmp)
297
     {
298
     mBitmapSet[0] = true; 
284
  public void setBitmap(Bitmap bmp)
285
    {
286
    mBitmapSet[0] = true;
299 287
      
300
     if( Distorted.isInitialized() )
301
       {
302
       GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
303
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);        
304
       GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);
305
       }
306
     else
307
       {
308
       mBmp[0] = bmp;  
309
       }
310
     }
288
    if( Distorted.isInitialized() )
289
      {
290
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
291
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
292
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);
293
      }
294
    else
295
      {
296
      mBmp[0] = bmp;
297
      }
298
    }
311 299
    
312 300
///////////////////////////////////////////////////////////////////////////////////////////////////
313 301
/**
......
316 304
 * 
317 305
 * @param el A class implementing the EffectListener interface that wants to get notifications.
318 306
 */
319
   public void addEventListener(EffectListener el)
320
     {
321
     mV.addListener(el);
322
     mF.addListener(el);
323
     mM.addListener(el);
324
     }
307
  public void addEventListener(EffectListener el)
308
    {
309
    mV.addListener(el);
310
    mF.addListener(el);
311
    mM.addListener(el);
312
    }
325 313

  
326 314
///////////////////////////////////////////////////////////////////////////////////////////////////
327 315
/**
......
329 317
 * 
330 318
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
331 319
 */
332
   public void removeEventListener(EffectListener el)
333
     {
334
     mV.removeListener(el);
335
     mF.removeListener(el);
336
     mM.removeListener(el);
337
     }
320
  public void removeEventListener(EffectListener el)
321
    {
322
    mV.removeListener(el);
323
    mF.removeListener(el);
324
    mM.removeListener(el);
325
    }
338 326
   
339 327
///////////////////////////////////////////////////////////////////////////////////////////////////
340 328
/**
......
342 330
 *    
343 331
 * @return height of the object, in pixels.
344 332
 */
345
   public int getWidth()
333
  public int getWidth()
346 334
     {
347 335
     return mSizeX;   
348 336
     }
......
353 341
 * 
354 342
 * @return width of the Object, in pixels.
355 343
 */
356
    public int getHeight()
344
  public int getHeight()
357 345
      {
358 346
      return mSizeY;  
359 347
      }
......
364 352
 * 
365 353
 * @return depth of the Object, in pixels.
366 354
 */
367
    public int getDepth()
355
  public int getDepth()
368 356
      {
369 357
      return mSizeZ;  
370 358
      }
......
375 363
 * 
376 364
 * @return ID of the object.
377 365
 */
378
    public long getID()
366
  public long getID()
379 367
      {
380 368
      return mID;  
381 369
      }
......
385 373
 * Aborts all Effects.
386 374
 * @return Number of effects aborted.
387 375
 */
388
    public int abortAllEffects()
376
  public int abortAllEffects()
389 377
      {
390 378
      return mM.abortAll() + mV.abortAll() + mF.abortAll();
391 379
      }
......
397 385
 * @param type one of the constants defined in {@link EffectTypes}
398 386
 * @return Number of effects aborted.
399 387
 */
400
    public int abortEffects(EffectTypes type)
388
  public int abortEffects(EffectTypes type)
389
    {
390
    switch(type)
401 391
      {
402
      switch(type)
403
        {
404
        case MATRIX  : return mM.abortAll();
405
        case VERTEX  : return mV.abortAll();
406
        case FRAGMENT: return mF.abortAll();
407
        default      : return 0;
408
        }
392
      case MATRIX  : return mM.abortAll();
393
      case VERTEX  : return mV.abortAll();
394
      case FRAGMENT: return mF.abortAll();
395
      default      : return 0;
409 396
      }
397
    }
410 398
    
411 399
///////////////////////////////////////////////////////////////////////////////////////////////////
412 400
/**
......
415 403
 * @param id ID of the Effect we want to abort.
416 404
 * @return number of Effects aborted. Always either 0 or 1.
417 405
 */
418
    public int abortEffect(long id)
419
      {
420
      int type = (int)(id&EffectTypes.MASK);
406
  public int abortEffect(long id)
407
    {
408
    int type = (int)(id&EffectTypes.MASK);
421 409

  
422
      if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
423
      if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
424
      if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
410
    if( type==EffectTypes.MATRIX.type   ) return mM.removeByID(id>>EffectTypes.LENGTH);
411
    if( type==EffectTypes.VERTEX.type   ) return mV.removeByID(id>>EffectTypes.LENGTH);
412
    if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
425 413

  
426
      return 0;
427
      }
414
    return 0;
415
    }
428 416

  
429 417
///////////////////////////////////////////////////////////////////////////////////////////////////
430 418
/**
......
433 421
 * @param name one of the constants defined in {@link EffectNames}
434 422
 * @return number of Effects aborted.
435 423
 */
436
    public int abortEffects(EffectNames name)
424
  public int abortEffects(EffectNames name)
425
    {
426
    switch(name.getType())
437 427
      {
438
      switch(name.getType())
439
        {
440
        case MATRIX  : return mM.removeByType(name);
441
        case VERTEX  : return mV.removeByType(name);
442
        case FRAGMENT: return mF.removeByType(name);
443
        default      : return 0;
444
        }
428
      case MATRIX  : return mM.removeByType(name);
429
      case VERTEX  : return mV.removeByType(name);
430
      case FRAGMENT: return mF.removeByType(name);
431
      default      : return 0;
445 432
      }
433
    }
446 434
    
447 435
///////////////////////////////////////////////////////////////////////////////////////////////////
448 436
/**
......
452 440
 * @return <code>true</code> if a single Effect of type effectType has been found.
453 441
 */
454 442
    
455
    public boolean printEffect(long id)
456
      {
457
      int type = (int)(id&EffectTypes.MASK);
443
  public boolean printEffect(long id)
444
    {
445
    int type = (int)(id&EffectTypes.MASK);
458 446

  
459
      if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
460
      if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
461
      if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
447
    if( type==EffectTypes.MATRIX.type   )  return mM.printByID(id>>EffectTypes.LENGTH);
448
    if( type==EffectTypes.VERTEX.type   )  return mV.printByID(id>>EffectTypes.LENGTH);
449
    if( type==EffectTypes.FRAGMENT.type )  return mF.printByID(id>>EffectTypes.LENGTH);
462 450

  
463
      return false;
464
      }
451
    return false;
452
    }
465 453
   
466 454
///////////////////////////////////////////////////////////////////////////////////////////////////   
467 455
///////////////////////////////////////////////////////////////////////////////////////////////////
......
501 489
 * @param scale The factor to scale all 3 dimensions with.
502 490
 * @return      ID of the effect added, or -1 if we failed to add one.
503 491
 */
504
public long scale(float scale)
505
  {
506
  return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
507
  }
492
  public long scale(float scale)
493
    {
494
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
495
    }
508 496

  
509 497
///////////////////////////////////////////////////////////////////////////////////////////////////
510 498
/**
......
765 753
///////////////////////////////////////////////////////////////////////////////////////////////////
766 754
/**
767 755
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
768
 * <p>
769
 * Only at most one of the 'center' and 'region' can be a Dynamic!
770 756
 *
771 757
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
772 758
 *               currently being dragged with.
......
788 774
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
789 775
 * @return       ID of the effect added, or -1 if we failed to add one.
790 776
 */
791
public long distort(Data3D vector, Data2D center)
792
  {
793
  return mV.add(EffectNames.DISTORT, vector, center);
794
  }
777
  public long distort(Data3D vector, Data2D center)
778
    {
779
    return mV.add(EffectNames.DISTORT, vector, center);
780
    }
795 781

  
796 782
///////////////////////////////////////////////////////////////////////////////////////////////////
797 783
/**
......
811 797
/**
812 798
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
813 799
 * away from the center (degree<=1)
814
 * <p>
815
 * Only at most one of the 'center' and 'region' can be a Dynamic!
816 800
 *
817 801
 * @param sink   The current degree of the Effect.
818 802
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
......
833 817
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
834 818
 * @return       ID of the effect added, or -1 if we failed to add one.
835 819
 */
836
public long sink(Data1D sink, Data2D center)
837
  {
838
  return mV.add(EffectNames.SINK, sink, center);
839
  }
820
  public long sink(Data1D sink, Data2D center)
821
    {
822
    return mV.add(EffectNames.SINK, sink, center);
823
    }
840 824

  
841 825
///////////////////////////////////////////////////////////////////////////////////////////////////  
842 826
/**
843 827
 * Rotate part of the Object around the Center of the Effect by a certain angle.
844
 * <p>
845
 * Only at most one of the 'center' and 'region' can be a Dynamic!
846 828
 *
847 829
 * @param swirl  The degree of Swirl. Positive values swirl clockwise.
848 830
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
......
862 844
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
863 845
 * @return       ID of the effect added, or -1 if we failed to add one.
864 846
 */
865
public long swirl(Data1D swirl, Data2D center)
866
  {
867
  return mV.add(EffectNames.SWIRL, swirl, center);
847
  public long swirl(Data1D swirl, Data2D center)
848
    {
849
    return mV.add(EffectNames.SWIRL, swirl, center);
850
    }
868 851
  }
869
}
src/main/java/org/distorted/library/EffectQueue.java
22 22
import org.distorted.library.message.EffectListener;
23 23
import org.distorted.library.message.EffectMessage;
24 24
import org.distorted.library.type.Dynamic;
25
import org.distorted.library.type.Dynamic2D;
26 25

  
27 26
import java.util.Vector;
28 27

  
......
35 34
  
36 35
  protected int[] mType;
37 36
  protected float[] mUniforms;
38
  protected Dynamic[] mInterP;  // center of the effect
39
  protected Dynamic[] mInterI;  // all other interpolated values
37
  protected Dynamic[][] mInter;  // center of the effect
40 38
  protected long[] mCurrentDuration;
41 39
  protected byte[] mFreeIndexes;
42 40
  protected byte[] mIDIndex;
......
80 78
      {
81 79
      mType            = new int[mMax[mMaxIndex]];
82 80
      mUniforms        = new float[numUniforms*mMax[mMaxIndex]];
83
      mInterI          = new Dynamic[mMax[mMaxIndex]];
84
      mInterP          = new Dynamic[mMax[mMaxIndex]];
81
      mInter           = new Dynamic[3][mMax[mMaxIndex]];
85 82
      mCurrentDuration = new long[mMax[mMaxIndex]];
86 83
      mID              = new long[mMax[mMaxIndex]];
87 84
      mIDIndex         = new byte[mMax[mMaxIndex]];
......
205 202

  
206 203
    for(int i=0; i<ret; i++ )
207 204
      {
208
      mInterI[i] = null;
209
      mInterP[i] = null;
205
      mInter[0][i] = null;
206
      mInter[1][i] = null;
207
      mInter[2][i] = null;
210 208
      }
211 209

  
212 210
    mNumEffects= 0;
......
236 234
    for(int j=effect; j<mNumEffects; j++ ) 
237 235
      {
238 236
      mType[j]            = mType[j+1];
239
      mInterI[j]          = mInterI[j+1];
240
      mInterP[j]          = mInterP[j+1];
237
      mInter[0][j]          = mInter[0][j+1];
238
      mInter[1][j]          = mInter[1][j+1];
239
      mInter[2][j]          = mInter[2][j+1];
241 240
      mCurrentDuration[j] = mCurrentDuration[j+1];
242 241
      mID[j]              = mID[j+1];
243 242
    
244 243
      moveEffect(j);
245 244
      }
246 245
   
247
    mInterI[mNumEffects] = null;
248
    mInterP[mNumEffects] = null;
249
   
246
    mInter[0][mNumEffects] = null;
247
    mInter[1][mNumEffects] = null;
248
    mInter[2][mNumEffects] = null;
249

  
250 250
    for(int i=0; i<mNumListeners; i++) 
251 251
      EffectMessageSender.newMessage( mListeners.elementAt(i),
252 252
                                      EffectMessage.EFFECT_REMOVED,
......
314 314
   
315 315
    if( index>=0 ) 
316 316
      {
317
      boolean interI = mInterI[index]==null; 
318
      boolean interP = mInterP[index]==null; 
319
      
320
      android.util.Log.e("EffectQueue", "numEffects="+mNumEffects+" effect id="+id+" index="+index+" duration="+mCurrentDuration[index]+" interI null="+interI+" interP null="+interP);
317
      boolean inter0 = mInter[0][index]==null;
318
      boolean inter1 = mInter[1][index]==null;
319
      boolean inter2 = mInter[2][index]==null;
320

  
321
      android.util.Log.e("EffectQueue", "numEffects="+mNumEffects+" effect id="+id+" index="+index+
322
                         " duration="+mCurrentDuration[index]+" inter[0] null="+inter0+" inter[1] null="+inter1+" inter[2] null="+inter2);
321 323
      
322
      if( interI==false )
324
      if( inter0==false )
323 325
        {
324
        android.util.Log.e("EffectQueue","interI: "+mInterI[index].print());
326
        android.util.Log.e("EffectQueue","inter[0]: "+mInter[0][index].print());
325 327
        }
326
      if( interP==false )
328
      if( inter1==false )
327 329
        {
328
        android.util.Log.e("EffectQueue","interP: "+mInterP[index].print());
330
        android.util.Log.e("EffectQueue","inter[1]: "+mInter[1][index].print());
329 331
        }
330
     
332
      if( inter2==false )
333
        {
334
        android.util.Log.e("EffectQueue","inter[2]: "+mInter[2][index].print());
335
        }
336

  
331 337
      return true;
332 338
      }
333 339
   
src/main/java/org/distorted/library/EffectQueueFragment.java
27 27
import org.distorted.library.type.Dynamic1D;
28 28
import org.distorted.library.type.Dynamic4D;
29 29
import org.distorted.library.type.Static1D;
30
import org.distorted.library.type.Static2D;
31 30
import org.distorted.library.type.Static3D;
32 31
import org.distorted.library.type.Static4D;
33
import org.distorted.library.type.Dynamic;
34
import org.distorted.library.type.Dynamic2D;
35 32

  
36 33
///////////////////////////////////////////////////////////////////////////////////////////////////
37 34

  
......
75 72
   
76 73
    for(int i=0; i<mNumEffects; i++)
77 74
      {
78
      if( mInterI[i]==null ) continue;    
75
      if( mInter[0][i]==null ) continue;
79 76
      
80
      if( mInterP[i]!=null ) mInterP[i].interpolateMain(mBuf, 4*i, mCurrentDuration[i]);
77
      if( mInter[1][i]!=null ) mInter[1][i].interpolateMain(mBuf, 4*i, mCurrentDuration[i]);
81 78
        
82
      if( mInterI[i].interpolateMain(mUniforms ,NUM_UNIFORMS*i, mCurrentDuration[i], step) )      
79
      if( mInter[0][i].interpolateMain(mUniforms ,NUM_UNIFORMS*i, mCurrentDuration[i], step) )
83 80
        {
84 81
        for(int j=0; j<mNumListeners; j++)   
85 82
          EffectMessageSender.newMessage( mListeners.elementAt(j),
......
180 177
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); 
181 178

  
182 179
      if( data instanceof Dynamic1D)
183
        mInterI[mNumEffects] = (Dynamic1D)data;
180
        mInter[0][mNumEffects] = (Dynamic1D)data;
184 181
      else if( data instanceof Static1D )
185 182
        {
186
        mInterI[mNumEffects] = null;
183
        mInter[0][mNumEffects] = null;
187 184
        mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)data).getX();
188 185
        }
189 186
      else return -1;
190 187

  
191
      mInterP[mNumEffects] = null;
188
      mInter[1][mNumEffects] = null;
192 189
      mBuf[4*mNumEffects+2] = 1000*mObjHalfX;
193 190
      mBuf[4*mNumEffects+3] = 1000*mObjHalfY;
194 191

  
......
208 205
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
209 206

  
210 207
      if( data instanceof Dynamic1D)
211
        mInterI[mNumEffects] = (Dynamic1D)data;
208
        mInter[0][mNumEffects] = (Dynamic1D)data;
212 209
      else if( data instanceof Static1D )
213 210
        {
214
        mInterI[mNumEffects] = null;
211
        mInter[0][mNumEffects] = null;
215 212
        mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)data).getX();
216 213
        }
217 214
      else return -1;
218 215

  
219 216
      if( region instanceof Dynamic4D)
220
        mInterP[mNumEffects] = (Dynamic4D)region;
217
        mInter[1][mNumEffects] = (Dynamic4D)region;
221 218
      else if( region instanceof Static4D )
222 219
        {
223
        mInterP[mNumEffects]  = null;
220
        mInter[1][mNumEffects]  = null;
224 221
        mBuf[4*mNumEffects  ] = ((Static4D)region).getX();
225 222
        mBuf[4*mNumEffects+1] = ((Static4D)region).getY();
226 223
        mBuf[4*mNumEffects+2] = ((Static4D)region).getZ();
......
244 241
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
245 242

  
246 243
      if( level instanceof Dynamic1D)
247
        mInterI[mNumEffects] = (Dynamic1D)level;
244
        mInter[0][mNumEffects] = (Dynamic1D)level;
248 245
      else if( level instanceof Static1D )
249 246
        {
250
        mInterI[mNumEffects] = null;
247
        mInter[0][mNumEffects] = null;
251 248
        mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)level).getX();
252 249
        }
253 250
      else return -1;
......
257 254
      mUniforms[NUM_UNIFORMS*mNumEffects+3] = color.getZ();
258 255

  
259 256
      if( region instanceof Dynamic4D)
260
        mInterP[mNumEffects] = (Dynamic4D)region;
257
        mInter[1][mNumEffects] = (Dynamic4D)region;
261 258
      else if( region instanceof Static4D )
262 259
        {
263
        mInterP[mNumEffects]  = null;
260
        mInter[1][mNumEffects]  = null;
264 261
        mBuf[4*mNumEffects  ] = ((Static4D)region).getX();
265 262
        mBuf[4*mNumEffects+1] = ((Static4D)region).getY();
266 263
        mBuf[4*mNumEffects+2] = ((Static4D)region).getZ();
......
284 281
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
285 282

  
286 283
      if( level instanceof Dynamic1D)
287
        mInterI[mNumEffects] = (Dynamic1D)level;
284
        mInter[0][mNumEffects] = (Dynamic1D)level;
288 285
      else if( level instanceof Static1D )
289 286
        {
290
        mInterI[mNumEffects] = null;
287
        mInter[0][mNumEffects] = null;
291 288
        mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)level).getX();
292 289
        }
293 290
      else return -1;
......
296 293
      mUniforms[NUM_UNIFORMS*mNumEffects+2] = color.getY();
297 294
      mUniforms[NUM_UNIFORMS*mNumEffects+3] = color.getZ();
298 295

  
299
      mInterP[mNumEffects]  = null;            //
296
      mInter[1][mNumEffects]  = null;          //
300 297
      mBuf[4*mNumEffects+2] = 1000*mObjHalfX;  // i.e. null region
301 298
      mBuf[4*mNumEffects+3] = 1000*mObjHalfY;  //
302 299

  
......
316 313
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
317 314

  
318 315
      if( chroma instanceof Dynamic4D)
319
        mInterI[mNumEffects] = (Dynamic4D)chroma;
316
        mInter[0][mNumEffects] = (Dynamic4D)chroma;
320 317
      else if( chroma instanceof Static4D )
321 318
        {
322
        mInterI[mNumEffects] = null;
319
        mInter[0][mNumEffects] = null;
323 320
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static4D)chroma).getX();
324 321
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static4D)chroma).getY();
325 322
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static4D)chroma).getZ();
......
328 325
      else return -1;
329 326

  
330 327
      if( region instanceof Dynamic4D)
331
        mInterP[mNumEffects] = (Dynamic4D)region;
328
        mInter[1][mNumEffects] = (Dynamic4D)region;
332 329
      else if( region instanceof Static4D )
333 330
        {
334
        mInterP[mNumEffects]  = null;
331
        mInter[1][mNumEffects]  = null;
335 332
        mBuf[4*mNumEffects  ] = ((Static4D)region).getX();
336 333
        mBuf[4*mNumEffects+1] = ((Static4D)region).getY();
337 334
        mBuf[4*mNumEffects+2] = ((Static4D)region).getZ();
......
355 352
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
356 353

  
357 354
      if( chroma instanceof Dynamic4D)
358
        mInterI[mNumEffects] = (Dynamic4D)chroma;
355
        mInter[0][mNumEffects] = (Dynamic4D)chroma;
359 356
      else if( chroma instanceof Static4D )
360 357
        {
361
        mInterI[mNumEffects] = null;
358
        mInter[0][mNumEffects] = null;
362 359
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static4D)chroma).getX();
363 360
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static4D)chroma).getY();
364 361
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static4D)chroma).getZ();
......
366 363
        }
367 364
      else return -1;
368 365

  
369
      mInterP[mNumEffects]  = null;            //
366
      mInter[1][mNumEffects]  = null;          //
370 367
      mBuf[4*mNumEffects+2] = 1000*mObjHalfX;  // i.e. null region
371 368
      mBuf[4*mNumEffects+3] = 1000*mObjHalfY;  //
372 369

  
src/main/java/org/distorted/library/EffectQueueMatrix.java
32 32
import org.distorted.library.type.DynamicQuat;
33 33
import org.distorted.library.type.Static1D;
34 34
import org.distorted.library.type.Static3D;
35
import org.distorted.library.type.Dynamic;
36 35
import org.distorted.library.type.Static4D;
37 36

  
38 37
///////////////////////////////////////////////////////////////////////////////////////////////////
......
106 105
   
107 106
    for(int i=0; i<mNumEffects; i++)
108 107
      {
109
      if( mInterI[i]==null ) continue;    
108
      if( mInter[0][i]==null ) continue;
110 109
           
111
      if( mInterP[i]!=null ) 
110
      if( mInter[1][i]!=null )
112 111
        {
113
        mInterP[i].interpolateMain(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i]);
112
        mInter[1][i].interpolateMain(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i]);
114 113
        }
115 114
        
116
      if( mInterI[i].interpolateMain(mUniforms ,NUM_UNIFORMS*i+3, mCurrentDuration[i], step) )      
115
      if( mInter[0][i].interpolateMain(mUniforms ,NUM_UNIFORMS*i+3, mCurrentDuration[i], step) )
117 116
        {   
118 117
        for(int j=0; j<mNumListeners; j++)   
119 118
          EffectMessageSender.newMessage( mListeners.elementAt(j),
......
257 256
    {
258 257
    if( mMax[INDEX]>mNumEffects )
259 258
      {
260
      mInterP[mNumEffects] = null;
259
      mInter[1][mNumEffects] = null;
261 260

  
262
           if( vector instanceof Dynamic3D) mInterI[mNumEffects] = (Dynamic3D)vector;
261
           if( vector instanceof Dynamic3D) mInter[0][mNumEffects] = (Dynamic3D)vector;
263 262
      else if( vector instanceof Static3D )
264 263
        {
265
        mInterI[mNumEffects] = null;
264
        mInter[0][mNumEffects] = null;
266 265
        mUniforms[NUM_UNIFORMS*mNumEffects+3] = ((Static3D)vector).getX();
267 266
        mUniforms[NUM_UNIFORMS*mNumEffects+4] = ((Static3D)vector).getY();
268 267
        mUniforms[NUM_UNIFORMS*mNumEffects+5] = ((Static3D)vector).getZ();
......
282 281
    {
283 282
    if( mMax[INDEX]>mNumEffects )
284 283
      {
285
           if( center instanceof Dynamic3D) mInterP[mNumEffects] = (Dynamic3D)center;
284
           if( center instanceof Dynamic3D) mInter[1][mNumEffects] = (Dynamic3D)center;
286 285
      else if( center instanceof Static3D )
287 286
        {
288
        mInterP[mNumEffects] = null;
287
        mInter[1][mNumEffects] = null;
289 288
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static3D)center).getX();
290 289
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)center).getY();
291 290
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)center).getZ();
292 291
        }
293 292
      else return -1;
294 293

  
295
           if( angle instanceof Dynamic1D) mInterI[mNumEffects] = (Dynamic1D)angle;
294
           if( angle instanceof Dynamic1D) mInter[0][mNumEffects] = (Dynamic1D)angle;
296 295
      else if( angle instanceof Static1D)
297 296
        {
298
        mInterI[mNumEffects] = null;
297
        mInter[0][mNumEffects] = null;
299 298
        mUniforms[NUM_UNIFORMS*mNumEffects+3] = ((Static1D)angle).getX();
300 299
        }
301 300
      else return -1;
......
317 316
    {
318 317
    if( mMax[INDEX]>mNumEffects )
319 318
      {
320
           if( center instanceof Dynamic3D) mInterP[mNumEffects] = (Dynamic3D)center;
319
           if( center instanceof Dynamic3D) mInter[1][mNumEffects] = (Dynamic3D)center;
321 320
      else if( center instanceof Static3D )
322 321
        {
323
        mInterP[mNumEffects] = null;
322
        mInter[1][mNumEffects] = null;
324 323
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static3D)center).getX();
325 324
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)center).getY();
326 325
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)center).getZ();
327 326
        }
328 327
      else return -1;
329 328

  
330
           if( data instanceof Dynamic4D  ) mInterI[mNumEffects] = (Dynamic4D)data;
331
      else if( data instanceof DynamicQuat) mInterI[mNumEffects] = (DynamicQuat)data;
329
           if( data instanceof Dynamic4D  ) mInter[0][mNumEffects] = (Dynamic4D)data;
330
      else if( data instanceof DynamicQuat) mInter[0][mNumEffects] = (DynamicQuat)data;
332 331
      else if( data instanceof Static4D   )
333 332
        {
334
        mInterI[mNumEffects] = null;
333
        mInter[0][mNumEffects] = null;
335 334
        mUniforms[NUM_UNIFORMS*mNumEffects+3] = ((Static4D)data).getX();
336 335
        mUniforms[NUM_UNIFORMS*mNumEffects+4] = ((Static4D)data).getY();
337 336
        mUniforms[NUM_UNIFORMS*mNumEffects+5] = ((Static4D)data).getZ();
......
352 351
    {
353 352
    if( mMax[INDEX]>mNumEffects )
354 353
      {
355
           if( center instanceof Dynamic3D) mInterP[mNumEffects] = (Dynamic3D)center;
354
           if( center instanceof Dynamic3D) mInter[1][mNumEffects] = (Dynamic3D)center;
356 355
      else if( center instanceof Static3D )
357 356
        {
358
        mInterP[mNumEffects] = null;
357
        mInter[1][mNumEffects] = null;
359 358
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static3D)center).getX();
360 359
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)center).getY();
361 360
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)center).getZ();
362 361
        }
363 362
      else return -1;
364 363

  
365
           if( shear instanceof Dynamic3D) mInterI[mNumEffects] = (Dynamic3D)shear;
364
           if( shear instanceof Dynamic3D) mInter[0][mNumEffects] = (Dynamic3D)shear;
366 365
      else if( shear instanceof Static3D )
367 366
        {
368
        mInterI[mNumEffects] = null;
367
        mInter[0][mNumEffects] = null;
369 368
        mUniforms[NUM_UNIFORMS*mNumEffects+3] = ((Static3D)shear).getX();
370 369
        mUniforms[NUM_UNIFORMS*mNumEffects+4] = ((Static3D)shear).getY();
371 370
        mUniforms[NUM_UNIFORMS*mNumEffects+5] = ((Static3D)shear).getZ();
src/main/java/org/distorted/library/EffectQueueVertex.java
26 26
import org.distorted.library.type.Data2D;
27 27
import org.distorted.library.type.Data3D;
28 28
import org.distorted.library.type.Data4D;
29
import org.distorted.library.type.Dynamic;
30 29
import org.distorted.library.type.Dynamic1D;
31 30
import org.distorted.library.type.Dynamic2D;
31
import org.distorted.library.type.Dynamic3D;
32 32
import org.distorted.library.type.Dynamic4D;
33 33
import org.distorted.library.type.Static1D;
34 34
import org.distorted.library.type.Static2D;
35
import org.distorted.library.type.Static3D;
35 36
import org.distorted.library.type.Static4D;
36 37

  
37 38
///////////////////////////////////////////////////////////////////////////////////////////////////
......
70 71
   
71 72
    for(int i=0; i<mNumEffects; i++)
72 73
      {
73
      if( mInterI[i]==null ) continue;    
74
      if( mInter[0][i]==null ) continue;
74 75
      
75
      if( mInterP[i]!=null ) 
76
      if( mInter[1][i]!=null )
76 77
        {
77
        mInterP[i].interpolateMain(mUniforms, NUM_UNIFORMS*i+7, mCurrentDuration[i]);
78
        mInter[1][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+7, mCurrentDuration[i]);
78 79
      
79 80
        mUniforms[NUM_UNIFORMS*i+7] = mUniforms[NUM_UNIFORMS*i+7]-mObjHalfX;
80 81
        mUniforms[NUM_UNIFORMS*i+8] =-mUniforms[NUM_UNIFORMS*i+8]+mObjHalfY;
81 82
        }
82
        
83
      if( mInterI[i].interpolateMain(mUniforms ,NUM_UNIFORMS*i, mCurrentDuration[i], step) )      
83

  
84
      if( mInter[2][i]!=null )
85
        {
86
        mInter[2][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+3, mCurrentDuration[i]);
87
        }
88

  
89
      if( mInter[0][i].interpolateMain(mUniforms ,NUM_UNIFORMS*i, mCurrentDuration[i], step) )
84 90
        {
85 91
        for(int j=0; j<mNumListeners; j++)   
86 92
          EffectMessageSender.newMessage( mListeners.elementAt(j),
......
160 166
    }
161 167
  
162 168
///////////////////////////////////////////////////////////////////////////////////////////////////
163
  
169
// distort
170

  
164 171
  synchronized long add(EffectNames eln, Data3D data, Data2D center, Data4D region)
165 172
    {
166 173
    if( mMax[INDEX]>mNumEffects )
167 174
      {
168 175
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);    
169
      
170
      mInterI[mNumEffects] = inter;
171
      mInterP[mNumEffects] = point;
172 176

  
173
      return addPriv(eln,region);
177
      if( data instanceof Dynamic3D)
178
        mInter[0][mNumEffects] = (Dynamic3D)data;
179
      else if( data instanceof Static3D)
180
        {
181
        mInter[0][mNumEffects] = null;
182
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static3D)data).getX();
183
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)data).getY();
184
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)data).getZ();
185
        }
186

  
187
      return addPriv(eln,center,region);
174 188
      }
175 189
      
176 190
    return -1;
177 191
    }
178 192
   
179 193
///////////////////////////////////////////////////////////////////////////////////////////////////
180
  
194
// deform, distort
195

  
181 196
  synchronized long add(EffectNames eln, Data3D data, Data2D center)
182 197
    {
183 198
    if( mMax[INDEX]>mNumEffects )
184 199
      {
185 200
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);    
186
      
187
      mInterI[mNumEffects] = inter;
188
      mInterP[mNumEffects] = null;
189
      mUniforms[NUM_UNIFORMS*mNumEffects+7] = point.getX()-mObjHalfX;
190
      mUniforms[NUM_UNIFORMS*mNumEffects+8] =-point.getY()+mObjHalfY;
191
     
192
      return addPriv(eln,null);
201

  
202
      if( data instanceof Dynamic3D)
203
        mInter[0][mNumEffects] = (Dynamic3D)data;
204
      else if( data instanceof Static3D)
205
        {
206
        mInter[0][mNumEffects] = null;
207
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static3D)data).getX();
208
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)data).getY();
209
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)data).getZ();
210
        }
211

  
212
      return addPriv(eln,center,null);
193 213
      }
194 214
      
195 215
    return -1;
196 216
    }
197 217
 
198 218
///////////////////////////////////////////////////////////////////////////////////////////////////
199
  
219
// sink, swirl
220

  
200 221
  synchronized long add(EffectNames eln, Data1D data, Data2D center, Data4D region)
201 222
    {
202 223
    if( mMax[INDEX]>mNumEffects )
203 224
      {
204
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); 
205
      mUniforms[NUM_UNIFORMS*mNumEffects  ] = v1;
206
      mUniforms[NUM_UNIFORMS*mNumEffects+1] = v2;  
207
      mUniforms[NUM_UNIFORMS*mNumEffects+2] = v3;  
208
     
209
      mInterI[mNumEffects] = null;
210
      mInterP[mNumEffects] = null;
211
      mUniforms[NUM_UNIFORMS*mNumEffects+7] = point.getX()-mObjHalfX;
212
      mUniforms[NUM_UNIFORMS*mNumEffects+8] =-point.getY()+mObjHalfY;
213
      
214
      return addPriv(eln,region);    
225
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
226

  
227
      if( data instanceof Dynamic1D)
228
        mInter[0][mNumEffects] = (Dynamic1D)data;
229
      else if( data instanceof Static1D)
230
        {
231
        mInter[0][mNumEffects] = null;
232
        mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)data).getX();
233
        }
234

  
235
      return addPriv(eln,center,region);
215 236
      }
216 237
      
217 238
    return -1;
......
227 248
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
228 249

  
229 250
      if( data instanceof Dynamic1D)
230
        mInterI[mNumEffects] = (Dynamic1D)data;
251
        mInter[0][mNumEffects] = (Dynamic1D)data;
231 252
      else if( data instanceof Static1D)
232 253
        {
233
        mInterI[mNumEffects] = null;
254
        mInter[0][mNumEffects] = null;
234 255
        mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)data).getX();
235 256
        }
236 257

  
237
      mUniforms[NUM_UNIFORMS*mNumEffects+7] = point.getX()-mObjHalfX;
238
      mUniforms[NUM_UNIFORMS*mNumEffects+8] =-point.getY()+mObjHalfY;
239

  
240
      return addPriv(eln,null);
258
      return addPriv(eln,center,null);
241 259
      }
242 260

  
243 261
    return -1;
......
245 263

  
246 264
///////////////////////////////////////////////////////////////////////////////////////////////////
247 265
  
248
  private long addPriv(EffectNames eln, Data4D region)
249
    {    
266
  private long addPriv(EffectNames eln, Data2D center, Data4D region)
267
    {
268
    if( center instanceof Dynamic2D)
269
      mInter[1][mNumEffects] = (Dynamic2D)center;
270
    else if( center instanceof Static2D)
271
      {
272
      mInter[1][mNumEffects] = null;
273
      mUniforms[NUM_UNIFORMS*mNumEffects+7] = ((Static2D)center).getX()-mObjHalfX;
274
      mUniforms[NUM_UNIFORMS*mNumEffects+8] =-((Static2D)center).getY()+mObjHalfY;
275
      }
276

  
250 277
    if( region!=null )
251 278
      {
252 279
      if( region instanceof Dynamic4D)
253 280
        {
254
        mInterP[mNumEffects] = (Dynamic4D)region;
281
        mInter[2][mNumEffects] = (Dynamic4D)region;
255 282
        }
256 283
      else if ( region instanceof Static4D)
257 284
        {
......
263 290
        mUniforms[NUM_UNIFORMS*mNumEffects+4] =-tmp.getY();   // invert y already
264 291
        mUniforms[NUM_UNIFORMS*mNumEffects+5] = z<=0.0f ? 1000*mObjHalfX : z;
265 292
        mUniforms[NUM_UNIFORMS*mNumEffects+6] = tmp.getW();
293
        mInter[2][mNumEffects] = null;
266 294
        }
267 295
      else return -1;
268 296
      }
......
272 300
      mUniforms[NUM_UNIFORMS*mNumEffects+4] = 0.0f;
273 301
      mUniforms[NUM_UNIFORMS*mNumEffects+5] = 1000*mObjHalfX;
274 302
      mUniforms[NUM_UNIFORMS*mNumEffects+6] = 0.0f;
303
      mInter[2][mNumEffects] = null;
275 304
      }
276 305
    
277 306
    return addBase(eln);

Also available in: Unified diff