Project

General

Profile

« Previous | Next » 

Revision 2f2f6176

Added by Leszek Koltunski about 8 years ago

Make the WAVE effect 5D (extra parameter 'offset')

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DEffect.java
31 31
import org.distorted.library.type.Dynamic2D;
32 32
import org.distorted.library.type.Dynamic3D;
33 33
import org.distorted.library.type.Dynamic4D;
34
import org.distorted.library.type.Dynamic5D;
34 35
import org.distorted.library.type.Static1D;
35 36
import org.distorted.library.type.Static2D;
36 37
import org.distorted.library.type.Static3D;
37 38
import org.distorted.library.type.Static4D;
39
import org.distorted.library.type.Static5D;
38 40

  
39 41
import java.lang.ref.WeakReference;
40 42

  
41 43
///////////////////////////////////////////////////////////////////////////////////////////////////
42 44

  
43
public class Effects3DEffect implements SeekBar.OnSeekBarChangeListener
45
class Effects3DEffect implements SeekBar.OnSeekBarChangeListener
44 46
  {
45 47
  private WeakReference<Effects3DActivity> mAct;
46 48

  
......
56 58

  
57 59
  private Dynamic1D mDyn1;
58 60
  private Dynamic3D mDyn3;
59
  private Dynamic4D mDyn4;
61
  private Dynamic5D mDyn5;
60 62
  private Static1D  mSta1;
61 63
  private Static3D  mSta3;
62
  private Static4D  mSta4;
64
  private Static5D  mSta5;
63 65
  private Dynamic4D mRegionDyn;
64 66
  private Static4D  mRegionSta;
65 67
  private Dynamic2D mCenterDyn;
......
76 78
      case DEFORM       : return 3;
77 79

  
78 80
      case CHROMA       :
79
      case SMOOTH_CHROMA:
80
      case WAVE         : return 4;
81
      case SMOOTH_CHROMA: return 4;
82

  
83
      case WAVE         : return 5;
81 84

  
82 85
      default           : return 1;
83 86
      }
......
86 89
///////////////////////////////////////////////////////////////////////////////////////////////////
87 90
// requires knowledge about effect nature
88 91

  
89
  public void apply(DistortedObject object)
92
  void apply(DistortedObject object)
90 93
    {
91 94
    switch(mName)
92 95
      {
......
94 97
      case DEFORM : object.deform (mDyn3, mCenterDyn            ); break;
95 98
      case SINK   : object.sink   (mDyn1, mCenterDyn, mRegionDyn); break;
96 99
      case SWIRL  : object.swirl  (mDyn1, mCenterDyn, mRegionDyn); break;
97
      case WAVE   : object.wave   (mDyn4, mCenterDyn, mRegionDyn); break;
100
      case WAVE   : object.wave   (mDyn5, mCenterDyn, mRegionDyn); break;
98 101

  
99 102
      case ALPHA            : object.alpha     (mDyn1,        mRegionDyn, false); break;
100 103
      case SMOOTH_ALPHA     : object.alpha     (mDyn1,        mRegionDyn, true ); break;
......
114 117

  
115 118
  private boolean supportsRegion()
116 119
    {
117
    return mName == EffectNames.DEFORM ? false : true;
120
    return mName != EffectNames.DEFORM;
118 121
    }
119 122

  
120 123
///////////////////////////////////////////////////////////////////////////////////////////////////
......
136 139
                              float y2 = (mInter[1]-50)*l2;
137 140
                              float z2 = (mInter[2]-50)*180 / 50;
138 141
                              float w2 = (mInter[3]-50)*180 / 50;
139
                              mSta4.set(x2,y2,z2,w2);
142
                              float v2 = (mInter[4]-50)*180 / 50;
143
                              mSta5.set(x2,y2,z2,w2,v2);
140 144
                              break;
141 145
      case SINK             : mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f);
142 146
                              break;
......
178 182
                              mInter[1] = 50;
179 183
                              mInter[2] = 50;
180 184
                              mInter[3] = 50;
185
                              mInter[4] = 50;
181 186
                              break;
182 187
      case SINK             :
183 188
      case SWIRL            : mInter[0] = 50;
......
222 227
      text += " ("+f1+","+f2+","+f3+")";
223 228
      }
224 229

  
225
    if( mSta4 !=null )
230
    if( mSta5 !=null )
226 231
      {
227
      int f1 = (int)mSta4.getX();
228
      int f2 = (int)mSta4.getY();
229
      int f3 = (int)mSta4.getZ();
230
      int f4 = (int)mSta4.getW();
231
      text += " ("+f1+","+f2+","+f3+","+f4+")";
232
      int f1 = (int)mSta5.getX();
233
      int f2 = (int)mSta5.getY();
234
      int f3 = (int)mSta5.getZ();
235
      int f4 = (int)mSta5.getW();
236
      int f5 = (int)mSta5.getV();
237
      text += " ("+f1+","+f2+","+f3+","+f4+","+f5+")";
232 238
      }
233 239

  
234 240
    mText.setText(text);
......
306 312

  
307 313
///////////////////////////////////////////////////////////////////////////////////////////////////
308 314

  
309
  public Effects3DEffect(EffectNames name, Effects3DActivity act)
315
  Effects3DEffect(EffectNames name, Effects3DActivity act)
310 316
    {
311 317
    mAct = new WeakReference<>(act);
312 318
    mName = name;
313 319

  
314 320
    mDyn1 = null;
315 321
    mDyn3 = null;
316
    mDyn4 = null;
322
    mDyn5 = null;
317 323
    mSta1 = null;
318 324
    mSta3 = null;
319
    mSta4 = null;
325
    mSta5 = null;
320 326

  
321 327
    mDimension = getDimension();
322 328

  
......
330 336
               mSta3 = new Static3D(0,0,0);
331 337
               mDyn3.add(mSta3);
332 338
               break;
333
      case 4 : if( mName == EffectNames.WAVE )
334
                 {
335
                 mDyn4 = new Dynamic4D();
336
                 mSta4 = new Static4D(0,0,0,0);
337
                 mDyn4.add(mSta4);
338
                 }
339
               else
340
                 {
341
                 mDyn3 = new Dynamic3D();
342
                 mSta3 = new Static3D(0,0,0);
343
                 mDyn3.add(mSta3);
344
                 mDyn1 = new Dynamic1D();
345
                 mSta1 = new Static1D(0);
346
                 mDyn1.add(mSta1);
347
                 }
339
      case 4 : mDyn3 = new Dynamic3D();
340
               mSta3 = new Static3D(0,0,0);
341
               mDyn3.add(mSta3);
342
               mDyn1 = new Dynamic1D();
343
               mSta1 = new Static1D(0);
344
               mDyn1.add(mSta1);
345
               break;
346
      case 5 : mDyn5 = new Dynamic5D();
347
               mSta5 = new Static5D(0,0,0,0,0);
348
               mDyn5.add(mSta5);
348 349
               break;
349 350
      default: throw new RuntimeException("unsupported effect");
350 351
      }
......
367 368

  
368 369
///////////////////////////////////////////////////////////////////////////////////////////////////
369 370

  
370
  public View createView()
371
  View createView()
371 372
    {
372 373
    View effect;
373 374
    SeekBar[] seek = new SeekBar[mDimension];
......
408 409
               mSeekID[2] = seek[2].getId();
409 410
               mSeekID[3] = seek[3].getId();
410 411
               break;
412
      case 5 : effect     = act.getLayoutInflater().inflate(R.layout.effect5d, null);
413
               mText      = (TextView)effect.findViewById(R.id.effect5dText);
414
               seek[0]    = (SeekBar)effect.findViewById(R.id.effect5dbar1);
415
               seek[1]    = (SeekBar)effect.findViewById(R.id.effect5dbar2);
416
               seek[2]    = (SeekBar)effect.findViewById(R.id.effect5dbar3);
417
               seek[3]    = (SeekBar)effect.findViewById(R.id.effect5dbar4);
418
               seek[4]    = (SeekBar)effect.findViewById(R.id.effect5dbar5);
419
               mSeekID[0] = seek[0].getId();
420
               mSeekID[1] = seek[1].getId();
421
               mSeekID[2] = seek[2].getId();
422
               mSeekID[3] = seek[3].getId();
423
               mSeekID[4] = seek[4].getId();
424
               break;
411 425
      default: android.util.Log.e("Effects3DEffect", "dimension "+mDimension+" not supported!");
412 426
               return null;
413 427
      }
......
428 442

  
429 443
///////////////////////////////////////////////////////////////////////////////////////////////////
430 444

  
431
  public View createRegion()
445
  View createRegion()
432 446
    {
433 447
    Effects3DActivity act = mAct.get();
434 448

  
......
463 477

  
464 478
///////////////////////////////////////////////////////////////////////////////////////////////////
465 479

  
466
  public View createCenter()
480
  View createCenter()
467 481
    {
468 482
    Effects3DActivity act = mAct.get();
469 483

  
......
520 534
      fillStatics();
521 535
      setText();
522 536
      }
537
    if ( mDimension>=5 && bar.getId()==mSeekID[4] )
538
      {
539
      mInter[4] = progress;
540
      fillStatics();
541
      setText();
542
      }
523 543

  
524 544
    if( bar.getId() == mSeekRegionID[0] )
525 545
      {
src/main/res/layout/effect5d.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
              android:id="@+id/effect5dLayout"
4
              android:layout_width="match_parent"
5
              android:layout_height="wrap_content"
6
              android:orientation="vertical">
7

  
8
        <TextView
9
            android:id="@+id/effect5dText"
10
            android:layout_width="wrap_content"
11
            android:layout_height="wrap_content"
12
            android:layout_marginEnd="5dp"
13
            android:layout_marginStart="5dp"
14
            android:layout_marginTop="3dp" />
15

  
16
        <SeekBar
17
            android:id="@+id/effect5dbar1"
18
            android:layout_width="fill_parent"
19
            android:layout_height="wrap_content"
20
            android:layout_marginEnd="5dp"
21
            android:layout_marginLeft="5dp"
22
            android:layout_marginRight="5dp" />
23

  
24
        <SeekBar
25
            android:id="@+id/effect5dbar2"
26
            android:layout_width="fill_parent"
27
            android:layout_height="wrap_content"
28
            android:layout_marginEnd="5dp"
29
            android:layout_marginLeft="5dp"
30
            android:layout_marginRight="5dp" />
31

  
32
        <SeekBar
33
            android:id="@+id/effect5dbar3"
34
            android:layout_width="fill_parent"
35
            android:layout_height="wrap_content"
36
            android:layout_marginEnd="5dp"
37
            android:layout_marginLeft="5dp"
38
            android:layout_marginRight="5dp" />
39

  
40
        <SeekBar
41
            android:id="@+id/effect5dbar4"
42
            android:layout_width="fill_parent"
43
            android:layout_height="wrap_content"
44
            android:layout_marginEnd="5dp"
45
            android:layout_marginLeft="5dp"
46
            android:layout_marginRight="5dp" />
47

  
48
        <SeekBar
49
            android:id="@+id/effect5dbar5"
50
            android:layout_width="fill_parent"
51
            android:layout_height="wrap_content"
52
            android:layout_marginEnd="5dp"
53
            android:layout_marginLeft="5dp"
54
            android:layout_marginRight="5dp" />
55

  
56
</LinearLayout>

Also available in: Unified diff