Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effects3d / Effects3DEffect.java @ 9e7b6dbd

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 9e7b6dbd Leszek Koltunski
   // float factorZ = act.getDepth() / 100.0f;
396 56cbe1cf Leszek Koltunski
397 a418b421 Leszek Koltunski
    int deduct = (mName.getType() == EffectType.VERTEX ? 50:0);
398 76a81b6a Leszek Koltunski
399 9e7b6dbd Leszek Koltunski
    float x = (mInterRegion[0]-deduct)*factorX;
400
    float y = (mInterRegion[1]-deduct)*factorY;
401
    float z = (mInterRegion[2]-deduct)*factorX;   // ??
402
    float r =  mInterRegion[3]        *(factorX+factorY)/2;
403 56cbe1cf Leszek Koltunski
404 9e7b6dbd Leszek Koltunski
    mRegionSta.set(x,y,z,r);
405 56cbe1cf Leszek Koltunski
    }
406
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408
409
  private void setDefaultRegionInter()
410
    {
411
    mInterRegion[0] = 50;
412
    mInterRegion[1] = 50;
413
    mInterRegion[2] = 50;
414
    mInterRegion[3] = 50;
415
    }
416
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418
419
  private void setRegionText()
420
    {
421 e3eab072 Leszek Koltunski
    int f0 = (int)mRegionSta.get1();
422
    int f1 = (int)mRegionSta.get2();
423
    int f2 = (int)mRegionSta.get3();
424
    int f3 = (int)mRegionSta.get4();
425 56cbe1cf Leszek Koltunski
426
    mTextRegion.setText("region ("+f0+","+f1+","+f2+","+f3+")");
427
    }
428
429 3b1e9c7e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
430
431
  void setBackground(int pos)
432
    {
433
    int color = (pos%2==1 ? BACKGROUND_ODD:BACKGROUND_EVEN);
434
435
    if( mEffect!=null ) mEffect.setBackgroundColor(color);
436
    if( mCenter!=null ) mCenter.setBackgroundColor(color);
437
    if( mRegion!=null ) mRegion.setBackgroundColor(color);
438
    }
439
440 56cbe1cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
441
442 348dbeea Leszek Koltunski
  Effects3DEffect(EffectName name, Effects3DActivity2 act)
443 56cbe1cf Leszek Koltunski
    {
444
    mAct = new WeakReference<>(act);
445
    mName = name;
446
447 f4e44230 Leszek Koltunski
    mDyn1 = null;
448 c11a3a15 Leszek Koltunski
    mDyn2 = null;
449 f4e44230 Leszek Koltunski
    mDyn3 = null;
450 334c13fa Leszek Koltunski
    mDyn4 = null;
451 2f2f6176 Leszek Koltunski
    mDyn5 = null;
452 f4e44230 Leszek Koltunski
    mSta1 = null;
453 c11a3a15 Leszek Koltunski
    mSta2 = null;
454 f4e44230 Leszek Koltunski
    mSta3 = null;
455 334c13fa Leszek Koltunski
    mSta4 = null;
456 2f2f6176 Leszek Koltunski
    mSta5 = null;
457 f4e44230 Leszek Koltunski
458 c11a3a15 Leszek Koltunski
    mDimension = mName.getDimension();
459 8fd9f5fa Leszek Koltunski
460 76a81b6a Leszek Koltunski
    switch(mDimension)
461 8fd9f5fa Leszek Koltunski
      {
462 76a81b6a Leszek Koltunski
      case 1 : mDyn1 = new Dynamic1D();
463
               mSta1 = new Static1D(0);
464
               mDyn1.add(mSta1);
465
               break;
466 c11a3a15 Leszek Koltunski
      case 2 : mDyn2 = new Dynamic2D();
467
               mSta2 = new Static2D(0,0);
468
               mDyn2.add(mSta2);
469
               break;
470 76a81b6a Leszek Koltunski
      case 3 : mDyn3 = new Dynamic3D();
471
               mSta3 = new Static3D(0,0,0);
472
               mDyn3.add(mSta3);
473
               break;
474 2a261997 Leszek Koltunski
      case 4 : if( mName == EffectName.QUATERNION )
475 334c13fa Leszek Koltunski
                 {
476
                 mDyn4 = new Dynamic4D();
477
                 mSta4 = new Static4D(0,0,0,0);
478
                 mDyn4.add(mSta4);
479
                 }
480
               else
481
                 {
482
                 mDyn3 = new Dynamic3D();
483
                 mSta3 = new Static3D(0,0,0);
484
                 mDyn3.add(mSta3);
485
                 mDyn1 = new Dynamic1D();
486
                 mSta1 = new Static1D(0);
487
                 mDyn1.add(mSta1);
488
                 }
489 2f2f6176 Leszek Koltunski
               break;
490 06c636a5 Leszek Koltunski
      case 5 : if( mName == EffectName.WAVE )
491
                 {
492
                 mDyn5 = new Dynamic5D();
493
                 mSta5 = new Static5D(0, 0, 0, 0, 0);
494
                 mDyn5.add(mSta5);
495
                 }
496
               else
497
                 {
498
                 mDyn4 = new Dynamic4D();
499
                 mSta4 = new Static4D(0,0,0,0);
500
                 mDyn4.add(mSta4);
501
                 mDyn1 = new Dynamic1D();
502
                 mSta1 = new Static1D(0);
503
                 mDyn1.add(mSta1);
504
                 }
505 76a81b6a Leszek Koltunski
               break;
506
      default: throw new RuntimeException("unsupported effect");
507 8fd9f5fa Leszek Koltunski
      }
508 56cbe1cf Leszek Koltunski
509
    mInter = new int[mDimension];
510
    mSeekID= new int[mDimension];
511
512
    mInterRegion = new int[4];
513
    mSeekRegionID= new int[4];
514
    mRegionDyn   = new Dynamic4D();
515
    mRegionSta   = new Static4D(0,0,0,0);
516
    mRegionDyn.add(mRegionSta);
517
518 334c13fa Leszek Koltunski
    mInterCenter = new int[3];
519
    mSeekCenterID= new int[3];
520
    mCenterDyn   = new Dynamic3D();
521
    mCenterSta   = new Static3D(0,0,0);
522 56cbe1cf Leszek Koltunski
    mCenterDyn.add(mCenterSta);
523 fed00329 Leszek Koltunski
524
    mButton = null;
525
    mEffect = null;
526
    mCenter = null;
527
    mRegion = null;
528 56cbe1cf Leszek Koltunski
    }
529
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531
532 3b1e9c7e Leszek Koltunski
  View createView(int num)
533 56cbe1cf Leszek Koltunski
    {
534
    SeekBar[] seek = new SeekBar[mDimension];
535
536 348dbeea Leszek Koltunski
    Effects3DActivity2 act = mAct.get();
537 56cbe1cf Leszek Koltunski
538
    switch(mDimension)
539
      {
540 fed00329 Leszek Koltunski
      case 1 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect1d, null);
541 fe7fe83e Leszek Koltunski
               mText      = mEffect.findViewById(R.id.effect1dText);
542
               seek[0]    = mEffect.findViewById(R.id.effect1dbar1);
543 56cbe1cf Leszek Koltunski
               mSeekID[0] = seek[0].getId();
544 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button1dRemove);
545 56cbe1cf Leszek Koltunski
               break;
546 fed00329 Leszek Koltunski
      case 2 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect2d, null);
547 fe7fe83e Leszek Koltunski
               mText      = mEffect.findViewById(R.id.effect2dText);
548
               seek[0]    = mEffect.findViewById(R.id.effect2dbar1);
549
               seek[1]    = mEffect.findViewById(R.id.effect2dbar2);
550 56cbe1cf Leszek Koltunski
               mSeekID[0] = seek[0].getId();
551
               mSeekID[1] = seek[1].getId();
552 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button2dRemove);
553 56cbe1cf Leszek Koltunski
               break;
554 fed00329 Leszek Koltunski
      case 3 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect3d, null);
555 fe7fe83e Leszek Koltunski
               mText      = mEffect.findViewById(R.id.effect3dText);
556
               seek[0]    = mEffect.findViewById(R.id.effect3dbar1);
557
               seek[1]    = mEffect.findViewById(R.id.effect3dbar2);
558
               seek[2]    = mEffect.findViewById(R.id.effect3dbar3);
559 56cbe1cf Leszek Koltunski
               mSeekID[0] = seek[0].getId();
560
               mSeekID[1] = seek[1].getId();
561
               mSeekID[2] = seek[2].getId();
562 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button3dRemove);
563 56cbe1cf Leszek Koltunski
               break;
564 fed00329 Leszek Koltunski
      case 4 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect4d, null);
565 fe7fe83e Leszek Koltunski
               mText      = mEffect.findViewById(R.id.effect4dText);
566
               seek[0]    = mEffect.findViewById(R.id.effect4dbar1);
567
               seek[1]    = mEffect.findViewById(R.id.effect4dbar2);
568
               seek[2]    = mEffect.findViewById(R.id.effect4dbar3);
569
               seek[3]    = mEffect.findViewById(R.id.effect4dbar4);
570 56cbe1cf Leszek Koltunski
               mSeekID[0] = seek[0].getId();
571
               mSeekID[1] = seek[1].getId();
572
               mSeekID[2] = seek[2].getId();
573
               mSeekID[3] = seek[3].getId();
574 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button4dRemove);
575 56cbe1cf Leszek Koltunski
               break;
576 fed00329 Leszek Koltunski
      case 5 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect5d, null);
577 fe7fe83e Leszek Koltunski
               mText      = mEffect.findViewById(R.id.effect5dText);
578
               seek[0]    = mEffect.findViewById(R.id.effect5dbar1);
579
               seek[1]    = mEffect.findViewById(R.id.effect5dbar2);
580
               seek[2]    = mEffect.findViewById(R.id.effect5dbar3);
581
               seek[3]    = mEffect.findViewById(R.id.effect5dbar4);
582
               seek[4]    = mEffect.findViewById(R.id.effect5dbar5);
583 2f2f6176 Leszek Koltunski
               mSeekID[0] = seek[0].getId();
584
               mSeekID[1] = seek[1].getId();
585
               mSeekID[2] = seek[2].getId();
586
               mSeekID[3] = seek[3].getId();
587
               mSeekID[4] = seek[4].getId();
588 fed00329 Leszek Koltunski
               mButton    = mEffect.findViewById(R.id.button5dRemove);
589 2f2f6176 Leszek Koltunski
               break;
590 3b1e9c7e Leszek Koltunski
      default: android.util.Log.e("Effects3DEffect", "dimension "+mDimension+" not supported!");
591 56cbe1cf Leszek Koltunski
               return null;
592
      }
593
594 3b1e9c7e Leszek Koltunski
    mEffect.setBackgroundColor( num%2==1 ? BACKGROUND_EVEN: BACKGROUND_ODD );
595
596 56cbe1cf Leszek Koltunski
    setDefaultInter();
597
598
    for(int i=0; i<mDimension; i++)
599
      {
600
      seek[i].setOnSeekBarChangeListener(this);
601
      seek[i].setProgress( mInter[i] );
602
      }
603
604 fed00329 Leszek Koltunski
    return mEffect;
605 56cbe1cf Leszek Koltunski
    }
606
607
///////////////////////////////////////////////////////////////////////////////////////////////////
608
609 3b1e9c7e Leszek Koltunski
  View createRegion(int num)
610 56cbe1cf Leszek Koltunski
    {
611 348dbeea Leszek Koltunski
    Effects3DActivity2 act = mAct.get();
612 56cbe1cf Leszek Koltunski
613 fed00329 Leszek Koltunski
    mRegion = act.getLayoutInflater().inflate(R.layout.effectregion, null);
614 3b1e9c7e Leszek Koltunski
    mRegion.setBackgroundColor( num%2==1 ? BACKGROUND_EVEN: BACKGROUND_ODD );
615 56cbe1cf Leszek Koltunski
616
    SeekBar[] seek = new SeekBar[4];
617
618 fe7fe83e Leszek Koltunski
    seek[0] = mRegion.findViewById(R.id.effectRegionBarX );
619
    seek[1] = mRegion.findViewById(R.id.effectRegionBarY );
620
    seek[2] = mRegion.findViewById(R.id.effectRegionBarRX);
621
    seek[3] = mRegion.findViewById(R.id.effectRegionBarRY);
622 56cbe1cf Leszek Koltunski
623
    mSeekRegionID[0] = seek[0].getId();
624
    mSeekRegionID[1] = seek[1].getId();
625
    mSeekRegionID[2] = seek[2].getId();
626
    mSeekRegionID[3] = seek[3].getId();
627
628 fe7fe83e Leszek Koltunski
    mTextRegion = mRegion.findViewById(R.id.effectRegionText);
629 56cbe1cf Leszek Koltunski
630
    setDefaultRegionInter();
631
632
    for(int i=0; i<4; i++)
633
      {
634
      seek[i].setOnSeekBarChangeListener(this);
635
      seek[i].setProgress( mInterRegion[i] );
636
      }
637
638 9e7b6dbd Leszek Koltunski
    act.setRegion(mRegionSta.get1(),mRegionSta.get2(),mRegionSta.get3(), mRegionSta.get4() );
639 24991bc2 Leszek Koltunski
640 fed00329 Leszek Koltunski
    return mRegion;
641 56cbe1cf Leszek Koltunski
    }
642
643
///////////////////////////////////////////////////////////////////////////////////////////////////
644
645 3b1e9c7e Leszek Koltunski
  View createCenter(int num)
646 56cbe1cf Leszek Koltunski
    {
647 348dbeea Leszek Koltunski
    Effects3DActivity2 act = mAct.get();
648 56cbe1cf Leszek Koltunski
649 fed00329 Leszek Koltunski
    mCenter = act.getLayoutInflater().inflate(R.layout.effectcenter, null);
650 3b1e9c7e Leszek Koltunski
    mCenter.setBackgroundColor( num%2==1 ? BACKGROUND_EVEN: BACKGROUND_ODD );
651 56cbe1cf Leszek Koltunski
652 334c13fa Leszek Koltunski
    SeekBar[] seek = new SeekBar[3];
653 56cbe1cf Leszek Koltunski
654 fe7fe83e Leszek Koltunski
    seek[0] = mCenter.findViewById(R.id.effectCenterBarX );
655
    seek[1] = mCenter.findViewById(R.id.effectCenterBarY );
656
    seek[2] = mCenter.findViewById(R.id.effectCenterBarZ );
657 56cbe1cf Leszek Koltunski
658
    mSeekCenterID[0] = seek[0].getId();
659
    mSeekCenterID[1] = seek[1].getId();
660 334c13fa Leszek Koltunski
    mSeekCenterID[2] = seek[2].getId();
661 56cbe1cf Leszek Koltunski
662 fe7fe83e Leszek Koltunski
    mTextCenter = mCenter.findViewById(R.id.effectCenterText);
663 56cbe1cf Leszek Koltunski
664
    setDefaultCenterInter();
665
666 334c13fa Leszek Koltunski
    for(int i=0; i<3; i++)
667 56cbe1cf Leszek Koltunski
      {
668
      seek[i].setOnSeekBarChangeListener(this);
669
      seek[i].setProgress( mInterCenter[i] );
670
      }
671
672 e3eab072 Leszek Koltunski
    act.setCenter(mCenterSta.get1(),mCenterSta.get2(),mCenterSta.get3());
673 24991bc2 Leszek Koltunski
674 fed00329 Leszek Koltunski
    return mCenter;
675 56cbe1cf Leszek Koltunski
    }
676
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678
679
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
680
    {
681
    if ( mDimension>=1 && bar.getId()==mSeekID[0] )
682
      {
683
      mInter[0] = progress;
684
      fillStatics();
685
      setText();
686
      }
687
    if ( mDimension>=2 && bar.getId()==mSeekID[1] )
688
      {
689
      mInter[1] = progress;
690
      fillStatics();
691
      setText();
692
      }
693
    if ( mDimension>=3 && bar.getId()==mSeekID[2] )
694
      {
695
      mInter[2] = progress;
696
      fillStatics();
697
      setText();
698
      }
699
    if ( mDimension>=4 && bar.getId()==mSeekID[3] )
700
      {
701
      mInter[3] = progress;
702
      fillStatics();
703
      setText();
704
      }
705 2f2f6176 Leszek Koltunski
    if ( mDimension>=5 && bar.getId()==mSeekID[4] )
706
      {
707
      mInter[4] = progress;
708
      fillStatics();
709
      setText();
710
      }
711 56cbe1cf Leszek Koltunski
712
    if( bar.getId() == mSeekRegionID[0] )
713
      {
714
      mInterRegion[0] = progress;
715
      fillRegionStatics();
716
      setRegionText();
717
      }
718
    if( bar.getId() == mSeekRegionID[1] )
719
      {
720
      mInterRegion[1] = progress;
721
      fillRegionStatics();
722
      setRegionText();
723
      }
724
    if( bar.getId() == mSeekRegionID[2] )
725
      {
726
      mInterRegion[2] = progress;
727
      fillRegionStatics();
728
      setRegionText();
729
      }
730
    if( bar.getId() == mSeekRegionID[3] )
731
      {
732
      mInterRegion[3] = progress;
733
      fillRegionStatics();
734
      setRegionText();
735
      }
736
737
    if( bar.getId() == mSeekCenterID[0] )
738
      {
739
      mInterCenter[0] = progress;
740
      fillCenterStatics();
741
      setCenterText();
742
      }
743
    if( bar.getId() == mSeekCenterID[1] )
744
      {
745
      mInterCenter[1] = progress;
746
      fillCenterStatics();
747
      setCenterText();
748
      }
749 334c13fa Leszek Koltunski
    if( bar.getId() == mSeekCenterID[2] )
750
      {
751
      mInterCenter[2] = progress;
752
      fillCenterStatics();
753
      setCenterText();
754
      }
755 24991bc2 Leszek Koltunski
756
    if( fromUser )
757
      {
758 348dbeea Leszek Koltunski
      Effects3DActivity2 act = mAct.get();
759 0ab55f0c Leszek Koltunski
760 a418b421 Leszek Koltunski
      boolean show = (mName.getType()==EffectType.VERTEX);
761 0ab55f0c Leszek Koltunski
      boolean showR= (show && act.getShowRegion());
762
      boolean showC= (show && act.getShowCenter());
763
764 fe7fe83e Leszek Koltunski
      Effects3DSurfaceView view = act.findViewById(R.id.effects3dSurfaceView);
765 0ab55f0c Leszek Koltunski
      view.getRenderer().showRegionAndCenter( showR,showC );
766 24991bc2 Leszek Koltunski
767 e3eab072 Leszek Koltunski
      act.setCenter(mCenterSta.get1(),mCenterSta.get2(),mCenterSta.get3());
768 9e7b6dbd Leszek Koltunski
      act.setRegion(mRegionSta.get1(),mRegionSta.get2(),mRegionSta.get3(), mRegionSta.get4());
769 24991bc2 Leszek Koltunski
      }
770 56cbe1cf Leszek Koltunski
    }
771
772 fa9053f5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
773
774 6f3024ae Leszek Koltunski
  boolean thisView(View v)
775 fa9053f5 Leszek Koltunski
    {
776
    return v==mButton;
777
    }
778
779 fed00329 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
780
781
  public long getId()
782
    {
783
    return mId;
784
    }
785
786
///////////////////////////////////////////////////////////////////////////////////////////////////
787
788
  public View getEffect()
789
    {
790
    return mEffect;
791
    }
792
793
///////////////////////////////////////////////////////////////////////////////////////////////////
794
795
  public View getRegion()
796
    {
797
    return mRegion;
798
    }
799
800
///////////////////////////////////////////////////////////////////////////////////////////////////
801
802
  public View getCenter()
803
    {
804
    return mCenter;
805
    }
806
807 56cbe1cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
808
809
  public void onStartTrackingTouch(SeekBar bar) { }
810
811
///////////////////////////////////////////////////////////////////////////////////////////////////
812
813
  public void onStopTrackingTouch(SeekBar bar)  { }
814
  }