Project

General

Profile

« Previous | Next » 

Revision 06c636a5

Added by Leszek Koltunski almost 6 years ago

More progress with Effects3D app.

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DActivity2.java
47 47

  
48 48
public class Effects3DActivity2 extends AppCompatActivity
49 49
  {
50
  public static final int NUM_TABS = 3;
51

  
50 52
  private int mNumCols;
51 53
  private int mNumRows;
52 54
  private int mNumSlic;
......
69 71
  private static boolean mShowNormal = true;
70 72
  private static boolean mUseOIT     = false;
71 73

  
74
  private Effects3DTab[] mTab;
75

  
72 76
///////////////////////////////////////////////////////////////////////////////////////////////////
73 77

  
74 78
  @Override
......
78 82

  
79 83
    setTheme(R.style.Theme_AppCompat_NoActionBar);
80 84

  
85
    mTab = new Effects3DTab[NUM_TABS];
86

  
81 87
    Bundle b = getIntent().getExtras();
82 88

  
83 89
    mObjectType = b.getInt("type");
......
102 108
    setContentView(view);
103 109

  
104 110
    mViewPager = findViewById(R.id.effects3d_viewpager);
105
    mViewPager.setOffscreenPageLimit(2);
111
    mViewPager.setOffscreenPageLimit( (NUM_TABS+1)/2 );
106 112
    mPager = new Effects3DTabViewPager(this, getSupportFragmentManager() );
107 113
    mViewPager.setAdapter(mPager);
108 114
    TabLayout tabLayout = findViewById(R.id.effects3d_sliding_tabs);
......
291 297

  
292 298
  public void newEffect(View v)
293 299
    {
294
    mPager.newEffect(v,mViewPager.getCurrentItem());
300
    int pos = mViewPager.getCurrentItem();
301

  
302
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].newEffect();
295 303
    }
296 304

  
297 305
///////////////////////////////////////////////////////////////////////////////////////////////////
298 306

  
299 307
  public void removeAll(View v)
300 308
    {
301
    mPager.removeAll(v,mViewPager.getCurrentItem());
309
    int pos = mViewPager.getCurrentItem();
310

  
311
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].removeAll();
302 312
    }
303 313

  
304 314
///////////////////////////////////////////////////////////////////////////////////////////////////
305 315

  
306 316
  public void remove(View v)
307 317
    {
308
    mPager.remove(v,mViewPager.getCurrentItem());
318
    int pos = mViewPager.getCurrentItem();
319

  
320
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].remove(v);
321
    }
322

  
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

  
325
  void setTab(int pos, Effects3DTab tab)
326
    {
327
    if( pos>=0 && pos<NUM_TABS ) mTab[pos] = tab;
309 328
    }
310 329

  
311 330
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/effects3d/Effects3DEffect.java
37 37
import org.distorted.library.effect.MatrixEffectRotate;
38 38
import org.distorted.library.effect.MatrixEffectScale;
39 39
import org.distorted.library.effect.MatrixEffectShear;
40
import org.distorted.library.effect.PostprocessEffectBlur;
41
import org.distorted.library.effect.PostprocessEffectGlow;
40 42
import org.distorted.library.effect.VertexEffectDeform;
41 43
import org.distorted.library.effect.VertexEffectDistort;
42 44
import org.distorted.library.effect.VertexEffectPinch;
......
123 125
      case SMOOTH_SATURATION: effect = new FragmentEffectSaturation(mDyn1,        mRegionDyn, true ); break;
124 126
      case CONTRAST         : effect = new FragmentEffectContrast  (mDyn1,        mRegionDyn, false); break;
125 127
      case SMOOTH_CONTRAST  : effect = new FragmentEffectContrast  (mDyn1,        mRegionDyn, true ); break;
128

  
129
      case BLUR             : effect = new PostprocessEffectBlur   (mDyn1       ); break;
130
      case GLOW             : effect = new PostprocessEffectGlow   (mDyn1, mDyn4); break;
126 131
      }
127 132

  
128 133
    if( effect!=null )
......
139 144
    {
140 145
    switch(mName)
141 146
      {
147
      ///////////////////////////////////////////////////////////////////////////////////////
148
      // MATRIX
149
      ///////////////////////////////////////////////////////////////////////////////////////
150

  
142 151
      case ROTATE           : float an = (mInter[0]-50)*180/50;
143 152
                              float rx = (mInter[1]-50)/ 50.0f;
144 153
                              float ry = (mInter[2]-50)/ 50.0f;
......
173 182
                              mSta3.set(xsh,ysh,zsh);
174 183
                              break;
175 184

  
185
      ///////////////////////////////////////////////////////////////////////////////////////
186
      // VERTEX
187
      ///////////////////////////////////////////////////////////////////////////////////////
188

  
176 189
      case DISTORT          :
177 190
      case DEFORM           : float ld = mAct.get().getWidth()/50.0f;
178 191
                              float xd = (mInter[0]-50)*ld;
......
197 210
                              mSta2.set(dp,ap);
198 211
                              break;
199 212

  
213
      ///////////////////////////////////////////////////////////////////////////////////////
214
      // FRAGMENT
215
      ///////////////////////////////////////////////////////////////////////////////////////
216

  
200 217
      case ALPHA            :
201 218
      case SMOOTH_ALPHA     : mSta1.set(mInter[0]/100.0f);
202 219
                              break;
......
213 230
                                        mInter[2]/100.0f,
214 231
                                        mInter[3]/100.0f);
215 232
                              break;
233

  
234
      ///////////////////////////////////////////////////////////////////////////////////////
235
      // POSTPROCESS
236
      ///////////////////////////////////////////////////////////////////////////////////////
237

  
238
      case BLUR             : mSta1.set(mInter[0]/2.0f);
239
                              break;
240
      case GLOW             : mSta1.set(mInter[0]/2.0f);
241
                              mSta4.set(mInter[1]/100.0f,
242
                                        mInter[2]/100.0f,
243
                                        mInter[3]/100.0f,
244
                                        mInter[4]/100.0f );
245
                              break;
216 246
      }
217 247
    }
218 248

  
......
405 435
                 mDyn1.add(mSta1);
406 436
                 }
407 437
               break;
408
      case 5 : mDyn5 = new Dynamic5D();
409
               mSta5 = new Static5D(0,0,0,0,0);
410
               mDyn5.add(mSta5);
438
      case 5 : if( mName == EffectName.WAVE )
439
                 {
440
                 mDyn5 = new Dynamic5D();
441
                 mSta5 = new Static5D(0, 0, 0, 0, 0);
442
                 mDyn5.add(mSta5);
443
                 }
444
               else
445
                 {
446
                 mDyn4 = new Dynamic4D();
447
                 mSta4 = new Static4D(0,0,0,0);
448
                 mDyn4.add(mSta4);
449
                 mDyn1 = new Dynamic1D();
450
                 mSta1 = new Static1D(0);
451
                 mDyn1.add(mSta1);
452
                 }
411 453
               break;
412 454
      default: throw new RuntimeException("unsupported effect");
413 455
      }
src/main/java/org/distorted/examples/effects3d/Effects3DTab.java
87 87
      }
88 88

  
89 89
    Effects3DActivity2 act = (Effects3DActivity2)getActivity();
90
    act.setTab(position, this);
91

  
90 92
    mEffects = act.getEffects();
91 93

  
92 94
    createEffectNames(mType);
src/main/java/org/distorted/examples/effects3d/Effects3DTabViewPager.java
22 22
import android.support.v4.app.Fragment;
23 23
import android.support.v4.app.FragmentManager;
24 24
import android.support.v4.app.FragmentPagerAdapter;
25
import android.view.View;
26 25
import android.os.Bundle;
27 26

  
28 27
import org.distorted.examples.R;
......
33 32

  
34 33
public class Effects3DTabViewPager extends FragmentPagerAdapter
35 34
  {
36
  private static final int NUM_TABS = 3;
37

  
38 35
  private WeakReference<Effects3DActivity2> mAct;
39
  private Effects3DTab[] mTab;
40 36

  
41 37
///////////////////////////////////////////////////////////////////////////////////////////////////
42 38

  
43
  public Effects3DTabViewPager(Effects3DActivity2 act, FragmentManager fm)
39
  Effects3DTabViewPager(Effects3DActivity2 act, FragmentManager fm)
44 40
    {
45 41
    super(fm);
46 42
    mAct = new WeakReference<>(act);
47
    mTab = new Effects3DTab[NUM_TABS];
48 43

  
49 44
    android.util.Log.e("viewPager"," CONSTRUCTOR ");
50 45
    }
51 46

  
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

  
54
  void newEffect(View v, int pos)
55
    {
56
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].newEffect();
57
    }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

  
61
  void removeAll(View v, int pos)
62
    {
63
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].removeAll();
64
    }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
  void remove(View v, int pos)
69
    {
70
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].remove(v);
71
    }
72

  
73 47
///////////////////////////////////////////////////////////////////////////////////////////////////
74 48

  
75 49
  @Override
......
77 51
    {
78 52
    android.util.Log.e("viewPager","creating tab "+position);
79 53

  
80
    if( position>=0 && position<NUM_TABS )
54
    if( position>=0 && position<Effects3DActivity2.NUM_TABS )
81 55
      {
82 56
      Bundle bundle = new Bundle();
83 57
      bundle.putInt("position", position);
84 58

  
85
      mTab[position] = new Effects3DTab();
86
      mTab[position].setArguments(bundle);
87
      return mTab[position];
59
      Effects3DTab tab = new Effects3DTab();
60
      tab.setArguments(bundle);
61
      return tab;
88 62
      }
89 63

  
90 64
    return null;
......
95 69
  @Override
96 70
  public int getCount()
97 71
    {
98
    return NUM_TABS;
72
    return Effects3DActivity2.NUM_TABS;
99 73
    }
100 74

  
101 75
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/values/strings.xml
144 144
    <string name="example_quaternion_subtitle">Random rotations using quaternions.</string>
145 145
    <string name="example_matrix3d">Matrix Effects</string>
146 146
    <string name="example_matrix3d_subtitle">Test results of Matrix effects on a 3D object.</string>
147
    <string name="example_effects3d">Vertex and Fragment effects</string>
148
    <string name="example_effects3d_subtitle">Test results of Vertex and Fragment effects on a 3D object.</string>
147
    <string name="example_effects3d">Generic Test</string>
148
    <string name="example_effects3d_subtitle">Apply any Effect on a 3D object.</string>
149 149
    <string name="example_plainmonalisa">SurfaceView</string>
150 150
    <string name="example_plainmonalisa_subtitle">MonaLisa rendered on a plain SurfaceView</string>
151 151
    <string name="example_save">Save to PNG</string>

Also available in: Unified diff