Project

General

Profile

« Previous | Next » 

Revision d2337a3a

Added by Leszek Koltunski over 8 years ago

Progress with Vertex3D

View differences:

src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
221 221
    sinkA =  50;
222 222
    swirlA = 50;
223 223

  
224
    centerX = 25;
225
    centerY = 25;
224
    centerX = 50;
225
    centerY = 50;
226 226

  
227 227
    textCenter = (TextView)findViewById(R.id.vertex3dcenterText);
228
    computeCenter();
228 229
    setCenterText();
229 230

  
230 231
    setBar(R.id.vertex3dcenterX, centerX);
......
279 280

  
280 281
    setBar(R.id.vertex3dswirlBar1, swirlA);
281 282

  
282
    Vertex3DRenderer.setOrder(effects);
283
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
284
    view.getRenderer().setOrder(effects);
283 285
    }
284 286

  
285 287
///////////////////////////////////////////////////////////////////////////////////////////////////
......
355 357

  
356 358
  private void computeDeform()
357 359
    {
358
    fdeformX = (deformX-50)*Vertex3DRenderer.mScreenMin/50.0f;
359
    fdeformY = (deformY-50)*Vertex3DRenderer.mScreenMin/50.0f;
360
    fdeformZ = (deformZ-50)*Vertex3DRenderer.mScreenMin/50.0f;
360
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
361
    Vertex3DRenderer renderer = view.getRenderer();
361 362

  
362
    Vertex3DRenderer.setDeform( fdeformX, fdeformY, fdeformZ );
363
    fdeformX = (deformX-50)*renderer.mScreenMin/200.0f;
364
    fdeformY = (deformY-50)*renderer.mScreenMin/200.0f;
365
    fdeformZ = (deformZ-50)*renderer.mScreenMin/200.0f;
366

  
367
    renderer.setDeform( fdeformX, fdeformY, fdeformZ );
363 368
    }
364 369

  
365 370
///////////////////////////////////////////////////////////////////////////////////////////////////
......
377 382

  
378 383
  private void computeDistort()
379 384
    {
380
    fdistortX = (distortX-50)*Vertex3DRenderer.mScreenMin/50.0f;
381
    fdistortY = (distortY-50)*Vertex3DRenderer.mScreenMin/50.0f;
382
    fdistortZ = (distortZ-50)*Vertex3DRenderer.mScreenMin/50.0f;
385
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
386
    Vertex3DRenderer renderer = view.getRenderer();
387

  
388
    fdistortX = (distortX-50)*renderer.mScreenMin/200.0f;
389
    fdistortY = (distortY-50)*renderer.mScreenMin/200.0f;
390
    fdistortZ = (distortZ-50)*renderer.mScreenMin/200.0f;
383 391

  
384
    Vertex3DRenderer.setDistort(fdistortX, fdistortY, fdistortZ);
392
    renderer.setDistort(fdistortX, fdistortY, fdistortZ);
385 393
    }
386 394

  
387 395
///////////////////////////////////////////////////////////////////////////////////////////////////
......
399 407

  
400 408
  private void computeSink()
401 409
    {
410
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
411

  
402 412
    fsinkA = (sinkA>= 50 ? 0.18f*sinkA-8.0f : 0.018f*sinkA + 0.1f);
403 413

  
404
    Vertex3DRenderer.setSink( fsinkA );
414
    view.getRenderer().setSink( fsinkA );
405 415
    }
406 416

  
407 417
///////////////////////////////////////////////////////////////////////////////////////////////////
......
417 427

  
418 428
  private void computeSwirl()
419 429
    {
430
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
431

  
420 432
    fswirlA = (swirlA-50)*3.6f;
421 433

  
422
    Vertex3DRenderer.setSwirl( fswirlA );
434
    view.getRenderer().setSwirl( fswirlA );
423 435
    }
424 436
    
425 437
///////////////////////////////////////////////////////////////////////////////////////////////////
......
435 447

  
436 448
  private void computeCenter()
437 449
    {
438
    fcenterX = (centerX*0.02f - 0.5f)*Vertex3DRenderer.SIZE;
439
    fcenterY = (centerY*0.02f - 0.5f)*Vertex3DRenderer.SIZE;
450
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
440 451

  
441
    Vertex3DRenderer.setCenter( fcenterX, fcenterY );
452
    fcenterX = centerX;
453
    fcenterY = centerY;
454

  
455
    view.getRenderer().setCenter( fcenterX, fcenterY );
442 456
    }
443 457

  
444 458
///////////////////////////////////////////////////////////////////////////////////////////////////
......
451 465
    textCenter.setText("center("+fcenterX+","+fcenterY+")");
452 466
    }
453 467

  
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

  
470
  public float getCenterX()
471
    {
472
    return fcenterX;
473
    }
474

  
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

  
477
  public float getCenterY()
478
    {
479
    return fcenterY;
480
    }
481

  
454 482
///////////////////////////////////////////////////////////////////////////////////////////////////
455 483
// Overrides
456 484

  
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
50 50

  
51 51
class Vertex3DRenderer implements GLSurfaceView.Renderer
52 52
{
53
    public static final int SIZE = 100;
53
    private static final int SIZE = 100;
54 54

  
55 55
    private GLSurfaceView mView;
56
    private static DistortedObject mObject;
56
    private DistortedObject mObject;
57 57
    private DistortedBitmap mCenter;
58
    private int mCols;
58
    private float mFactorCen, mFactorObj;
59 59

  
60 60
    private int mObjWidth, mObjHeight;
61 61

  
62 62
    private DynamicQuat mQuatInt1, mQuatInt2;
63 63

  
64
    private static EffectNames[] order;
64
    private EffectNames[] order;
65 65

  
66
    private static Dynamic2D mCenterInter;
67
    private static Dynamic3D mDeformInter, mDistortInter, mMoveInter;
68
    private static Dynamic1D mSinkInter, mSwirlInter;
66
    private Dynamic2D mCenterInter;
67
    private Dynamic3D mDeformInter, mDistortInter, mMoveInter;
68
    private Dynamic1D mSinkInter, mSwirlInter;
69 69

  
70
    private static Static2D mCenterPoint;
71
    private static Static3D mDeformPoint, mDistortPoint, mMovePoint;
72
    private static Static1D mSinkPoint, mSwirlPoint;
70
    private Static2D mCenterPoint;
71
    private Static3D mDeformPoint, mDistortPoint, mMovePoint;
72
    private Static1D mSinkPoint, mSwirlPoint;
73 73

  
74 74
    Static4D mQuat1, mQuat2;
75
    static int mScreenMin;
75
    int mScreenMin;
76 76

  
77 77
///////////////////////////////////////////////////////////////////////////////////////////////////
78 78

  
79
    public static void setDeform(float x, float y, float z)
79
    public void setDeform(float x, float y, float z)
80 80
      {
81 81
      mDeformPoint.set(x, y, z);
82 82
      }
83 83
    
84 84
///////////////////////////////////////////////////////////////////////////////////////////////////
85 85

  
86
    public static void setDistort(float x, float y, float z)
86
    public void setDistort(float x, float y, float z)
87 87
      {
88 88
      mDistortPoint.set(x, y, z);
89 89
      }
90 90
     
91 91
///////////////////////////////////////////////////////////////////////////////////////////////////
92 92

  
93
    public static void setSink(float s)
93
    public void setSink(float s)
94 94
      {
95 95
      mSinkPoint.set(s);
96 96
      }
97 97
    
98 98
///////////////////////////////////////////////////////////////////////////////////////////////////
99 99

  
100
    public static void setSwirl(float s)
100
    public void setSwirl(float s)
101 101
      {
102 102
      mSwirlPoint.set(s);
103 103
      }
104 104

  
105 105
///////////////////////////////////////////////////////////////////////////////////////////////////
106 106

  
107
    public static void setCenter(float x, float y)
107
    public void setCenter(float x, float y)
108 108
      {
109
      x = (0.012f*x-0.1f)*mObjWidth;
110
      y = (0.012f*y-0.1f)*mObjHeight;
111

  
109 112
      mCenterPoint.set(x,y);
110
      mMovePoint.set(x,y,0);
113
      mMovePoint.set(mFactorObj*x,mFactorObj*y,0);
111 114
      }
112 115

  
113 116
///////////////////////////////////////////////////////////////////////////////////////////////////
114 117

  
115
    public static void setOrder(EffectNames[] effects)
118
    public void setOrder(EffectNames[] effects)
116 119
      {
117 120
      order = effects;
118 121
      setVertexEffects();
......
120 123
      
121 124
///////////////////////////////////////////////////////////////////////////////////////////////////
122 125

  
123
    public static void setVertexEffects()
126
    public void setVertexEffects()
124 127
      {
125 128
      mObject.abortEffects(EffectTypes.VERTEX);
126 129

  
......
142 145
      {
143 146
      mView = v;
144 147

  
145
      mCols = Vertex3DActivity.getCols();
146

  
147
      mObject = new DistortedCubes( mCols, Vertex3DActivity.getShape(), SIZE);
148
      mObject = new DistortedCubes( Vertex3DActivity.getCols(), Vertex3DActivity.getShape(), SIZE);
148 149
      //mObject = new DistortedBitmap( SIZE, SIZE, 10);
149 150
      mCenter = new DistortedBitmap(SIZE, SIZE, 1);
150 151

  
......
204 205
      mObject.abortEffects(EffectTypes.MATRIX);
205 206
      mCenter.abortEffects(EffectTypes.MATRIX);
206 207

  
207
      float factorObj;
208
      int centerSize = mCenter.getWidth();
208 209

  
209 210
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
210 211
        {
211
        factorObj = (0.7f*height)/mObjHeight;
212
        mFactorObj = (0.70f*height)/mObjHeight;
213
        mFactorCen = (0.15f*height)/centerSize;
212 214
        }
213 215
      else
214 216
        {
215
        factorObj = (0.7f*width)/mObjWidth;
217
        mFactorObj = (0.70f*width)/mObjWidth;
218
        mFactorCen = (0.15f*width)/centerSize;
216 219
        }
217 220

  
221
      Vertex3DActivity act = (Vertex3DActivity)mView.getContext();
222
      float cX = act.getCenterX();
223
      float cY = act.getCenterY();
224

  
225
      cX = (0.012f*cX-0.1f)*mObjWidth;
226
      cY = (0.012f*cY-0.1f)*mObjHeight;
227

  
228
      mMovePoint.set(cX*mFactorObj,cY*mFactorObj,0);
229

  
218 230
      Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0);
219 231

  
220
      mObject.move( new Static3D( (width-factorObj*mObjWidth)/2 , (height-factorObj*mObjHeight)/2 , 0) );
221
      mObject.scale(factorObj);
232
      mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
233
      mObject.scale(mFactorObj);
222 234
      mObject.quaternion(mQuatInt1, rotateObj);
223 235
      mObject.quaternion(mQuatInt2, rotateObj);
224 236

  
225
      int centerSize = mCenter.getWidth();
226 237
      Static3D rotateCen = new Static3D(width/2,height/2, 0);
227 238

  
228
      float factorCen = (float)(mCols*SIZE) / (5*centerSize);  // make the 'center' bitmap 1/5 of the Object's width
229

  
230 239
      mCenter.quaternion(mQuatInt1, rotateCen);
231 240
      mCenter.quaternion(mQuatInt2, rotateCen);
232
      mCenter.move( new Static3D( (width -factorCen*centerSize-factorObj*mObjWidth )/2 ,
233
                                  (height-factorCen*centerSize-factorObj*mObjHeight)/2 , 10) );
241
      mCenter.move( new Static3D( (width -mFactorCen*centerSize-mFactorObj*mObjWidth )/2 ,
242
                                  (height-mFactorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) );
234 243
      mCenter.move(mMoveInter);
235
      mCenter.scale(factorCen);
244
      mCenter.scale(mFactorCen);
236 245

  
237 246
      setVertexEffects();
238 247

  
src/main/java/org/distorted/examples/vertex3d/Vertex3DSurfaceView.java
53 53
      }
54 54
    }
55 55

  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

  
58
  public Vertex3DRenderer getRenderer()
59
    {
60
    return mRenderer;
61
    }
62

  
56 63
///////////////////////////////////////////////////////////////////////////////////////////////////
57 64

  
58 65
  @Override

Also available in: Unified diff