Project

General

Profile

« Previous | Next » 

Revision e8c81a8e

Added by Leszek Koltunski over 8 years ago

Cleanup, consistent variable names, minor details.

View differences:

src/main/java/org/distorted/library/Distorted.java
38 38
public class Distorted 
39 39
{
40 40
  /**
41
   * When creating an instance of a DistortedBitmap from another instance, do not clone anything.
41
   * When creating an instance of a DistortedObject from another instance, do not clone anything.
42 42
   * Used in the copy constructor.
43 43
   */
44 44
  public static final int CLONE_NOTHING = 0x0;
......
297 297
    mFOV = fov;
298 298
   
299 299
    if( mProjection.width>0 && mProjection.height>0 )
300
      mProjection.onSurfaceChanged( (int)mProjection.width, (int)mProjection.height);
300
      mProjection.onSurfaceChanged( mProjection.width, mProjection.height);
301 301
    }
302 302
  
303 303
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedObject.java
415 415

  
416 416
///////////////////////////////////////////////////////////////////////////////////////////////////
417 417
/**
418
 * Abort all Effects of a given type, for example all rotations.
418
 * Abort all Effects of a given name, for example all rotations.
419 419
 * 
420 420
 * @param name one of the constants defined in {@link EffectNames}
421 421
 * @return number of Effects aborted.
......
457 457
// Matrix-based effects
458 458
///////////////////////////////////////////////////////////////////////////////////////////////////
459 459
/**
460
 * Moves the Object by a vector that changes in time as interpolated by the Dynamic.
460
 * Moves the Object by a (possibly changing in time) vector.
461 461
 * 
462 462
 * @param vector 3-dimensional Data which at any given time will return a Static3D
463 463
 *               representing the current coordinates of the vector we want to move the Object with.
......
470 470

  
471 471
///////////////////////////////////////////////////////////////////////////////////////////////////
472 472
/**
473
 * Scales the Object by factors that change in time as returned by the Dynamic.
473
 * Scales the Object by (possibly changing in time) 3D scale factors.
474 474
 * 
475 475
 * @param scale 3-dimensional Dynamic which at any given time returns a Static3D
476 476
 *              representing the current x- , y- and z- scale factors.
......
483 483

  
484 484
///////////////////////////////////////////////////////////////////////////////////////////////////
485 485
/**
486
 * Scales the Object by one uniform factor in all 3 dimensions. Convenience function.
486
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
487 487
 *
488 488
 * @param scale The factor to scale all 3 dimensions with.
489 489
 * @return      ID of the effect added, or -1 if we failed to add one.
src/main/java/org/distorted/library/EffectMessageSender.java
105 105
      while( mList.size()>0 )
106 106
        {
107 107
        tmp = mList.remove(0);
108
        tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, tmp.mEffectName, tmp.mBitmapID, tmp.mStr);
108
        tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, EffectNames.getName(tmp.mEffectName),
109
                                    tmp.mBitmapID, tmp.mStr);
109 110
        }
110 111

  
111 112
      synchronized(mThis)
src/main/java/org/distorted/library/EffectNames.java
93 93
   * Uniforms: (forceX,forceY,forceZ,regionX,regionY,regionRX,regionRY,centerX,centerY)
94 94
   * Unity: (forceX,forceY,forceZ) = (0,0,0)
95 95
   */
96
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),      // keep this the first VERT effect (reason: getType)
96
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),
97 97
 /**
98 98
   * Deform the whole Object by applying a 2D vector of force to a center point.
99 99
   * <p>
......
126 126
   * Uniforms: (macroblockSize,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
127 127
   * Unity: macroblockSize = 1
128 128
   */
129
  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),      // keep this the first FRAG effect (reason: getType)
129
  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
130 130
 /**
131 131
   * Make a given Region (partially) transparent.
132 132
   * <p>
......
204 204
  
205 205
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
206 206
  
207
  private EffectTypes type;
208
  private float[] unity;
209
  
210
  static private float[] unities;
211
  static private int[] dimensions;
207
  private final EffectTypes type;
208
  private final float[] unity;
212 209
  
210
  private static final float[] unities;
211
  private static final int[] dimensions;
212
  private static final EffectNames[] names;
213

  
213 214
  static
214 215
    {
215 216
    int len = values().length;
......
217 218
    
218 219
    dimensions = new int[len];
219 220
    unities    = new float[MAXDIM*len];
220
    
221
    names      = new EffectNames[len];
222

  
221 223
    for(EffectNames name: EffectNames.values())
222 224
      {
223 225
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
224
      
226
      names[i]      = name;
227

  
225 228
      switch(dimensions[i])
226 229
        {
227 230
        case 4: unities[MAXDIM*i+3] = name.unity[3];
......
244 247
    }
245 248

  
246 249
///////////////////////////////////////////////////////////////////////////////////////////////////
247
// yes, I know we could have used values(i) but that allocates a new copy each time!
248 250

  
249 251
  static EffectTypes getType(int ordinal)
250 252
    {
251
    if( ordinal<DISTORT.ordinal()     ) return EffectTypes.MATRIX;
252
    if( ordinal<MACROBLOCK.ordinal()  ) return EffectTypes.VERTEX;
253
    return names[ordinal].type;
254
    }
253 255

  
254
    return EffectTypes.FRAGMENT;
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

  
258
  static EffectNames getName(int ordinal)
259
    {
260
    return names[ordinal];
255 261
    }
256 262

  
257 263
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/EffectQueue.java
32 32
  protected byte mNumEffects;   // number of effects at the moment
33 33
  protected long mTotalEffects; // total number of effects ever created
34 34
  
35
  protected int[] mType;
35
  protected int[] mName;
36 36
  protected float[] mUniforms;
37 37
  protected Dynamic[][] mInter;  // center of the effect
38 38
  protected long[] mCurrentDuration;
......
76 76

  
77 77
    if( mMax[mMaxIndex]>0 )
78 78
      {
79
      mType            = new int[mMax[mMaxIndex]];
79
      mName            = new int[mMax[mMaxIndex]];
80 80
      mUniforms        = new float[numUniforms*mMax[mMaxIndex]];
81 81
      mInter           = new Dynamic[3][mMax[mMaxIndex]];
82 82
      mCurrentDuration = new long[mMax[mMaxIndex]];
......
175 175
     
176 176
    for(int i=0; i<mNumEffects; i++)
177 177
      {
178
      if( mType[i]==ord )
178
      if( mName[i]==ord )
179 179
        {
180 180
        remove(i);
181 181
        i--;
......
202 202
    {
203 203
    int ret = mNumEffects;
204 204
    long removedID;
205
    int removedType;
205
    int removedName;
206 206

  
207 207
    for(int i=0; i<ret; i++ )
208 208
      {
......
213 213
      if( notify )
214 214
        {
215 215
        removedID = mID[i];
216
        removedType= mType[i];
216
        removedName= mName[i];
217 217

  
218 218
        for(int j=0; j<mNumListeners; j++)
219 219
          EffectMessageSender.newMessage( mListeners.elementAt(j),
220 220
                                          EffectMessage.EFFECT_REMOVED,
221
                                          (removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedType).type,
222
                                          removedType,
221
                                          (removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedName).type,
222
                                          removedName,
223 223
                                          mBitmapID,
224 224
                                          null);
225 225
        }
......
242 242
    mFreeIndexes[mNumEffects] = removedIndex;
243 243
    
244 244
    long removedID = mID[effect];
245
    int removedType= mType[effect];
245
    int removedName= mName[effect];
246 246
    
247 247
    for(int j=0; j<mMax[mMaxIndex]; j++)
248 248
      {
......
251 251
         
252 252
    for(int j=effect; j<mNumEffects; j++ ) 
253 253
      {
254
      mType[j]            = mType[j+1];
254
      mName[j]            = mName[j+1];
255 255
      mInter[0][j]        = mInter[0][j+1];
256 256
      mInter[1][j]        = mInter[1][j+1];
257 257
      mInter[2][j]        = mInter[2][j+1];
......
268 268
    for(int i=0; i<mNumListeners; i++) 
269 269
      EffectMessageSender.newMessage( mListeners.elementAt(i),
270 270
                                      EffectMessage.EFFECT_REMOVED,
271
                                      (removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedType).type,
272
                                      removedType,
271
                                      (removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedName).type,
272
                                      removedName,
273 273
                                      mBitmapID,
274 274
                                      null);
275 275
    }
276 276
  
277 277
///////////////////////////////////////////////////////////////////////////////////////////////////
278 278
  
279
  protected long addBase(EffectNames eln)
279
  protected long addBase(EffectNames name)
280 280
    {    
281
    mType[mNumEffects]  = eln.ordinal();  
281
    mName[mNumEffects]  = name.ordinal();
282 282
    mCurrentDuration[mNumEffects] = 0;
283 283
    
284 284
    int index = mFreeIndexes[mNumEffects];
......
289 289
    mNumEffects++; 
290 290
    mTotalEffects++;
291 291
   
292
    return (id<<EffectTypes.LENGTH)+eln.getType().type;
292
    return (id<<EffectTypes.LENGTH)+name.getType().type;
293 293
    }
294 294
    
295 295
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/EffectQueueFragment.java
80 80
          EffectMessageSender.newMessage( mListeners.elementAt(j),
81 81
                                          EffectMessage.EFFECT_FINISHED,
82 82
                                          (mID[i]<<EffectTypes.LENGTH)+EffectTypes.FRAGMENT.type,
83
                                          mType[i], 
83
                                          mName[i],
84 84
                                          mBitmapID,
85 85
                                          null);
86 86
      
87
        if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i) )
87
        if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
88 88
          {
89 89
          remove(i);
90 90
          i--;
91 91
          continue;
92 92
          }
93
        else mInter[0][i] = null;
93 94
        }
94 95

  
95 96
      if( mInter[1][i]!=null ) mInter[1][i].interpolateMain(     mBuf,            4*i  , mCurrentDuration[i]);
......
125 126
      
126 127
    if( mNumEffects>0 )
127 128
      {     
128
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mType    ,0);
129
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName,0);
129 130
      GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
130 131
      }  
131 132
    }
......
160 161
        mUniforms[NUM_UNIFORMS*i+6] = w*mBuf[4*i+2];                                  // in fragment shader rx and ry radii are the last two values of the second vec4
161 162
        mUniforms[NUM_UNIFORMS*i+7] = h*mBuf[4*i+3];                                  //
162 163

  
163
        if( mType[i]==EffectNames.MACROBLOCK.ordinal() ) // fill up the .y and .z components of the Interpolated values already to avoid having to compute this in the fragment shader
164
        if( mName[i]==EffectNames.MACROBLOCK.ordinal() ) // fill up the .y and .z components of the Interpolated values already to avoid having to compute this in the fragment shader
164 165
          {
165 166
          mUniforms[NUM_UNIFORMS*i+1] = 2.0f*mObjHalfX/mUniforms[NUM_UNIFORMS*i];
166 167
          mUniforms[NUM_UNIFORMS*i+2] = 2.0f*mObjHalfY/mUniforms[NUM_UNIFORMS*i];
src/main/java/org/distorted/library/EffectQueueMatrix.java
111 111
          EffectMessageSender.newMessage( mListeners.elementAt(j),
112 112
                                          EffectMessage.EFFECT_FINISHED,
113 113
                                         (mID[i]<<EffectTypes.LENGTH)+EffectTypes.MATRIX.type,
114
                                          mType[i],
114
                                          mName[i],
115 115
                                          mBitmapID,
116 116
                                          null);
117 117

  
118
        if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i) )
118
        if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
119 119
          {
120 120
          remove(i);
121 121
          i--;
122 122
          continue;
123 123
          }
124
        else mInter[0][i] = null;
124 125
        }
125 126

  
126 127
      if( mInter[1][i]!=null )
......
159 160
   
160 161
    for(int i=0; i<mNumEffects; i++)
161 162
      {
162
      if (mType[i] == EffectNames.ROTATE.ordinal() )
163
      if (mName[i] == EffectNames.ROTATE.ordinal() )
163 164
        {
164 165
        x = mUniforms[NUM_UNIFORMS*i+4];
165 166
        y = mUniforms[NUM_UNIFORMS*i+5];
......
169 170
        Matrix.rotateM( viewMatrix, 0, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
170 171
        Matrix.translateM(viewMatrix, 0,-x, y,-z);  
171 172
        }
172
      else if(mType[i] == EffectNames.QUATERNION.ordinal() )
173
      else if(mName[i] == EffectNames.QUATERNION.ordinal() )
173 174
        {
174 175
        x = mUniforms[NUM_UNIFORMS*i+4];
175 176
        y = mUniforms[NUM_UNIFORMS*i+5];
......
179 180
        multiplyByQuat(viewMatrix, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
180 181
        Matrix.translateM(viewMatrix, 0,-x, y,-z);  
181 182
        }
182
      else if(mType[i] == EffectNames.MOVE.ordinal() )
183
      else if(mName[i] == EffectNames.MOVE.ordinal() )
183 184
        {
184 185
        sx = mUniforms[NUM_UNIFORMS*i  ];
185 186
        sy = mUniforms[NUM_UNIFORMS*i+1];
......
187 188
        
188 189
        Matrix.translateM(viewMatrix, 0, sx,-sy, sz);   
189 190
        }
190
      else if(mType[i] == EffectNames.SCALE.ordinal() )
191
      else if(mName[i] == EffectNames.SCALE.ordinal() )
191 192
        {
192 193
        sx = mUniforms[NUM_UNIFORMS*i  ];
193 194
        sy = mUniforms[NUM_UNIFORMS*i+1];
......
195 196

  
196 197
        Matrix.scaleM(viewMatrix, 0, sx, sy, sz);  
197 198
        }
198
      else if(mType[i] == EffectNames.SHEAR.ordinal() )
199
      else if(mName[i] == EffectNames.SHEAR.ordinal() )
199 200
        {
200 201
        sx = mUniforms[NUM_UNIFORMS*i  ];
201 202
        sy = mUniforms[NUM_UNIFORMS*i+1];
src/main/java/org/distorted/library/EffectQueueVertex.java
77 77
          EffectMessageSender.newMessage( mListeners.elementAt(j),
78 78
                                          EffectMessage.EFFECT_FINISHED,
79 79
                                         (mID[i]<<EffectTypes.LENGTH)+EffectTypes.VERTEX.type,
80
                                          mType[i],
80
                                          mName[i],
81 81
                                          mBitmapID,
82 82
                                          null);
83 83

  
84
        if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i) )
84
        if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
85 85
          {
86 86
          remove(i);
87 87
          i--;
88 88
          continue;
89 89
          }
90
        else mInter[0][i] = null;
90 91
        }
91 92

  
92 93
      if( mInter[1][i]!=null )
......
100 101

  
101 102
        mUniforms[NUM_UNIFORMS*i+7] = mUniforms[NUM_UNIFORMS*i+7]-mObjHalfX;
102 103
        mUniforms[NUM_UNIFORMS*i+8] =-mUniforms[NUM_UNIFORMS*i+8]+mObjHalfY;
103

  
104
        //android.util.Log.e("queue", "computing dynamic center, x="+(mUniforms[NUM_UNIFORMS*i+7]));
105 104
        }
106 105

  
107 106
      mCurrentDuration[i] += step;
......
133 132
      
134 133
    if( mNumEffects>0 )
135 134
      {     
136
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mType    ,0);
135
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName,0);
137 136
      GLES20.glUniform3fv( mUniformsH,3*mNumEffects, mUniforms,0);
138 137
      }
139 138
    }
......
156 155
     
157 156
    for(int i=0; i<mNumEffects; i++)
158 157
      {      
159
      if( mType[i]==EffectNames.SWIRL.ordinal() )
158
      if( mName[i]==EffectNames.SWIRL.ordinal() )
160 159
        {
161 160
        d = Math.PI*mUniforms[NUM_UNIFORMS*i]/180;  
162 161
        mUniforms[NUM_UNIFORMS*i+1] = (float)Math.sin(d);
src/main/java/org/distorted/library/message/EffectListener.java
37 37
 * @param eventType  Type of event that happened.
38 38
 * @param effectID   ID of the effect the event happened to. This ID must have been previously returned by one
39 39
 *                   of the DistortedObject.{deform,distort,move,...} functions.
40
 * @param effectName Name of the effect as defined by EffectNames.ordinal()
41
 * @param bitmapID   the ID of the DistortedObject object, as returned by {@link org.distorted.library.DistortedObject#getID()},
40
 * @param effectName Name of the effect as defined by EffectNames.
41
 * @param objectID   the ID of the DistortedObject object, as returned by {@link org.distorted.library.DistortedObject#getID()},
42 42
 *                   this event happened to. If the Object has been created using a copy constructor
43 43
 *                   from another instance of DistortedObject, the ID here will be the one of the original object.
44 44
 * @param message    Any message string associated with it. 'Failed' event types have one.
......
46 46
 * @see EffectNames
47 47
 */
48 48
   
49
  void effectMessage(final EffectMessage eventType, final long effectID, final int effectName, final long bitmapID, final String message);
49
  void effectMessage(final EffectMessage eventType, final long effectID, final EffectNames effectName, final long objectID, final String message);
50 50
  }
51 51

  
52 52
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/message/EffectMessage.java
21 21

  
22 22
///////////////////////////////////////////////////////////////////////////////////////////////////
23 23

  
24
import org.distorted.library.DistortedBitmap;
25
import org.distorted.library.type.Dynamic;
26

  
27 24
/**
28 25
* Defines all possible events a class implementing the {@link EffectListener} interface can receive.
29 26
*/
......
33 30
/**
34 31
 * The effect has been removed. This can happen if:
35 32
 * <ul>
36
 * <li> someone explicitly removed the effect with a call to {@link DistortedBitmap#abortEffect(long)} (or one of the other 'abort' methods)
33
 * <li> someone explicitly removed the effect with a call to {@link org.distorted.library.DistortedObject#abortEffect(long)}
34
 *      (or one of the other 'abort' methods)
37 35
 * <li> the interpolation of the effect has finished and the end result is equal to the effect's unity.
38 36
 * </ul>    
39 37
 */
......
43 41
 * Interpolation of the effect has finished. 
44 42
 * <p>
45 43
 * If you set up an interpolated effect and set its Dynamic to do 3.5 interpolations of 1000 ms each
46
 * with calls to {@link Dynamic#setCount(float)} and {@link Dynamic#setDuration(long)},
44
 * with calls to {@link org.distorted.library.type.Dynamic#setCount(float)} and {@link org.distorted.library.type.Dynamic#setDuration(long)},
47 45
 * then you are going to get this message exactly once after 3.5*1000 = 3500 milliseconds when the interpolation 
48 46
 * finishes. You will never get this message if you set the effect to go on indefinitely with a call to 
49
 * {@link Dynamic#setCount(float)}.
47
 * {@link org.distorted.library.type.Dynamic#setCount(float)} where float=0.0f.
50 48
 * <p>  
51 49
 * If then the end effect is equal to the effect's unity, then immediately after this message you
52 50
 * will also get a EFFECT_REMOVED message.

Also available in: Unified diff