Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 0e1437c1

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.io.InputStream;
23

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

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

    
33
import org.distorted.objectlib.helpers.BlockController;
34
import org.distorted.objectlib.helpers.MovesFinished;
35
import org.distorted.objectlib.helpers.ObjectLibInterface;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

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

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

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

    
56
    private final ObjectLibInterface mInterface;
57
    private final ObjectPreRender mPreRender;
58
    private Movement mMovement;
59
    private TwistyObjectNode mObjectNode;
60
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
61
    private int mScreenWidth, mScreenHeight, mScreenMin;
62
    private float mMoveX, mMoveY;
63

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

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

    
81
    private boolean mIsLocked, mRemLocked;
82

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

    
86
    private static boolean mForcedIconMode = false;
87

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

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

    
96
      mAxisX =result.get0();
97
      mAxisY =result.get1();
98

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

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

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

    
111
      mLastIndex++;
112
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
113

    
114
      mLastT[mLastIndex] = currTime;
115
      mLastX[mLastIndex] = x;
116
      mLastY[mLastIndex] = y;
117

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

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

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

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

    
143
      long timeDiff = lastTime-firstTime;
144

    
145
      mLastIndex = 0;
146
      mFirstIndex= 0;
147

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

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

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

    
159
      return distInPixels/mDensity;
160
      }
161

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

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

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

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

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

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

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

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

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

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

    
231
        mRotAngle = angleNow;
232

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

    
245
      mPreRender.setQuatOnNextRender();
246
      mX = x;
247
      mY = y;
248
      }
249

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

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

    
260
      if( angle!=0 )
261
        {
262
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
263
        int realAngle = (angle*basicAngle)/360;
264
        mInterface.onFinishRotation(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 touchPoint = new Static4D(x, y, 0, 0);
305
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
306
      Static2D res = mMovement.newRotation(rotatedTouchPoint,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
      mInterface.onBeginRotation();
317

    
318
      addSpeedProbe(x,y);
319

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

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

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

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

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

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

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

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

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

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

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

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

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

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

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

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

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

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

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

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

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

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

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432

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

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

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

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

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

    
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

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

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

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

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480

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

    
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496

    
497
    void setMovement(Movement movement)
498
      {
499
      mMovement = movement;
500
      }
501

    
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503
// INTERNAL API (for AutomaticControl)
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505

    
506
    public ObjectPreRender getPreRender()
507
      {
508
      return mPreRender;
509
      }
510

    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

    
513
    public ObjectLibInterface getInterface()
514
      {
515
      return mInterface;
516
      }
517

    
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519

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

    
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526

    
527
    public static boolean isInIconMode()
528
      {
529
      return mForcedIconMode;
530
      }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
// PUBLIC API
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535

    
536
    public ObjectControl(Activity act, ObjectLibInterface actioner)
537
      {
538
      mIsAutomatic = false;
539

    
540
      mLastCubitColor = -1;
541
      mCurrRotSpeed   = 0.0f;
542

    
543
      mLastX = new float[NUM_SPEED_PROBES];
544
      mLastY = new float[NUM_SPEED_PROBES];
545
      mLastT = new long[NUM_SPEED_PROBES];
546
      mFirstIndex =0;
547
      mLastIndex  =0;
548

    
549
      DisplayMetrics dm = new DisplayMetrics();
550
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
551

    
552
      mDensity = dm.densityDpi;
553

    
554
      mPreRender = new ObjectPreRender(act,this,actioner);
555
      mInterface = actioner;
556
      }
557

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

    
560
    public TwistyObjectNode getNode()
561
      {
562
      return mObjectNode;
563
      }
564

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

    
567
    public void createNode(int width, int height)
568
      {
569
      if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
570
      }
571

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

    
574
    public void setScreenSize(int width, int height)
575
      {
576
      mScreenWidth = width;
577
      mScreenHeight= height;
578
      mScreenMin   = Math.min(width,height);
579

    
580
      mPreRender.setScreenSize();
581
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
582
      }
583

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

    
586
    public void setMove(int xmove, int ymove)
587
      {
588
      mMoveX = xmove;
589
      mMoveY = ymove;
590

    
591
      mPreRender.setMove(xmove,ymove);
592
      }
593

    
594
///////////////////////////////////////////////////////////////////////////////////////////////////
595

    
596
    public void onPause()
597
      {
598
      BlockController.onPause();
599
      }
600

    
601
///////////////////////////////////////////////////////////////////////////////////////////////////
602

    
603
    public void onResume()
604
      {
605
      mPointer1 = INVALID_POINTER_ID;
606
      mPointer2 = INVALID_POINTER_ID;
607

    
608
      unlock();
609

    
610
      BlockController.onResume();
611
      }
612

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

    
615
    public void rotateNow(Static4D quat)
616
      {
617
      mTemp.set(quat);
618
      mQuat.set(mTemp);
619
      }
620

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

    
623
    public void scaleNow(float scale)
624
      {
625
      mPreRender.getObject().setObjectRatioNow(scale,mObjectNode.getScale(), mObjectNode.getMinSize() );
626
      }
627

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

    
630
    public void setQuat()
631
      {
632
      mQuat.set(mTemp);
633
      }
634

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

    
637
    public Static4D getQuat()
638
      {
639
      return mQuat;
640
      }
641

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

    
644
    public void preRender()
645
      {
646
      mPreRender.preRender();
647
      }
648

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

    
651
    public void blockEverything(int place)
652
      {
653
      setLock(true);
654
      mPreRender.blockEverything(place);
655
      }
656

    
657
///////////////////////////////////////////////////////////////////////////////////////////////////
658

    
659
    public void blockTouch(int place)
660
      {
661
      setLock(true);
662
      mPreRender.blockTouch(place);
663
      }
664

    
665
///////////////////////////////////////////////////////////////////////////////////////////////////
666

    
667
    public void unblockEverything()
668
      {
669
      unsetLock();
670
      mPreRender.unblockEverything();
671
      }
672

    
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674

    
675
    public void unblockTouch()
676
      {
677
      unsetLock();
678
      mPreRender.unblockTouch();
679
      }
680

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

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

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

    
690
    public boolean isTouchBlocked()
691
      {
692
      return mPreRender.isTouchBlocked();
693
      }
694

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

    
697
    public boolean isUINotBlocked()
698
      {
699
      return mPreRender.isUINotBlocked();
700
      }
701

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

    
704
    public void initializeObject(int[][] moves)
705
      {
706
      mPreRender.initializeObject(moves);
707
      }
708

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

    
711
    public void changeObject(int ordinal, InputStream jsonStream, InputStream meshStream)
712
      {
713
      mPreRender.changeObject(ordinal, jsonStream, meshStream);
714
      }
715

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

    
718
    public void changeIfDifferent(int ordinal, InputStream jsonStream, InputStream meshStream)
719
      {
720
      TwistyObject object = mPreRender.getObject();
721
      ObjectType old = object==null ? null : object.getObjectType();
722

    
723
      if( old==null || old.ordinal() != ordinal )
724
        {
725
        mPreRender.changeObject(ordinal, jsonStream, meshStream);
726
        }
727
      }
728

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

    
731
    public void scrambleObject(int num)
732
      {
733
      mPreRender.scrambleObject(num);
734
      }
735

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

    
738
    public void solveObject()
739
      {
740
      mPreRender.solveObject();
741
      }
742

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

    
745
    public void solveOnly()
746
      {
747
      mPreRender.solveOnly();
748
      }
749

    
750
///////////////////////////////////////////////////////////////////////////////////////////////////
751

    
752
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
753
      {
754
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
755
      }
756

    
757
///////////////////////////////////////////////////////////////////////////////////////////////////
758

    
759
    public void resetAllTextureMaps()
760
      {
761
      mPreRender.resetAllTextureMaps();
762
      }
763

    
764
///////////////////////////////////////////////////////////////////////////////////////////////////
765

    
766
    public TwistyObject getObject()
767
      {
768
      return mPreRender.getObject();
769
      }
770

    
771
///////////////////////////////////////////////////////////////////////////////////////////////////
772

    
773
    public void savePreferences(SharedPreferences.Editor editor)
774
      {
775
      mPreRender.savePreferences(editor);
776
      }
777

    
778
///////////////////////////////////////////////////////////////////////////////////////////////////
779

    
780
    public void restorePreferences(SharedPreferences preferences)
781
      {
782
      mPreRender.restorePreferences(preferences);
783
      }
784
///////////////////////////////////////////////////////////////////////////////////////////////////
785

    
786
    public boolean retLocked()
787
      {
788
      return mIsLocked;
789
      }
790

    
791
///////////////////////////////////////////////////////////////////////////////////////////////////
792

    
793
    public void toggleLock()
794
      {
795
      mIsLocked = !mIsLocked;
796
      }
797

    
798
///////////////////////////////////////////////////////////////////////////////////////////////////
799

    
800
    public void unlock()
801
      {
802
      mIsLocked = false;
803
      }
804

    
805
///////////////////////////////////////////////////////////////////////////////////////////////////
806

    
807
    public void setLock(boolean value)
808
      {
809
      mRemLocked = mIsLocked;
810
      mIsLocked = value;
811
      }
812

    
813
///////////////////////////////////////////////////////////////////////////////////////////////////
814

    
815
    public void unsetLock()
816
      {
817
      mIsLocked = mRemLocked;
818
      }
819

    
820
///////////////////////////////////////////////////////////////////////////////////////////////////
821

    
822
    public boolean onTouchEvent(MotionEvent event, int mode)
823
      {
824
      int action = event.getActionMasked();
825

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

    
847
      return true;
848
      }
849
}
850

    
(8-8/18)