Project

General

Profile

« Previous | Next » 

Revision d57f3a14

Added by Leszek Koltunski over 7 years ago

Further progress with Apps.

View differences:

src/main/java/org/distorted/examples/deform/DeformRenderer.java
23 23
import javax.microedition.khronos.opengles.GL10;
24 24

  
25 25
import org.distorted.library.effect.EffectName;
26
import org.distorted.library.effect.MatrixEffectMove;
27
import org.distorted.library.effect.MatrixEffectShear;
28
import org.distorted.library.effect.VertexEffectDeform;
29
import org.distorted.library.effect.VertexEffectDistort;
26 30
import org.distorted.library.main.Distorted;
27 31
import org.distorted.library.main.DistortedEffects;
28 32
import org.distorted.library.main.DistortedScreen;
......
54 58
   private DistortedScreen mScreen;
55 59
   private Static3D touchPoint;
56 60

  
57
   private Dynamic3D mReleasedDistortDynamic;
58
   private Dynamic3D mMovingDistortDynamic;
59 61
   private Static3D[] vDistort;
60
   private Dynamic3D mReleasedDeformDynamic;
61
   private Dynamic3D mMovingDeformDynamic;
62 62
   private Static3D[] vDeform;
63
   private Dynamic3D mReleasedShearDynamic;
64
   private Dynamic3D mMovingShearDynamic;
65 63
   private Static3D[] vShear;
66 64

  
67 65
   private Static4D mRegion;
66
   private Static3D mMove;
68 67
   private int scrHeight, scrWidth;
69 68
   private float mRadius;
70 69

  
71 70
   private EffectName mMode = EffectName.DISTORT;
72
   private EffectName mLastEffect = EffectName.DISTORT;
71
   private long mLastEffect = -1;
72

  
73
   private MatrixEffectShear mMovingShear, mReleasedShear;
74
   private VertexEffectDistort mMovingDistort, mReleasedDistort;
75
   private VertexEffectDeform mMovingDeform, mReleasedDeform;
73 76

  
74 77
///////////////////////////////////////////////////////////////////////////////////////////////////
75 78

  
......
79 82

  
80 83
      stretchEffects = new DistortedEffects();
81 84
      mRegion = new Static4D(0,0,0,0);
85
      mMove   = new Static3D(0,0,0);
82 86

  
83 87
      // DISTORT
84
      mReleasedDistortDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f);
85
      mReleasedDistortDynamic.setMode(Dynamic3D.MODE_PATH);
86
      mMovingDistortDynamic = new Dynamic3D(0,0.5f);
87
      mMovingDistortDynamic.setMode(Dynamic3D.MODE_PATH);
88
      Dynamic3D releasedDistortDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f);
89
      releasedDistortDynamic.setMode(Dynamic3D.MODE_PATH);
90
      Dynamic3D movingDistortDynamic = new Dynamic3D(0,0.5f);
91
      movingDistortDynamic.setMode(Dynamic3D.MODE_PATH);
88 92

  
89 93
      vDistort = new Static3D[NUM_VECTORS];
90 94

  
91 95
      for(int i=0; i<NUM_VECTORS; i++)
92 96
        {
93 97
        vDistort[i] = new Static3D(0,0,0);
94
        mReleasedDistortDynamic.add(vDistort[i]);
98
        releasedDistortDynamic.add(vDistort[i]);
95 99
        }
96 100

  
97
      mMovingDistortDynamic.add(vDistort[0]);
101
      movingDistortDynamic.add(vDistort[0]);
98 102

  
99 103
      // Deform
100
      mReleasedDeformDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f);
101
      mReleasedDeformDynamic.setMode(Dynamic3D.MODE_PATH);
102
      mMovingDeformDynamic = new Dynamic3D(0,0.5f);
103
      mMovingDeformDynamic.setMode(Dynamic3D.MODE_PATH);
104
      Dynamic3D releasedDeformDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f);
105
      releasedDeformDynamic.setMode(Dynamic3D.MODE_PATH);
106
      Dynamic3D movingDeformDynamic = new Dynamic3D(0,0.5f);
107
      movingDeformDynamic.setMode(Dynamic3D.MODE_PATH);
104 108

  
105 109
      vDeform = new Static3D[NUM_VECTORS];
106 110

  
107 111
      for(int i=0; i<NUM_VECTORS; i++)
108 112
        {
109 113
        vDeform[i] = new Static3D(0,0,0);
110
        mReleasedDeformDynamic.add(vDeform[i]);
114
        releasedDeformDynamic.add(vDeform[i]);
111 115
        }
112 116

  
113
      mMovingDeformDynamic.add(vDeform[0]);
117
      movingDeformDynamic.add(vDeform[0]);
114 118

  
115 119
      // Shear
116
      mReleasedShearDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f);
117
      mReleasedShearDynamic.setMode(Dynamic3D.MODE_PATH);
118
      mMovingShearDynamic = new Dynamic3D(0,0.5f);
119
      mMovingShearDynamic.setMode(Dynamic3D.MODE_PATH);
120
      Dynamic3D releasedShearDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f);
121
      releasedShearDynamic.setMode(Dynamic3D.MODE_PATH);
122
      Dynamic3D movingShearDynamic = new Dynamic3D(0,0.5f);
123
      movingShearDynamic.setMode(Dynamic3D.MODE_PATH);
120 124

  
121 125
      vShear = new Static3D[NUM_VECTORS];
122 126

  
123 127
      for(int i=0; i<NUM_VECTORS; i++)
124 128
        {
125 129
        vShear[i] = new Static3D(0,0,0);
126
        mReleasedShearDynamic.add(vShear[i]);
130
        releasedShearDynamic.add(vShear[i]);
127 131
        }
128 132

  
129
      mMovingShearDynamic.add(vShear[0]);
133
      movingShearDynamic.add(vShear[0]);
130 134

  
131 135
      mScreen = new DistortedScreen(mView);
132 136
      mScreen.setDebug(DistortedScreen.DEBUG_FPS);
137

  
138
      mMovingDistort   = new VertexEffectDistort(movingDistortDynamic, touchPoint, mRegion);
139
      mMovingDeform    = new VertexEffectDeform(movingDeformDynamic, touchPoint, mRegion);
140
      mMovingShear     = new MatrixEffectShear(movingShearDynamic, touchPoint);
141
      mReleasedDistort = new VertexEffectDistort(releasedDistortDynamic, touchPoint, mRegion);
142
      mReleasedDeform  = new VertexEffectDeform(releasedDeformDynamic, touchPoint, mRegion);
143
      mReleasedShear   = new MatrixEffectShear(releasedShearDynamic, touchPoint);
144

  
145
      stretchEffects.apply(new MatrixEffectMove(mMove));
133 146
      }
134 147

  
135 148
///////////////////////////////////////////////////////////////////////////////////////////////////
......
190 203
     if( stretchTexture==null ) stretchTexture = new DistortedTexture(w,h);
191 204
     stretchTexture.setTexture(stretchBitmap);
192 205

  
193
     stretchEffects.abortAllEffects();
194
     stretchEffects.move( new Static3D(scrWidth/4,scrHeight/4,0) );
206
     mMove.set(scrWidth/4,scrHeight/4,0);
195 207

  
196 208
     mScreen.detachAll();
197 209
     mScreen.attach(stretchTexture,stretchEffects,stretchMesh);
......
233 245
     switch(mMode)
234 246
       {
235 247
       case DISTORT: vDistort[0].set(0,0,0);
236
                     mLastEffect = stretchEffects.distort( mMovingDistortDynamic, touchPoint, mRegion);
248
                     stretchEffects.apply(mMovingDistort);
249
                     mLastEffect = mMovingDeform.getID();
237 250
                     break;
238 251
       case DEFORM : vDeform[0].set(0,0,0);
239
                     mLastEffect = stretchEffects.deform( mMovingDeformDynamic, touchPoint, mRegion);
252
                     stretchEffects.apply(mMovingDeform);
253
                     mLastEffect = mMovingDeform.getID();
240 254
                     break;
241 255
       case SHEAR  : vShear[0].set(0,0,0);
242
                     mLastEffect = stretchEffects.shear(mMovingShearDynamic, touchPoint);
256
                     stretchEffects.apply(mMovingShear);
257
                     mLastEffect = mMovingShear.getID();
243 258
                     break;
244 259
       }
245 260
     }
......
263 278

  
264 279
   void up()
265 280
     {
266
     stretchEffects.abortByName(mLastEffect);
281
     stretchEffects.abortById(mLastEffect);
267 282

  
268 283
     float damp = -0.65f;
269 284

  
......
274 289
                       vDistort[i].set( vDistort[i-1].getX()*damp, vDistort[i-1].getY()*damp );
275 290
                       }
276 291
                     vDistort[NUM_VECTORS-1].set(0,0);
277
                     stretchEffects.distort( mReleasedDistortDynamic, touchPoint, mRegion);
292
                     stretchEffects.apply( mReleasedDistort);
278 293
                     break;
279 294
       case DEFORM : for(int i=1; i<NUM_VECTORS-1; i++)
280 295
                       {
281 296
                       vDeform[i].set( vDeform[i-1].getX()*damp, vDeform[i-1].getY()*damp );
282 297
                       }
283 298
                     vDeform[NUM_VECTORS-1].set(0,0);
284
                     stretchEffects.deform( mReleasedDeformDynamic, touchPoint, mRegion);
299
                     stretchEffects.apply( mReleasedDeform);
285 300
                     break;
286 301
       case SHEAR  : for(int i=1; i<NUM_VECTORS-1; i++)
287 302
                       {
288 303
                       vShear[i].set( vShear[i-1].getX()*damp, vShear[i-1].getY()*damp );
289 304
                       }
290 305
                     vShear[NUM_VECTORS-1].set(0,0);
291
                     stretchEffects.shear(mReleasedShearDynamic, touchPoint);
306
                     stretchEffects.apply(mReleasedShear);
292 307
                     break;
293 308
       }
294 309
     }

Also available in: Unified diff