Project

General

Profile

Download (25.2 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / effects3d / Effects3DEffect.java @ 752c6b57

1 56cbe1cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 76a81b6a Leszek Koltunski
package org.distorted.examples.effects3d;
21 56cbe1cf Leszek Koltunski
22
import android.view.View;
23
import android.widget.SeekBar;
24
import android.widget.TextView;
25
26
import org.distorted.examples.R;
27 d04a4886 Leszek Koltunski
import org.distorted.library.DistortedEffects;
28 56cbe1cf Leszek Koltunski
import org.distorted.library.EffectNames;
29 76a81b6a Leszek Koltunski
import org.distorted.library.EffectTypes;
30 56cbe1cf Leszek Koltunski
import org.distorted.library.type.Dynamic1D;
31
import org.distorted.library.type.Dynamic2D;
32
import org.distorted.library.type.Dynamic3D;
33
import org.distorted.library.type.Dynamic4D;
34 2f2f6176 Leszek Koltunski
import org.distorted.library.type.Dynamic5D;
35 56cbe1cf Leszek Koltunski
import org.distorted.library.type.Static1D;
36
import org.distorted.library.type.Static2D;
37
import org.distorted.library.type.Static3D;
38
import org.distorted.library.type.Static4D;
39 2f2f6176 Leszek Koltunski
import org.distorted.library.type.Static5D;
40 56cbe1cf Leszek Koltunski
41
import java.lang.ref.WeakReference;
42
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45 2f2f6176 Leszek Koltunski
class Effects3DEffect implements SeekBar.OnSeekBarChangeListener
46 56cbe1cf Leszek Koltunski
  {
47 76a81b6a Leszek Koltunski
  private WeakReference<Effects3DActivity> mAct;
48 56cbe1cf Leszek Koltunski
49
  private EffectNames mName;
50
  private int[] mInter;
51
  private int[] mInterRegion;
52
  private int[] mInterCenter;
53
  private int[] mSeekID;
54
  private int[] mSeekRegionID;
55
  private int[] mSeekCenterID;
56
  private int mDimension;
57
  private TextView mText,mTextRegion,mTextCenter;
58
59
  private Dynamic1D mDyn1;
60 c11a3a15 Leszek Koltunski
  private Dynamic2D mDyn2;
61 56cbe1cf Leszek Koltunski
  private Dynamic3D mDyn3;
62 334c13fa Leszek Koltunski
  private Dynamic4D mDyn4;
63 2f2f6176 Leszek Koltunski
  private Dynamic5D mDyn5;
64 56cbe1cf Leszek Koltunski
  private Static1D  mSta1;
65 c11a3a15 Leszek Koltunski
  private Static2D  mSta2;
66 56cbe1cf Leszek Koltunski
  private Static3D  mSta3;
67 334c13fa Leszek Koltunski
  private Static4D  mSta4;
68 2f2f6176 Leszek Koltunski
  private Static5D  mSta5;
69 56cbe1cf Leszek Koltunski
  private Dynamic4D mRegionDyn;
70
  private Static4D  mRegionSta;
71 334c13fa Leszek Koltunski
  private Dynamic3D mCenterDyn;
72
  private Static3D  mCenterSta;
73 56cbe1cf Leszek Koltunski
74 fed00329 Leszek Koltunski
  private View mButton, mEffect, mCenter, mRegion;
75 fa9053f5 Leszek Koltunski
  private long mId;
76
77 8fd9f5fa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
78
// requires knowledge about effect nature
79
80 d04a4886 Leszek Koltunski
  void apply(DistortedEffects effects)
81 8fd9f5fa Leszek Koltunski
    {
82
    switch(mName)
83
      {
84 d04a4886 Leszek Koltunski
      case ROTATE           : mId = effects.rotate    (mDyn4, mCenterDyn); break;
85
      case QUATERNION       : mId = effects.quaternion(mDyn4, mCenterDyn); break;
86
      case MOVE             : mId = effects.move      (mDyn3)            ; break;
87
      case SCALE            : mId = effects.scale     (mDyn3)            ; break;
88
      case SHEAR            : mId = effects.shear     (mDyn3, mCenterDyn); break;
89
90
      case DISTORT          : mId = effects.distort   (mDyn3, mCenterDyn, mRegionDyn); break;
91
      case DEFORM           : mId = effects.deform    (mDyn3, mCenterDyn, mRegionDyn); break;
92
      case SINK             : mId = effects.sink      (mDyn1, mCenterDyn, mRegionDyn); break;
93
      case PINCH            : mId = effects.pinch     (mDyn2, mCenterDyn, mRegionDyn); break;
94
      case SWIRL            : mId = effects.swirl     (mDyn1, mCenterDyn, mRegionDyn); break;
95
      case WAVE             : mId = effects.wave      (mDyn5, mCenterDyn, mRegionDyn); break;
96
97
      case ALPHA            : mId = effects.alpha     (mDyn1,        mRegionDyn, false); break;
98
      case SMOOTH_ALPHA     : mId = effects.alpha     (mDyn1,        mRegionDyn, true ); break;
99
      case CHROMA           : mId = effects.chroma    (mDyn1, mDyn3, mRegionDyn, false); break;
100
      case SMOOTH_CHROMA    : mId = effects.chroma    (mDyn1, mDyn3, mRegionDyn, true ); break;
101
      case BRIGHTNESS       : mId = effects.brightness(mDyn1,        mRegionDyn, false); break;
102
      case SMOOTH_BRIGHTNESS: mId = effects.brightness(mDyn1,        mRegionDyn, true ); break;
103
      case SATURATION       : mId = effects.saturation(mDyn1,        mRegionDyn, false); break;
104
      case SMOOTH_SATURATION: mId = effects.saturation(mDyn1,        mRegionDyn, true ); break;
105
      case CONTRAST         : mId = effects.contrast  (mDyn1,        mRegionDyn, false); break;
106
      case SMOOTH_CONTRAST  : mId = effects.contrast  (mDyn1,        mRegionDyn, true ); break;
107 fa9053f5 Leszek Koltunski
108
      default: mId = -1;
109 8fd9f5fa Leszek Koltunski
      }
110
    }
111
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
// requires knowledge about effect nature
114
115
  private void fillStatics()
116
    {
117
    switch(mName)
118
      {
119 334c13fa Leszek Koltunski
      case ROTATE           : float an = (mInter[0]-50)*180/50;
120
                              float rx = (mInter[1]-50)/ 50.0f;
121
                              float ry = (mInter[2]-50)/ 50.0f;
122
                              float rz = (mInter[3]-50)/ 50.0f;
123
                              mSta4.set(an,rx,ry,rz);
124
                              break;
125 7c8012ee Leszek Koltunski
      case QUATERNION       : float qx = (mInter[0]-50)/ 50.0f;
126
                              float qy = (mInter[1]-50)/ 50.0f;
127
                              float qz = (mInter[2]-50)/ 50.0f;
128
                              float qa = (mInter[3]-50)*3.1415f/50;
129
                              float cosA = (float)Math.cos(qa/2);
130
                              float len = (float)Math.sqrt(qx*qx+qy*qy+qz*qz);
131
                              float sinAnorm = (float)Math.sin(qa/2)/len;
132
                              mSta4.set(sinAnorm*qx,sinAnorm*qy,sinAnorm*qz, cosA);
133 334c13fa Leszek Koltunski
                              break;
134 752c6b57 Leszek Koltunski
      case MOVE             : float s  = 0.04f;
135
                              float xm = (mInter[0]-50)*s;
136
                              float ym = (mInter[1]-50)*s;
137
                              float zm = (mInter[2]-50)*s;
138 334c13fa Leszek Koltunski
                              mSta3.set(xm,ym,zm);
139
                              break;
140 752c6b57 Leszek Koltunski
      case SCALE            : double coeff = Math.PI / 100;
141
142
                              if( mInter[0]<=  0 ) mInter[0]= 1;
143
                              if( mInter[0]>=100 ) mInter[0]=99;
144
                              if( mInter[1]<=  0 ) mInter[1]= 1;
145
                              if( mInter[1]>=100 ) mInter[1]=99;
146
                              if( mInter[2]<=  0 ) mInter[2]= 1;
147
                              if( mInter[2]>=100 ) mInter[2]=99;
148
149
                              float xs = (float)Math.tan((mInter[0]-50)*coeff);
150
                              float ys = (float)Math.tan((mInter[1]-50)*coeff);
151
                              float zs = (float)Math.tan((mInter[2]-50)*coeff);
152 334c13fa Leszek Koltunski
                              mSta3.set(xs,ys,zs);
153
                              break;
154
      case SHEAR            : float xsh = (mInter[0]-50)/25.0f;
155
                              float ysh = (mInter[1]-50)/25.0f;
156
                              float zsh = (mInter[2]-50)/25.0f;
157
                              mSta3.set(xsh,ysh,zsh);
158
                              break;
159 7c8012ee Leszek Koltunski
160 76a81b6a Leszek Koltunski
      case DISTORT          :
161 334c13fa Leszek Koltunski
      case DEFORM           : float ld = mAct.get().getWidth()/50.0f;
162
                              float xd = (mInter[0]-50)*ld;
163
                              float yd = (mInter[1]-50)*ld;
164
                              float zd = (mInter[2]-50)*ld;
165
                              mSta3.set(xd,yd,zd);
166 76a81b6a Leszek Koltunski
                              break;
167 30e77a6c Leszek Koltunski
      case WAVE             : float l2 = mAct.get().getWidth()/50.0f;
168
                              float x2 = (mInter[0]-50)*l2;
169 2e7c7abf Leszek Koltunski
                              float y2 = (mInter[1]-50)*l2;
170
                              float z2 = (mInter[2]-50)*180 / 50;
171 f4e44230 Leszek Koltunski
                              float w2 = (mInter[3]-50)*180 / 50;
172 2f2f6176 Leszek Koltunski
                              float v2 = (mInter[4]-50)*180 / 50;
173
                              mSta5.set(x2,y2,z2,w2,v2);
174 30e77a6c Leszek Koltunski
                              break;
175 76a81b6a Leszek Koltunski
      case SWIRL            : mSta1.set( 3.6f*(mInter[0]-50) );
176
                              break;
177 7908dbc2 Leszek Koltunski
      case SINK             : mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f);
178
                              break;
179
      case PINCH            : float dp = mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f;
180
                              float ap = (mInter[1]-50)*180 / 50;
181
                              mSta2.set(dp,ap);
182
                              break;
183
184 76a81b6a Leszek Koltunski
      case ALPHA            :
185 889a962e Leszek Koltunski
      case SMOOTH_ALPHA     : mSta1.set(mInter[0]/100.0f);
186
                              break;
187 76a81b6a Leszek Koltunski
      case SATURATION       :
188
      case SMOOTH_SATURATION:
189
      case CONTRAST         :
190 889a962e Leszek Koltunski
      case SMOOTH_CONTRAST  :
191
      case BRIGHTNESS       :
192
      case SMOOTH_BRIGHTNESS: mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f);
193 76a81b6a Leszek Koltunski
                              break;
194
      case CHROMA           :
195
      case SMOOTH_CHROMA    : mSta1.set(mInter[0]/100.0f);
196 889a962e Leszek Koltunski
                              mSta3.set(mInter[1]/100.0f,
197
                                        mInter[2]/100.0f,
198
                                        mInter[3]/100.0f);
199 76a81b6a Leszek Koltunski
                              break;
200 8fd9f5fa Leszek Koltunski
      }
201
    }
202
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204
205
  private void setDefaultInter()
206
    {
207 c11a3a15 Leszek Koltunski
    switch(mDimension)
208 8fd9f5fa Leszek Koltunski
      {
209 c11a3a15 Leszek Koltunski
      case 5: mInter[4] = 50;
210
      case 4: mInter[3] = 50;
211
      case 3: mInter[2] = 50;
212
      case 2: mInter[1] = 50;
213
      case 1: mInter[0] = 50;
214 8fd9f5fa Leszek Koltunski
      }
215 334c13fa Leszek Koltunski
216 752c6b57 Leszek Koltunski
    if( mName==EffectNames.ROTATE || mName==EffectNames.QUATERNION )
217
      {
218
      mInter[1]= 100;
219
      }
220
    if( mName==EffectNames.SCALE )
221
      {
222
      mInter[0]= 75;
223
      mInter[1]= 75;
224
      mInter[2]= 75;
225
      }
226 8fd9f5fa Leszek Koltunski
    }
227
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
230
  private void setText()
231
    {
232
    String text = mName.name();
233
234 f4e44230 Leszek Koltunski
    if( mSta1 !=null )
235 76a81b6a Leszek Koltunski
      {
236 47093bfd Leszek Koltunski
      float f1 = ((int)(mSta1.getX()*100))/100.0f;
237 f4e44230 Leszek Koltunski
      text += " "+f1;
238 76a81b6a Leszek Koltunski
      }
239
240 c11a3a15 Leszek Koltunski
    if( mSta2 !=null )
241
      {
242
      float f1 = ((int)(mSta2.getX()*100))/100.0f;
243
      float f2 = ((int)(mSta2.getY()*100))/100.0f;
244
      text += " ("+f1+","+f2+")";
245
      }
246
247 f4e44230 Leszek Koltunski
    if( mSta3 !=null )
248 8fd9f5fa Leszek Koltunski
      {
249 47093bfd Leszek Koltunski
      float f1 = ((int)(mSta3.getX()*100))/100.0f;
250
      float f2 = ((int)(mSta3.getY()*100))/100.0f;
251
      float f3 = ((int)(mSta3.getZ()*100))/100.0f;
252 8fd9f5fa Leszek Koltunski
      text += " ("+f1+","+f2+","+f3+")";
253
      }
254 f4e44230 Leszek Koltunski
255 334c13fa Leszek Koltunski
    if( mSta4 !=null )
256
      {
257
      float f1 = ((int)(mSta4.getX()*100))/100.0f;
258
      float f2 = ((int)(mSta4.getY()*100))/100.0f;
259
      float f3 = ((int)(mSta4.getZ()*100))/100.0f;
260
      float f4 = ((int)(mSta4.getW()*100))/100.0f;
261
      text += " ("+f1+","+f2+","+f3+","+f4+")";
262
      }
263
264 2f2f6176 Leszek Koltunski
    if( mSta5 !=null )
265 8fd9f5fa Leszek Koltunski
      {
266 47093bfd Leszek Koltunski
      float f1 = ((int)(mSta5.getX()*100))/100.0f;
267
      float f2 = ((int)(mSta5.getY()*100))/100.0f;
268
      float f3 = ((int)(mSta5.getZ()*100))/100.0f;
269
      float f4 = ((int)(mSta5.getW()*100))/100.0f;
270
      float f5 = ((int)(mSta5.getV()*100))/100.0f;
271 2f2f6176 Leszek Koltunski
      text += " ("+f1+","+f2+","+f3+","+f4+","+f5+")";
272 8fd9f5fa Leszek Koltunski
      }
273
274
    mText.setText(text);
275
    }
276
277 56cbe1cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
278
279
  private void fillCenterStatics()
280
    {
281 752c6b57 Leszek Koltunski
    float x = (mInterCenter[0]-50)*0.02f;
282
    float y = (mInterCenter[1]-50)*0.02f;
283
    float z = (mInterCenter[2]-50)*0.02f;
284 334c13fa Leszek Koltunski
285
    mCenterSta.set(x,y,z);
286 56cbe1cf Leszek Koltunski
    }
287
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
290
  private void setDefaultCenterInter()
291
    {
292
    mInterCenter[0] = 50;
293
    mInterCenter[1] = 50;
294 334c13fa Leszek Koltunski
    mInterCenter[2] = 50;
295 56cbe1cf Leszek Koltunski
    }
296
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298
299
  private void setCenterText()
300
    {
301 752c6b57 Leszek Koltunski
    float f0 = ((int)(mCenterSta.getX()*100))/100.0f;
302
    float f1 = ((int)(mCenterSta.getY()*100))/100.0f;
303
    float f2 = ((int)(mCenterSta.getZ()*100))/100.0f;
304 56cbe1cf Leszek Koltunski
305 334c13fa Leszek Koltunski
    mTextCenter.setText("center ("+f0+","+f1+","+f2+")");
306 56cbe1cf Leszek Koltunski
    }
307
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309
310
  private void fillRegionStatics()
311
    {
312 76a81b6a Leszek Koltunski
    Effects3DActivity act = mAct.get();
313 56cbe1cf Leszek Koltunski
314
    float factorX = act.getWidth() / 100.0f;
315
    float factorY = act.getHeight()/ 100.0f;
316
317 76a81b6a Leszek Koltunski
    int deduct = (mName.getType() == EffectTypes.VERTEX ? 50:0);
318
319
    float  x = (mInterRegion[0]-deduct)*factorX;
320
    float  y = (mInterRegion[1]-deduct)*factorY;
321
    float rx =  mInterRegion[2]        *factorX;
322
    float ry =  mInterRegion[3]        *factorY;
323 56cbe1cf Leszek Koltunski
324
    mRegionSta.set(x,y,rx,ry);
325
    }
326
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328
329
  private void setDefaultRegionInter()
330
    {
331
    mInterRegion[0] = 50;
332
    mInterRegion[1] = 50;
333
    mInterRegion[2] = 50;
334
    mInterRegion[3] = 50;
335
    }
336
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338
339
  private void setRegionText()
340
    {
341
    int f0 = (int)mRegionSta.getX();
342
    int f1 = (int)mRegionSta.getY();
343
    int f2 = (int)mRegionSta.getZ();
344
    int f3 = (int)mRegionSta.getW();
345
346
    mTextRegion.setText("region ("+f0+","+f1+","+f2+","+f3+")");
347
    }
348
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350
351 2f2f6176 Leszek Koltunski
  Effects3DEffect(EffectNames name, Effects3DActivity act)
352 56cbe1cf Leszek Koltunski
    {
353
    mAct = new WeakReference<>(act);
354
    mName = name;
355
356 f4e44230 Leszek Koltunski
    mDyn1 = null;
357 c11a3a15 Leszek Koltunski
    mDyn2 = null;
358 f4e44230 Leszek Koltunski
    mDyn3 = null;
359 334c13fa Leszek Koltunski
    mDyn4 = null;
360 2f2f6176 Leszek Koltunski
    mDyn5 = null;
361 f4e44230 Leszek Koltunski
    mSta1 = null;
362 c11a3a15 Leszek Koltunski
    mSta2 = null;
363 f4e44230 Leszek Koltunski
    mSta3 = null;
364 334c13fa Leszek Koltunski
    mSta4 = null;
365 2f2f6176 Leszek Koltunski
    mSta5 = null;
366 f4e44230 Leszek Koltunski
367 c11a3a15 Leszek Koltunski
    mDimension = mName.getDimension();
368 8fd9f5fa Leszek Koltunski
369 76a81b6a Leszek Koltunski
    switch(mDimension)
370 8fd9f5fa Leszek Koltunski
      {
371 76a81b6a Leszek Koltunski
      case 1 : mDyn1 = new Dynamic1D();
372
               mSta1 = new Static1D(0);
373
               mDyn1.add(mSta1);
374
               break;
375 c11a3a15 Leszek Koltunski
      case 2 : mDyn2 = new Dynamic2D();
376
               mSta2 = new Static2D(0,0);
377
               mDyn2.add(mSta2);
378
               break;
379 76a81b6a Leszek Koltunski
      case 3 : mDyn3 = new Dynamic3D();
380
               mSta3 = new Static3D(0,0,0);
381
               mDyn3.add(mSta3);
382
               break;
383 7c8012ee Leszek Koltunski
      case 4 : if( mName == EffectNames.ROTATE || mName == EffectNames.QUATERNION )
384 334c13fa Leszek Koltunski
                 {
385
                 mDyn4 = new Dynamic4D();
386
                 mSta4 = new Static4D(0,0,0,0);
387
                 mDyn4.add(mSta4);
388
                 }
389
               else
390
                 {
391
                 mDyn3 = new Dynamic3D();
392
                 mSta3 = new Static3D(0,0,0);
393
                 mDyn3.add(mSta3);
394
                 mDyn1 = new Dynamic1D();
395
                 mSta1 = new Static1D(0);
396
                 mDyn1.add(mSta1);
397
                 }
398 2f2f6176 Leszek Koltunski
               break;
399
      case 5 : mDyn5 = new Dynamic5D();
400
               mSta5 = new Static5D(0,0,0,0,0);
401
               mDyn5.add(mSta5);
402 76a81b6a Leszek Koltunski
               break;
403
      default: throw new RuntimeException("unsupported effect");
404 8fd9f5fa Leszek Koltunski
      }
405 56cbe1cf Leszek Koltunski
406
    mInter = new int[mDimension];
407
    mSeekID= new int[mDimension];
408
409
    mInterRegion = new int[4];
410
    mSeekRegionID= new int[4];
411
    mRegionDyn   = new Dynamic4D();
412
    mRegionSta   = new Static4D(0,0,0,0);
413
    mRegionDyn.add(mRegionSta);
414
415 334c13fa Leszek Koltunski
    mInterCenter = new int[3];
416
    mSeekCenterID= new int[3];
417
    mCenterDyn   = new Dynamic3D();
418
    mCenterSta   = new Static3D(0,0,0);
419 56cbe1cf Leszek Koltunski
    mCenterDyn.add(mCenterSta);
420 fed00329 Leszek Koltunski
421
    mButton = null;
422
    mEffect = null;
423
    mCenter = null;
424
    mRegion = null;
425 56cbe1cf Leszek Koltunski
    }
426
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
429 2f2f6176 Leszek Koltunski
  View createView()
430 56cbe1cf Leszek Koltunski
    {
431
    SeekBar[] seek = new SeekBar[mDimension];
432
433 76a81b6a Leszek Koltunski
    Effects3DActivity act = mAct.get();
434 56cbe1cf Leszek Koltunski
435
    switch(mDimension)
436
      {
437 fed00329 Leszek Koltunski
      case 1 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect1d, null);
438
               mText      = (TextView)mEffect.findViewById(R.id.effect1dText);
439
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect1dbar1);
440 56cbe1cf Leszek Koltunski
               mSeekID[0] = seek[0].getId();
441 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button1dRemove);
442 56cbe1cf Leszek Koltunski
               break;
443 fed00329 Leszek Koltunski
      case 2 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect2d, null);
444
               mText      = (TextView)mEffect.findViewById(R.id.effect2dText);
445
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect2dbar1);
446
               seek[1]    = (SeekBar)mEffect.findViewById(R.id.effect2dbar2);
447 56cbe1cf Leszek Koltunski
               mSeekID[0] = seek[0].getId();
448
               mSeekID[1] = seek[1].getId();
449 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button2dRemove);
450 56cbe1cf Leszek Koltunski
               break;
451 fed00329 Leszek Koltunski
      case 3 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect3d, null);
452
               mText      = (TextView)mEffect.findViewById(R.id.effect3dText);
453
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect3dbar1);
454
               seek[1]    = (SeekBar)mEffect.findViewById(R.id.effect3dbar2);
455
               seek[2]    = (SeekBar)mEffect.findViewById(R.id.effect3dbar3);
456 56cbe1cf Leszek Koltunski
               mSeekID[0] = seek[0].getId();
457
               mSeekID[1] = seek[1].getId();
458
               mSeekID[2] = seek[2].getId();
459 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button3dRemove);
460 56cbe1cf Leszek Koltunski
               break;
461 fed00329 Leszek Koltunski
      case 4 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect4d, null);
462
               mText      = (TextView)mEffect.findViewById(R.id.effect4dText);
463
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect4dbar1);
464
               seek[1]    = (SeekBar)mEffect.findViewById(R.id.effect4dbar2);
465
               seek[2]    = (SeekBar)mEffect.findViewById(R.id.effect4dbar3);
466
               seek[3]    = (SeekBar)mEffect.findViewById(R.id.effect4dbar4);
467 56cbe1cf Leszek Koltunski
               mSeekID[0] = seek[0].getId();
468
               mSeekID[1] = seek[1].getId();
469
               mSeekID[2] = seek[2].getId();
470
               mSeekID[3] = seek[3].getId();
471 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button4dRemove);
472 56cbe1cf Leszek Koltunski
               break;
473 fed00329 Leszek Koltunski
      case 5 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect5d, null);
474
               mText      = (TextView)mEffect.findViewById(R.id.effect5dText);
475
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar1);
476
               seek[1]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar2);
477
               seek[2]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar3);
478
               seek[3]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar4);
479
               seek[4]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar5);
480 2f2f6176 Leszek Koltunski
               mSeekID[0] = seek[0].getId();
481
               mSeekID[1] = seek[1].getId();
482
               mSeekID[2] = seek[2].getId();
483
               mSeekID[3] = seek[3].getId();
484
               mSeekID[4] = seek[4].getId();
485 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button5dRemove);
486 2f2f6176 Leszek Koltunski
               break;
487 334c13fa Leszek Koltunski
      default: android.util.Log.e("Matrix3DEffect", "dimension "+mDimension+" not supported!");
488 56cbe1cf Leszek Koltunski
               return null;
489
      }
490
491
    setDefaultInter();
492
493
    for(int i=0; i<mDimension; i++)
494
      {
495
      seek[i].setOnSeekBarChangeListener(this);
496
      seek[i].setProgress( mInter[i] );
497
      }
498
499 f338550a leszek
    act.setSupportsCenter(mName.supportsCenter());
500
    act.setSupportsRegion(mName.supportsRegion());
501 24991bc2 Leszek Koltunski
502 fed00329 Leszek Koltunski
    return mEffect;
503 56cbe1cf Leszek Koltunski
    }
504
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506
507 2f2f6176 Leszek Koltunski
  View createRegion()
508 56cbe1cf Leszek Koltunski
    {
509 76a81b6a Leszek Koltunski
    Effects3DActivity act = mAct.get();
510 56cbe1cf Leszek Koltunski
511 fed00329 Leszek Koltunski
    mRegion = act.getLayoutInflater().inflate(R.layout.effectregion, null);
512 56cbe1cf Leszek Koltunski
513
    SeekBar[] seek = new SeekBar[4];
514
515 fed00329 Leszek Koltunski
    seek[0] = (SeekBar)mRegion.findViewById(R.id.effectRegionBarX );
516
    seek[1] = (SeekBar)mRegion.findViewById(R.id.effectRegionBarY );
517
    seek[2] = (SeekBar)mRegion.findViewById(R.id.effectRegionBarRX);
518
    seek[3] = (SeekBar)mRegion.findViewById(R.id.effectRegionBarRY);
519 56cbe1cf Leszek Koltunski
520
    mSeekRegionID[0] = seek[0].getId();
521
    mSeekRegionID[1] = seek[1].getId();
522
    mSeekRegionID[2] = seek[2].getId();
523
    mSeekRegionID[3] = seek[3].getId();
524
525 fed00329 Leszek Koltunski
    mTextRegion = (TextView)mRegion.findViewById(R.id.effectRegionText);
526 56cbe1cf Leszek Koltunski
527
    setDefaultRegionInter();
528
529
    for(int i=0; i<4; i++)
530
      {
531
      seek[i].setOnSeekBarChangeListener(this);
532
      seek[i].setProgress( mInterRegion[i] );
533
      }
534
535 24991bc2 Leszek Koltunski
    act.setRegion(mRegionSta.getX(),mRegionSta.getY(),mRegionSta.getZ());
536
537 fed00329 Leszek Koltunski
    return mRegion;
538 56cbe1cf Leszek Koltunski
    }
539
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541
542 2f2f6176 Leszek Koltunski
  View createCenter()
543 56cbe1cf Leszek Koltunski
    {
544 76a81b6a Leszek Koltunski
    Effects3DActivity act = mAct.get();
545 56cbe1cf Leszek Koltunski
546 fed00329 Leszek Koltunski
    mCenter = act.getLayoutInflater().inflate(R.layout.effectcenter, null);
547 56cbe1cf Leszek Koltunski
548 334c13fa Leszek Koltunski
    SeekBar[] seek = new SeekBar[3];
549 56cbe1cf Leszek Koltunski
550 fed00329 Leszek Koltunski
    seek[0] = (SeekBar)mCenter.findViewById(R.id.effectCenterBarX );
551
    seek[1] = (SeekBar)mCenter.findViewById(R.id.effectCenterBarY );
552 334c13fa Leszek Koltunski
    seek[2] = (SeekBar)mCenter.findViewById(R.id.effectCenterBarZ );
553 56cbe1cf Leszek Koltunski
554
    mSeekCenterID[0] = seek[0].getId();
555
    mSeekCenterID[1] = seek[1].getId();
556 334c13fa Leszek Koltunski
    mSeekCenterID[2] = seek[2].getId();
557 56cbe1cf Leszek Koltunski
558 fed00329 Leszek Koltunski
    mTextCenter = (TextView)mCenter.findViewById(R.id.effectCenterText);
559 56cbe1cf Leszek Koltunski
560
    setDefaultCenterInter();
561
562 334c13fa Leszek Koltunski
    for(int i=0; i<3; i++)
563 56cbe1cf Leszek Koltunski
      {
564
      seek[i].setOnSeekBarChangeListener(this);
565
      seek[i].setProgress( mInterCenter[i] );
566
      }
567
568 334c13fa Leszek Koltunski
    act.setCenter(mCenterSta.getX(),mCenterSta.getY(),mCenterSta.getZ());
569 24991bc2 Leszek Koltunski
570 fed00329 Leszek Koltunski
    return mCenter;
571 56cbe1cf Leszek Koltunski
    }
572
573
///////////////////////////////////////////////////////////////////////////////////////////////////
574
575
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
576
    {
577
    if ( mDimension>=1 && bar.getId()==mSeekID[0] )
578
      {
579
      mInter[0] = progress;
580
      fillStatics();
581
      setText();
582
      }
583
    if ( mDimension>=2 && bar.getId()==mSeekID[1] )
584
      {
585
      mInter[1] = progress;
586
      fillStatics();
587
      setText();
588
      }
589
    if ( mDimension>=3 && bar.getId()==mSeekID[2] )
590
      {
591
      mInter[2] = progress;
592
      fillStatics();
593
      setText();
594
      }
595
    if ( mDimension>=4 && bar.getId()==mSeekID[3] )
596
      {
597
      mInter[3] = progress;
598
      fillStatics();
599
      setText();
600
      }
601 2f2f6176 Leszek Koltunski
    if ( mDimension>=5 && bar.getId()==mSeekID[4] )
602
      {
603
      mInter[4] = progress;
604
      fillStatics();
605
      setText();
606
      }
607 56cbe1cf Leszek Koltunski
608
    if( bar.getId() == mSeekRegionID[0] )
609
      {
610
      mInterRegion[0] = progress;
611
      fillRegionStatics();
612
      setRegionText();
613
      }
614
    if( bar.getId() == mSeekRegionID[1] )
615
      {
616
      mInterRegion[1] = progress;
617
      fillRegionStatics();
618
      setRegionText();
619
      }
620
    if( bar.getId() == mSeekRegionID[2] )
621
      {
622
      mInterRegion[2] = progress;
623
      fillRegionStatics();
624
      setRegionText();
625
      }
626
    if( bar.getId() == mSeekRegionID[3] )
627
      {
628
      mInterRegion[3] = progress;
629
      fillRegionStatics();
630
      setRegionText();
631
      }
632
633
    if( bar.getId() == mSeekCenterID[0] )
634
      {
635
      mInterCenter[0] = progress;
636
      fillCenterStatics();
637
      setCenterText();
638
      }
639
    if( bar.getId() == mSeekCenterID[1] )
640
      {
641
      mInterCenter[1] = progress;
642
      fillCenterStatics();
643
      setCenterText();
644
      }
645 334c13fa Leszek Koltunski
    if( bar.getId() == mSeekCenterID[2] )
646
      {
647
      mInterCenter[2] = progress;
648
      fillCenterStatics();
649
      setCenterText();
650
      }
651 24991bc2 Leszek Koltunski
652
    if( fromUser )
653
      {
654 76a81b6a Leszek Koltunski
      Effects3DActivity act = mAct.get();
655 98c04ab8 leszek
      Effects3DSurfaceView view = (Effects3DSurfaceView)act.findViewById(R.id.effects3dSurfaceView);
656
      view.getRenderer().showRegionAndCenter(mName.getType()==EffectTypes.VERTEX);
657 24991bc2 Leszek Koltunski
658 f338550a leszek
      act.setSupportsCenter(mName.supportsCenter());
659
      act.setSupportsRegion(mName.supportsRegion());
660 334c13fa Leszek Koltunski
      act.setCenter(mCenterSta.getX(),mCenterSta.getY(),mCenterSta.getZ());
661 24991bc2 Leszek Koltunski
      act.setRegion(mRegionSta.getX(),mRegionSta.getY(),mRegionSta.getZ());
662
      }
663 56cbe1cf Leszek Koltunski
    }
664
665 fa9053f5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
666
667 6f3024ae Leszek Koltunski
  boolean thisView(View v)
668 fa9053f5 Leszek Koltunski
    {
669
    return v==mButton;
670
    }
671
672 fed00329 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
673
674
  public long getId()
675
    {
676
    return mId;
677
    }
678
679
///////////////////////////////////////////////////////////////////////////////////////////////////
680
681
  public View getEffect()
682
    {
683
    return mEffect;
684
    }
685
686
///////////////////////////////////////////////////////////////////////////////////////////////////
687
688
  public View getRegion()
689
    {
690
    return mRegion;
691
    }
692
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694
695
  public View getCenter()
696
    {
697
    return mCenter;
698
    }
699
700 56cbe1cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
701
702
  public void onStartTrackingTouch(SeekBar bar) { }
703
704
///////////////////////////////////////////////////////////////////////////////////////////////////
705
706
  public void onStopTrackingTouch(SeekBar bar)  { }
707
  }