Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ e32d318a

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 TwistyObjectNode mObjectNode;
58
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
59
    private int mScreenWidth, mScreenHeight, mScreenMin;
60
    private float mMoveX, mMoveY;
61

    
62
    private float mRotAngle, mInitDistance;
63
    private float mStartRotX, mStartRotY;
64
    private float mAxisX, mAxisY;
65
    private float mRotationFactor;
66
    private int mLastCubitColor, 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 boolean mIsLocked, mRemLocked;
80

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

    
84
    private static boolean mForcedIconMode = false, mForcedCreateMesh = false;
85

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

    
90
    private void computeCurrentAxis(Static4D axis)
91
      {
92
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
93

    
94
      mAxisX =result.get0();
95
      mAxisY =result.get1();
96

    
97
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
98
      mAxisX /= len;
99
      mAxisY /= len;
100
      }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
    private void addSpeedProbe(float x, float y)
105
      {
106
      long currTime = System.currentTimeMillis();
107
      boolean theSame = mLastIndex==mFirstIndex;
108

    
109
      mLastIndex++;
110
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
111

    
112
      mLastT[mLastIndex] = currTime;
113
      mLastX[mLastIndex] = x;
114
      mLastY[mLastIndex] = y;
115

    
116
      if( mLastIndex==mFirstIndex)
117
        {
118
        mFirstIndex++;
119
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
120
        }
121

    
122
      if( theSame )
123
        {
124
        mLastT[mFirstIndex] = currTime;
125
        mLastX[mFirstIndex] = x;
126
        mLastY[mFirstIndex] = y;
127
        }
128
      }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

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

    
141
      long timeDiff = lastTime-firstTime;
142

    
143
      mLastIndex = 0;
144
      mFirstIndex= 0;
145

    
146
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
147
      }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

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

    
157
      return distInPixels/mDensity;
158
      }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

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

    
175
        Static4D touchPoint = new Static4D(x, y, 0, 0);
176
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
177
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
178

    
179
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
180
          {
181
          mDragging           = false;
182
          mContinuingRotation = false;
183

    
184
          if( mode==MODE_ROTATE )
185
            {
186
            mBeginningRotation= !mPreRender.isTouchBlocked();
187
            }
188
          else if( mode==MODE_REPLACE )
189
            {
190
            mBeginningRotation= false;
191

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

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

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

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

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

    
229
        mRotAngle = angleNow;
230

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

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

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

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

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

    
265
      mContinuingRotation = false;
266
      mBeginningRotation  = false;
267
      mDragging           = true;
268
      }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

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

    
280
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
281

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

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

    
289
      addSpeedProbe(x2,y2);
290
      }
291

    
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

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

    
299
      TwistyObject object = mPreRender.getObject();
300
      int[] numLayers = object.getNumLayers();
301

    
302
      Static4D touchPoint = new Static4D(x, y, 0, 0);
303
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
304
      Static2D res = mMovement.newRotation(rotatedTouchPoint,object.getObjectRatio());
305

    
306
      mCurrentAxis = (int)res.get0();
307
      mCurrentRow  = (int)res.get1();
308

    
309
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
310
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
311

    
312
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
313

    
314
      mInterface.onBeginRotation();
315

    
316
      addSpeedProbe(x,y);
317

    
318
      mBeginningRotation = false;
319
      mContinuingRotation= true;
320
      }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

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

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

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

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

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

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

    
351
      int index2 = event.findPointerIndex(mPointer2);
352

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

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

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

    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369

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

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

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

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

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

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

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

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

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

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

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

    
436
      setUpDragOrRotate(true,mX,mY,mode);
437
      }
438

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

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

    
448
      if( mLastCubitColor>=0 )
449
        {
450
        mPreRender.setTextureMap( mLastCubit, 4, mLastCubitColor );
451
        mLastCubitColor = -1;
452
        }
453
      }
454

    
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

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

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

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

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

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

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
    void setMovement(Movement movement)
496
      {
497
      mMovement = movement;
498
      }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501
// INTERNAL API (for AutomaticControl)
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

    
504
    public ObjectPreRender getPreRender()
505
      {
506
      return mPreRender;
507
      }
508

    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
    public ObjectLibInterface getInterface()
512
      {
513
      return mInterface;
514
      }
515

    
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517

    
518
    public static void setIconMode(boolean mode)
519
      {
520
      mForcedIconMode = mode;
521
      }
522

    
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524

    
525
    public static void setForcedMesh(boolean mode)
526
      {
527
      mForcedCreateMesh = mode;
528
      }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531

    
532
    public static boolean isInIconMode()
533
      {
534
      return mForcedIconMode;
535
      }
536

    
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538

    
539
    public static boolean isInCreateMesh()
540
      {
541
      return mForcedCreateMesh;
542
      }
543

    
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545
// PUBLIC API
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547

    
548
    public ObjectControl(Activity act, ObjectLibInterface actioner)
549
      {
550
      mIsAutomatic = false;
551

    
552
      mLastCubitColor = -1;
553
      mCurrRotSpeed   = 0.0f;
554

    
555
      mLastX = new float[NUM_SPEED_PROBES];
556
      mLastY = new float[NUM_SPEED_PROBES];
557
      mLastT = new long[NUM_SPEED_PROBES];
558
      mFirstIndex =0;
559
      mLastIndex  =0;
560

    
561
      DisplayMetrics dm = new DisplayMetrics();
562
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
563

    
564
      mDensity = dm.densityDpi;
565

    
566
      mPreRender = new ObjectPreRender(act,this,actioner);
567
      mInterface = actioner;
568
      }
569

    
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571

    
572
    public TwistyObjectNode getNode()
573
      {
574
      return mObjectNode;
575
      }
576

    
577
///////////////////////////////////////////////////////////////////////////////////////////////////
578

    
579
    public void createNode(int width, int height)
580
      {
581
      if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
582
      }
583

    
584
///////////////////////////////////////////////////////////////////////////////////////////////////
585

    
586
    public void setScreenSize(int width, int height)
587
      {
588
      mScreenWidth = width;
589
      mScreenHeight= height;
590
      mScreenMin   = Math.min(width,height);
591

    
592
      mPreRender.setScreenSize();
593
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
594
      }
595

    
596
///////////////////////////////////////////////////////////////////////////////////////////////////
597

    
598
    public void setMove(int xmove, int ymove)
599
      {
600
      mMoveX = xmove;
601
      mMoveY = ymove;
602

    
603
      mPreRender.setMove(xmove,ymove);
604
      }
605

    
606
///////////////////////////////////////////////////////////////////////////////////////////////////
607

    
608
    public void onPause()
609
      {
610
      BlockController.onPause();
611
      }
612

    
613
///////////////////////////////////////////////////////////////////////////////////////////////////
614

    
615
    public void onResume()
616
      {
617
      mPointer1 = INVALID_POINTER_ID;
618
      mPointer2 = INVALID_POINTER_ID;
619

    
620
      unlock();
621

    
622
      BlockController.onResume();
623
      }
624

    
625
///////////////////////////////////////////////////////////////////////////////////////////////////
626

    
627
    public void rotateNow(Static4D quat)
628
      {
629
      mTemp.set(quat);
630
      mQuat.set(mTemp);
631
      }
632

    
633
///////////////////////////////////////////////////////////////////////////////////////////////////
634

    
635
    public void scaleNow(float scale)
636
      {
637
      mPreRender.getObject().setObjectRatioNow(scale,mObjectNode.getScaleFactor());
638
      }
639

    
640
///////////////////////////////////////////////////////////////////////////////////////////////////
641

    
642
    public void setQuat()
643
      {
644
      mQuat.set(mTemp);
645
      }
646

    
647
///////////////////////////////////////////////////////////////////////////////////////////////////
648

    
649
    public Static4D getQuat()
650
      {
651
      return mQuat;
652
      }
653

    
654
///////////////////////////////////////////////////////////////////////////////////////////////////
655

    
656
    public void preRender()
657
      {
658
      mPreRender.preRender();
659
      }
660

    
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662

    
663
    public void blockEverything(int place)
664
      {
665
      setLock(true);
666
      mPreRender.blockEverything(place);
667
      }
668

    
669
///////////////////////////////////////////////////////////////////////////////////////////////////
670

    
671
    public void blockTouch(int place)
672
      {
673
      setLock(true);
674
      mPreRender.blockTouch(place);
675
      }
676

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

    
679
    public void unblockEverything()
680
      {
681
      unsetLock();
682
      mPreRender.unblockEverything();
683
      }
684

    
685
///////////////////////////////////////////////////////////////////////////////////////////////////
686

    
687
    public void unblockTouch()
688
      {
689
      unsetLock();
690
      mPreRender.unblockTouch();
691
      }
692

    
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694

    
695
    public void unblockUI()
696
      {
697
      mPreRender.unblockUI();
698
      }
699

    
700
///////////////////////////////////////////////////////////////////////////////////////////////////
701

    
702
    public boolean isTouchBlocked()
703
      {
704
      return mPreRender.isTouchBlocked();
705
      }
706

    
707
///////////////////////////////////////////////////////////////////////////////////////////////////
708

    
709
    public boolean isUINotBlocked()
710
      {
711
      return mPreRender.isUINotBlocked();
712
      }
713

    
714
///////////////////////////////////////////////////////////////////////////////////////////////////
715

    
716
    public void initializeObject(int[][] moves)
717
      {
718
      mPreRender.initializeObject(moves);
719
      }
720

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

    
723
    public void changeObject(ObjectType newObject)
724
      {
725
      mPreRender.changeObject(newObject);
726
      }
727

    
728
///////////////////////////////////////////////////////////////////////////////////////////////////
729

    
730
    public void recreateObject()
731
      {
732
      mPreRender.recreateObject();
733
      }
734

    
735
///////////////////////////////////////////////////////////////////////////////////////////////////
736

    
737
    public void scrambleObject(int num)
738
      {
739
      mPreRender.scrambleObject(num);
740
      }
741

    
742
///////////////////////////////////////////////////////////////////////////////////////////////////
743

    
744
    public void solveObject()
745
      {
746
      mPreRender.solveObject();
747
      }
748

    
749
///////////////////////////////////////////////////////////////////////////////////////////////////
750

    
751
    public void solveOnly()
752
      {
753
      mPreRender.solveOnly();
754
      }
755

    
756
///////////////////////////////////////////////////////////////////////////////////////////////////
757

    
758
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
759
      {
760
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
761
      }
762

    
763
///////////////////////////////////////////////////////////////////////////////////////////////////
764

    
765
    public void resetAllTextureMaps()
766
      {
767
      mPreRender.resetAllTextureMaps();
768
      }
769

    
770
///////////////////////////////////////////////////////////////////////////////////////////////////
771

    
772
    public TwistyObject getObject()
773
      {
774
      return mPreRender.getObject();
775
      }
776

    
777
///////////////////////////////////////////////////////////////////////////////////////////////////
778

    
779
    public void savePreferences(SharedPreferences.Editor editor)
780
      {
781
      mPreRender.savePreferences(editor);
782
      }
783

    
784
///////////////////////////////////////////////////////////////////////////////////////////////////
785

    
786
    public void restorePreferences(SharedPreferences preferences)
787
      {
788
      mPreRender.restorePreferences(preferences);
789
      }
790
///////////////////////////////////////////////////////////////////////////////////////////////////
791

    
792
    public boolean retLocked()
793
      {
794
      return mIsLocked;
795
      }
796

    
797
///////////////////////////////////////////////////////////////////////////////////////////////////
798

    
799
    public void toggleLock()
800
      {
801
      mIsLocked = !mIsLocked;
802
      }
803

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

    
806
    public void unlock()
807
      {
808
      mIsLocked = false;
809
      }
810

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

    
813
    public void setLock(boolean value)
814
      {
815
      mRemLocked = mIsLocked;
816
      mIsLocked = value;
817
      }
818

    
819
///////////////////////////////////////////////////////////////////////////////////////////////////
820

    
821
    public void unsetLock()
822
      {
823
      mIsLocked = mRemLocked;
824
      }
825

    
826
///////////////////////////////////////////////////////////////////////////////////////////////////
827

    
828
    public boolean onTouchEvent(MotionEvent event, int mode)
829
      {
830
      int action = event.getActionMasked();
831

    
832
      switch(action)
833
         {
834
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
835
                                               actionDown(mX1, mY1, mode);
836
                                               break;
837
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
838
                                               actionMove(mX1, mY1, mX2, mY2, mode);
839
                                               break;
840
         case MotionEvent.ACTION_UP          : prepareUp(event);
841
                                               actionUp();
842
                                               break;
843
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
844
                                               actionDown2(mX1, mY1, mX2, mY2);
845
                                               break;
846
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
847
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
848
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
849
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
850
                                               break;
851
         }
852

    
853
      return true;
854
      }
855
}
856

    
(8-8/17)