Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effects3d / Effects3DEffect.java @ fe7fe83e

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