Project

General

Profile

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

magiccube / src / main / java / org / distorted / control / RubikControlWhole.java @ 3f7a4363

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.type.Dynamic;
33
import org.distorted.library.type.Dynamic3D;
34
import org.distorted.library.type.Static3D;
35

    
36
import org.distorted.main.R;
37
import org.distorted.main.RubikActivity;
38
import org.distorted.main.RubikSurfaceView;
39

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

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

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

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

    
56
  private static final int[] DUR = { D1, D2, D3, D2, D1/4, 3*D1/4, D1/4, D2, D4, D5, D4, D2, D1 };
57
  private static final int[] DYN = { 2, 1, 1, 1, 2, 2, 4, 2, 2, 2, 2, 2, 4};
58

    
59
  private float X0, X1, X2, Y1, D, s001, s014, s033, F;
60
  private int mWidth, mHeight;
61

    
62
  private final RubikControl mControl;
63
  private DistortedEffects[] mEffects;
64
  private DistortedNode[] mNodes;
65
  private long mEffectID;
66
  private int mCurrentStage;
67

    
68
  private MeshQuad mQuad;
69
  private DistortedTexture mTextureShad, mTextureCirc;
70
  private Dynamic3D mDynMoveHand1, mDynMoveShad1;
71
  private Dynamic3D mDynScaleHand1, mDynScaleShad1;
72
  private Dynamic3D mDynMoveHand2, mDynMoveShad2;
73
  private Dynamic3D mDynScaleHand2, mDynScaleShad2;
74
  private Dynamic3D mDyn1, mDyn2, mDyn3, mDyn4;
75
  private Static3D mPosition1, mPosition2, mPosition3, mPosition4;
76
  private float[] tmpBuffer;
77
  private long mLastTime, mDiffTime;
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
   private void setPostFrame(boolean on)
82
     {
83
     RubikActivity act = mControl.getActivity();
84
     act.setControlState(on);
85
     mLastTime = -1;
86
     }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
   private Bitmap openBitmap(RubikActivity act, int resource)
91
     {
92
     try( InputStream is = act.getResources().openRawResource(resource) )
93
       {
94
       return BitmapFactory.decodeStream(is);
95
       }
96
     catch( IOException e )
97
       {
98
       // ignore
99
       }
100

    
101
     return null;
102
     }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  private void resetDynamics1(int stage)
107
    {
108
    int dur = DUR[stage-1];
109

    
110
    mDynMoveHand1.removeAll();
111
    mDynMoveShad1.removeAll();
112
    mDynScaleHand1.removeAll();
113
    mDynScaleShad1.removeAll();
114

    
115
    mDynMoveHand1.setDuration(dur);
116
    mDynMoveShad1.setDuration(dur);
117
    mDynScaleHand1.setDuration(dur);
118
    mDynScaleShad1.setDuration(dur);
119
    mDynMoveHand1.resetToBeginning();
120
    mDynMoveShad1.resetToBeginning();
121
    mDynScaleHand1.resetToBeginning();
122
    mDynScaleShad1.resetToBeginning();
123

    
124
    mCurrentStage = stage;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  private void resetDynamics2(int stage)
130
    {
131
    int dur = DUR[stage-1];
132

    
133
    mDynMoveHand2.removeAll();
134
    mDynMoveShad2.removeAll();
135
    mDynScaleHand2.removeAll();
136
    mDynScaleShad2.removeAll();
137

    
138
    mDynMoveHand2.setDuration(dur);
139
    mDynMoveShad2.setDuration(dur);
140
    mDynScaleHand2.setDuration(dur);
141
    mDynScaleShad2.setDuration(dur);
142
    mDynMoveHand2.resetToBeginning();
143
    mDynMoveShad2.resetToBeginning();
144
    mDynScaleHand2.resetToBeginning();
145
    mDynScaleShad2.resetToBeginning();
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  private void resetDynamics3(int stage)
151
    {
152
    int dur = DUR[stage-1];
153

    
154
    mDyn1.removeAll();
155
    mDyn2.removeAll();
156
    mDyn1.setDuration(dur);
157
    mDyn2.setDuration(dur);
158
    mDyn1.resetToBeginning();
159
    mDyn2.resetToBeginning();
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  private void resetDynamics4(int stage)
165
    {
166
    int dur = DUR[stage-1];
167

    
168
    mDyn3.removeAll();
169
    mDyn4.removeAll();
170
    mDyn3.setDuration(dur);
171
    mDyn4.setDuration(dur);
172
    mDyn3.resetToBeginning();
173
    mDyn4.resetToBeginning();
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177
// first finger appears and approaches the screen
178

    
179
  private void setEffectsStage1()
180
    {
181
    resetDynamics1(1);
182
    resetDynamics2(1);
183
    resetDynamics3(1);
184

    
185
    Static3D point0h = new Static3D(-X0    ,-Y1    , 0);
186
    Static3D point1h = new Static3D(-X1    ,-Y1    , 0);
187
    Static3D point2h = new Static3D(-X2    ,-Y1    , 0);
188
    Static3D point3h = new Static3D(-X2  +D,-Y1  +D, 0);
189
    Static3D point0s = new Static3D(-X0+2*D,-Y1+2*D, 0);
190
    Static3D point1s = new Static3D(-X1+2*D,-Y1+2*D, 0);
191
    Static3D point2s = new Static3D(-X2+2*D,-Y1+2*D, 0);
192
    Static3D point3s = new Static3D(-X2  +D,-Y1  +D, 0);
193

    
194
    Static3D pointSc = new Static3D(s033,s033,s033);
195

    
196
    mDyn1.add(point0h);
197
    mDyn1.add(point1h);
198
    mDyn1.add(point2h);
199
    mDyn1.add(point2h);
200
    mDyn1.add(point3h);
201
    mDyn2.add(point0s);
202
    mDyn2.add(point1s);
203
    mDyn2.add(point2s);
204
    mDyn2.add(point2s);
205
    mDyn2.add(point3s);
206

    
207
    mPosition1.set(point0h);
208
    mPosition2.set(point0s);
209

    
210
    mDynMoveHand1.add(mPosition1);
211
    mDynMoveShad1.add(mPosition2);
212

    
213
    mDynScaleHand1.add(pointSc);
214
    mDynScaleShad1.add(pointSc);
215

    
216
    setPostFrame(true);
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220
// first finger touches the screen
221

    
222
  private void setEffectsStage2()
223
    {
224
    resetDynamics1(2);
225
    resetDynamics3(2);
226

    
227
    Static3D point3h = new Static3D(-X2  +D,-Y1  +D, 0);
228
    Static3D scaleS  = new Static3D(s001,s001,s001);
229
    Static3D scaleF  = new Static3D(s014,s014,s014);
230
    Static3D pointH  = new Static3D(s033,s033,s033);
231

    
232
    mPosition1.set(scaleS);
233
    mDyn1.add(scaleS);
234
    mDyn1.add(scaleF);
235

    
236
    mDynMoveHand1.add(point3h);
237
    mDynMoveShad1.add(point3h);
238
    mDynScaleHand1.add(pointH);
239
    mDynScaleShad1.add(mPosition1);
240

    
241
    mNodes[0].changeInputSurface(mTextureCirc);
242
    }
243

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245
// first finger moves across the screen in a triangular fashion
246

    
247
  private void setEffectsStage3()
248
    {
249
    resetDynamics1(3);
250
    resetDynamics3(3);
251

    
252
    Static3D scaleS = new Static3D(s014,s014,s014);
253
    Static3D pointH = new Static3D(s033,s033,s033);
254
    Static3D point1 = new Static3D(-X2  +D,-Y1  +D, 0);
255
    Static3D point2 = new Static3D(     +D,-Y1  +D, 0);
256
    Static3D point3 = new Static3D(+X2  +D,-Y1  +D, 0);
257
    Static3D point4 = new Static3D(+X2  +D,     +D, 0);
258
    Static3D point5 = new Static3D(+X2  +D,+Y1  +D, 0);
259
    Static3D point6 = new Static3D(     +D,     +D, 0);
260

    
261
    mDynScaleHand1.add(pointH);
262
    mDynScaleShad1.add(scaleS);
263

    
264
    mDyn1.add(point1);
265
    mDyn1.add(point1);
266
    mDyn1.add(point2);
267
    mDyn1.add(point3);
268
    mDyn1.add(point3);
269
    mDyn1.add(point4);
270
    mDyn1.add(point5);
271
    mDyn1.add(point5);
272
    mDyn1.add(point6);
273
    mDyn1.add(point1);
274
    mDyn1.add(point1);
275

    
276
    mPosition1.set(point1);
277

    
278
    mDynMoveHand1.add(mPosition1);
279
    mDynMoveShad1.add(mPosition1);
280

    
281
    RubikSurfaceView view = mControl.getSurfaceView();
282
    float x = point1.get0() + mWidth*0.5f;
283
    float y = mHeight*0.5f - point1.get1();
284
    view.prepareDown();
285
    view.actionDown(x,y);
286
    }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
// first finger un-touches the screen
290

    
291
  private void setEffectsStage4()
292
    {
293
    resetDynamics1(4);
294
    resetDynamics3(4);
295

    
296
    Static3D point3h = new Static3D(-X2+D,-Y1+D, 0);
297
    Static3D scaleS  = new Static3D(s014,s014,s014);
298
    Static3D scaleF  = new Static3D(s001,s001,s001);
299
    Static3D pointH  = new Static3D(s033,s033,s033);
300

    
301
    mDyn1.add(scaleS);
302
    mDyn1.add(scaleF);
303
    mPosition1.set(scaleS);
304

    
305
    mDynMoveHand1.add(point3h);
306
    mDynMoveShad1.add(point3h);
307
    mDynScaleHand1.add(pointH);
308
    mDynScaleShad1.add(mPosition1);
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
// first finger un-touches the screen (part2)
313

    
314
  private void setEffectsStage5()
315
    {
316
    resetDynamics1(5);
317
    resetDynamics3(5);
318

    
319
    Static3D pointH = new Static3D(-X2    ,-Y1    , 0);
320
    Static3D point0 = new Static3D(-X2  +D,-Y1  +D, 0);
321
    Static3D pointS = new Static3D(-X2+2*D,-Y1+2*D, 0);
322
    Static3D pointSc = new Static3D(s033,s033,s033);
323

    
324
    mPosition1.set(point0);
325
    mPosition2.set(point0);
326

    
327
    mDyn1.add(point0);
328
    mDyn1.add(pointH);
329
    mDyn2.add(point0);
330
    mDyn2.add(pointS);
331

    
332
    mDynScaleHand1.add(pointSc);
333
    mDynScaleShad1.add(pointSc);
334
    mDynMoveHand1.add(mPosition1);
335
    mDynMoveShad1.add(mPosition2);
336

    
337
    mNodes[0].changeInputSurface(mTextureShad);
338
    }
339

    
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341
// second finger appears
342

    
343
  private void setEffectsStage6()
344
    {
345
    resetDynamics1(6);
346
    resetDynamics2(6);
347
    resetDynamics3(6);
348

    
349
    Static3D pointH = new Static3D(-X2    ,-Y1    , 0);
350
    Static3D pointS = new Static3D(-X2+2*D,-Y1+2*D, 0);
351
    Static3D pointSc= new Static3D(s033,s033,s033);
352

    
353
    mDynScaleHand1.add(pointSc);
354
    mDynScaleShad1.add(pointSc);
355
    mDynMoveHand1.add(pointH);
356
    mDynMoveShad1.add(pointS);
357

    
358
    Static3D point0h = new Static3D( X0    , Y1    , 0);
359
    Static3D point1h = new Static3D( X1    , Y1    , 0);
360
    Static3D point2h = new Static3D( X2    , Y1    , 0);
361
    Static3D point0s = new Static3D( X0+2*D, Y1+2*D, 0);
362
    Static3D point1s = new Static3D( X1+2*D, Y1+2*D, 0);
363
    Static3D point2s = new Static3D( X2+2*D, Y1+2*D, 0);
364
    Static3D pointSm = new Static3D(-s033,s033,s033);
365

    
366
    mPosition1.set(point0h);
367
    mPosition2.set(point0s);
368

    
369
    mDyn1.add(point0h);
370
    mDyn1.add(point1h);
371
    mDyn1.add(point2h);
372
    mDyn1.add(point2h);
373
    mDyn2.add(point0s);
374
    mDyn2.add(point1s);
375
    mDyn2.add(point2s);
376
    mDyn2.add(point2s);
377

    
378
    mDynScaleHand2.add(pointSm);
379
    mDynScaleShad2.add(pointSm);
380
    mDynMoveHand2.add(mPosition1);
381
    mDynMoveShad2.add(mPosition2);
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385
// both fingers touch the screen (part1)
386

    
387
  private void setEffectsStage7()
388
    {
389
    resetDynamics1(7);
390
    resetDynamics2(7);
391
    resetDynamics3(7);
392
    resetDynamics4(7);
393

    
394
    Static3D point1Sc= new Static3D( s033,s033,s033);
395
    Static3D point2Sc= new Static3D(-s033,s033,s033);
396
    mDynScaleHand1.add(point1Sc);
397
    mDynScaleShad1.add(point1Sc);
398
    mDynScaleHand2.add(point2Sc);
399
    mDynScaleShad2.add(point2Sc);
400

    
401
    Static3D point1H = new Static3D(-X2    ,-Y1    , 0);
402
    Static3D point1F = new Static3D(-X2  +D,-Y1  +D, 0);
403
    Static3D point1S = new Static3D(-X2+2*D,-Y1+2*D, 0);
404

    
405
    mDyn1.add(point1H);
406
    mDyn1.add(point1F);
407
    mDyn2.add(point1S);
408
    mDyn2.add(point1F);
409

    
410
    mPosition1.set(point1H);
411
    mPosition2.set(point1S);
412
    mDynMoveHand1.add(mPosition1);
413
    mDynMoveShad1.add(mPosition2);
414

    
415
    Static3D point2H = new Static3D( X2    , Y1    , 0);
416
    Static3D point2F = new Static3D( X2  +D, Y1  +D, 0);
417
    Static3D point2S = new Static3D( X2+2*D, Y1+2*D, 0);
418

    
419
    mDyn3.add(point2H);
420
    mDyn3.add(point2F);
421
    mDyn4.add(point2S);
422
    mDyn4.add(point2F);
423

    
424
    mPosition3.set(point2H);
425
    mPosition4.set(point2S);
426
    mDynMoveHand2.add(mPosition3);
427
    mDynMoveShad2.add(mPosition4);
428
    }
429

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431
// both fingers touch the screen (part2)
432

    
433
  private void setEffectsStage8()
434
    {
435
    resetDynamics1(8);
436
    resetDynamics2(8);
437
    resetDynamics3(8);
438

    
439
    Static3D point1h= new Static3D(-X2  +D,-Y1  +D, 0);
440
    Static3D point2h= new Static3D( X2  +D, Y1  +D, 0);
441
    Static3D scale1S = new Static3D( s001,s001,s001);
442
    Static3D scale1F = new Static3D( s014,s014,s014);
443
    Static3D point1H = new Static3D( s033,s033,s033);
444
    Static3D scale2S = new Static3D(-s001,s001,s001);
445
    Static3D scale2F = new Static3D(-s014,s014,s014);
446
    Static3D point2H = new Static3D(-s033,s033,s033);
447

    
448
    mPosition1.set(scale1S);
449
    mDyn1.add(scale1S);
450
    mDyn1.add(scale1F);
451

    
452
    mDynMoveHand1.add(point1h);
453
    mDynMoveShad1.add(point1h);
454
    mDynScaleHand1.add(point1H);
455
    mDynScaleShad1.add(mPosition1);
456

    
457
    mPosition2.set(scale2S);
458
    mDyn2.add(scale2S);
459
    mDyn2.add(scale2F);
460

    
461
    mDynMoveHand2.add(point2h);
462
    mDynMoveShad2.add(point2h);
463
    mDynScaleHand2.add(point2H);
464
    mDynScaleShad2.add(mPosition2);
465

    
466
    mNodes[0].changeInputSurface(mTextureCirc);
467
    mNodes[1].changeInputSurface(mTextureCirc);
468
    }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471
// both fingers approach each other
472

    
473
  private void setEffectsStage9()
474
    {
475
    resetDynamics1(9);
476
    resetDynamics2(9);
477
    resetDynamics3(9);
478

    
479
    Static3D point1s = new Static3D(-X2+D,-Y1+D, 0);
480
    Static3D point2s = new Static3D( X2+D, Y1+D, 0);
481
    Static3D point1f = new Static3D(-Y1*F,-Y1*F, 0);
482
    Static3D point2f = new Static3D( Y1*F, Y1*F, 0);
483
    Static3D scale1F = new Static3D( s014,s014,s014);
484
    Static3D point1H = new Static3D( s033,s033,s033);
485
    Static3D scale2F = new Static3D(-s014,s014,s014);
486
    Static3D point2H = new Static3D(-s033,s033,s033);
487

    
488
    mDynScaleHand1.add(point1H);
489
    mDynScaleShad1.add(scale1F);
490
    mDynScaleHand2.add(point2H);
491
    mDynScaleShad2.add(scale2F);
492

    
493
    mDyn1.add(point1s);
494
    mDyn1.add(point1f);
495
    mDyn2.add(point2s);
496
    mDyn2.add(point2f);
497

    
498
    mPosition1.set(point1s);
499
    mPosition2.set(point2s);
500

    
501
    mDynMoveHand1.add(mPosition1);
502
    mDynMoveShad1.add(mPosition1);
503
    mDynMoveHand2.add(mPosition2);
504
    mDynMoveShad2.add(mPosition2);
505

    
506
    float x1 = point1s.get0() + mWidth*0.5f;
507
    float y1 = mHeight*0.5f - point1s.get1();
508
    float x2 = point2s.get0() + mWidth*0.5f;
509
    float y2 = mHeight*0.5f - point2s.get1();
510

    
511
    RubikSurfaceView view = mControl.getSurfaceView();
512
    view.prepareDown();
513
    view.prepareDown2();
514
    view.actionDown(x1,y1);
515
    view.actionDown2(x1,y1,x2,y2);
516
    }
517

    
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519
// both fingers go around
520

    
521
  private void setEffectsStage10()
522
    {
523
    resetDynamics1(10);
524
    resetDynamics2(10);
525
    resetDynamics3(10);
526

    
527
    Static3D scale1F = new Static3D( s014,s014,s014);
528
    Static3D point1H = new Static3D( s033,s033,s033);
529
    Static3D scale2F = new Static3D(-s014,s014,s014);
530
    Static3D point2H = new Static3D(-s033,s033,s033);
531

    
532
    Static3D point0= new Static3D(-Y1*F,-Y1*F, 0);
533
    Static3D point1= new Static3D(-Y1*F, Y1*F, 0);
534
    Static3D point2= new Static3D( Y1*F, Y1*F, 0);
535
    Static3D point3= new Static3D( Y1*F,-Y1*F, 0);
536

    
537
    mDynScaleHand1.add(point1H);
538
    mDynScaleShad1.add(scale1F);
539
    mDynScaleHand2.add(point2H);
540
    mDynScaleShad2.add(scale2F);
541

    
542
    mDyn1.add(point0);
543
    mDyn1.add(point1);
544
    mDyn1.add(point2);
545
    mDyn1.add(point3);
546
    mDyn1.add(point0);
547

    
548
    mDyn2.add(point2);
549
    mDyn2.add(point3);
550
    mDyn2.add(point0);
551
    mDyn2.add(point1);
552
    mDyn2.add(point2);
553

    
554
    mDyn1.setConvexity(1.0f);
555
    mDyn2.setConvexity(1.0f);
556

    
557
    mDyn1.setSpeedMode(Dynamic.SPEED_MODE_SEGMENT_CONSTANT);
558
    mDyn2.setSpeedMode(Dynamic.SPEED_MODE_SEGMENT_CONSTANT);
559

    
560
    mPosition1.set(point0);
561
    mPosition2.set(point2);
562

    
563
    mDynMoveHand1.add(mPosition1);
564
    mDynMoveShad1.add(mPosition1);
565
    mDynMoveHand2.add(mPosition2);
566
    mDynMoveShad2.add(mPosition2);
567
    }
568

    
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570
// both fingers move away from each other
571

    
572
  private void setEffectsStage11()
573
    {
574
    resetDynamics1(11);
575
    resetDynamics2(11);
576
    resetDynamics3(11);
577

    
578
    Static3D point1s= new Static3D(-X2+D,-Y1+D, 0);
579
    Static3D point2s= new Static3D( X2+D, Y1+D, 0);
580
    Static3D point1f= new Static3D(-Y1*F,-Y1*F, 0);
581
    Static3D point2f= new Static3D( Y1*F, Y1*F, 0);
582
    Static3D scale1F= new Static3D( s014,s014,s014);
583
    Static3D point1H= new Static3D( s033,s033,s033);
584
    Static3D scale2F= new Static3D(-s014,s014,s014);
585
    Static3D point2H= new Static3D(-s033,s033,s033);
586

    
587
    mDynScaleHand1.add(point1H);
588
    mDynScaleShad1.add(scale1F);
589
    mDynScaleHand2.add(point2H);
590
    mDynScaleShad2.add(scale2F);
591

    
592
    mDyn1.add(point1f);
593
    mDyn1.add(point1s);
594
    mDyn2.add(point2f);
595
    mDyn2.add(point2s);
596

    
597
    mDyn1.setConvexity(0.0f);
598
    mDyn2.setConvexity(0.0f);
599

    
600
    mDyn1.setSpeedMode(Dynamic.SPEED_MODE_SMOOTH);
601
    mDyn2.setSpeedMode(Dynamic.SPEED_MODE_SMOOTH);
602

    
603
    mPosition1.set(point1f);
604
    mPosition2.set(point2f);
605

    
606
    mDynMoveHand1.add(mPosition1);
607
    mDynMoveShad1.add(mPosition1);
608
    mDynMoveHand2.add(mPosition2);
609
    mDynMoveShad2.add(mPosition2);
610
    }
611

    
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613
// both fingers un-touch the screen (part1)
614

    
615
  private void setEffectsStage12()
616
    {
617
    resetDynamics1(12);
618
    resetDynamics2(12);
619
    resetDynamics3(12);
620

    
621
    Static3D point1h = new Static3D(-X2+D,-Y1+D, 0);
622
    Static3D point2h = new Static3D( X2+D, Y1+D, 0);
623
    Static3D scale1S = new Static3D( s014,s014,s014);
624
    Static3D scale1F = new Static3D( s001,s001,s001);
625
    Static3D point1H = new Static3D( s033,s033,s033);
626
    Static3D scale2S = new Static3D(-s014,s014,s014);
627
    Static3D scale2F = new Static3D(-s001,s001,s001);
628
    Static3D point2H = new Static3D(-s033,s033,s033);
629

    
630
    mPosition1.set(scale1S);
631
    mPosition2.set(scale2S);
632

    
633
    mDyn1.add(scale1S);
634
    mDyn1.add(scale1F);
635
    mDyn2.add(scale2S);
636
    mDyn2.add(scale2F);
637

    
638
    mDynMoveHand1.add(point1h);
639
    mDynMoveShad1.add(point1h);
640
    mDynScaleHand1.add(point1H);
641
    mDynScaleShad1.add(mPosition1);
642

    
643
    mDynMoveHand2.add(point2h);
644
    mDynMoveShad2.add(point2h);
645
    mDynScaleHand2.add(point2H);
646
    mDynScaleShad2.add(mPosition2);
647
    }
648

    
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650
// both fingers un-touch the screen (part2)
651

    
652
  private void setEffectsStage13()
653
    {
654
    resetDynamics1(13);
655
    resetDynamics2(13);
656
    resetDynamics3(13);
657
    resetDynamics4(13);
658

    
659
    Static3D point1_0 = new Static3D(-X2  +D,-Y1  +D, 0);
660
    Static3D point11H = new Static3D(-X2    ,-Y1    , 0);
661
    Static3D point12H = new Static3D(-X1    ,-Y1    , 0);
662
    Static3D point13H = new Static3D(-X0    ,-Y1    , 0);
663
    Static3D point11S = new Static3D(-X2+2*D,-Y1+2*D, 0);
664
    Static3D point12S = new Static3D(-X1+2*D,-Y1+2*D, 0);
665
    Static3D point13S = new Static3D(-X0+2*D,-Y1+2*D, 0);
666
    Static3D point1Sc = new Static3D( s033,s033,s033);
667

    
668
    mPosition1.set(point1_0);
669
    mDynMoveHand1.add(mPosition1);
670
    mPosition2.set(point1_0);
671
    mDynMoveShad1.add(mPosition2);
672

    
673
    mDynScaleHand1.add(point1Sc);
674
    mDynScaleShad1.add(point1Sc);
675

    
676
    mDyn1.add(point1_0);
677
    mDyn1.add(point11H);
678
    mDyn1.add(point11H);
679
    mDyn1.add(point12H);
680
    mDyn1.add(point13H);
681

    
682
    mDyn2.add(point1_0);
683
    mDyn2.add(point11S);
684
    mDyn2.add(point11S);
685
    mDyn2.add(point12S);
686
    mDyn2.add(point13S);
687

    
688
    Static3D point2_0 = new Static3D( X2  +D, Y1  +D, 0);
689
    Static3D point21H = new Static3D( X2    , Y1    , 0);
690
    Static3D point22H = new Static3D( X1    , Y1    , 0);
691
    Static3D point23H = new Static3D( X0    , Y1    , 0);
692
    Static3D point21S = new Static3D( X2+2*D, Y1+2*D, 0);
693
    Static3D point22S = new Static3D( X1+2*D, Y1+2*D, 0);
694
    Static3D point23S = new Static3D( X0+2*D, Y1+2*D, 0);
695
    Static3D point2Sc= new Static3D(-s033,s033,s033);
696

    
697
    mPosition3.set(point2_0);
698
    mDynMoveHand2.add(mPosition3);
699
    mPosition4.set(point2_0);
700
    mDynMoveShad2.add(mPosition4);
701

    
702
    mDynScaleHand2.add(point2Sc);
703
    mDynScaleShad2.add(point2Sc);
704

    
705
    mDyn3.add(point2_0);
706
    mDyn3.add(point21H);
707
    mDyn3.add(point21H);
708
    mDyn3.add(point22H);
709
    mDyn3.add(point23H);
710

    
711
    mDyn4.add(point2_0);
712
    mDyn4.add(point21S);
713
    mDyn4.add(point21S);
714
    mDyn4.add(point22S);
715
    mDyn4.add(point23S);
716

    
717
    mNodes[0].changeInputSurface(mTextureShad);
718
    mNodes[1].changeInputSurface(mTextureShad);
719
    }
720

    
721
///////////////////////////////////////////////////////////////////////////////////////////////////
722

    
723
  private void createEffects()
724
    {
725
    mEffects = new DistortedEffects[NUM_EFFE];
726
    for(int i=0; i<NUM_EFFE; i++) mEffects[i]= new DistortedEffects();
727

    
728
    int time = DUR[0];
729

    
730
    mDyn1 = new Dynamic3D(time,0.5f);
731
    mDyn1.setMode(Dynamic.MODE_PATH);
732
    mDyn1.setConvexity(0.0f);
733
    mDyn2 = new Dynamic3D(time,0.5f);
734
    mDyn2.setMode(Dynamic.MODE_PATH);
735
    mDyn2.setConvexity(0.0f);
736
    mDyn3 = new Dynamic3D(time,0.5f);
737
    mDyn3.setMode(Dynamic.MODE_PATH);
738
    mDyn3.setConvexity(0.0f);
739
    mDyn4 = new Dynamic3D(time,0.5f);
740
    mDyn4.setMode(Dynamic.MODE_PATH);
741
    mDyn4.setConvexity(0.0f);
742

    
743
    mPosition1 = new Static3D(0,0,0);
744
    mPosition2 = new Static3D(0,0,0);
745
    mPosition3 = new Static3D(0,0,0);
746
    mPosition4 = new Static3D(0,0,0);
747

    
748
    tmpBuffer = new float[12];
749

    
750
    mDynMoveHand1 = new Dynamic3D(time,0.5f);
751
    mDynMoveHand1.setMode(Dynamic.MODE_PATH);
752
    mDynMoveHand1.setConvexity(0.0f);
753
    mDynMoveShad1 = new Dynamic3D(time,0.5f);
754
    mDynMoveShad1.setMode(Dynamic.MODE_PATH);
755
    mDynMoveShad1.setConvexity(0.0f);
756
    mDynScaleHand1 = new Dynamic3D(time,0.5f);
757
    mDynScaleHand1.setMode(Dynamic.MODE_PATH);
758
    mDynScaleHand1.setConvexity(0.0f);
759
    mDynScaleShad1 = new Dynamic3D(time,0.5f);
760
    mDynScaleShad1.setMode(Dynamic.MODE_PATH);
761
    mDynScaleShad1.setConvexity(0.0f);
762

    
763
    MatrixEffectMove  moveHand1 = new MatrixEffectMove(mDynMoveHand1);
764
    MatrixEffectMove  moveShad1 = new MatrixEffectMove(mDynMoveShad1);
765
    MatrixEffectScale scaleHand1= new MatrixEffectScale(mDynScaleHand1);
766
    MatrixEffectScale scaleShad1= new MatrixEffectScale(mDynScaleShad1);
767

    
768
    mEffects[0].apply(scaleShad1);
769
    mEffects[0].apply(moveShad1);
770
    mEffects[2].apply(scaleHand1);
771
    mEffects[2].apply(moveHand1);
772

    
773
    mDynMoveHand2 = new Dynamic3D(time,0.5f);
774
    mDynMoveHand2.setMode(Dynamic.MODE_PATH);
775
    mDynMoveHand2.setConvexity(0.0f);
776
    mDynMoveShad2 = new Dynamic3D(time,0.5f);
777
    mDynMoveShad2.setMode(Dynamic.MODE_PATH);
778
    mDynMoveShad2.setConvexity(0.0f);
779
    mDynScaleHand2 = new Dynamic3D(time,0.5f);
780
    mDynScaleHand2.setMode(Dynamic.MODE_PATH);
781
    mDynScaleHand2.setConvexity(0.0f);
782
    mDynScaleShad2 = new Dynamic3D(time,0.5f);
783
    mDynScaleShad2.setMode(Dynamic.MODE_PATH);
784
    mDynScaleShad2.setConvexity(0.0f);
785

    
786
    MatrixEffectMove  moveHand2 = new MatrixEffectMove(mDynMoveHand2);
787
    MatrixEffectMove  moveShad2 = new MatrixEffectMove(mDynMoveShad2);
788
    MatrixEffectScale scaleHand2= new MatrixEffectScale(mDynScaleHand2);
789
    MatrixEffectScale scaleShad2= new MatrixEffectScale(mDynScaleShad2);
790

    
791
    mEffects[1].apply(scaleShad2);
792
    mEffects[1].apply(moveShad2);
793
    mEffects[3].apply(scaleHand2);
794
    mEffects[3].apply(moveHand2);
795

    
796
    DistortedScreen screen = mControl.getScreen();
797
    mWidth = screen.getWidth();
798
    mHeight= screen.getHeight();
799

    
800
    X0   = mWidth*0.65f;
801
    X1   = mWidth*0.50f;
802
    X2   = mWidth*0.35f;
803
    Y1   = mHeight*0.28f;
804
    D    = mWidth*0.01f;
805
    s001 = mWidth*0.0001f;
806
    s014 = mWidth*0.14f;
807
    s033 = mWidth*0.33f;
808
    F    = 0.50f;
809
    }
810

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

    
813
  private void createNodes()
814
    {
815
    if( mNodes==null )
816
      {
817
      mNodes = new DistortedNode[NUM_NODE];
818
      mQuad  = new MeshQuad();
819
      }
820

    
821
    RubikActivity act = mControl.getActivity();
822

    
823
    if( act!=null )
824
      {
825
      Bitmap bmpCirc = openBitmap(act, R.drawable.ui_fading_circle);
826
      Bitmap bmpShad = openBitmap(act, R.drawable.ui_hand_shadow);
827
      Bitmap bmpHand = openBitmap(act, R.drawable.ui_hand_pointer);
828

    
829
      mTextureCirc = new DistortedTexture();
830
      mTextureShad = new DistortedTexture();
831
      DistortedTexture textureHand = new DistortedTexture();
832

    
833
      if( bmpCirc!=null ) mTextureCirc.setTexture(bmpCirc);
834
      if( bmpShad!=null ) mTextureShad.setTexture(bmpShad);
835
      if( bmpHand!=null ) textureHand.setTexture(bmpHand);
836

    
837
      mNodes[0]= new DistortedNode(mTextureShad,mEffects[0],mQuad);
838
      mNodes[1]= new DistortedNode(mTextureShad,mEffects[1],mQuad);
839
      mNodes[2]= new DistortedNode( textureHand,mEffects[2],mQuad);
840
      mNodes[3]= new DistortedNode( textureHand,mEffects[3],mQuad);
841
      }
842
    else
843
      {
844
      android.util.Log.e("D", "Activity NULL!!");
845
      }
846
    }
847

    
848
///////////////////////////////////////////////////////////////////////////////////////////////////
849

    
850
  long getEffectID()
851
    {
852
    return mEffectID;
853
    }
854

    
855
///////////////////////////////////////////////////////////////////////////////////////////////////
856

    
857
  DistortedNode[] getNodes()
858
    {
859
    if( mEffects==null ) createEffects();
860
    createNodes();
861
    setEffectsStage1();
862

    
863
    return mNodes;
864
    }
865

    
866
///////////////////////////////////////////////////////////////////////////////////////////////////
867

    
868
  DistortedNode[] returnNodes()
869
    {
870
    return mNodes;
871
    }
872

    
873
///////////////////////////////////////////////////////////////////////////////////////////////////
874

    
875
  RubikControlWhole(RubikControl control)
876
    {
877
    mControl = control;
878
    }
879

    
880
///////////////////////////////////////////////////////////////////////////////////////////////////
881

    
882
  private void stageFinished(int stage)
883
    {
884
    switch(stage)
885
      {
886
      case  1: setEffectsStage2() ; break;
887
      case  2: setEffectsStage3() ; break;
888
      case  3: setEffectsStage4() ; break;
889
      case  4: setEffectsStage5() ; break;
890
      case  5: setEffectsStage6() ; break;
891
      case  6: setEffectsStage7() ; break;
892
      case  7: setEffectsStage8() ; break;
893
      case  8: setEffectsStage9() ; break;
894
      case  9: setEffectsStage10(); break;
895
      case 10: setEffectsStage11(); break;
896
      case 11: setEffectsStage12(); break;
897
      case 12: setEffectsStage13(); break;
898
      default: setPostFrame(false);
899
               mEffectID = -1;
900
               mControl.effectFinished(mEffectID);
901
      }
902
    }
903

    
904
///////////////////////////////////////////////////////////////////////////////////////////////////
905
// PUBLIC
906

    
907
  public void postDrawFrame(long time)
908
    {
909
    if( mLastTime<0 ) mLastTime = time;
910
    else mDiffTime = time - mLastTime;
911
    mLastTime = time;
912

    
913
    switch(DYN[mCurrentStage-1])
914
      {
915
      case 1: boolean finished1 = mDyn1.get( tmpBuffer,0, time, mDiffTime);
916
              mPosition1.set(tmpBuffer[0], tmpBuffer[1], tmpBuffer[2]);
917

    
918
              if( mCurrentStage==3 )
919
                {
920
                RubikSurfaceView view = mControl.getSurfaceView();
921
                float x1 = tmpBuffer[0]+mWidth*0.5f;
922
                float y1 = mHeight*0.5f-tmpBuffer[1];
923
                view.actionMove(x1,y1,0,0);
924
                }
925

    
926
              if( finished1 )
927
                {
928
                if( mCurrentStage==3 )
929
                  {
930
                  RubikSurfaceView view = mControl.getSurfaceView();
931
                  view.prepareUp();
932
                  view.actionUp();
933
                  }
934

    
935
                stageFinished(mCurrentStage);
936
                }
937
              break;
938
      case 2: boolean finished2_1 = mDyn1.get( tmpBuffer,0, time, mDiffTime);
939
              boolean finished2_2 = mDyn2.get( tmpBuffer,3, time, mDiffTime);
940
              mPosition1.set(tmpBuffer[0], tmpBuffer[1], tmpBuffer[2]);
941
              mPosition2.set(tmpBuffer[3], tmpBuffer[4], tmpBuffer[5]);
942

    
943
              if( mCurrentStage==9 || mCurrentStage==10 || mCurrentStage==11 )
944
                {
945
                RubikSurfaceView view = mControl.getSurfaceView();
946
                float x1 = tmpBuffer[0]+mWidth*0.5f;
947
                float y1 = mHeight*0.5f-tmpBuffer[1];
948
                float x2 = tmpBuffer[3]+mWidth*0.5f;
949
                float y2 = mHeight*0.5f-tmpBuffer[4];
950
                view.prepareMove(x1,y1,x2,y2);
951
                view.actionMove(x1,y1,x2,y2);
952
                }
953

    
954
              if( finished2_1 && finished2_2 )
955
                {
956
                 if( mCurrentStage==11 )
957
                  {
958
                  RubikSurfaceView view = mControl.getSurfaceView();
959
                  view.prepareUp();
960
                  view.actionUp2(true,0,0,false,0,0);
961
                  view.actionUp();
962
                  }
963

    
964
                stageFinished(mCurrentStage);
965
                }
966
              break;
967
      case 4: boolean finished4_1 = mDyn1.get( tmpBuffer,0, time, mDiffTime);
968
              boolean finished4_2 = mDyn2.get( tmpBuffer,3, time, mDiffTime);
969
              boolean finished4_3 = mDyn3.get( tmpBuffer,6, time, mDiffTime);
970
              boolean finished4_4 = mDyn4.get( tmpBuffer,9, time, mDiffTime);
971
              mPosition1.set(tmpBuffer[0], tmpBuffer[ 1], tmpBuffer[ 2]);
972
              mPosition2.set(tmpBuffer[3], tmpBuffer[ 4], tmpBuffer[ 5]);
973
              mPosition3.set(tmpBuffer[6], tmpBuffer[ 7], tmpBuffer[ 8]);
974
              mPosition4.set(tmpBuffer[9], tmpBuffer[10], tmpBuffer[11]);
975
              if( finished4_1 && finished4_2 && finished4_3 && finished4_4 ) stageFinished(mCurrentStage);
976
              break;
977
      }
978
    }
979
  }
(3-3/3)