Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effects3d / Effects3DEffect.java @ 3b1e9c7e

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