Project

General

Profile

Download (27.3 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / control / RubikControlWhole.java @ 6968a6ef

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube 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
// Magic Cube 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 Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.control;
21

    
22
import android.graphics.Bitmap;
23
import android.graphics.BitmapFactory;
24

    
25
import org.distorted.library.effect.MatrixEffectMove;
26
import org.distorted.library.effect.MatrixEffectScale;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedNode;
29
import org.distorted.library.main.DistortedScreen;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshQuad;
32
import org.distorted.library.message.EffectListener;
33
import org.distorted.library.type.Dynamic;
34
import org.distorted.library.type.Dynamic3D;
35
import org.distorted.library.type.Static3D;
36
import org.distorted.main.R;
37
import org.distorted.main.RubikActivity;
38

    
39
import java.io.IOException;
40
import java.io.InputStream;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
class RubikControlWhole implements EffectListener
45
  {
46
  private static final int NUM_NODE = 4;
47
  private static final int NUM_EFFE = 4;
48

    
49
  private static final int D1 = 2600; // time it takes for the finger to appear
50
  private static final int D2 =  250; // finger press
51
  private static final int D3 =10000; // finger triangle
52
  private static final int D4 = 3000; // fingers approach
53
  private static final int D5 =10000; // fingers circle
54

    
55
  private static final int[] DUR = { D1, D2, D3, D2, D1/4, 3*D1/4, D1/4, D2, D4, D5, D4, D2, D1 };
56

    
57
  private final RubikControl mControl;
58
  private DistortedEffects[] mEffects;
59
  private DistortedNode[] mNodes;
60
  private long mEffectID;
61
  private int mStageFinished, mWidth, mHeight;
62

    
63
  private MeshQuad mQuad;
64
  private DistortedTexture mTextureShad, mTextureCirc;
65

    
66
  private Dynamic3D mDynMoveHand1, mDynMoveShad1;
67
  private Dynamic3D mDynScaleHand1, mDynScaleShad1;
68
  private MatrixEffectMove mMoveHand1, mMoveShad1;
69
  private MatrixEffectScale mScaleHand1, mScaleShad1;
70

    
71
  private Dynamic3D mDynMoveHand2, mDynMoveShad2;
72
  private Dynamic3D mDynScaleHand2, mDynScaleShad2;
73
  private MatrixEffectMove mMoveHand2, mMoveShad2;
74
  private MatrixEffectScale mScaleHand2, mScaleShad2;
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
   private Bitmap openBitmap(RubikActivity act, int resource)
79
     {
80
     try( InputStream is = act.getResources().openRawResource(resource) )
81
       {
82
       return BitmapFactory.decodeStream(is);
83
       }
84
     catch( IOException e )
85
       {
86
       // ignore
87
       }
88

    
89
     return null;
90
     }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  private void resetDynamics1(int stage)
95
    {
96
    int dur = DUR[stage-1];
97

    
98
    mDynMoveHand1.removeAll();
99
    mDynMoveShad1.removeAll();
100
    mDynScaleHand1.removeAll();
101
    mDynScaleShad1.removeAll();
102

    
103
    mDynMoveHand1.setDuration(dur);
104
    mDynMoveShad1.setDuration(dur);
105
    mDynScaleHand1.setDuration(dur);
106
    mDynScaleShad1.setDuration(dur);
107
    mDynMoveHand1.resetToBeginning();
108
    mDynMoveShad1.resetToBeginning();
109
    mDynScaleHand1.resetToBeginning();
110
    mDynScaleShad1.resetToBeginning();
111

    
112
    mStageFinished = stage;
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
  private void resetDynamics2(int stage)
118
    {
119
    int dur = DUR[stage-1];
120

    
121
    mDynMoveHand2.removeAll();
122
    mDynMoveShad2.removeAll();
123
    mDynScaleHand2.removeAll();
124
    mDynScaleShad2.removeAll();
125

    
126
    mDynMoveHand2.setDuration(dur);
127
    mDynMoveShad2.setDuration(dur);
128
    mDynScaleHand2.setDuration(dur);
129
    mDynScaleShad2.setDuration(dur);
130
    mDynMoveHand2.resetToBeginning();
131
    mDynMoveShad2.resetToBeginning();
132
    mDynScaleHand2.resetToBeginning();
133
    mDynScaleShad2.resetToBeginning();
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137
// first finger appears and approaches the screen
138

    
139
  private void setEffectsStage1()
140
    {
141
    resetDynamics1(1);
142
    resetDynamics2(1);
143

    
144
    float x0 = mWidth*0.55f;
145
    float x1 = mWidth*0.45f;
146
    float x2 = mWidth*0.35f;
147
    float y1 = mHeight*0.28f;
148
    float z  = 0;
149
    float d  = mWidth*0.01f;
150
    float s  = mWidth*0.33f;
151

    
152
    Static3D point0h = new Static3D(-x0    ,-y1    , z);
153
    Static3D point1h = new Static3D(-x1    ,-y1    , z);
154
    Static3D point2h = new Static3D(-x2    ,-y1    , z);
155
    Static3D point3h = new Static3D(-x2  +d,-y1  +d, z);
156
    Static3D point0s = new Static3D(-x0+2*d,-y1+2*d, z);
157
    Static3D point1s = new Static3D(-x1+2*d,-y1+2*d, z);
158
    Static3D point2s = new Static3D(-x2+2*d,-y1+2*d, z);
159
    Static3D point3s = new Static3D(-x2  +d,-y1  +d, z);
160

    
161
    Static3D pointSc = new Static3D(s,s,s);
162

    
163
    mDynMoveHand1.add(point0h);
164
    mDynMoveHand1.add(point1h);
165
    mDynMoveHand1.add(point2h);
166
    mDynMoveHand1.add(point2h);
167
    mDynMoveHand1.add(point3h);
168
    mDynMoveShad1.add(point0s);
169
    mDynMoveShad1.add(point1s);
170
    mDynMoveShad1.add(point2s);
171
    mDynMoveShad1.add(point2s);
172
    mDynMoveShad1.add(point3s);
173
    mDynScaleHand1.add(pointSc);
174
    mDynScaleShad1.add(pointSc);
175

    
176
    mMoveHand1.notifyWhenFinished(this);
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
// first finger touches the screen
181

    
182
  private void setEffectsStage2()
183
    {
184
    resetDynamics1(2);
185

    
186
    float x2 = mWidth*0.35f;
187
    float y1 = mHeight*0.28f;
188
    float z  = 0;
189
    float d  = mWidth*0.01f;
190
    float sS = mWidth*0.0001f;
191
    float sF = mWidth*0.14f;
192
    float sH = mWidth*0.33f;
193

    
194
    Static3D point3h = new Static3D(-x2  +d,-y1  +d, z);
195
    Static3D scaleS  = new Static3D(sS,sS,sS);
196
    Static3D scaleF  = new Static3D(sF,sF,sF);
197
    Static3D pointH  = new Static3D(sH,sH,sH);
198

    
199
    mDynMoveHand1.add(point3h);
200
    mDynMoveShad1.add(point3h);
201
    mDynScaleHand1.add(pointH);
202
    mDynScaleShad1.add(scaleS);
203
    mDynScaleShad1.add(scaleF);
204

    
205
    mScaleShad1.notifyWhenFinished(this);
206

    
207
    mNodes[0].changeInputSurface(mTextureCirc);
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211
// first finger moves across the screen in a triangular fashion
212

    
213
  private void setEffectsStage3()
214
    {
215
    resetDynamics1(3);
216

    
217
    float x2 = mWidth*0.35f;
218

    
219
    float y1 = mHeight*0.28f;
220
    float z  = 0;
221
    float d  = mWidth*0.01f;
222
    float sH = mWidth*0.33f;
223
    float sF = mWidth*0.14f;
224

    
225
    Static3D scaleS = new Static3D(sF,sF,sF);
226
    Static3D pointH = new Static3D(sH,sH,sH);
227
    Static3D point1 = new Static3D(-x2  +d,-y1  +d, z);
228
    Static3D point2 = new Static3D(     +d,-y1  +d, z);
229
    Static3D point3 = new Static3D(+x2  +d,-y1  +d, z);
230
    Static3D point4 = new Static3D(+x2  +d,     +d, z);
231
    Static3D point5 = new Static3D(+x2  +d,+y1  +d, z);
232
    Static3D point6 = new Static3D(     +d,     +d, z);
233

    
234
    mDynScaleHand1.add(pointH);
235
    mDynScaleShad1.add(scaleS);
236

    
237
    mDynMoveHand1.add(point1);
238
    mDynMoveHand1.add(point1);
239
    mDynMoveHand1.add(point2);
240
    mDynMoveHand1.add(point3);
241
    mDynMoveHand1.add(point3);
242
    mDynMoveHand1.add(point4);
243
    mDynMoveHand1.add(point5);
244
    mDynMoveHand1.add(point5);
245
    mDynMoveHand1.add(point6);
246
    mDynMoveHand1.add(point1);
247
    mDynMoveHand1.add(point1);
248

    
249
    mDynMoveShad1.add(point1);
250
    mDynMoveShad1.add(point1);
251
    mDynMoveShad1.add(point2);
252
    mDynMoveShad1.add(point3);
253
    mDynMoveShad1.add(point3);
254
    mDynMoveShad1.add(point4);
255
    mDynMoveShad1.add(point5);
256
    mDynMoveShad1.add(point5);
257
    mDynMoveShad1.add(point6);
258
    mDynMoveShad1.add(point1);
259
    mDynMoveShad1.add(point1);
260

    
261
    mMoveHand1.notifyWhenFinished(this);
262
    }
263

    
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265
// first finger un-touches the screen
266

    
267
  private void setEffectsStage4()
268
    {
269
    resetDynamics1(4);
270

    
271
    float x2 = mWidth*0.35f;
272
    float y1 = mHeight*0.28f;
273
    float z  = 0;
274
    float d  = mWidth*0.01f;
275
    float sF = mWidth*0.0001f;
276
    float sS = mWidth*0.14f;
277
    float sH = mWidth*0.33f;
278

    
279
    Static3D point3h = new Static3D(-x2  +d,-y1  +d, z);
280
    Static3D scaleS  = new Static3D(sS,sS,sS);
281
    Static3D scaleF  = new Static3D(sF,sF,sF);
282
    Static3D pointH  = new Static3D(sH,sH,sH);
283

    
284
    mDynMoveHand1.add(point3h);
285
    mDynMoveShad1.add(point3h);
286
    mDynScaleHand1.add(pointH);
287
    mDynScaleShad1.add(scaleS);
288
    mDynScaleShad1.add(scaleF);
289

    
290
    mScaleShad1.notifyWhenFinished(this);
291
    }
292

    
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294
// first finger un-touches the screen (part2)
295

    
296
  private void setEffectsStage5()
297
    {
298
    resetDynamics1(5);
299

    
300
    float x2 = mWidth*0.35f;
301
    float y1 = mHeight*0.28f;
302
    float z  = 0;
303
    float d  = mWidth*0.01f;
304
    float s  = mWidth*0.33f;
305

    
306
    Static3D pointH = new Static3D(-x2    ,-y1    , z);
307
    Static3D point0 = new Static3D(-x2  +d,-y1  +d, z);
308
    Static3D pointS = new Static3D(-x2+2*d,-y1+2*d, z);
309
    Static3D pointSc = new Static3D(s,s,s);
310

    
311
    mDynScaleHand1.add(pointSc);
312
    mDynScaleShad1.add(pointSc);
313
    mDynMoveHand1.add(point0);
314
    mDynMoveHand1.add(pointH);
315
    mDynMoveShad1.add(point0);
316
    mDynMoveShad1.add(pointS);
317

    
318
    mMoveShad1.notifyWhenFinished(this);
319
    mNodes[0].changeInputSurface(mTextureShad);
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323
// second finger appears
324

    
325
  private void setEffectsStage6()
326
    {
327
    resetDynamics1(6);
328
    resetDynamics2(6);
329

    
330
    float x0 = mWidth*0.55f;
331
    float x1 = mWidth*0.45f;
332
    float x2 = mWidth*0.35f;
333
    float y1 = mHeight*0.28f;
334
    float z  = 0;
335
    float d  = mWidth*0.01f;
336
    float s  = mWidth*0.33f;
337

    
338
    Static3D pointH = new Static3D(-x2    ,-y1    , z);
339
    Static3D pointS = new Static3D(-x2+2*d,-y1+2*d, z);
340
    Static3D pointSc= new Static3D(s,s,s);
341

    
342
    mDynScaleHand1.add(pointSc);
343
    mDynScaleShad1.add(pointSc);
344
    mDynMoveHand1.add(pointH);
345
    mDynMoveShad1.add(pointS);
346

    
347
    Static3D point0h = new Static3D( x0    , y1    , z);
348
    Static3D point1h = new Static3D( x1    , y1    , z);
349
    Static3D point2h = new Static3D( x2    , y1    , z);
350
    Static3D point0s = new Static3D( x0+2*d, y1+2*d, z);
351
    Static3D point1s = new Static3D( x1+2*d, y1+2*d, z);
352
    Static3D point2s = new Static3D( x2+2*d, y1+2*d, z);
353
    Static3D pointSm= new Static3D(-s,s,s);
354

    
355
    mDynMoveHand2.add(point0h);
356
    mDynMoveHand2.add(point1h);
357
    mDynMoveHand2.add(point2h);
358
    mDynMoveHand2.add(point2h);
359
    mDynMoveShad2.add(point0s);
360
    mDynMoveShad2.add(point1s);
361
    mDynMoveShad2.add(point2s);
362
    mDynMoveShad2.add(point2s);
363
    mDynScaleHand2.add(pointSm);
364
    mDynScaleShad2.add(pointSm);
365

    
366
    mMoveHand2.notifyWhenFinished(this);
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370
// both fingers touch the screen (part1)
371

    
372
  private void setEffectsStage7()
373
    {
374
    resetDynamics1(7);
375
    resetDynamics2(7);
376

    
377
    float x2 = mWidth*0.35f;
378
    float y1 = mHeight*0.28f;
379
    float z  = 0;
380
    float d  = mWidth*0.01f;
381
    float s  = mWidth*0.33f;
382

    
383
    Static3D point1H = new Static3D(-x2    ,-y1    , z);
384
    Static3D point1F = new Static3D(-x2  +d,-y1  +d, z);
385
    Static3D point1S = new Static3D(-x2+2*d,-y1+2*d, z);
386
    Static3D point1Sc= new Static3D(s,s,s);
387

    
388
    mDynScaleHand1.add(point1Sc);
389
    mDynScaleShad1.add(point1Sc);
390
    mDynMoveHand1.add(point1H);
391
    mDynMoveHand1.add(point1F);
392
    mDynMoveShad1.add(point1S);
393
    mDynMoveShad1.add(point1F);
394

    
395
    Static3D point2H = new Static3D( x2    , y1    , z);
396
    Static3D point2F = new Static3D( x2  +d, y1  +d, z);
397
    Static3D point2S = new Static3D( x2+2*d, y1+2*d, z);
398
    Static3D point2Sc= new Static3D(-s,s,s);
399

    
400
    mDynScaleHand2.add(point2Sc);
401
    mDynScaleShad2.add(point2Sc);
402
    mDynMoveHand2.add(point2H);
403
    mDynMoveHand2.add(point2F);
404
    mDynMoveShad2.add(point2S);
405
    mDynMoveShad2.add(point2F);
406

    
407
    mMoveHand2.notifyWhenFinished(this);
408
    }
409

    
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411
// both fingers touch the screen (part2)
412

    
413
  private void setEffectsStage8()
414
    {
415
    resetDynamics1(8);
416
    resetDynamics2(8);
417

    
418
    float x2 = mWidth*0.35f;
419
    float y1 = mHeight*0.28f;
420
    float z  = 0;
421
    float d  = mWidth*0.01f;
422
    float sS = mWidth*0.0001f;
423
    float sF = mWidth*0.14f;
424
    float sH = mWidth*0.33f;
425

    
426
    Static3D point1h= new Static3D(-x2  +d,-y1  +d, z);
427
    Static3D point2h= new Static3D( x2  +d, y1  +d, z);
428
    Static3D scale1S = new Static3D( sS,sS,sS);
429
    Static3D scale1F = new Static3D( sF,sF,sF);
430
    Static3D point1H = new Static3D( sH,sH,sH);
431
    Static3D scale2S = new Static3D(-sS,sS,sS);
432
    Static3D scale2F = new Static3D(-sF,sF,sF);
433
    Static3D point2H = new Static3D(-sH,sH,sH);
434

    
435
    mDynMoveHand1.add(point1h);
436
    mDynMoveShad1.add(point1h);
437
    mDynScaleHand1.add(point1H);
438
    mDynScaleShad1.add(scale1S);
439
    mDynScaleShad1.add(scale1F);
440

    
441
    mDynMoveHand2.add(point2h);
442
    mDynMoveShad2.add(point2h);
443
    mDynScaleHand2.add(point2H);
444
    mDynScaleShad2.add(scale2S);
445
    mDynScaleShad2.add(scale2F);
446

    
447
    mScaleShad1.notifyWhenFinished(this);
448

    
449
    mNodes[0].changeInputSurface(mTextureCirc);
450
    mNodes[1].changeInputSurface(mTextureCirc);
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454
// both fingers approach each other
455

    
456
  private void setEffectsStage9()
457
    {
458
    resetDynamics1(9);
459
    resetDynamics2(9);
460

    
461
    float x2 = mWidth*0.35f;
462
    float y1 = mHeight*0.28f;
463
    float z  = 0;
464
    float d  = mWidth*0.01f;
465
    float f  = 0.60f;
466
    float sF = mWidth*0.14f;
467
    float sH = mWidth*0.33f;
468

    
469
    Static3D point1s= new Static3D(-x2  +d,-y1  +d, z);
470
    Static3D point2s= new Static3D( x2  +d, y1  +d, z);
471
    Static3D point1f= new Static3D((-x2  +d)*f,(-y1  +d)*f, z);
472
    Static3D point2f= new Static3D(( x2  +d)*f,( y1  +d)*f, z);
473
    Static3D scale1F = new Static3D( sF,sF,sF);
474
    Static3D point1H = new Static3D( sH,sH,sH);
475
    Static3D scale2F = new Static3D(-sF,sF,sF);
476
    Static3D point2H = new Static3D(-sH,sH,sH);
477

    
478
    mDynMoveHand1.add(point1s);
479
    mDynMoveHand1.add(point1f);
480
    mDynMoveShad1.add(point1s);
481
    mDynMoveShad1.add(point1f);
482
    mDynScaleHand1.add(point1H);
483
    mDynScaleShad1.add(scale1F);
484

    
485
    mDynMoveHand2.add(point2s);
486
    mDynMoveHand2.add(point2f);
487
    mDynMoveShad2.add(point2s);
488
    mDynMoveShad2.add(point2f);
489
    mDynScaleHand2.add(point2H);
490
    mDynScaleShad2.add(scale2F);
491

    
492
    mMoveShad1.notifyWhenFinished(this);
493
    }
494

    
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496
// both fingers go around
497

    
498
  private void setEffectsStage10()
499
    {
500
    resetDynamics1(10);
501
    resetDynamics2(10);
502

    
503
    float sF = mWidth*0.14f;
504
    float sH = mWidth*0.33f;
505
    float x2 = mWidth*0.35f;
506
    float y1 = mHeight*0.28f;
507
    float z  = 0;
508
    float d  = mWidth*0.01f;
509
    float f  = 0.60f;
510

    
511
    Static3D scale1F = new Static3D( sF,sF,sF);
512
    Static3D point1H = new Static3D( sH,sH,sH);
513
    Static3D scale2F = new Static3D(-sF,sF,sF);
514
    Static3D point2H = new Static3D(-sH,sH,sH);
515

    
516
    Static3D point0= new Static3D((-x2  +d)*f,(-y1  +d)*f, z);
517
    Static3D point1= new Static3D((-x2  +d)*f,( y1  +d)*f, z);
518
    Static3D point2= new Static3D(( x2  +d)*f,( y1  +d)*f, z);
519
    Static3D point3= new Static3D(( x2  +d)*f,(-y1  +d)*f, z);
520

    
521
    mDynMoveHand1.add(point0);
522
    mDynMoveHand1.add(point1);
523
    mDynMoveHand1.add(point2);
524
    mDynMoveHand1.add(point3);
525
    mDynMoveHand1.add(point0);
526
    mDynMoveShad1.add(point0);
527
    mDynMoveShad1.add(point1);
528
    mDynMoveShad1.add(point2);
529
    mDynMoveShad1.add(point3);
530
    mDynMoveShad1.add(point0);
531
    mDynScaleHand1.add(point1H);
532
    mDynScaleShad1.add(scale1F);
533

    
534
    mDynMoveHand2.add(point2);
535
    mDynMoveHand2.add(point3);
536
    mDynMoveHand2.add(point0);
537
    mDynMoveHand2.add(point1);
538
    mDynMoveHand2.add(point2);
539
    mDynMoveShad2.add(point2);
540
    mDynMoveShad2.add(point3);
541
    mDynMoveShad2.add(point0);
542
    mDynMoveShad2.add(point1);
543
    mDynMoveShad2.add(point2);
544
    mDynScaleHand2.add(point2H);
545
    mDynScaleShad2.add(scale2F);
546

    
547
    mDynMoveHand1.setConvexity(1.0f);
548
    mDynMoveHand2.setConvexity(1.0f);
549
    mDynMoveShad1.setConvexity(1.0f);
550
    mDynMoveShad2.setConvexity(1.0f);
551

    
552
    mMoveShad1.notifyWhenFinished(this);
553
    }
554

    
555
///////////////////////////////////////////////////////////////////////////////////////////////////
556
// both fingers move away from each other
557

    
558
  private void setEffectsStage11()
559
    {
560
    resetDynamics1(11);
561
    resetDynamics2(11);
562

    
563
    float x2 = mWidth*0.35f;
564
    float y1 = mHeight*0.28f;
565
    float z  = 0;
566
    float d  = mWidth*0.01f;
567
    float f  = 0.60f;
568
    float sF = mWidth*0.14f;
569
    float sH = mWidth*0.33f;
570

    
571
    Static3D point1s= new Static3D(-x2  +d,-y1  +d, z);
572
    Static3D point2s= new Static3D( x2  +d, y1  +d, z);
573
    Static3D point1f= new Static3D((-x2  +d)*f,(-y1  +d)*f, z);
574
    Static3D point2f= new Static3D(( x2  +d)*f,( y1  +d)*f, z);
575
    Static3D scale1F= new Static3D( sF,sF,sF);
576
    Static3D point1H= new Static3D( sH,sH,sH);
577
    Static3D scale2F= new Static3D(-sF,sF,sF);
578
    Static3D point2H= new Static3D(-sH,sH,sH);
579

    
580
    mDynMoveHand1.add(point1f);
581
    mDynMoveHand1.add(point1s);
582
    mDynMoveShad1.add(point1f);
583
    mDynMoveShad1.add(point1s);
584
    mDynScaleHand1.add(point1H);
585
    mDynScaleShad1.add(scale1F);
586

    
587
    mDynMoveHand2.add(point2f);
588
    mDynMoveHand2.add(point2s);
589
    mDynMoveShad2.add(point2f);
590
    mDynMoveShad2.add(point2s);
591
    mDynScaleHand2.add(point2H);
592
    mDynScaleShad2.add(scale2F);
593

    
594
    mDynMoveHand1.setConvexity(0.0f);
595
    mDynMoveHand2.setConvexity(0.0f);
596
    mDynMoveShad1.setConvexity(0.0f);
597
    mDynMoveShad2.setConvexity(0.0f);
598

    
599
    mMoveShad1.notifyWhenFinished(this);
600
    }
601

    
602
///////////////////////////////////////////////////////////////////////////////////////////////////
603
// both fingers un-touch the screen (part1)
604

    
605
  private void setEffectsStage12()
606
    {
607
    resetDynamics1(12);
608
    resetDynamics2(12);
609

    
610
    float x2 = mWidth*0.35f;
611
    float y1 = mHeight*0.28f;
612
    float z  = 0;
613
    float d  = mWidth*0.01f;
614
    float sS = mWidth*0.0001f;
615
    float sF = mWidth*0.14f;
616
    float sH = mWidth*0.33f;
617

    
618
    Static3D point1h= new Static3D(-x2  +d,-y1  +d, z);
619
    Static3D point2h= new Static3D( x2  +d, y1  +d, z);
620
    Static3D scale1S = new Static3D( sS,sS,sS);
621
    Static3D scale1F = new Static3D( sF,sF,sF);
622
    Static3D point1H = new Static3D( sH,sH,sH);
623
    Static3D scale2S = new Static3D(-sS,sS,sS);
624
    Static3D scale2F = new Static3D(-sF,sF,sF);
625
    Static3D point2H = new Static3D(-sH,sH,sH);
626

    
627
    mDynMoveHand1.add(point1h);
628
    mDynMoveShad1.add(point1h);
629
    mDynScaleHand1.add(point1H);
630
    mDynScaleShad1.add(scale1F);
631
    mDynScaleShad1.add(scale1S);
632

    
633
    mDynMoveHand2.add(point2h);
634
    mDynMoveShad2.add(point2h);
635
    mDynScaleHand2.add(point2H);
636
    mDynScaleShad2.add(scale2F);
637
    mDynScaleShad2.add(scale2S);
638

    
639
    mScaleShad1.notifyWhenFinished(this);
640
    }
641

    
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643
// both fingers un-touch the screen (part2)
644

    
645
  private void setEffectsStage13()
646
    {
647
    resetDynamics1(13);
648
    resetDynamics2(13);
649

    
650
    float x0 = mWidth*0.55f;
651
    float x1 = mWidth*0.45f;
652
    float x2 = mWidth*0.35f;
653
    float y1 = mHeight*0.28f;
654
    float z  = 0;
655
    float d  = mWidth*0.01f;
656
    float s  = mWidth*0.33f;
657

    
658
    Static3D point1_0 = new Static3D(-x2  +d,-y1  +d, z);
659
    Static3D point11H = new Static3D(-x2    ,-y1    , z);
660
    Static3D point12H = new Static3D(-x1    ,-y1    , z);
661
    Static3D point13H = new Static3D(-x0    ,-y1    , z);
662
    Static3D point11S = new Static3D(-x2+2*d,-y1+2*d, z);
663
    Static3D point12S = new Static3D(-x1+2*d,-y1+2*d, z);
664
    Static3D point13S = new Static3D(-x0+2*d,-y1+2*d, z);
665
    Static3D point1Sc = new Static3D( s,s,s);
666

    
667
    mDynScaleHand1.add(point1Sc);
668
    mDynScaleShad1.add(point1Sc);
669
    mDynMoveHand1.add(point1_0);
670
    mDynMoveHand1.add(point11H);
671
    mDynMoveHand1.add(point11H);
672
    mDynMoveHand1.add(point12H);
673
    mDynMoveHand1.add(point13H);
674
    mDynMoveShad1.add(point1_0);
675
    mDynMoveShad1.add(point11S);
676
    mDynMoveShad1.add(point11S);
677
    mDynMoveShad1.add(point12S);
678
    mDynMoveShad1.add(point13S);
679

    
680
    Static3D point2_0 = new Static3D( x2  +d, y1  +d, z);
681
    Static3D point21H = new Static3D( x2    , y1    , z);
682
    Static3D point22H = new Static3D( x1    , y1    , z);
683
    Static3D point23H = new Static3D( x0    , y1    , z);
684
    Static3D point21S = new Static3D( x2+2*d, y1+2*d, z);
685
    Static3D point22S = new Static3D( x1+2*d, y1+2*d, z);
686
    Static3D point23S = new Static3D( x0+2*d, y1+2*d, z);
687
    Static3D point2Sc= new Static3D(-s,s,s);
688

    
689
    mDynScaleHand2.add(point2Sc);
690
    mDynScaleShad2.add(point2Sc);
691
    mDynMoveHand2.add(point2_0);
692
    mDynMoveHand2.add(point21H);
693
    mDynMoveHand2.add(point21H);
694
    mDynMoveHand2.add(point22H);
695
    mDynMoveHand2.add(point23H);
696
    mDynMoveShad2.add(point2_0);
697
    mDynMoveShad2.add(point21S);
698
    mDynMoveShad2.add(point21S);
699
    mDynMoveShad2.add(point22S);
700
    mDynMoveShad2.add(point23S);
701

    
702
    mMoveHand2.notifyWhenFinished(this);
703

    
704
    mNodes[0].changeInputSurface(mTextureShad);
705
    mNodes[1].changeInputSurface(mTextureShad);
706
    }
707

    
708
///////////////////////////////////////////////////////////////////////////////////////////////////
709

    
710
  private void createEffects()
711
    {
712
    mEffects = new DistortedEffects[NUM_EFFE];
713
    for(int i=0; i<NUM_EFFE; i++) mEffects[i]= new DistortedEffects();
714

    
715
    int time = DUR[0];
716

    
717
    mDynMoveHand1 = new Dynamic3D(time,0.5f);
718
    mDynMoveHand1.setMode(Dynamic.MODE_PATH);
719
    mDynMoveHand1.setConvexity(0.0f);
720
    mDynMoveShad1 = new Dynamic3D(time,0.5f);
721
    mDynMoveShad1.setMode(Dynamic.MODE_PATH);
722
    mDynMoveShad1.setConvexity(0.0f);
723
    mDynScaleHand1 = new Dynamic3D(time,0.5f);
724
    mDynScaleHand1.setMode(Dynamic.MODE_PATH);
725
    mDynScaleHand1.setConvexity(0.0f);
726
    mDynScaleShad1 = new Dynamic3D(time,0.5f);
727
    mDynScaleShad1.setMode(Dynamic.MODE_PATH);
728
    mDynScaleShad1.setConvexity(0.0f);
729

    
730
    mMoveHand1 = new MatrixEffectMove(mDynMoveHand1);
731
    mMoveShad1 = new MatrixEffectMove(mDynMoveShad1);
732
    mScaleHand1= new MatrixEffectScale(mDynScaleHand1);
733
    mScaleShad1= new MatrixEffectScale(mDynScaleShad1);
734

    
735
    mEffects[0].apply(mScaleShad1);
736
    mEffects[0].apply(mMoveShad1);
737
    mEffects[2].apply(mScaleHand1);
738
    mEffects[2].apply(mMoveHand1);
739

    
740
    mDynMoveHand2 = new Dynamic3D(time,0.5f);
741
    mDynMoveHand2.setMode(Dynamic.MODE_PATH);
742
    mDynMoveHand2.setConvexity(0.0f);
743
    mDynMoveShad2 = new Dynamic3D(time,0.5f);
744
    mDynMoveShad2.setMode(Dynamic.MODE_PATH);
745
    mDynMoveShad2.setConvexity(0.0f);
746
    mDynScaleHand2 = new Dynamic3D(time,0.5f);
747
    mDynScaleHand2.setMode(Dynamic.MODE_PATH);
748
    mDynScaleHand2.setConvexity(0.0f);
749
    mDynScaleShad2 = new Dynamic3D(time,0.5f);
750
    mDynScaleShad2.setMode(Dynamic.MODE_PATH);
751
    mDynScaleShad2.setConvexity(0.0f);
752

    
753
    mMoveHand2 = new MatrixEffectMove(mDynMoveHand2);
754
    mMoveShad2 = new MatrixEffectMove(mDynMoveShad2);
755
    mScaleHand2= new MatrixEffectScale(mDynScaleHand2);
756
    mScaleShad2= new MatrixEffectScale(mDynScaleShad2);
757

    
758
    mEffects[1].apply(mScaleShad2);
759
    mEffects[1].apply(mMoveShad2);
760
    mEffects[3].apply(mScaleHand2);
761
    mEffects[3].apply(mMoveHand2);
762

    
763
    DistortedScreen screen = mControl.getScreen();
764
    mWidth = screen.getWidth();
765
    mHeight= screen.getHeight();
766
    }
767

    
768
///////////////////////////////////////////////////////////////////////////////////////////////////
769

    
770
  private void createNodes()
771
    {
772
    if( mNodes==null )
773
      {
774
      mNodes = new DistortedNode[NUM_NODE];
775
      mQuad  = new MeshQuad();
776
      }
777

    
778
    RubikActivity act = mControl.getActivity();
779

    
780
    if( act!=null )
781
      {
782
      Bitmap bmpCirc = openBitmap(act, R.drawable.ui_fading_circle);
783
      Bitmap bmpShad = openBitmap(act, R.drawable.ui_hand_shadow);
784
      Bitmap bmpHand = openBitmap(act, R.drawable.ui_hand_pointer);
785

    
786
      mTextureCirc = new DistortedTexture();
787
      mTextureCirc.setTexture(bmpCirc);
788
      mTextureShad = new DistortedTexture();
789
      mTextureShad.setTexture(bmpShad);
790
      DistortedTexture textureHand = new DistortedTexture();
791
      textureHand.setTexture(bmpHand);
792

    
793
      mNodes[0]= new DistortedNode(mTextureShad,mEffects[0],mQuad);
794
      mNodes[1]= new DistortedNode(mTextureShad,mEffects[1],mQuad);
795
      mNodes[2]= new DistortedNode( textureHand,mEffects[2],mQuad);
796
      mNodes[3]= new DistortedNode( textureHand,mEffects[3],mQuad);
797
      }
798
    else
799
      {
800
      android.util.Log.e("D", "Activity NULL!!");
801
      }
802
    }
803

    
804
///////////////////////////////////////////////////////////////////////////////////////////////////
805

    
806
  long getEffectID()
807
    {
808
    return mEffectID;
809
    }
810

    
811
///////////////////////////////////////////////////////////////////////////////////////////////////
812

    
813
  DistortedNode[] getNodes()
814
    {
815
    if( mEffects==null ) createEffects();
816
    createNodes();
817
    setEffectsStage1();
818

    
819
    return mNodes;
820
    }
821

    
822
///////////////////////////////////////////////////////////////////////////////////////////////////
823

    
824
  DistortedNode[] returnNodes()
825
    {
826
    return mNodes;
827
    }
828

    
829
///////////////////////////////////////////////////////////////////////////////////////////////////
830

    
831
  RubikControlWhole(RubikControl control)
832
    {
833
    mControl = control;
834
    }
835

    
836
///////////////////////////////////////////////////////////////////////////////////////////////////
837
// PUBLIC
838

    
839
  public void effectFinished(long effectID)
840
    {
841
    switch( mStageFinished )
842
      {
843
      case  1: setEffectsStage2(); break;
844
      case  2: setEffectsStage3(); break;
845
      case  3: setEffectsStage4(); break;
846
      case  4: setEffectsStage5(); break;
847
      case  5: setEffectsStage6(); break;
848
      case  6: setEffectsStage7(); break;
849
      case  7: setEffectsStage8(); break;
850
      case  8: setEffectsStage9(); break;
851
      case  9: setEffectsStage10();break;
852
      case 10: setEffectsStage11();break;
853
      case 11: setEffectsStage12();break;
854
      case 12: setEffectsStage13();break;
855
      default: mEffectID = -1;
856
               mControl.effectFinished(mEffectID);
857
               break;
858
      }
859
    }
860
  }
(3-3/3)