Project

General

Profile

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

examples / src / main / java / org / distorted / examples / generic / Effects3DEffect.java @ e52bd0c8

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