Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 758b028d

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 android.app.Activity;
23
import android.content.SharedPreferences;
24
import android.util.DisplayMetrics;
25
import android.view.MotionEvent;
26

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

    
31
import org.distorted.objectlib.helpers.BlockController;
32
import org.distorted.objectlib.helpers.MovesFinished;
33
import org.distorted.objectlib.helpers.ObjectLibInterface;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

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

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

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

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

    
54
    private final ObjectLibInterface mInterface;
55
    private final ObjectPreRender mPreRender;
56
    private Movement mMovement;
57
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
58
    private int mScreenWidth, mScreenHeight, mScreenMin;
59
    private float mMoveX, mMoveY;
60

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

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

    
78
    private boolean mIsLocked, mRemLocked;
79

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

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

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

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

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

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

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

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

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

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

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

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

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

    
138
      long timeDiff = lastTime-firstTime;
139

    
140
      mLastIndex = 0;
141
      mFirstIndex= 0;
142

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

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

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

    
154
      return distInPixels/mDensity;
155
      }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

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

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

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

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

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

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

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

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

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

    
227
        mRotAngle = angleNow;
228

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

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

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

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

    
256
      if( angle!=0 )
257
        {
258
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
259
        int realAngle = (angle*basicAngle)/360;
260
        mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
261
        }
262

    
263
      mContinuingRotation = false;
264
      mBeginningRotation  = false;
265
      mDragging           = true;
266
      }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269

    
270
    private void continueRotation(float x, float y)
271
      {
272
      float dx = x-mStartRotX;
273
      float dy = y-mStartRotY;
274
      float alpha = dx*mAxisX + dy*mAxisY;
275
      float x2 = dx - alpha*mAxisX;
276
      float y2 = dy - alpha*mAxisY;
277

    
278
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
279

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

    
283
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
284
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
285
      mPreRender.getObject().continueRotation(mCurrentAngle);
286

    
287
      addSpeedProbe(x2,y2);
288
      }
289

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

    
292
    private void beginRotation(float x, float y)
293
      {
294
      mStartRotX = x;
295
      mStartRotY = y;
296

    
297
      TwistyObject object = mPreRender.getObject();
298
      int numLayers = object.getNumLayers();
299

    
300
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
301
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
302
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
303

    
304
      mCurrentAxis = (int)res.get0();
305
      mCurrentRow  = (int)res.get1();
306

    
307
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
308
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
309

    
310
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
311

    
312
      mInterface.onBeginRotation();
313

    
314
      addSpeedProbe(x,y);
315

    
316
      mBeginningRotation = false;
317
      mContinuingRotation= true;
318
      }
319

    
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

    
322
    private float getAngle(float x1, float y1, float x2, float y2)
323
      {
324
      return (float) Math.atan2(y1-y2, x1-x2);
325
      }
326

    
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

    
329
    private void prepareDown(MotionEvent event)
330
      {
331
      mPointer1 = event.getPointerId(0);
332
      mX1 = event.getX() - mMoveX;
333
      mY1 = event.getY() + mMoveY;
334
      mPointer2 = INVALID_POINTER_ID;
335
      }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
    private void prepareMove(MotionEvent event)
340
      {
341
      int index1 = event.findPointerIndex(mPointer1);
342

    
343
      if( index1>=0 )
344
        {
345
        mX1 = event.getX(index1) - mMoveX;
346
        mY1 = event.getY(index1) + mMoveY;
347
        }
348

    
349
      int index2 = event.findPointerIndex(mPointer2);
350

    
351
      if( index2>=0 )
352
        {
353
        mX2 = event.getX(index2) - mMoveX;
354
        mY2 = event.getY(index2) + mMoveY;
355
        }
356
      }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
    private void prepareUp(MotionEvent event)
361
      {
362
      mPointer1 = INVALID_POINTER_ID;
363
      mPointer2 = INVALID_POINTER_ID;
364
      }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
    private void prepareDown2(MotionEvent event)
369
      {
370
      int index = event.getActionIndex();
371

    
372
      if( mPointer1==INVALID_POINTER_ID )
373
        {
374
        mPointer1 = event.getPointerId(index);
375
        mX1 = event.getX(index) - mMoveX;
376
        mY1 = event.getY(index) + mMoveY;
377
        }
378
      else if( mPointer2==INVALID_POINTER_ID )
379
        {
380
        mPointer2 = event.getPointerId(index);
381
        mX2 = event.getX(index) - mMoveX;
382
        mY2 = event.getY(index) + mMoveY;
383
        }
384
      }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
    private void prepareUp2(MotionEvent event)
389
      {
390
      int index = event.getActionIndex();
391

    
392
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
393
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
394
      }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397

    
398
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
399
      {
400
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
401
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
402

    
403
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
404
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
405

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

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
    private void actionDown(float x, float y, int mode)
430
      {
431
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
432
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
433

    
434
      setUpDragOrRotate(true,mX,mY,mode);
435
      }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
    private void actionUp()
440
      {
441
      if( mContinuingRotation )
442
        {
443
        finishRotation();
444
        }
445

    
446
      if( mLastCubitColor>=0 )
447
        {
448
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
449
        mLastCubitColor = -1;
450
        }
451
      }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
    private void actionDown2(float x1, float y1, float x2, float y2)
456
      {
457
      mRotAngle = getAngle(x1,-y1, x2,-y2);
458
      mInitDistance = -1;
459

    
460
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
461
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
462

    
463
      if( mBeginningRotation )
464
        {
465
        mContinuingRotation = false;
466
        mBeginningRotation  = false;
467
        mDragging           = true;
468
        }
469
      else if( mContinuingRotation )
470
        {
471
        finishRotation();
472
        }
473
      }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

    
477
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
478
      {
479
      if( p1isUp )
480
        {
481
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
482
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
483
        }
484
      if( p2isUp )
485
        {
486
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
487
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
488
        }
489
      }
490

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492
// INTERNAL API (for AutomaticControl)
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
    public ObjectPreRender getPreRender()
496
      {
497
      return mPreRender;
498
      }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

    
502
    public ObjectLibInterface getInterface()
503
      {
504
      return mInterface;
505
      }
506

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508
// PUBLIC API
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
    public ObjectControl(Activity act, ObjectLibInterface actioner)
512
      {
513
      mIsAutomatic = false;
514

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

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

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

    
527
      mDensity = dm.densityDpi;
528

    
529
      mPreRender = new ObjectPreRender(act,this,actioner);
530
      mInterface = 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 setMove(int xmove, int ymove)
546
      {
547
      mMoveX = xmove;
548
      mMoveY = ymove;
549

    
550
      mPreRender.setMove(xmove,ymove);
551
      }
552

    
553
///////////////////////////////////////////////////////////////////////////////////////////////////
554

    
555
    public void onPause()
556
      {
557
      BlockController.onPause();
558
      }
559

    
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561

    
562
    public void onResume()
563
      {
564
      mPointer1 = INVALID_POINTER_ID;
565
      mPointer2 = INVALID_POINTER_ID;
566

    
567
      unlock();
568

    
569
      BlockController.onResume();
570
      }
571

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

    
574
    public void setQuat()
575
      {
576
      mQuat.set(mTemp);
577
      }
578

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

    
581
    public Static4D getQuat()
582
      {
583
      return mQuat;
584
      }
585

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

    
588
    public void setMovement(Movement movement)
589
      {
590
      mMovement = movement;
591
      }
592

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

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

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

    
602
    public void blockEverything(int place)
603
      {
604
      setLock(true);
605
      mPreRender.blockEverything(place);
606
      }
607

    
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609

    
610
    public void blockTouch(int place)
611
      {
612
      setLock(true);
613
      mPreRender.blockTouch(place);
614
      }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617

    
618
    public void unblockEverything()
619
      {
620
      unsetLock();
621
      mPreRender.unblockEverything();
622
      }
623

    
624
///////////////////////////////////////////////////////////////////////////////////////////////////
625

    
626
    public void unblockTouch()
627
      {
628
      unsetLock();
629
      mPreRender.unblockTouch();
630
      }
631

    
632
///////////////////////////////////////////////////////////////////////////////////////////////////
633

    
634
    public void unblockUI()
635
      {
636
      mPreRender.unblockUI();
637
      }
638

    
639
///////////////////////////////////////////////////////////////////////////////////////////////////
640

    
641
    public boolean isTouchBlocked()
642
      {
643
      return mPreRender.isTouchBlocked();
644
      }
645

    
646
///////////////////////////////////////////////////////////////////////////////////////////////////
647

    
648
    public boolean isUINotBlocked()
649
      {
650
      return mPreRender.isUINotBlocked();
651
      }
652

    
653
///////////////////////////////////////////////////////////////////////////////////////////////////
654

    
655
    public void initializeObject(int[][] moves)
656
      {
657
      mPreRender.initializeObject(moves);
658
      }
659

    
660
///////////////////////////////////////////////////////////////////////////////////////////////////
661

    
662
    public void changeObject(ObjectType object)
663
      {
664
      mPreRender.changeObject(object);
665
      }
666

    
667
///////////////////////////////////////////////////////////////////////////////////////////////////
668

    
669
    public void scrambleObject(int num)
670
      {
671
      mPreRender.scrambleObject(num);
672
      }
673

    
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675

    
676
    public void solveObject()
677
      {
678
      mPreRender.solveObject();
679
      }
680

    
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682

    
683
    public void solveOnly()
684
      {
685
      mPreRender.solveOnly();
686
      }
687

    
688
///////////////////////////////////////////////////////////////////////////////////////////////////
689

    
690
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
691
      {
692
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
693
      }
694

    
695
///////////////////////////////////////////////////////////////////////////////////////////////////
696

    
697
    public void resetAllTextureMaps()
698
      {
699
      mPreRender.resetAllTextureMaps();
700
      }
701

    
702
///////////////////////////////////////////////////////////////////////////////////////////////////
703

    
704
    public TwistyObject getObject()
705
      {
706
      return mPreRender.getObject();
707
      }
708

    
709
///////////////////////////////////////////////////////////////////////////////////////////////////
710

    
711
    public void savePreferences(SharedPreferences.Editor editor)
712
      {
713
      mPreRender.savePreferences(editor);
714
      }
715

    
716
///////////////////////////////////////////////////////////////////////////////////////////////////
717

    
718
    public void restorePreferences(SharedPreferences preferences)
719
      {
720
      mPreRender.restorePreferences(preferences);
721
      }
722
///////////////////////////////////////////////////////////////////////////////////////////////////
723

    
724
    public boolean retLocked()
725
      {
726
      return mIsLocked;
727
      }
728

    
729
///////////////////////////////////////////////////////////////////////////////////////////////////
730

    
731
    public void toggleLock()
732
      {
733
      mIsLocked = !mIsLocked;
734
      }
735

    
736
///////////////////////////////////////////////////////////////////////////////////////////////////
737

    
738
    public void unlock()
739
      {
740
      mIsLocked = false;
741
      }
742

    
743
///////////////////////////////////////////////////////////////////////////////////////////////////
744

    
745
    public void setLock(boolean value)
746
      {
747
      mRemLocked = mIsLocked;
748
      mIsLocked = value;
749
      }
750

    
751
///////////////////////////////////////////////////////////////////////////////////////////////////
752

    
753
    public void unsetLock()
754
      {
755
      mIsLocked = mRemLocked;
756
      }
757

    
758
///////////////////////////////////////////////////////////////////////////////////////////////////
759

    
760
    public boolean onTouchEvent(MotionEvent event, int mode)
761
      {
762
      int action = event.getActionMasked();
763

    
764
      switch(action)
765
         {
766
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
767
                                               actionDown(mX1, mY1, mode);
768
                                               break;
769
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
770
                                               actionMove(mX1, mY1, mX2, mY2, mode);
771
                                               break;
772
         case MotionEvent.ACTION_UP          : prepareUp(event);
773
                                               actionUp();
774
                                               break;
775
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
776
                                               actionDown2(mX1, mY1, mX2, mY2);
777
                                               break;
778
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
779
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
780
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
781
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
782
                                               break;
783
         }
784

    
785
      return true;
786
      }
787
}
788

    
(7-7/15)