Project

General

Profile

« Previous | Next » 

Revision 1d811f85

Added by Leszek Koltunski about 8 years ago

Tidy up 'Matrix3D'

View differences:

src/main/java/org/distorted/examples/matrix3d/Matrix3DActivity.java
36 36

  
37 37
public class Matrix3DActivity extends Activity implements OnSeekBarChangeListener
38 38
{
39
    private SeekBar bar;
40 39
    private TextView textMove, textScale, textRotate, textShear;
41 40
    private int moveX, moveY, moveZ;
42 41
    private int scaleX, scaleY, scaleZ;
43 42
    private int rotateX, rotateY, rotateZ, rotateA;
44 43
    private int shearX, shearY, shearZ;
45
    
46 44
    private int maxX, maxY, maxZ;
47
    
48 45
    private float fmoveX, fmoveY, fmoveZ;
49 46
    private float fscaleX, fscaleY, fscaleZ;
50 47
    private float frotateX, frotateY, frotateZ, frotateA;
......
142 139
      setBar(R.id.matrix3dshearBar2, shearY);
143 140
      setBar(R.id.matrix3dshearBar3, shearZ);
144 141
      
145
      Matrix3DRenderer.setOrder(effects);
142
      Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
143
      view.getRenderer().setOrder(effects);
146 144
      }
147 145

  
148 146
///////////////////////////////////////////////////////////////////////////////////////////////////
......
209 207
    
210 208
    private void setBar(int id, int value)
211 209
      {
212
      bar = (SeekBar)findViewById(id);
210
      SeekBar bar = (SeekBar)findViewById(id);
213 211
      bar.setOnSeekBarChangeListener(this); 
214 212
      bar.setProgress(value);
215 213
      }
......
222 220
      fmoveY = (moveY-50)*maxY/50.0f;
223 221
      fmoveZ = (moveZ-50)*maxZ/50.0f;
224 222

  
225
      Matrix3DRenderer.setMove( fmoveX, fmoveY, fmoveZ);
223
      Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
224
      view.getRenderer().setMove( fmoveX, fmoveY, fmoveZ);
226 225
      }
227 226
    
228 227
///////////////////////////////////////////////////////////////////////////////////////////////////
......
244 243
      fscaleY = (scaleY>50 ? 0.18f : 0.018f)*(scaleY-50)+1;
245 244
      fscaleZ = (scaleZ>50 ? 0.18f : 0.018f)*(scaleZ-50)+1;
246 245

  
247
      Matrix3DRenderer.setScale(fscaleX, fscaleY, fscaleZ);
246
      Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
247
      view.getRenderer().setScale(fscaleX, fscaleY, fscaleZ);
248 248
      }
249 249
    
250 250
///////////////////////////////////////////////////////////////////////////////////////////////////
......
266 266
      frotateY = (rotateY-50)/50.0f;
267 267
      frotateZ = (rotateZ-50)/50.0f;
268 268
    
269
      Matrix3DRenderer.setRotate( frotateA, frotateX, frotateY, frotateZ );
269
      Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
270
      view.getRenderer().setRotate( frotateA, frotateX, frotateY, frotateZ );
270 271
      }
271 272
    
272 273
///////////////////////////////////////////////////////////////////////////////////////////////////
......
289 290
      fshearX = (shearX-50)/25.0f;
290 291
      fshearY = (shearY-50)/25.0f;
291 292
      fshearZ = (shearZ-50)/25.0f;
292
    		
293
      Matrix3DRenderer.setShear( fshearX, fshearY, fshearZ );
293

  
294
    	Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
295
      view.getRenderer().setShear( fshearX, fshearY, fshearZ );
294 296
      }
295 297
    
296 298
///////////////////////////////////////////////////////////////////////////////////////////////////
......
309 311
    @Override
310 312
    protected void onPause() 
311 313
      {
312
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
313
      mView.onPause(); 
314
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
315
      view.onPause();
314 316
      super.onPause();
315 317
      }
316 318

  
......
320 322
    protected void onResume() 
321 323
      {
322 324
      super.onResume();
323
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
324
      mView.onResume();
325
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
326
      view.onResume();
325 327
      }
326 328

  
327 329
///////////////////////////////////////////////////////////////////////////////////////////////////
......
331 333
      {
332 334
      super.onWindowFocusChanged(hasFocus);
333 335
  
334
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
336
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
335 337
      
336
      maxX = mView.getWidth();
337
      maxY = mView.getHeight();
338
      maxX = view.getWidth();
339
      maxY = view.getHeight();
338 340
      maxZ = (maxX+maxY)/2;
339 341
      }
340 342

  
src/main/java/org/distorted/examples/matrix3d/Matrix3DRenderer.java
48 48
    private static final int SIZE = 100;
49 49
	
50 50
    private GLSurfaceView mView;
51
    private static DistortedCubes mCube;
52

  
53
    private static EffectNames[] order;
51
    private DistortedCubes mCube;
52
    private EffectNames[] order;
54 53
    
55
    private static Dynamic3D mMoveInter, mScaleInter, mShearInter;
56
    private static Dynamic4D mDynamicRotate;
57

  
58
    private static Static3D mZeroPoint, mMovePoint, mScalePoint, mShearPoint;
59
    private static Static4D mRotatePoint;
54
    private Dynamic3D mMoveInter, mScaleInter, mShearInter;
55
    private Dynamic4D mDynamicRotate;
56
    private Static3D mZeroPoint, mMovePoint, mScalePoint, mShearPoint;
57
    private Static4D mRotatePoint;
60 58

  
61 59
///////////////////////////////////////////////////////////////////////////////////////////////////
62 60

  
63
    public static void setMove(float x, float y, float z)
61
    void setMove(float x, float y, float z)
64 62
      {
65 63
      mMovePoint.set(x, y, z);
66 64
      }
67 65
    
68 66
///////////////////////////////////////////////////////////////////////////////////////////////////
69 67

  
70
    public static void setScale(float x, float y, float z)
68
    void setScale(float x, float y, float z)
71 69
      {
72 70
      mScalePoint.set(x, y, z);
73 71
      }
74 72
     
75 73
///////////////////////////////////////////////////////////////////////////////////////////////////
76 74

  
77
    public static void setRotate(float a, float x, float y, float z)
75
    void setRotate(float a, float x, float y, float z)
78 76
      {
79 77
      mRotatePoint.set(a,x,y,z);
80 78
      }
81 79
    
82 80
///////////////////////////////////////////////////////////////////////////////////////////////////
83 81

  
84
    public static void setShear(float x, float y, float z)
82
    void setShear(float x, float y, float z)
85 83
      {
86 84
      mShearPoint.set(x, y, z);
87 85
      }
88 86

  
89 87
///////////////////////////////////////////////////////////////////////////////////////////////////
90 88

  
91
    public static void setOrder(EffectNames[] effects)
89
    void setOrder(EffectNames[] effects)
92 90
      {
93 91
      order = effects;
94 92
      setMatrixEffects();
......
96 94
      
97 95
///////////////////////////////////////////////////////////////////////////////////////////////////
98 96

  
99
    public static void setMatrixEffects()
97
    private void setMatrixEffects()
100 98
      {
101 99
      mCube.abortEffects(EffectTypes.MATRIX);
102 100
	
......
114 112
    
115 113
///////////////////////////////////////////////////////////////////////////////////////////////////
116 114

  
117
    public Matrix3DRenderer(GLSurfaceView v)
115
    Matrix3DRenderer(GLSurfaceView v)
118 116
      {
119 117
      mView = v;
120 118
      mCube = new DistortedCubes( 1, "1", SIZE);
src/main/java/org/distorted/examples/matrix3d/Matrix3DSurfaceView.java
28 28

  
29 29
class Matrix3DSurfaceView extends GLSurfaceView
30 30
{
31
    private Matrix3DRenderer mRenderer;
32

  
31 33
///////////////////////////////////////////////////////////////////////////////////////////////////
32 34
   
33 35
    public Matrix3DSurfaceView(Context c, AttributeSet attrs)
......
42 44
          { 
43 45
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
44 46
          }
45
        
46
        setRenderer(new Matrix3DRenderer(this));
47

  
48
        mRenderer = new Matrix3DRenderer(this);
49

  
50
        setRenderer(mRenderer);
47 51
        }
48 52
      }
53

  
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

  
56
    Matrix3DRenderer getRenderer()
57
      {
58
      return mRenderer;
59
      }
49 60
}
50 61

  

Also available in: Unified diff