Project

General

Profile

« Previous | Next » 

Revision d1abb41e

Added by Leszek Koltunski almost 5 years ago

Port Deform to the new setStretch-less API.

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.MatrixEffectScale;
26 27
import org.distorted.library.effect.MatrixEffectShear;
27 28
import org.distorted.library.effect.VertexEffectDeform;
28 29
import org.distorted.library.effect.VertexEffectDistort;
......
56 57
   private DistortedEffects mEffects;
57 58
   private MeshBase mMesh;
58 59
   private DistortedScreen mScreen;
59
   private Static3D mTouchPoint;
60
   private Static3D mTouchPoint, mScale;
60 61

  
61 62
   private Static3D[] vDistort;
62 63
   private Static3D[] vDeform;
......
80 81
      { 
81 82
      mView = view;
82 83

  
84
      mTexture    = new DistortedTexture();
83 85
      mEffects    = new DistortedEffects();
84 86
      mRegion     = new Static4D(0,0,0,0);
85 87
      mTouchPoint = new Static3D(0,0,0);
88
      mScale      = new Static3D(1,1,1);
89

  
90
      mEffects.apply( new MatrixEffectScale(mScale) );
86 91

  
87 92
      // DISTORT
88 93
      Dynamic3D releasedDistortDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f);
......
154 159

  
155 160
   void setRegionRadius(int r)
156 161
      {
157
      mRadius = ( r==100 ? 100.0f : r/200.0f);
158
      mRegion.set3(mRadius*scrWidth);
162
      mRadius = ( r==100 ? 100.0f : r/100.0f);
163
      mRegion.set3(mRadius);
159 164
      }
160 165

  
161 166
///////////////////////////////////////////////////////////////////////////////////////////////////
......
181 186
     scrHeight = height;
182 187
     scrWidth  = width;
183 188

  
184
     mRegion.set3(mRadius*scrWidth);
189
     mRegion.set3(mRadius);
185 190

  
186 191
     Canvas stretchCanvas;
187 192
     textureWidth = (int)(0.6f*width);
......
189 194

  
190 195
     if( mMesh!=null ) mMesh.markForDeletion();
191 196
     mMesh = new MeshRectangles(50,50*textureHeight/textureWidth);
192
     mMesh.setStretch(textureWidth,textureHeight,0);
197

  
198
     mScale.set(textureWidth,textureHeight,1);
193 199

  
194 200
     Bitmap stretchBitmap = Bitmap.createBitmap(textureWidth,textureHeight, Bitmap.Config.ARGB_8888);
195 201
     stretchCanvas = new Canvas(stretchBitmap);
......
206 212
       stretchCanvas.drawRect(                         0, textureHeight*i/NUM_LINES-1, textureWidth              , textureHeight*i/NUM_LINES+1, paint);
207 213
       }
208 214

  
209
     if( mTexture==null ) mTexture = new DistortedTexture();
210 215
     mTexture.setTexture(stretchBitmap);
211 216

  
212 217
     mScreen.detachAll();
......
236 241

  
237 242
   void down(int x, int y)
238 243
     {
239
     int xt = x-(scrWidth/2);
240
     int yt = (scrHeight/2)-y;
244
     float xt = (float)x/scrWidth-0.5f;
245
     float yt = 0.5f-(float)y/scrHeight;
241 246

  
242 247
     switch(mMode)
243 248
       {
......
263 268

  
264 269
   void move(int x, int y)
265 270
     {
271
     float xm = (float)x/textureWidth;
272
     float ym = (float)y/textureHeight;
273

  
266 274
     switch(mMode)
267 275
       {
268
       case DISTORT: vDistort[0].set(x,-y,0);
276
       case DISTORT: vDistort[0].set( xm,-ym, 0);
269 277
                     break;
270
       case DEFORM:  vDeform[0].set(x,-y,0);
278
       case DEFORM:  vDeform[0].set ( xm,-ym, 0);
271 279
                     break;
272
       case SHEAR:   vShear[0].set( (float)x/textureWidth, (float)(-y)/textureHeight, 0);
280
       case SHEAR:   vShear[0].set  ( xm,-ym, 0);
273 281
                     break;
274 282
       }
275 283
     }
......
280 288
     {
281 289
     mEffects.abortById(mLastEffect);
282 290

  
283
     float damp = -0.65f;
291
     final float DAMP = -0.65f;
284 292

  
285 293
     switch(mMode)
286 294
       {
287 295
       case DISTORT: for(int i=1; i<NUM_VECTORS-1; i++)
288 296
                       {
289
                       vDistort[i].set( vDistort[i-1].get0()*damp, vDistort[i-1].get1()*damp, 0 );
297
                       vDistort[i].set( vDistort[i-1].get0()*DAMP, vDistort[i-1].get1()*DAMP, 0 );
290 298
                       }
291 299
                     vDistort[NUM_VECTORS-1].set(0,0,0);
292 300
                     mEffects.apply(mReleasedDistort);
......
294 302
                     break;
295 303
       case DEFORM : for(int i=1; i<NUM_VECTORS-1; i++)
296 304
                       {
297
                       vDeform[i].set( vDeform[i-1].get0()*damp, vDeform[i-1].get1()*damp, 0 );
305
                       vDeform[i].set( vDeform[i-1].get0()*DAMP, vDeform[i-1].get1()*DAMP, 0 );
298 306
                       }
299 307
                     vDeform[NUM_VECTORS-1].set(0,0,0);
300 308
                     mEffects.apply(mReleasedDeform);
......
302 310
                     break;
303 311
       case SHEAR  : for(int i=1; i<NUM_VECTORS-1; i++)
304 312
                       {
305
                       vShear[i].set( vShear[i-1].get0()*damp, vShear[i-1].get1()*damp, 0 );
313
                       vShear[i].set( vShear[i-1].get0()*DAMP, vShear[i-1].get1()*DAMP, 0 );
306 314
                       }
307 315
                     vShear[NUM_VECTORS-1].set(0,0,0);
308 316
                     mEffects.apply(mReleasedShear);

Also available in: Unified diff