Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effects3d / Effects3DEffect.java @ 6c548f65

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