Project

General

Profile

« Previous | Next » 

Revision 97dadfe5

Added by Leszek Koltunski over 7 years ago

1. Attempt to deal with unstable Orthonormal Base in Dynamic class (so far unsuccessful)
2. Improvements to the 'Dynamic' (and by necessity, 'MovingEffects') applications (to be able to debug the previous)

View differences:

src/main/java/org/distorted/examples/dynamic/DynamicActivity.java
56 56
      progress1=0;
57 57
      progress2=0;
58 58

  
59

  
60
      //textD.setText("Duration: 10 s");
61
      //textN.setText("Noise: 0.0");
62

  
63 59
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise0);
64 60
      bar.setProgress(0);
65 61
      bar.setOnSeekBarChangeListener(this);
src/main/java/org/distorted/examples/dynamic/DynamicRenderer.java
31 31

  
32 32
import org.distorted.library.DistortedBitmap;
33 33
import org.distorted.library.Distorted;
34
import org.distorted.library.EffectTypes;
35
import org.distorted.library.type.Static3D;
36 34

  
37 35
///////////////////////////////////////////////////////////////////////////////////////////////////
38 36

  
39
public class DynamicRenderer implements GLSurfaceView.Renderer
37
class DynamicRenderer implements GLSurfaceView.Renderer
40 38
   {  
41
   public static final int BWID = 300;
42
   public static final int BHEI = 400;
43
   
44 39
   private GLSurfaceView mView;
45 40
   private DistortedBitmap mBackground;
46 41
   private Canvas mCanvas;
47 42
   private Bitmap mBitmap;
48 43
   private Paint mPaint;
49
   private int texWidth, texHeight;
44

  
45
   static int texW, texH;
50 46
    
51 47
///////////////////////////////////////////////////////////////////////////////////////////////////
52 48

  
53
   public DynamicRenderer(GLSurfaceView v)
49
   DynamicRenderer(GLSurfaceView v)
54 50
     {    
55 51
     mPaint = new Paint();
56 52
     mPaint.setAntiAlias(true);
......
59 55
     mPaint.setStyle(Style.FILL);
60 56
      
61 57
     mView = v;
62
      
63
     texWidth = BWID;
64
     texHeight= BHEI;
65 58
     }
66 59

  
67 60
///////////////////////////////////////////////////////////////////////////////////////////////////
68 61
   
69 62
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
70 63
     {   
71
     mBackground = new DistortedBitmap(texWidth,texHeight, 2);    
72
     mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
73
     mCanvas = new Canvas(mBitmap);
74
     
75 64
     try
76 65
        {
77 66
        Distorted.onSurfaceCreated(mView.getContext());
......
86 75

  
87 76
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
88 77
     {
89
     mBackground.abortEffects(EffectTypes.MATRIX);
90
     mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
91
     Distorted.onSurfaceChanged(width, height);
92
     DynamicSurfaceView.setScreenSize(width,height);
78
     texW = width;
79
     texH = height;
80

  
81
     mBackground = new DistortedBitmap(texW,texH, 2);
82
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
83
     mCanvas = new Canvas(mBitmap);
84

  
85
     Distorted.onSurfaceChanged(texW,texH);
93 86
     }
94 87
   
95 88
///////////////////////////////////////////////////////////////////////////////////////////////////
......
100 93
       
101 94
     long time = System.currentTimeMillis();
102 95
      
103
     mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
96
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
104 97
     DynamicSurfaceView.drawCurve(mCanvas,time);
105 98
     mBackground.setBitmap(mBitmap);
106 99
     mBackground.draw(time);
src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java
44 44
    public static final int DIM_3DXY = 2; 
45 45
    public static final int DIM_3DXZ = 3; 
46 46

  
47
    private static final int NUM_INTERPOLATIONS= 100;
48
    private static final int MAX_VECTORS       =   6;
47
    private static final int NUM_POINTS = 400;
48
    private static final int MAX_VECTORS=   6;
49 49

  
50 50
    private static final Object lock = new Object();
51 51

  
52
    private static int xDown,yDown;
53
    private static int mScrW, mScrH;
54
   
55 52
    private static Dynamic1D di1D;
56 53
    private static Dynamic2D di2D;
57 54
    private static Dynamic3D di3D;
58 55
    
59 56
    private static Paint mPaint;
60 57
    private static int moving;
61
    private static long mTime = 0;
62 58
    private static int mDuration;
63
    private static float mPosition;
59
    private static int mPosition;
64 60
    private static float mNoise0, mNoise1, mNoise2;
65 61
    
66
    private static int currentDim = DIM_2D;
62
    private static int currentDim;
67 63
    
68 64
    private static Static1D p1D;
69 65
    private static Static2D p2D;
......
73 69
    private static Static2D p2N;
74 70
    private static Static3D p3N;
75 71

  
76
    private static float[] mDrawCoord = new float[3];
72
    private static float[] mPoints = new float[3*NUM_POINTS];
77 73
      
78 74
///////////////////////////////////////////////////////////////////
79 75
    
......
84 80
      mPaint = new Paint();
85 81
      mPaint.setStyle(Style.FILL);
86 82
      mPaint.setAntiAlias(true);
87
      
83

  
84
      currentDim= DIM_2D;
88 85
      moving    = -1;
89 86
      mDuration = 10000;
90 87
      mPosition = 0;
......
92 89
      mNoise1   = 0.0f;
93 90
      mNoise2   = 0.0f;
94 91

  
95
      di1D = new Dynamic1D(mDuration,0.5f);
92
      di1D = new Dynamic1D(mDuration,0.0f);
96 93
      p1N  = new Static1D(mNoise0);
97
      di2D = new Dynamic2D(mDuration,0.5f);
94
      di2D = new Dynamic2D(mDuration,0.0f);
98 95
      p2N  = new Static2D(mNoise0,mNoise1);
99
      di3D = new Dynamic3D(mDuration,0.5f);
96
      di3D = new Dynamic3D(mDuration,0.0f);
100 97
      p3N  = new Static3D(mNoise0,mNoise1,mNoise2);
101 98

  
102 99
      if(!isInEditMode())
......
124 121
      di2D.setMode(mode);
125 122
      di3D.setMode(mode);
126 123
      }
127
      
128
///////////////////////////////////////////////////////////////////
129
    
130
    public static void setScreenSize(int width, int height)
131
      {
132
      mScrW = width;
133
      mScrH = height;
134
      }
135 124

  
136 125
///////////////////////////////////////////////////////////////////
137 126

  
......
174 163
            di1D.removeAll();
175 164
            di2D.removeAll();
176 165
            di3D.removeAll();
166

  
167
            for(int i=0; i<3*NUM_POINTS; i++)
168
              {
169
              mPoints[i] = -10.0f;
170
              }
177 171
            }
178 172
          }
179 173
      
......
185 179
    
186 180
    public static void drawCurve(Canvas c, long time)
187 181
      {
188
      mPosition += (mTime>0 && mDuration>0) ? ((float)(time-mTime)*NUM_INTERPOLATIONS/mDuration) : 0; 
182
      if ( ++mPosition >= NUM_POINTS ) mPosition=0;
189 183
         
190 184
      synchronized(lock)
191 185
        {
......
196 190
          default    : drawCurve3D(c,time); break;
197 191
          }
198 192
        }
199
      
200
      mTime = time;
201 193
      }
202 194

  
203 195
///////////////////////////////////////////////////////////////////
......
205 197
    private static void drawCurve1D(Canvas c, long time)
206 198
      {
207 199
      int len = di1D.getNumPoints();   
208
        
200
      int size1 = DynamicRenderer.texH/200;
201
      int size2 = DynamicRenderer.texH/80;
202

  
209 203
      mPaint.setColor(0xff000000);
210 204
      
211
      c.drawLine(0, DynamicRenderer.BHEI/2, DynamicRenderer.BWID, DynamicRenderer.BHEI/2, mPaint);
212
      c.drawText("x", 0.95f* DynamicRenderer.BWID, 0.55f* DynamicRenderer.BHEI , mPaint);
213
      
205
      c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW, DynamicRenderer.texH/2, mPaint);
206
      c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
207

  
214 208
      if( len>=2 )
215 209
        {
216
        for(int i=0; i<NUM_INTERPOLATIONS; i++) 
210
        di1D.interpolateMain(mPoints,3*mPosition, time);
211

  
212
        for(int i=0; i<NUM_POINTS; i++)
217 213
          {
218
          int color = i<=mPosition ? 0xff - ((int)mPosition                   -i)*0xff/(NUM_INTERPOLATIONS-1)  
219
                                   : 0xff - ((int)mPosition+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
214
          int color = i<=mPosition ? 0xff - (mPosition           -i)*0xff/(NUM_POINTS-1)
215
                                   : 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
220 216
         
221 217
          mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); 
222
          di1D.interpolate(mDrawCoord,0, (float)i/NUM_INTERPOLATIONS);
223
          c.drawCircle(mDrawCoord[0], DynamicRenderer.BHEI/2 , 2.0f, mPaint );
218
          c.drawCircle(mPoints[3*i], DynamicRenderer.texH/2 , size1, mPaint );
224 219
          }
225 220
        }
226 221
     
......
229 224
      for(int curr=0; curr<len; curr++)
230 225
        {      
231 226
        p1D = di1D.getPoint(curr);
232
        c.drawCircle(p1D.getX(), DynamicRenderer.BHEI/2 , 5.0f, mPaint);
227
        c.drawCircle(p1D.getX(), DynamicRenderer.texH/2 , size2, mPaint);
233 228
        }   
234 229
      }
235 230
    
......
238 233
    private static void drawCurve2D(Canvas c, long time)
239 234
      {
240 235
      int len = di2D.getNumPoints();   
241
        
236
      int size1 = DynamicRenderer.texH/200;
237
      int size2 = DynamicRenderer.texH/80;
238

  
242 239
      mPaint.setColor(0xff000000);
243 240
      
244
      c.drawLine(0, DynamicRenderer.BHEI/2, DynamicRenderer.BWID, DynamicRenderer.BHEI/2, mPaint);
245
      c.drawLine(DynamicRenderer.BWID/2, 0, DynamicRenderer.BWID/2, DynamicRenderer.BHEI, mPaint);
241
      c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW, DynamicRenderer.texH/2, mPaint);
242
      c.drawLine(DynamicRenderer.texW/2, 0, DynamicRenderer.texW/2, DynamicRenderer.texH, mPaint);
246 243
      
247
      c.drawText("x", 0.95f* DynamicRenderer.BWID, 0.55f* DynamicRenderer.BHEI , mPaint);
248
      c.drawText("y", 0.55f* DynamicRenderer.BWID, 0.05f* DynamicRenderer.BHEI , mPaint);
244
      c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
245
      c.drawText("y", 0.55f* DynamicRenderer.texW, 0.05f* DynamicRenderer.texH , mPaint);
249 246
      
250 247
      if( len>=2 )
251 248
        {
252
        for(int i=0; i<NUM_INTERPOLATIONS; i++) 
249
        di2D.interpolateMain(mPoints,3*mPosition, time);
250

  
251
//android.util.Log.e("surface", "pos="+mPosition+" x="+mPoints[3*mPosition]+" y="+mPoints[3*mPosition+1]+" time="+time);
252

  
253
        for(int i=0; i<NUM_POINTS; i++)
253 254
          {
254
          int color = i<=mPosition ? 0xff - ((int)mPosition                   -i)*0xff/(NUM_INTERPOLATIONS-1)  
255
                                   : 0xff - ((int)mPosition+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
255
          int color = i<=mPosition ? 0xff - (mPosition           -i)*0xff/(NUM_POINTS-1)
256
                                   : 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
256 257
         
257
          mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); 
258
          di2D.interpolate(mDrawCoord,0, (float)i/NUM_INTERPOLATIONS);
259
          c.drawCircle(mDrawCoord[0], mDrawCoord[1], 2.0f, mPaint );
258
          mPaint.setColor( 0xffffff + ((color&0xff)<<24) );
259
          c.drawCircle(mPoints[3*i], mPoints[3*i+1], size1, mPaint );
260 260
          }
261 261
        }
262 262
     
......
265 265
      for(int curr=0; curr<len; curr++)
266 266
        {      
267 267
        p2D = di2D.getPoint(curr);
268
        c.drawCircle(p2D.getX(),p2D.getY(), 5.0f, mPaint);
268
        c.drawCircle(p2D.getX(),p2D.getY(), size2, mPaint);
269 269
        }
270 270
      }
271 271

  
......
274 274
    private static void drawCurve3D(Canvas c, long time)
275 275
      {
276 276
      int len = di3D.getNumPoints();   
277
      
277
      int size1 = DynamicRenderer.texH/200;
278
      int size2 = DynamicRenderer.texH/80;
279

  
278 280
      mPaint.setColor(0xff000000);
279 281
      
280
      c.drawLine(0, DynamicRenderer.BHEI/2, DynamicRenderer.BWID, DynamicRenderer.BHEI/2, mPaint);
281
      c.drawLine(DynamicRenderer.BWID/2, 0, DynamicRenderer.BWID/2, DynamicRenderer.BHEI, mPaint);
282
      c.drawLine(0, DynamicRenderer.texH/2, DynamicRenderer.texW  , DynamicRenderer.texH/2, mPaint);
283
      c.drawLine(DynamicRenderer.texW/2, 0, DynamicRenderer.texW/2, DynamicRenderer.texH  , mPaint);
282 284
      
283
      c.drawText("x", 0.95f* DynamicRenderer.BWID, 0.55f* DynamicRenderer.BHEI , mPaint);
284
      c.drawText( currentDim==DIM_3DXY ? "y" : "z", 0.55f* DynamicRenderer.BWID, 0.05f* DynamicRenderer.BHEI , mPaint);
285
      c.drawText("x", 0.95f* DynamicRenderer.texW, 0.55f* DynamicRenderer.texH , mPaint);
286
      c.drawText( currentDim==DIM_3DXY ? "y" : "z", 0.55f* DynamicRenderer.texW, 0.05f* DynamicRenderer.texH , mPaint);
285 287
      
286 288
      if( len>=2 )
287 289
        {
288
        for(int i=0; i<NUM_INTERPOLATIONS; i++) 
290
        di3D.interpolateMain(mPoints, 3*mPosition, time);
291

  
292
        for(int i=0; i<NUM_POINTS; i++)
289 293
          {
290
          int color = i<=mPosition ? 0xff - ((int)mPosition                   -i)*0xff/(NUM_INTERPOLATIONS-1)  
291
                                   : 0xff - ((int)mPosition+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
294
          int color = i<=mPosition ? 0xff - (mPosition           -i)*0xff/(NUM_POINTS-1)
295
                                   : 0xff - (mPosition+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
292 296
         
293 297
          mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); 
294
          di3D.interpolate(mDrawCoord,0, (float)i/NUM_INTERPOLATIONS);
295
          c.drawCircle(mDrawCoord[0], mDrawCoord[currentDim==DIM_3DXY ? 1:2], 2.0f, mPaint );
298
          c.drawCircle(mPoints[3*i], mPoints[3*i + (currentDim==DIM_3DXY ? 1:2) ], size1, mPaint );
296 299
          }
297 300
        }
298 301
     
......
301 304
      for(int curr=0; curr<len; curr++)
302 305
        {      
303 306
        p3D = di3D.getPoint(curr);
304
        c.drawCircle(p3D.getX(), currentDim==DIM_3DXY ? p3D.getY():p3D.getZ(), 5.0f, mPaint);
307
        c.drawCircle(p3D.getX(), currentDim==DIM_3DXY ? p3D.getY():p3D.getZ(), size2, mPaint);
305 308
        }   
306 309
      }
307 310
    
......
321 324
                       p1D = di1D.getPoint(g);  
322 325
                       gx = p1D.getX();
323 326
                                    
324
                       if( (xDown-gx)*(xDown-gx) < (DynamicRenderer.BHEI)*(DynamicRenderer.BHEI)/100 )
327
                       if( (x-gx)*(x-gx) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
325 328
                         {
326 329
                         moving = g;
327 330
                         break;
......
332 335
                       synchronized(lock)
333 336
                         {
334 337
                         if( len>=MAX_VECTORS ) di1D.removeAll();
335
                         di1D.add(new Static1D(xDown));
338
                         di1D.add(new Static1D(x));
336 339
                         }
337 340
                       }
338 341
                     break;
......
344 347
                       gx = p2D.getX();
345 348
                       gy = p2D.getY();
346 349
                                    
347
                       if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (DynamicRenderer.BHEI)*(DynamicRenderer.BHEI)/100 )
350
                       if( (x-gx)*(x-gx) + (y-gy)*(y-gy) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
348 351
                         {
349 352
                         moving = g;
350 353
                         break;
......
355 358
                       synchronized(lock)
356 359
                         {
357 360
                         if( len>=MAX_VECTORS ) di2D.removeAll();
358
                         di2D.add(new Static2D(xDown,yDown));
361
                         di2D.add(new Static2D(x,y));
359 362
                         }
360 363
                       }
361 364
                     break;
......
370 373
                               
371 374
                     if( currentDim==DIM_3DXY )
372 375
                       {
373
                       if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (DynamicRenderer.BHEI)*(DynamicRenderer.BHEI)/100 )
376
                       if( (x-gx)*(x-gx) + (y-gy)*(y-gy) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
374 377
                         {
375 378
                         moving = g;
376 379
                         break;
......
378 381
                       }
379 382
                     if( currentDim==DIM_3DXZ )
380 383
                       {
381
                       if( (xDown-gx)*(xDown-gx) + (yDown-gz)*(yDown-gz) < (DynamicRenderer.BHEI)*(DynamicRenderer.BHEI)/100 )
384
                       if( (x-gx)*(x-gx) + (y-gz)*(y-gz) < (DynamicRenderer.texH)*(DynamicRenderer.texH)/100 )
382 385
                         {
383 386
                         moving = g;
384 387
                         break;
......
393 396
                    
394 397
                       if( currentDim==DIM_3DXY )
395 398
                         {
396
                         di3D.add(new Static3D(xDown,yDown, DynamicRenderer.BHEI/2));
399
                         di3D.add(new Static3D(x,y, DynamicRenderer.texH/2));
397 400
                         }
398 401
                       if( currentDim==DIM_3DXZ )
399 402
                         {
400
                         di3D.add(new Static3D(xDown, DynamicRenderer.BHEI/2,yDown));
403
                         di3D.add(new Static3D(x, DynamicRenderer.texH/2,y));
401 404
                         }
402 405
                       }
403 406
                     }
......
410 413
    @Override public boolean onTouchEvent(MotionEvent event) 
411 414
      {
412 415
      int action = event.getAction();
413
          
416
      int xDown, yDown;
417

  
414 418
      switch(action)
415 419
        {
416
        case MotionEvent.ACTION_DOWN: xDown = (int)event.getX()* DynamicRenderer.BWID/mScrW;
417
                                      yDown = (int)event.getY()* DynamicRenderer.BHEI/mScrH;
420
        case MotionEvent.ACTION_DOWN: xDown = (int)event.getX();
421
                                      yDown = (int)event.getY();
418 422
                                      
419 423
                                      addNewPoint(xDown,yDown);
420 424
                                    
421 425
                                      break;
422 426
        case MotionEvent.ACTION_MOVE: if( moving>=0 )
423 427
                                        {
424
                                        xDown = (int)event.getX()* DynamicRenderer.BWID/mScrW;
425
                                        yDown = (int)event.getY()* DynamicRenderer.BHEI/mScrH;
428
                                        xDown = (int)event.getX();
429
                                        yDown = (int)event.getY();
426 430
                                        
427 431
                                        switch(currentDim)
428 432
                                          {
src/main/java/org/distorted/examples/movingeffects/MovingEffectsRenderer.java
31 31

  
32 32
import org.distorted.library.DistortedBitmap;
33 33
import org.distorted.library.Distorted;
34
import org.distorted.library.EffectTypes;
35
import org.distorted.library.type.Static3D;
36 34

  
37 35
///////////////////////////////////////////////////////////////////////////////////////////////////
38 36

  
39
public class MovingEffectsRenderer implements GLSurfaceView.Renderer 
37
class MovingEffectsRenderer implements GLSurfaceView.Renderer
40 38
   {  
41
   public static final int NUMLINES = 10;
42
   public static final int BWID = 300;
43
   public static final int BHEI = 400;
44
   
45 39
   private GLSurfaceView mView;
46
   public static DistortedBitmap mBackground;
47 40
   private Canvas mCanvas;
48 41
   private Bitmap mBitmap;
49 42
   private Paint mPaint;
50
   private int texWidth, texHeight;
51
    
43
   private int texW, texH;
44

  
45
   static DistortedBitmap mBackground;
46

  
52 47
///////////////////////////////////////////////////////////////////////////////////////////////////
53 48

  
54
   public MovingEffectsRenderer(GLSurfaceView v)
49
   MovingEffectsRenderer(GLSurfaceView v)
55 50
     {    
56 51
     mPaint = new Paint();
57 52
     mPaint.setAntiAlias(true);
......
59 54
     mPaint.setStyle(Style.FILL);
60 55
      
61 56
     mView = v;
62
      
63
     texWidth = BWID;
64
     texHeight= BHEI;
65 57
     }
66 58

  
67 59
///////////////////////////////////////////////////////////////////////////////////////////////////
68 60

  
69 61
   private void drawBackground()
70 62
     {
63
     int NW, NH;
64

  
65
     if( texH<texW )
66
       {
67
       NH = 10;
68
       NW = NH*texW/texH;
69
       }
70
     else
71
       {
72
       NW = 10;
73
       NH = NW*texH/texW;
74
       }
75

  
71 76
     mPaint.setColor(0xff008800);
72
     mCanvas.drawRect(0, 0, texWidth, texHeight, mPaint);
77
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
73 78
     mPaint.setColor(0xffffffff);
74 79
         
75
     for(int i=0; i<=NUMLINES ; i++ )
76
       {
77
       mCanvas.drawRect(texWidth*i/NUMLINES - 2,                       0,  texWidth*i/NUMLINES + 2,  texHeight               , mPaint);
78
       mCanvas.drawRect(                      0, texHeight*i/NUMLINES -2,  texWidth               ,  texHeight*i/NUMLINES + 2, mPaint);  
79
       } 
80
     for(int i=0; i<=NH ; i++ ) mCanvas.drawRect( 0, texH*i/NH -2,  texW,  texH*i/NH + 2, mPaint);
81
     for(int i=0; i<=NW ; i++ ) mCanvas.drawRect( texW*i/NW - 2, 0, texW*i/NW + 2,  texH, mPaint);
80 82
     }
81 83
   
82 84
///////////////////////////////////////////////////////////////////////////////////////////////////
83 85
   
84 86
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
85
     {         
86
     mBackground = new DistortedBitmap(texWidth,texHeight, 80);   
87
     mBitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
88
     mCanvas = new Canvas(mBitmap); 
89
      
87
     {
90 88
     try
91
        {
92
        Distorted.onSurfaceCreated(mView.getContext());
93
        }
94
      catch(Exception ex)
95
        {
96
        android.util.Log.e("Renderer", ex.getMessage() );
97
        }
89
       {
90
       Distorted.onSurfaceCreated(mView.getContext());
91
       }
92
     catch(Exception ex)
93
       {
94
       android.util.Log.e("Renderer", ex.getMessage() );
95
       }
98 96
     }
99 97

  
100 98
///////////////////////////////////////////////////////////////////////////////////////////////////
101 99

  
102 100
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
103 101
     {
104
     mBackground.abortEffects(EffectTypes.MATRIX);
105
     mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
106
   
107
     Distorted.onSurfaceChanged(width, height);
108
     MovingEffectsSurfaceView.setScreenSize(width, height);    
102
     texW = width;
103
     texH = height;
104

  
105
     mBackground = new DistortedBitmap(texW,texH, 80);
106
     mBitmap = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
107
     mCanvas = new Canvas(mBitmap);
108

  
109
     Distorted.onSurfaceChanged(texW, texH);
110
     MovingEffectsSurfaceView.onSurfaceChanged(texW,texH);
109 111
     }
110 112
   
111 113
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java
29 29
import android.util.AttributeSet;
30 30

  
31 31
import org.distorted.library.EffectTypes;
32
import org.distorted.library.type.Dynamic1D;
33 32
import org.distorted.library.type.Dynamic2D;
34
import org.distorted.library.type.Dynamic3D;
35 33
import org.distorted.library.type.Dynamic4D;
36 34
import org.distorted.library.type.Static1D;
37 35
import org.distorted.library.type.Static2D;
......
43 41
public class MovingEffectsSurfaceView extends GLSurfaceView
44 42
    {
45 43
    private static final int LOOP_TIME = 5000;
46
    private static final int NUM_INTERPOLATIONS= 100;
44
    private static final int NUM_POINTS= 100;
47 45
   
48 46
    public static final int EFFECT_POINTS=0;
49 47
    public static final int EFFECT_BUBBLE=1;
......
51 49
    public static final int EFFECT_TRANS =3;
52 50
    public static final int EFFECT_CHROMA=4;
53 51
    public static final int EFFECT_SWIRL =5;
54
   
55
    private static MovingEffectsRenderer mRenderer;
56
    
57
    private static int xDown,yDown;
58
    private static int mScrW, mScrH;
59 52

  
60 53
    private static Dynamic2D di2D;
61 54
    private static Static4D dr;
......
63 56

  
64 57
    private static Paint mPaint;
65 58
    private static int moving;
66
    private static Object lock = new Object();
59
    private static final Object lock = new Object();
67 60
    private static long mTime = 0;
68 61
    
69 62
    private static int mCurrEffect;
70
    
63
    private static int mSize1, mSize2, mSizeR;
64
    private static int mMax;
65

  
71 66
///////////////////////////////////////////////////////////////////////////////////////////////////
72 67
    
73 68
    public MovingEffectsSurfaceView(Context c, AttributeSet attrs) 
......
81 76
      
82 77
      di2D    = new Dynamic2D(LOOP_TIME,0.0f);
83 78
      mRegion = new Dynamic4D(LOOP_TIME,0.0f);
84
      dr      = new Static4D(0,0,60,60);
85 79

  
86 80
      if(!isInEditMode())
87 81
        {
......
95 89
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
96 90
          }
97 91
        
98
        mRenderer = new MovingEffectsRenderer(this);
92
        MovingEffectsRenderer mRenderer = new MovingEffectsRenderer(this);
99 93
        setRenderer(mRenderer);
100 94
        }
101 95
      }
102 96

  
103 97
///////////////////////////////////////////////////////////////////////////////////////////////////
104 98

  
105
    public static void setScreenSize(int width, int height)
99
    public static void onSurfaceChanged(int width,int height)
106 100
      {
107
      mScrW = width;
108
      mScrH = height;
101
      mMax = width>height ? width:height;
102

  
103
      mSize1 = mMax/200;
104
      mSize2 = mMax/80;
105
      mSizeR = mMax/6;
106

  
107
      dr = new Static4D(0,0, mSizeR,mSizeR);
109 108
      }
110 109

  
111 110
///////////////////////////////////////////////////////////////////////////////////////////////////
......
125 124
        {
126 125
        MovingEffectsRenderer.mBackground.abortEffects(EffectTypes.VERTEX);
127 126
        MovingEffectsRenderer.mBackground.abortEffects(EffectTypes.FRAGMENT);
128
        MovingEffectsRenderer.mBackground.distort( new Static3D(0,0,30) , di2D, dr);
127
        MovingEffectsRenderer.mBackground.distort( new Static3D(0,0,mMax/10) , di2D, dr);
129 128
        mCurrEffect = EFFECT_BUBBLE;
130 129
        }
131 130
      }
......
211 210
      synchronized(lock)
212 211
        {  
213 212
        int len = di2D.getNumPoints();
213

  
214 214
        float[] drawCoord = new float[2];
215 215
        Static2D cu;
216
        int lit = mTime> 0 ? (int)((float)(time-mTime)*NUM_INTERPOLATIONS/LOOP_TIME)  : 0; 
216
        int lit = mTime> 0 ? (int)((float)(time-mTime)*NUM_POINTS/LOOP_TIME)  : 0;
217 217
            
218 218
        if( len>=2 )
219 219
          {
220
          for(int i=0; i<NUM_INTERPOLATIONS; i++) 
220
          float step = (float)LOOP_TIME/(NUM_POINTS+1);
221

  
222
          for(int i=0; i<NUM_POINTS; i++)
221 223
            {
222
            int color = i<=lit ? 0xff - (lit                   -i)*0xff/(NUM_INTERPOLATIONS-1)  
223
                               : 0xff - (lit+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
224
            int color = i<=lit ? 0xff - (lit           -i)*0xff/(NUM_POINTS-1)
225
                               : 0xff - (lit+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
224 226
         
225 227
            mPaint.setColor( 0xffffff + ((color&0xff)<<24) );  
226
            di2D.interpolate( drawCoord, 0, (float)i/NUM_INTERPOLATIONS);
227
            c.drawCircle(drawCoord[0], drawCoord[1], 2.0f, mPaint );
228
            di2D.interpolateMain( drawCoord, 0, (long)(i*step) );
229
            c.drawCircle(drawCoord[0], drawCoord[1], mSize1, mPaint );
228 230
            }
229 231
          }
230 232
     
......
233 235
        for(int curr=0; curr<len; curr++)
234 236
          {       
235 237
          cu = di2D.getPoint(curr);
236
          c.drawCircle(cu.getX(), cu.getY(), 5.0f, mPaint);
238
          c.drawCircle(cu.getX(), cu.getY(), mSize2, mPaint);
237 239
          }
238 240
        
239 241
        if( time-mTime > LOOP_TIME ) mTime = time;
......
245 247
    @Override public boolean onTouchEvent(MotionEvent event) 
246 248
      {
247 249
      if( mCurrEffect!=EFFECT_POINTS ) return true;   
248
      
250

  
251
      int xDown, yDown;
252

  
249 253
      switch(event.getAction())
250 254
        {
251
        case MotionEvent.ACTION_DOWN: xDown = (int)event.getX()*MovingEffectsRenderer.BWID/mScrW; 
252
                                      yDown = (int)event.getY()*MovingEffectsRenderer.BHEI/mScrH;
255
        case MotionEvent.ACTION_DOWN: xDown = (int)event.getX();
256
                                      yDown = (int)event.getY();
253 257
                                    
254 258
                                      float gx, gy;
255 259
                                      Static2D dv;
......
261 265
                                        gx = dv.getX();
262 266
                                        gy = dv.getY();
263 267
                                    
264
                                        if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (MovingEffectsRenderer.BHEI*MovingEffectsRenderer.BHEI)/100 )
268
                                        if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (mMax*mMax)/100 )
265 269
                                          {
266 270
                                          moving = g;
267 271
                                          break;
......
272 276
                                        synchronized(lock)
273 277
                                          {
274 278
                                          di2D.add(new Static2D(xDown,yDown));
275
                                          mRegion.add(new Static4D(xDown,yDown,60,60));
279
                                          mRegion.add(new Static4D(xDown,yDown,mSizeR,mSizeR));
276 280
                                          }
277 281
                                        } 
278 282
                                      break;
279 283
        case MotionEvent.ACTION_MOVE: if( moving>=0 )
280 284
                                        {
281
                                        xDown = (int)event.getX()*MovingEffectsRenderer.BWID/mScrW; 
282
                                        yDown = (int)event.getY()*MovingEffectsRenderer.BHEI/mScrH;
285
                                        xDown = (int)event.getX();
286
                                        yDown = (int)event.getY();
287

  
283 288
                                        di2D.setPoint(moving, xDown, yDown);
284
                                        mRegion.setPoint(moving, xDown, yDown, 60, 60);
289
                                        mRegion.setPoint(moving, xDown, yDown, mSizeR, mSizeR);
285 290
                                        }                           
286 291
                                      break;
287 292
        case MotionEvent.ACTION_UP  : moving = -1;

Also available in: Unified diff