Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effects3d / Effects3DEffect.java @ 7054bb1d

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