Project

General

Profile

« Previous | Next » 

Revision 30c71dd5

Added by Leszek Koltunski over 7 years ago

Remove 'statics' from the Deform app

View differences:

src/main/java/org/distorted/examples/deform/DeformActivity.java
57 57

  
58 58
      RadioButton effect = (RadioButton)findViewById(R.id.deformDistortButton);
59 59
      effect.setChecked(true);
60
      DeformRenderer.setMode(EffectNames.DISTORT);
60

  
61
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
62

  
63
      view.getRenderer().setMode(EffectNames.DISTORT);
61 64
      }
62 65

  
63 66
///////////////////////////////////////////////////////////////////////////////////////////////////
......
65 68
    @Override
66 69
    protected void onPause() 
67 70
      {
68
      DeformRenderer.onPause();
69
      
70
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.deformSurfaceView);
71
      mView.onPause();
72
      
71
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
72

  
73
      view.getRenderer().onPause();
74
      view.onPause();
73 75
      super.onPause();
74 76
      }
75 77

  
......
80 82
      {
81 83
      super.onResume();
82 84
      
83
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.deformSurfaceView);
84
      mView.onResume();
85
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.deformSurfaceView);
86
      view.onResume();
85 87
      }
86 88
 
87 89
///////////////////////////////////////////////////////////////////////////////////////////////////
......
97 99
    
98 100
    public void Distort(View v)
99 101
      {
100
      DeformRenderer.setMode(EffectNames.DISTORT);
102
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
103
      view.getRenderer().setMode(EffectNames.DISTORT);
101 104
      }     
102 105
    
103 106
///////////////////////////////////////////////////////////////////////////////////////////////////
104 107

  
105 108
    public void Deform(View v)
106 109
      {
107
      DeformRenderer.setMode(EffectNames.DEFORM);
110
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
111
      view.getRenderer().setMode(EffectNames.DEFORM);
108 112
      }       
109 113

  
110 114
///////////////////////////////////////////////////////////////////////////////////////////////////
111 115

  
112 116
    public void Shear(View v)
113 117
      {
114
      DeformRenderer.setMode(EffectNames.SHEAR);
118
      DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
119
      view.getRenderer().setMode(EffectNames.SHEAR);
115 120
      }       
116 121
    
117 122
///////////////////////////////////////////////////////////////////////////////////////////////////
......
120 125
      {
121 126
      switch (bar.getId()) 
122 127
        {
123
        case R.id.deformSeekRadius: DeformRenderer.setRegionRadius(progress);
124
                              textR.setText("Radius: "+progress);
125
                              break;
128
        case R.id.deformSeekRadius: DeformSurfaceView view = (DeformSurfaceView) this.findViewById(R.id.deformSurfaceView);
129
                                    view.getRenderer().setRegionRadius(progress);
130
                                    textR.setText("Radius: "+progress);
131
                                    break;
126 132
        }
127 133
      }
128 134

  
src/main/java/org/distorted/examples/deform/DeformRenderer.java
42 42
class DeformRenderer implements GLSurfaceView.Renderer 
43 43
{
44 44
   private static final int NUM_VECTORS = 8;
45
   private static final int NUMLINES = 10;
46
   private static final int NUMFRAMES =10;
45
   private static final int NUM_LINES = 10;
46
   private static final int NUM_FRAMES =10;
47 47

  
48 48
   private GLSurfaceView mView;
49 49
   private DistortedBitmap fps;
50 50
   private DistortedBitmap stretch;
51 51
   private Static3D touchPoint;
52 52

  
53
   private static Dynamic3D mReleasedDistortDynamic;
54
   private static Dynamic3D mMovingDistortDynamic;
55
   private static Static3D[] vDistort;
56
   private static Dynamic3D mReleasedDeformDynamic;
57
   private static Dynamic3D mMovingDeformDynamic;
58
   private static Static3D[] vDeform;
59
   private static Dynamic3D mReleasedShearDynamic;
60
   private static Dynamic3D mMovingShearDynamic;
61
   private static Static3D[] vShear;
62

  
63
   private static Static4D dr;
53
   private Dynamic3D mReleasedDistortDynamic;
54
   private Dynamic3D mMovingDistortDynamic;
55
   private Static3D[] vDistort;
56
   private Dynamic3D mReleasedDeformDynamic;
57
   private Dynamic3D mMovingDeformDynamic;
58
   private Static3D[] vDeform;
59
   private Dynamic3D mReleasedShearDynamic;
60
   private Dynamic3D mMovingShearDynamic;
61
   private Static3D[] vShear;
62

  
63
   private Static4D dr;
64 64
   private Canvas fpsCanvas;
65
   private Bitmap fpsBitmap, stretchBitmap;
65
   private Bitmap fpsBitmap;
66 66
   private int scrHeight, scrWidth;
67 67
   private Paint mPaint;
68 68
   private int fpsH, fpsW;
......
71 71
   private long[] durations;
72 72
   private int currDuration;
73 73

  
74
   private static EffectNames mMode = EffectNames.DISTORT;
75
   private static boolean bitmapCreated = false;
76

  
77
   private static long mLastEffect = -1;
74
   private EffectNames mMode = EffectNames.DISTORT;
75
   private boolean bitmapCreated = false;
76
   private long mLastEffect = -1;
78 77

  
79 78
///////////////////////////////////////////////////////////////////////////////////////////////////
80 79

  
81
   public DeformRenderer(GLSurfaceView view) 
80
   DeformRenderer(GLSurfaceView view)
82 81
      { 
83 82
      mView = view;
84 83
      
85 84
      dr = new Static4D(0,0,0,0);
86 85

  
87
      durations = new long[NUMFRAMES+1];
86
      durations = new long[NUM_FRAMES+1];
88 87
      currDuration = 0;
89 88

  
90
      for(int i=0; i<NUMFRAMES+1; i++)
89
      for(int i=0; i<NUM_FRAMES+1; i++)
91 90
        {
92 91
        durations[i]=0;
93 92
        }
......
143 142

  
144 143
///////////////////////////////////////////////////////////////////////////////////////////////////
145 144

  
146
   public static void setMode(EffectNames mode)
145
   void setMode(EffectNames mode)
147 146
      {
148 147
      mMode = mode;  
149 148
      }
150 149
   
151 150
///////////////////////////////////////////////////////////////////////////////////////////////////
152 151

  
153
   public static void setRegionRadius(int r)
152
   void setRegionRadius(int r)
154 153
      {
155 154
      dr.set(0,0,r); 
156 155
      }
157 156

  
158 157
///////////////////////////////////////////////////////////////////////////////////////////////////
159 158

  
160
    public static void onPause()
159
    public void onPause()
161 160
      {
162 161
      bitmapCreated = false;  
163 162
      }
......
230 229
      
231 230
      mPaint = new Paint();
232 231
      stretch = new DistortedBitmap(w,h, 50);   
233
      stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
232
      Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
234 233
      stretchCanvas = new Canvas(stretchBitmap);
235 234
      
236 235
      fpsW = scrWidth/5;
......
244 243
      stretchCanvas.drawRect(0, 0, w, h, mPaint);
245 244
      mPaint.setColor(0xffffffff);
246 245
      
247
      for(int i=0; i<=NUMLINES ; i++ )
246
      for(int i=0; i<=NUM_LINES ; i++ )
248 247
        {
249
        stretchCanvas.drawRect(w*i/NUMLINES - 1,                0,  w*i/NUMLINES + 1,  h               , mPaint);
250
        stretchCanvas.drawRect(               0, h *i/NUMLINES -1,  w               ,  h*i/NUMLINES + 1, mPaint);  
248
        stretchCanvas.drawRect(w*i/NUM_LINES - 1,                 0,  w*i/NUM_LINES + 1,  h                , mPaint);
249
        stretchCanvas.drawRect(                0, h *i/NUM_LINES -1,  w                ,  h*i/NUM_LINES + 1, mPaint);
251 250
        }
252 251
        
253 252
      touchPoint= new Static3D(0,0,0);
......
262 261

  
263 262
///////////////////////////////////////////////////////////////////////////////////////////////////
264 263

  
265
    public void down(int x, int y)
264
    void down(int x, int y)
266 265
      {
267 266
      int xt = x-scrWidth/4;
268 267
      int yt = y-scrHeight/4;
......
290 289
    
291 290
///////////////////////////////////////////////////////////////////////////////////////////////////
292 291

  
293
    public void move(int x, int y)
292
    void move(int x, int y)
294 293
      {
295 294
      switch(mMode)
296 295
        {
......
305 304
    
306 305
///////////////////////////////////////////////////////////////////////////////////////////////////
307 306

  
308
    public void up()
307
    void up()
309 308
      {
310 309
      stretch.abortEffect(mLastEffect);
311 310

  
......
344 343
      if( lastTime!=0 )
345 344
        {
346 345
        currDuration++;
347
        if( currDuration>=NUMFRAMES ) currDuration = 0;  
348
        durations[NUMFRAMES] += ((currentTime-lastTime)-durations[currDuration]);
346
        if( currDuration>=NUM_FRAMES ) currDuration = 0;
347
        durations[NUM_FRAMES] += ((currentTime-lastTime)-durations[currDuration]);
349 348
        durations[currDuration] = currentTime-lastTime;
350 349

  
351
        fpsString = "" + ((int)(10000.0f*NUMFRAMES/durations[NUMFRAMES]))/10.0f;
350
        fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
352 351
        }
353 352
      
354 353
      lastTime = currentTime;   
src/main/java/org/distorted/examples/deform/DeformSurfaceView.java
29 29

  
30 30
class DeformSurfaceView extends GLSurfaceView 
31 31
{
32
    private DeformRenderer renderer;
32
    private DeformRenderer mRenderer;
33 33
    private int xTouch, yTouch;
34 34
   
35 35
///////////////////////////////////////////////////////////////////////////////////////////////////
......
47 47
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
48 48
          }
49 49
    
50
        renderer = new DeformRenderer(this);
51
        setRenderer(renderer);
50
        mRenderer = new DeformRenderer(this);
51
        setRenderer(mRenderer);
52 52
        }
53 53
      }
54 54
    
55 55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
    
56

  
57
    DeformRenderer getRenderer()
58
      {
59
      return mRenderer;
60
      }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
57 64
    @Override public boolean onTouchEvent(MotionEvent event) 
58 65
      {
59 66
      int action = event.getAction();
......
64 71
         {
65 72
         case MotionEvent.ACTION_DOWN: xTouch =x;
66 73
                                       yTouch =y; 
67
                                       renderer.down(x,y);
74
                                       mRenderer.down(x,y);
68 75
                                       break;
69
         case MotionEvent.ACTION_MOVE: renderer.move(x-xTouch,y-yTouch);                      
76
         case MotionEvent.ACTION_MOVE: mRenderer.move(x-xTouch,y-yTouch);
70 77
                                       break;
71
         case MotionEvent.ACTION_UP  : renderer.up(); 
78
         case MotionEvent.ACTION_UP  : mRenderer.up();
72 79
                                       break;
73 80
         }
74 81
             

Also available in: Unified diff