Project

General

Profile

« Previous | Next » 

Revision 8fd9f5fa

Added by Leszek Koltunski over 8 years ago

Vertex3D: make the Activity independent of Effects

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  };
82
  private EffectNames[] mEffectNames;
86 83

  
87 84
  private static boolean mSupportsRegion = true;
88 85

  
......
95 92

  
96 93
    mEffects = new ArrayList<>();
97 94

  
95
    createEffectNames();
96

  
98 97
    setContentView(R.layout.objectpickerlayout);
99 98

  
100 99
    mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols);
......
146 145
    bitmapSpinner.setAdapter(adapterBitmap);
147 146
    }
148 147

  
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

  
150
  private void createEffectNames()
151
    {
152
    EffectNames[] names = EffectNames.values();
153

  
154
    int numVertex=0;
155

  
156
    for(int i=0; i<names.length; i++)
157
      if( names[i].getType() == EffectTypes.VERTEX ) numVertex++;
158

  
159
    mEffectNames = new EffectNames[numVertex];
160

  
161
    numVertex=0;
162

  
163
    for(int i=0; i<names.length; i++)
164
      if( names[i].getType() == EffectTypes.VERTEX )
165
        {
166
        mEffectNames[numVertex++] = names[i];
167
        }
168
    }
169

  
149 170
///////////////////////////////////////////////////////////////////////////////////////////////////
150 171

  
151 172
  private void setGrid()
src/main/java/org/distorted/examples/vertex3d/Vertex3DEffect.java
63 63
  private Static2D  mCenterSta;
64 64

  
65 65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
// requires knowledge about effect nature
67

  
68
  private int getDimension()
69
    {
70
    switch(mName)
71
      {
72
      case SWIRL  :
73
      case SINK   : return 1;
74
      case DISTORT:
75
      case DEFORM : return 3;
76
      }
77

  
78
    return 0;
79
    }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
// requires knowledge about effect nature
83

  
84
  public void apply(DistortedObject object)
85
    {
86
    switch(mName)
87
      {
88
      case DISTORT: object.distort(mDyn3, mCenterDyn, mRegionDyn); break;
89
      case DEFORM : object.deform (mDyn3, mCenterDyn            ); break;
90
      case SINK   : object.sink   (mDyn1, mCenterDyn, mRegionDyn); break;
91
      case SWIRL  : object.swirl  (mDyn1, mCenterDyn, mRegionDyn); break;
92
      }
93
    }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
// requires knowledge about effect nature
66 97

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

  
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
// requires knowledge about effect nature
105

  
106
  private void fillStatics()
107
    {
108
    switch(mName)
109
      {
110
      case DISTORT:
111
      case DEFORM : float l = mAct.get().getWidth()/50.0f;
112
                    float x = (mInter[0]-50)*l;
113
                    float y = (mInter[1]-50)*l;
114
                    float z = (mInter[2]-50)*l;
115
                    mSta3.set(x,y,z);
116
                    break;
117
      case SINK   : mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f);
118
                    break;
119
      case SWIRL  : mSta1.set( 3.6f*(mInter[0]-50) );
120
                    break;
121
      }
122
    }
123

  
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
// requires knowledge about effect nature
126

  
127
  private void setDefaultInter()
128
    {
129
    switch(mName)
130
      {
131
      case DISTORT:
132
      case DEFORM : mInter[0] = 50;
133
                    mInter[1] = 50;
134
                    mInter[2] = 50;
135
                    break;
136
      case SINK   :
137
      case SWIRL  : mInter[0] = 50;
138
                    break;
139
      }
140
    }
141

  
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
// requires knowledge about effect nature
144

  
145
  private void setText()
146
    {
147
    String text = mName.name();
148

  
149
    if( mName==EffectNames.DISTORT || mName==EffectNames.DEFORM)
150
      {
151
      int f1 = (int)mSta3.getX();
152
      int f2 = (int)mSta3.getY();
153
      int f3 = (int)mSta3.getZ();
154
      text += " ("+f1+","+f2+","+f3+")";
155
      }
156
    else
157
      {
158
      float f1 = ((int)(mSta1.getX()*100))/100.0f;
159
      text += " ("+f1+")";
160
      }
161

  
162
    mText.setText(text);
163
    }
164

  
72 165
///////////////////////////////////////////////////////////////////////////////////////////////////
73 166

  
74 167
  private void fillCenterStatics()
......
137 230
    mTextRegion.setText("region ("+f0+","+f1+","+f2+","+f3+")");
138 231
    }
139 232

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

  
142
  private void fillStatics()
143
    {
144
    switch(mName)
145
      {
146
      case DISTORT:
147
      case DEFORM : Vertex3DActivity act = mAct.get();
148
                    float l = act.getWidth()/50.0f;
149
                    float x = (mInter[0]-50)*l;
150
                    float y = (mInter[1]-50)*l;
151
                    float z = (mInter[2]-50)*l;
152
                    mSta3.set(x,y,z);
153
                    break;
154
      case SINK   : mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f);
155
                    break;
156
      case SWIRL  : mSta1.set( 3.6f*(mInter[0]-50) );
157
                    break;
158
      }
159
    }
160

  
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

  
163
  private void setDefaultInter()
164
    {
165
    switch(mName)
166
      {
167
      case DISTORT:
168
      case DEFORM : mInter[0] = 50;
169
                    mInter[1] = 50;
170
                    mInter[2] = 50;
171
                    break;
172
      case SINK   :
173
      case SWIRL  : mInter[0] = 50;
174
                    break;
175
      }
176
    }
177

  
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

  
180
  private void setText()
181
    {
182
    String text = mName.name();
183

  
184
    if( mName==EffectNames.DISTORT || mName==EffectNames.DEFORM)
185
      {
186
      int f1 = (int)mSta3.getX();
187
      int f2 = (int)mSta3.getY();
188
      int f3 = (int)mSta3.getZ();
189
      text += " ("+f1+","+f2+","+f3+")";
190
      }
191
    else
192
      {
193
      float f1 = ((int)(mSta1.getX()*100))/100.0f;
194
      text += " ("+f1+")";
195
      }
196

  
197
    mText.setText(text);
198
    }
199

  
200 233
///////////////////////////////////////////////////////////////////////////////////////////////////
201 234

  
202 235
  public Vertex3DEffect(EffectNames name, Vertex3DActivity act)
......
204 237
    mAct = new WeakReference<>(act);
205 238
    mName = name;
206 239

  
207
    if( mName==EffectNames.SINK || mName==EffectNames.SWIRL )
240
    mDimension = getDimension();
241

  
242
    if( mDimension==1 )
208 243
      {
209
      mDimension = 1;
210 244
      mDyn1 = new Dynamic1D();
211 245
      mSta1 = new Static1D(0);
212 246
      mDyn1.add(mSta1);
213 247
      mDyn3 = null;
214 248
      }
215
    else
249
    else if( mDimension==3 )
216 250
      {
217
      mDimension = 3;
218 251
      mDyn3 = new Dynamic3D();
219 252
      mSta3 = new Static3D(0,0,0);
220 253
      mDyn3.add(mSta3);
221 254
      mDyn1 = null;
222 255
      }
256
    else
257
      {
258
      throw new RuntimeException("unsupported effect");
259
      }
223 260

  
224 261
    mInter = new int[mDimension];
225 262
    mSeekID= new int[mDimension];
......
348 385
    mSeekCenterID[0] = seek[0].getId();
349 386
    mSeekCenterID[1] = seek[1].getId();
350 387

  
351
    mTextCenter    = (TextView)center.findViewById(R.id.effectCenterText);
388
    mTextCenter = (TextView)center.findViewById(R.id.effectCenterText);
352 389

  
353 390
    setDefaultCenterInter();
354 391

  
......
363 400
    return center;
364 401
    }
365 402

  
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

  
379 403
///////////////////////////////////////////////////////////////////////////////////////////////////
380 404

  
381 405
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)

Also available in: Unified diff