Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 17d623f1

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.objectlib.main;
21

    
22
import java.lang.ref.WeakReference;
23

    
24
import android.content.SharedPreferences;
25
import android.util.DisplayMetrics;
26
import android.view.MotionEvent;
27

    
28
import org.distorted.library.main.QuatHelper;
29
import org.distorted.library.type.Static2D;
30
import org.distorted.library.type.Static4D;
31

    
32
import org.distorted.objectlib.helpers.MovesFinished;
33
import org.distorted.objectlib.helpers.ObjectStateActioner;
34
import org.distorted.objectlib.helpers.TwistyActivity;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class ObjectControl
39
{
40
    public static final int NUM_SPEED_PROBES = 10;
41
    public static final int INVALID_POINTER_ID = -1;
42

    
43
    public static final int MODE_ROTATE  = 0;
44
    public static final int MODE_DRAG    = 1;
45
    public static final int MODE_REPLACE = 2;
46

    
47
    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
48
    // given face by SWIPING_SENSITIVITY/2 degrees.
49
    public final static int SWIPING_SENSITIVITY  = 240;
50
    // Moving the finger by 0.3 of an inch will start a Rotation.
51
    public final static float ROTATION_SENSITIVITY = 0.3f;
52

    
53
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
54

    
55
    private final WeakReference<TwistyActivity> mAct;
56
    private final ObjectStateActioner mActioner;
57
    private final ObjectPreRender mPreRender;
58
    private Movement mMovement;
59
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
60
    private int mScreenWidth, mScreenHeight, mScreenMin;
61

    
62
    private float mRotAngle, mInitDistance;
63
    private float mStartRotX, mStartRotY;
64
    private float mAxisX, mAxisY;
65
    private float mRotationFactor;
66
    private int mLastCubitColor, mLastCubitFace, mLastCubit;
67
    private int mCurrentAxis, mCurrentRow;
68
    private float mCurrentAngle, mCurrRotSpeed;
69
    private final float[] mLastX;
70
    private final float[] mLastY;
71
    private final long[] mLastT;
72
    private int mFirstIndex, mLastIndex;
73
    private final int mDensity;
74

    
75
    private int mPointer1, mPointer2;
76
    private float mX1, mY1, mX2, mY2, mX, mY;
77
    private final boolean mIsAutomatic;
78

    
79
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
80
    private static final Static4D mTemp= new Static4D(0,0,0,1);
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
84
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
85

    
86
    private void computeCurrentAxis(Static4D axis)
87
      {
88
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
89

    
90
      mAxisX =result.get0();
91
      mAxisY =result.get1();
92

    
93
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
94
      mAxisX /= len;
95
      mAxisY /= len;
96
      }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
    private void addSpeedProbe(float x, float y)
101
      {
102
      long currTime = System.currentTimeMillis();
103
      boolean theSame = mLastIndex==mFirstIndex;
104

    
105
      mLastIndex++;
106
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
107

    
108
      mLastT[mLastIndex] = currTime;
109
      mLastX[mLastIndex] = x;
110
      mLastY[mLastIndex] = y;
111

    
112
      if( mLastIndex==mFirstIndex)
113
        {
114
        mFirstIndex++;
115
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
116
        }
117

    
118
      if( theSame )
119
        {
120
        mLastT[mFirstIndex] = currTime;
121
        mLastX[mFirstIndex] = x;
122
        mLastY[mFirstIndex] = y;
123
        }
124
      }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
    private void computeCurrentSpeedInInchesPerSecond()
129
      {
130
      long firstTime = mLastT[mFirstIndex];
131
      long lastTime  = mLastT[mLastIndex];
132
      float fX = mLastX[mFirstIndex];
133
      float fY = mLastY[mFirstIndex];
134
      float lX = mLastX[mLastIndex];
135
      float lY = mLastY[mLastIndex];
136

    
137
      long timeDiff = lastTime-firstTime;
138

    
139
      mLastIndex = 0;
140
      mFirstIndex= 0;
141

    
142
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
143
      }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
148
      {
149
      float xDist = mScreenWidth*(xFrom-xTo);
150
      float yDist = mScreenHeight*(yFrom-yTo);
151
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
152

    
153
      return distInPixels/mDensity;
154
      }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
    private void setUpDragOrRotate(boolean down, float x, float y, int mode)
159
      {
160
      if( mode==MODE_DRAG )
161
        {
162
        mDragging           = true;
163
        mBeginningRotation  = false;
164
        mContinuingRotation = false;
165
        }
166
      else
167
        {
168
        TwistyObject object = mPreRender.getObject();
169
        CAMERA_POINT.set2( object==null ? 1.21f : object.getCameraDist() );
170

    
171
        Static4D touchPoint = new Static4D(x, y, 0, 0);
172
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
173
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
174

    
175
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
176
          {
177
          mDragging           = false;
178
          mContinuingRotation = false;
179

    
180
          if( mode==MODE_ROTATE )
181
            {
182
            mBeginningRotation= !mPreRender.isTouchBlocked();
183
            }
184
          else if( mode==MODE_REPLACE )
185
            {
186
            mBeginningRotation= false;
187

    
188
            if( down )
189
              {
190
              int color = mActioner.getCurrentColor();
191
              mLastCubitFace = mMovement.getTouchedFace();
192
              float[] point = mMovement.getTouchedPoint3D();
193
              mLastCubit = object.getCubit(point);
194
              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
195
              mLastCubitColor = mActioner.cubitIsLocked(object.getObjectType(),mLastCubit);
196
              }
197
            }
198
          }
199
        else
200
          {
201
          final TwistyActivity act = mAct.get();
202
          final boolean locked= act.isLocked();
203
          mDragging           = (!locked || mIsAutomatic);
204
          mBeginningRotation  = false;
205
          mContinuingRotation = false;
206
          if( !mDragging ) mActioner.failedToDrag(act);
207
          }
208
        }
209
      }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
    private void drag(float x, float y)
214
      {
215
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
216
        {
217
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
218
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
219

    
220
        float angleNow = getAngle(x,y,x2,y2);
221
        float angleDiff = angleNow-mRotAngle;
222
        float sinA =-(float)Math.sin(angleDiff);
223
        float cosA = (float)Math.cos(angleDiff);
224

    
225
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
226
        mTemp.set(dragQuat);
227

    
228
        mRotAngle = angleNow;
229

    
230
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
231
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
232
        mInitDistance = distNow;
233
        TwistyObject object = mPreRender.getObject();
234
        if( object!=null ) object.setObjectRatio(distQuot);
235
        }
236
      else
237
        {
238
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
239
        mTemp.set(dragQuat);
240
        }
241

    
242
      mPreRender.setQuatOnNextRender();
243
      mX = x;
244
      mY = y;
245
      }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

    
249
    private void finishRotation()
250
      {
251
      computeCurrentSpeedInInchesPerSecond();
252
      TwistyObject object = mPreRender.getObject();
253
      int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
254
      mPreRender.finishRotation(angle);
255
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
256

    
257
      if( angle!=0 )
258
        {
259
        TwistyActivity act = mAct.get();
260

    
261
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
262
        int realAngle = (angle*basicAngle)/360;
263

    
264
        mActioner.onFinishRotation(act,mCurrentAxis,mCurrentRow,realAngle);
265
        }
266

    
267
      mContinuingRotation = false;
268
      mBeginningRotation  = false;
269
      mDragging           = true;
270
      }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

    
274
    private void continueRotation(float x, float y)
275
      {
276
      float dx = x-mStartRotX;
277
      float dy = y-mStartRotY;
278
      float alpha = dx*mAxisX + dy*mAxisY;
279
      float x2 = dx - alpha*mAxisX;
280
      float y2 = dy - alpha*mAxisY;
281

    
282
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
283

    
284
      // we have the length of 1D vector 'angle', now the direction:
285
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
286

    
287
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
288
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
289
      mPreRender.getObject().continueRotation(mCurrentAngle);
290

    
291
      addSpeedProbe(x2,y2);
292
      }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
    private void beginRotation(float x, float y)
297
      {
298
      mStartRotX = x;
299
      mStartRotY = y;
300

    
301
      TwistyObject object = mPreRender.getObject();
302
      int numLayers = object.getNumLayers();
303

    
304
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
305
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
306
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
307

    
308
      mCurrentAxis = (int)res.get0();
309
      mCurrentRow  = (int)res.get1();
310

    
311
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
312
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
313

    
314
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
315

    
316
      TwistyActivity act = mAct.get();
317
      mActioner.onBeginRotation(act);
318

    
319
      addSpeedProbe(x,y);
320

    
321
      mBeginningRotation = false;
322
      mContinuingRotation= true;
323
      }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
    private float getAngle(float x1, float y1, float x2, float y2)
328
      {
329
      return (float) Math.atan2(y1-y2, x1-x2);
330
      }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
    private void prepareDown(MotionEvent event)
335
      {
336
      mPointer1 = event.getPointerId(0);
337
      mX1 = event.getX();
338
      mY1 = event.getY();
339
      mPointer2 = INVALID_POINTER_ID;
340
      }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
    private void prepareMove(MotionEvent event)
345
      {
346
      int index1 = event.findPointerIndex(mPointer1);
347

    
348
      if( index1>=0 )
349
        {
350
        mX1 = event.getX(index1);
351
        mY1 = event.getY(index1);
352
        }
353

    
354
      int index2 = event.findPointerIndex(mPointer2);
355

    
356
      if( index2>=0 )
357
        {
358
        mX2 = event.getX(index2);
359
        mY2 = event.getY(index2);
360
        }
361
      }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
    private void prepareUp(MotionEvent event)
366
      {
367
      mPointer1 = INVALID_POINTER_ID;
368
      mPointer2 = INVALID_POINTER_ID;
369
      }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
    private void prepareDown2(MotionEvent event)
374
      {
375
      int index = event.getActionIndex();
376

    
377
      if( mPointer1==INVALID_POINTER_ID )
378
        {
379
        mPointer1 = event.getPointerId(index);
380
        mX1 = event.getX(index);
381
        mY1 = event.getY(index);
382
        }
383
      else if( mPointer2==INVALID_POINTER_ID )
384
        {
385
        mPointer2 = event.getPointerId(index);
386
        mX2 = event.getX(index);
387
        mY2 = event.getY(index);
388
        }
389
      }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
    private void prepareUp2(MotionEvent event)
394
      {
395
      int index = event.getActionIndex();
396

    
397
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
398
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
399
      }
400

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402

    
403
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
404
      {
405
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
406
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
407

    
408
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
409
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
410

    
411
      if( mBeginningRotation )
412
        {
413
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
414
          {
415
          beginRotation(x,y);
416
          }
417
        }
418
      else if( mContinuingRotation )
419
        {
420
        continueRotation(x,y);
421
        }
422
      else if( mDragging )
423
        {
424
        drag(x,y);
425
        }
426
      else
427
        {
428
        setUpDragOrRotate(false,x,y,mode);
429
        }
430
      }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433

    
434
    private void actionDown(float x, float y, int mode)
435
      {
436
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
437
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
438

    
439
      setUpDragOrRotate(true,mX,mY,mode);
440
      }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
    private void actionUp()
445
      {
446
      if( mContinuingRotation )
447
        {
448
        finishRotation();
449
        }
450

    
451
      if( mLastCubitColor>=0 )
452
        {
453
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
454
        mLastCubitColor = -1;
455
        }
456
      }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
    private void actionDown2(float x1, float y1, float x2, float y2)
461
      {
462
      mRotAngle = getAngle(x1,-y1, x2,-y2);
463
      mInitDistance = -1;
464

    
465
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
466
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
467

    
468
      if( mBeginningRotation )
469
        {
470
        mContinuingRotation = false;
471
        mBeginningRotation  = false;
472
        mDragging           = true;
473
        }
474
      else if( mContinuingRotation )
475
        {
476
        finishRotation();
477
        }
478
      }
479

    
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

    
482
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
483
      {
484
      if( p1isUp )
485
        {
486
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
487
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
488
        }
489
      if( p2isUp )
490
        {
491
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
492
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
493
        }
494
      }
495

    
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498
// INTERNAL API (for AutomaticControl)
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
    public ObjectPreRender getPreRender()
502
      {
503
      return mPreRender;
504
      }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507
// PUBLIC API
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509

    
510
    public ObjectControl(TwistyActivity act, ObjectStateActioner actioner)
511
      {
512
      mIsAutomatic = false;
513

    
514
      mLastCubitColor = -1;
515
      mCurrRotSpeed   = 0.0f;
516

    
517
      mLastX = new float[NUM_SPEED_PROBES];
518
      mLastY = new float[NUM_SPEED_PROBES];
519
      mLastT = new long[NUM_SPEED_PROBES];
520
      mFirstIndex =0;
521
      mLastIndex  =0;
522

    
523
      DisplayMetrics dm = new DisplayMetrics();
524
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
525

    
526
      mDensity = dm.densityDpi;
527

    
528
      mPreRender = new ObjectPreRender(act,this,actioner);
529
      mAct = new WeakReference<>(act);
530
      mActioner = actioner;
531
      }
532

    
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534

    
535
    public void setScreenSize(int width, int height)
536
      {
537
      mScreenWidth = width;
538
      mScreenHeight= height;
539
      mScreenMin = Math.min(width, height);
540
      mPreRender.setScreenSize(width);
541
      }
542

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544

    
545
    public void initialize()
546
      {
547
      mPointer1 = INVALID_POINTER_ID;
548
      mPointer2 = INVALID_POINTER_ID;
549
      }
550

    
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552

    
553
    public void setQuat()
554
      {
555
      mQuat.set(mTemp);
556
      }
557

    
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559

    
560
    public Static4D getQuat()
561
      {
562
      return mQuat;
563
      }
564

    
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566

    
567
    public void setMovement(Movement movement)
568
      {
569
      mMovement = movement;
570
      }
571

    
572
///////////////////////////////////////////////////////////////////////////////////////////////////
573

    
574
    public void preRender()
575
      {
576
      mPreRender.preRender();
577
      }
578

    
579
///////////////////////////////////////////////////////////////////////////////////////////////////
580

    
581
    public void blockEverything(int place)
582
      {
583
      mPreRender.blockEverything(place);
584
      }
585

    
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587

    
588
    public void blockTouch(int place)
589
      {
590
      mPreRender.blockTouch(place);
591
      }
592

    
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594

    
595
    public void unblockEverything()
596
      {
597
      mPreRender.unblockEverything();
598
      }
599

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601

    
602
    public void unblockTouch()
603
      {
604
      mPreRender.unblockTouch();
605
      }
606

    
607
///////////////////////////////////////////////////////////////////////////////////////////////////
608

    
609
    public void unblockUI()
610
      {
611
      mPreRender.unblockUI();
612
      }
613

    
614
///////////////////////////////////////////////////////////////////////////////////////////////////
615

    
616
    public boolean isTouchBlocked()
617
      {
618
      return mPreRender.isTouchBlocked();
619
      }
620

    
621
///////////////////////////////////////////////////////////////////////////////////////////////////
622

    
623
    public boolean isUINotBlocked()
624
      {
625
      return mPreRender.isUINotBlocked();
626
      }
627

    
628
///////////////////////////////////////////////////////////////////////////////////////////////////
629

    
630
    public void initializeObject(int[][] moves)
631
      {
632
      mPreRender.initializeObject(moves);
633
      }
634

    
635
///////////////////////////////////////////////////////////////////////////////////////////////////
636

    
637
    public void changeObject(ObjectType object)
638
      {
639
      mPreRender.changeObject(object);
640
      }
641

    
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643

    
644
    public void setupObject(ObjectType object, int[][] moves)
645
      {
646
      mPreRender.setupObject(object,moves);
647
      }
648

    
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650

    
651
    public void scrambleObject(int num)
652
      {
653
      mPreRender.scrambleObject(num);
654
      }
655

    
656
///////////////////////////////////////////////////////////////////////////////////////////////////
657

    
658
    public void solveObject()
659
      {
660
      mPreRender.solveObject();
661
      }
662

    
663
///////////////////////////////////////////////////////////////////////////////////////////////////
664

    
665
    public void solveOnly()
666
      {
667
      mPreRender.solveOnly();
668
      }
669

    
670
///////////////////////////////////////////////////////////////////////////////////////////////////
671

    
672
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
673
      {
674
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
675
      }
676

    
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678

    
679
    public void resetAllTextureMaps()
680
      {
681
      mPreRender.resetAllTextureMaps();
682
      }
683

    
684
///////////////////////////////////////////////////////////////////////////////////////////////////
685

    
686
    public TwistyObject getObject()
687
      {
688
      return mPreRender.getObject();
689
      }
690

    
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692

    
693
    public void savePreferences(SharedPreferences.Editor editor)
694
      {
695
      mPreRender.savePreferences(editor);
696
      }
697

    
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699

    
700
    public void restorePreferences(SharedPreferences preferences)
701
      {
702
      mPreRender.restorePreferences(preferences);
703
      }
704

    
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706

    
707
    public boolean onTouchEvent(MotionEvent event, int mode)
708
      {
709
      int action = event.getActionMasked();
710

    
711
      switch(action)
712
         {
713
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
714
                                               actionDown(mX1, mY1, mode);
715
                                               break;
716
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
717
                                               actionMove(mX1, mY1, mX2, mY2, mode);
718
                                               break;
719
         case MotionEvent.ACTION_UP          : prepareUp(event);
720
                                               actionUp();
721
                                               break;
722
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
723
                                               actionDown2(mX1, mY1, mX2, mY2);
724
                                               break;
725
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
726
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
727
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
728
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
729
                                               break;
730
         }
731

    
732
      return true;
733
      }
734
}
735

    
(7-7/15)