Project

General

Profile

« Previous | Next » 

Revision 24991bc2

Added by Leszek Koltunski over 8 years ago

Vertex3D: app finished!

View differences:

src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
79 79
  private float mCenterX, mCenterY;
80 80
  private float mRegionX, mRegionY, mRegionR;
81 81

  
82
  private final EffectNames[] mEffectNames = { EffectNames.DISTORT,
83
                                               EffectNames.DEFORM ,
84
                                               EffectNames.SINK   ,
85
                                               EffectNames.SWIRL  };
86

  
87
  private static boolean mSupportsRegion = true;
88

  
82 89
///////////////////////////////////////////////////////////////////////////////////////////////////
83 90

  
84 91
  @Override
......
192 199
    return mObject;
193 200
    }
194 201

  
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

  
204
  public static void setSupportsRegion(boolean supports)
205
    {
206
    mSupportsRegion = supports;
207
    }
208

  
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210

  
211
  public static boolean supportsRegion()
212
    {
213
    return mSupportsRegion;
214
    }
215

  
195 216
///////////////////////////////////////////////////////////////////////////////////////////////////
196 217

  
197 218
  public Bitmap getBitmap()
......
256 277
  public void setRegion(float x, float y, float r)
257 278
    {
258 279
    mRegionX = x;
259
    mRegionY = y;
280
    mRegionY =-y;
260 281
    mRegionR = r;
261 282

  
262 283
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
......
417 438

  
418 439
    setContentView(view);
419 440

  
420
    String[] effects = new String[] { "DISTORT",
421
                                      "DEFORM",
422
                                      "SINK",
423
                                      "SWIRL" };
441
    String[] effects = new String[mEffectNames.length];
442

  
443
    for(int i=0; i<mEffectNames.length; i++) effects[i] = mEffectNames[i].name();
424 444

  
425 445
    Spinner effectSpinner = (Spinner)findViewById(R.id.vertex3dspinner );
426 446
    effectSpinner.setOnItemSelectedListener(this);
......
436 456

  
437 457
  public void newEffect(View v)
438 458
    {
439
    EffectNames name;
440

  
441
    switch(mEffectAdd)
442
      {
443
      case 0 : name = EffectNames.DISTORT; break;
444
      case 1 : name = EffectNames.DEFORM ; break;
445
      case 2 : name = EffectNames.SINK   ; break;
446
      case 3 : name = EffectNames.SWIRL  ; break;
447
      default: return;
448
      }
449

  
450
    Vertex3DEffect eff = new Vertex3DEffect(name, this);
459
    Vertex3DEffect eff = new Vertex3DEffect(mEffectNames[mEffectAdd], this);
451 460
    mEffects.add(eff);
452 461

  
453 462
    LinearLayout layout = (LinearLayout)findViewById(R.id.vertex3dlayout);
454 463
    View view = eff.createView();
455 464
    layout.addView(view);
456 465

  
457
    if( mEffectAdd!=1 ) // deform does not support regions
466
    if( eff.supportsRegion() )
458 467
      {
459 468
      View region = eff.createRegion();
460 469
      layout.addView(region);
......
463 472
    View center = eff.createCenter();
464 473
    layout.addView(center);
465 474

  
466
    Dynamic1D dyn1 = eff.getDyn1();
467
    Dynamic2D cent = eff.getCenter();
468
    Dynamic3D dyn3 = eff.getDyn3();
469
    Dynamic4D regi = eff.getRegion();
470

  
471
    switch(mEffectAdd)
472
      {
473
      case 0: mObject.distort(dyn3, cent, regi); break;
474
      case 1: mObject.deform (dyn3, cent      ); break;
475
      case 2: mObject.sink   (dyn1, cent, regi); break;
476
      case 3: mObject.swirl  (dyn1, cent, regi); break;
477
      }
475
    eff.apply(mObject);
478 476
    }
479 477

  
480 478
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/vertex3d/Vertex3DEffect.java
24 24
import android.widget.TextView;
25 25

  
26 26
import org.distorted.examples.R;
27
import org.distorted.library.DistortedObject;
27 28
import org.distorted.library.EffectNames;
28 29
import org.distorted.library.type.Dynamic1D;
29 30
import org.distorted.library.type.Dynamic2D;
......
61 62
  private Dynamic2D mCenterDyn;
62 63
  private Static2D  mCenterSta;
63 64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  public boolean supportsRegion()
68
    {
69
    return mName == EffectNames.DEFORM ? false : true;
70
    }
71

  
64 72
///////////////////////////////////////////////////////////////////////////////////////////////////
65 73

  
66 74
  private void fillCenterStatics()
......
70 78
    float x = (mInterCenter[0]*0.012f - 0.1f)*act.getWidth();
71 79
    float y = (mInterCenter[1]*0.012f - 0.1f)*act.getHeight();
72 80
    mCenterSta.set(x,y);
73

  
74
    act.setCenter(x,y);
75 81
    }
76 82

  
77 83
///////////////////////////////////////////////////////////////////////////////////////////////////
......
107 113
    float ry =  mInterRegion[3]    *factorY;
108 114

  
109 115
    mRegionSta.set(x,y,rx,ry);
110

  
111
    act.setRegion(x,y,rx);
112 116
    }
113 117

  
114 118
///////////////////////////////////////////////////////////////////////////////////////////////////
......
233 237
    mCenterDyn.add(mCenterSta);
234 238
    }
235 239

  
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

  
238
  public Dynamic1D getDyn1()
239
    {
240
    return mDyn1;
241
    }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
  public Dynamic3D getDyn3()
246
    {
247
    return mDyn3;
248
    }
249

  
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

  
252
  public Dynamic4D getRegion()
253
    {
254
    return mRegionDyn;
255
    }
256

  
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

  
259
  public Dynamic2D getCenter()
260
    {
261
    return mCenterDyn;
262
    }
263

  
264 240
///////////////////////////////////////////////////////////////////////////////////////////////////
265 241

  
266 242
  public View createView()
......
316 292
      seek[i].setProgress( mInter[i] );
317 293
      }
318 294

  
295
    Vertex3DActivity.setSupportsRegion(supportsRegion());
296

  
319 297
    return effect;
320 298
    }
321 299

  
......
339 317
    mSeekRegionID[2] = seek[2].getId();
340 318
    mSeekRegionID[3] = seek[3].getId();
341 319

  
342
    mTextRegion    = (TextView)region.findViewById(R.id.effectRegionText);
320
    mTextRegion = (TextView)region.findViewById(R.id.effectRegionText);
343 321

  
344 322
    setDefaultRegionInter();
345 323

  
......
349 327
      seek[i].setProgress( mInterRegion[i] );
350 328
      }
351 329

  
330
    act.setRegion(mRegionSta.getX(),mRegionSta.getY(),mRegionSta.getZ());
331

  
352 332
    return region;
353 333
    }
354 334

  
......
378 358
      seek[i].setProgress( mInterCenter[i] );
379 359
      }
380 360

  
361
    act.setCenter(mCenterSta.getX(),mCenterSta.getY());
362

  
381 363
    return center;
382 364
    }
383 365

  
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

  
368
  public void apply(DistortedObject object)
369
    {
370
    switch(mName)
371
      {
372
      case DISTORT: object.distort(mDyn3, mCenterDyn, mRegionDyn); break;
373
      case DEFORM : object.deform (mDyn3, mCenterDyn            ); break;
374
      case SINK   : object.sink   (mDyn1, mCenterDyn, mRegionDyn); break;
375
      case SWIRL  : object.swirl  (mDyn1, mCenterDyn, mRegionDyn); break;
376
      }
377
    }
378

  
384 379
///////////////////////////////////////////////////////////////////////////////////////////////////
385 380

  
386 381
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
......
447 442
      fillCenterStatics();
448 443
      setCenterText();
449 444
      }
445

  
446
    if( fromUser )
447
      {
448
      Vertex3DActivity.setSupportsRegion(supportsRegion());
449

  
450
      Vertex3DActivity act = mAct.get();
451

  
452
      act.setCenter(mCenterSta.getX(),mCenterSta.getY());
453
      act.setRegion(mRegionSta.getX(),mRegionSta.getY(),mRegionSta.getZ());
454
      }
450 455
    }
451 456

  
452 457
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
52 52
    private int mObjWidth, mObjHeight;
53 53
    private DynamicQuat mQuatInt1, mQuatInt2;
54 54

  
55
    private Dynamic3D mMoveInter;
56
    private Static3D mMovePoint;
55
    private Dynamic3D mCenterInter, mRegionInter;
56
    private Static3D mCenterPoint, mRegionPoint;
57 57
    private Dynamic3D mRegionScaleInter;
58 58
    private Static3D mRegionScalePoint;
59 59

  
......
85 85
      mQuatInt1.add(mQuat1);
86 86
      mQuatInt2.add(mQuat2);
87 87

  
88
      mMoveInter= new Dynamic3D();
89
      mMovePoint= new Static3D(0,0,0);
90
      mMoveInter.add(mMovePoint);
88
      mCenterInter= new Dynamic3D();
89
      mCenterPoint= new Static3D(0,0,0);
90
      mCenterInter.add(mCenterPoint);
91

  
92
      mRegionInter= new Dynamic3D();
93
      mRegionPoint= new Static3D(0,0,0);
94
      mRegionInter.add(mRegionPoint);
91 95

  
92 96
      mRegionScaleInter = new Dynamic3D();
93 97
      mRegionScalePoint = new Static3D(0,0,0);
......
98 102

  
99 103
    public void setCenter(float x, float y)
100 104
      {
101
      mMovePoint.set(mFactorObj*x,mFactorObj*y,0);
105
      mCenterPoint.set(mFactorObj*x,mFactorObj*y,0);
102 106
      }
103 107

  
104 108
///////////////////////////////////////////////////////////////////////////////////////////////////
......
106 110
    public void setRegion(float x, float y, float r)
107 111
      {
108 112
      mFactorReg = 2*mFactorObj*r/mRegion.getWidth();
113
      mRegionPoint.set(mFactorObj*x,mFactorObj*y,0);
109 114
      mRegionScalePoint.set(mFactorReg,mFactorReg,mFactorReg);
110 115
      }
111 116

  
......
121 126
      mBackground.draw(time);
122 127
      mObject.draw(time);
123 128
      mCenter.draw(time);
124
      mRegion.draw(time);
129

  
130
      if( Vertex3DActivity.supportsRegion() ) mRegion.draw(time);
125 131
      }
126 132

  
127 133
///////////////////////////////////////////////////////////////////////////////////////////////////
......
151 157
        }
152 158

  
153 159
      Vertex3DActivity act = (Vertex3DActivity)mView.getContext();
154
      mMovePoint.set(mFactorObj*act.getCenterX(),mFactorObj*act.getCenterY(),0);
160
      mCenterPoint.set(mFactorObj*act.getCenterX(),mFactorObj*act.getCenterY(),0);
161
      mRegionPoint.set(mFactorObj*act.getRegionX(),mFactorObj*act.getRegionY(),0);
155 162

  
156 163
      mFactorReg = 2*mFactorObj*act.getRegionR()/regionSize;
157 164
      mRegionScalePoint.set(mFactorReg,mFactorReg,mFactorReg);
......
170 177

  
171 178
      mCenter.move( new Static3D( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 ,
172 179
                                  (height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) );
173
      mCenter.move(mMoveInter);
180
      mCenter.move(mCenterInter);
174 181
      mCenter.scale(factorCen);
175 182

  
176 183
      mRegion.quaternion(mQuatInt1, rotateCen);
......
178 185

  
179 186
      mRegion.move( new Static3D( (width -mFactorObj*mObjWidth )/2 ,
180 187
                                  (height-mFactorObj*mObjHeight)/2 , 12) );
181
      mRegion.move(mMoveInter);
188
      mRegion.move(mCenterInter);
189
      mRegion.move(mRegionInter);
182 190
      mRegion.scale(mRegionScaleInter);
183 191
      mRegion.move( new Static3D( -regionSize/2 , -regionSize/2 , 0) );
184 192

  

Also available in: Unified diff