Project

General

Profile

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

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

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
      TwistyObject object = mPreRender.getObject();
255
      int[] angles = object.getBasicAngle();
256

    
257
      if( mCurrentAxis<angles.length )
258
        {
259
        computeCurrentSpeedInInchesPerSecond();
260

    
261
        int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
262
        mPreRender.finishRotation(angle);
263
        mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
264

    
265
        if( angle!=0 )
266
          {
267
          int basicAngle= angles[mCurrentAxis];
268
          int realAngle = (angle*basicAngle)/360;
269
          mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
270
          }
271

    
272
        mContinuingRotation = false;
273
        mBeginningRotation  = false;
274
        mDragging           = true;
275
        }
276
      }
277

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

    
280
    private void continueRotation(float x, float y)
281
      {
282
      float dx = x-mStartRotX;
283
      float dy = y-mStartRotY;
284
      float alpha = dx*mAxisX + dy*mAxisY;
285
      float x2 = dx - alpha*mAxisX;
286
      float y2 = dy - alpha*mAxisY;
287

    
288
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
289

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

    
293
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
294
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
295
      mPreRender.getObject().continueRotation(mCurrentAngle);
296

    
297
      addSpeedProbe(x2,y2);
298
      }
299

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

    
302
    private void beginRotation(float x, float y)
303
      {
304
      mStartRotX = x;
305
      mStartRotY = y;
306

    
307
      TwistyObject object = mPreRender.getObject();
308
      int[] numLayers = object.getNumLayers();
309

    
310
      Static4D touchPoint = new Static4D(x, y, 0, 0);
311
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
312
      Static2D res = mMovement.newRotation(rotatedTouchPoint,object.getObjectRatio());
313

    
314
      mCurrentAxis = (int)res.get0();
315
      mCurrentRow  = (int)res.get1();
316

    
317
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
318
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
319

    
320
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
321

    
322
      mInterface.onBeginRotation();
323

    
324
      addSpeedProbe(x,y);
325

    
326
      mBeginningRotation = false;
327
      mContinuingRotation= true;
328
      }
329

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

    
332
    private float getAngle(float x1, float y1, float x2, float y2)
333
      {
334
      return (float) Math.atan2(y1-y2, x1-x2);
335
      }
336

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

    
339
    private void prepareDown(MotionEvent event)
340
      {
341
      mPointer1 = event.getPointerId(0);
342
      mX1 = event.getX() - mMoveX;
343
      mY1 = event.getY() + mMoveY;
344
      mPointer2 = INVALID_POINTER_ID;
345
      }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
    private void prepareMove(MotionEvent event)
350
      {
351
      int index1 = event.findPointerIndex(mPointer1);
352

    
353
      if( index1>=0 )
354
        {
355
        mX1 = event.getX(index1) - mMoveX;
356
        mY1 = event.getY(index1) + mMoveY;
357
        }
358

    
359
      int index2 = event.findPointerIndex(mPointer2);
360

    
361
      if( index2>=0 )
362
        {
363
        mX2 = event.getX(index2) - mMoveX;
364
        mY2 = event.getY(index2) + mMoveY;
365
        }
366
      }
367

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

    
370
    private void prepareUp(MotionEvent event)
371
      {
372
      mPointer1 = INVALID_POINTER_ID;
373
      mPointer2 = INVALID_POINTER_ID;
374
      }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
    private void prepareDown2(MotionEvent event)
379
      {
380
      int index = event.getActionIndex();
381

    
382
      if( mPointer1==INVALID_POINTER_ID )
383
        {
384
        mPointer1 = event.getPointerId(index);
385
        mX1 = event.getX(index) - mMoveX;
386
        mY1 = event.getY(index) + mMoveY;
387
        }
388
      else if( mPointer2==INVALID_POINTER_ID )
389
        {
390
        mPointer2 = event.getPointerId(index);
391
        mX2 = event.getX(index) - mMoveX;
392
        mY2 = event.getY(index) + mMoveY;
393
        }
394
      }
395

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

    
398
    private void prepareUp2(MotionEvent event)
399
      {
400
      int index = event.getActionIndex();
401

    
402
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
403
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
404
      }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
409
      {
410
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
411
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
412

    
413
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
414
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
415

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

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

    
439
    private void actionDown(float x, float y, int mode)
440
      {
441
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
442
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
443

    
444
      setUpDragOrRotate(true,mX,mY,mode);
445
      }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

    
449
    private void actionUp()
450
      {
451
      if( mContinuingRotation )
452
        {
453
        finishRotation();
454
        }
455

    
456
      if( mLastCubitColor>=0 )
457
        {
458
        mPreRender.setTextureMap( mLastCubit, 4, mLastCubitColor );
459
        mLastCubitColor = -1;
460
        }
461
      }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

    
465
    private void actionDown2(float x1, float y1, float x2, float y2)
466
      {
467
      mRotAngle = getAngle(x1,-y1, x2,-y2);
468
      mInitDistance = -1;
469

    
470
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
471
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
472

    
473
      if( mBeginningRotation )
474
        {
475
        mContinuingRotation = false;
476
        mBeginningRotation  = false;
477
        mDragging           = true;
478
        }
479
      else if( mContinuingRotation )
480
        {
481
        finishRotation();
482
        }
483
      }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

    
487
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
488
      {
489
      if( p1isUp )
490
        {
491
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
492
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
493
        }
494
      if( p2isUp )
495
        {
496
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
497
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
498
        }
499
      }
500

    
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502

    
503
    void setMovement(Movement movement)
504
      {
505
      mMovement = movement;
506
      }
507

    
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509
// INTERNAL API (for AutomaticControl)
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511

    
512
    public ObjectPreRender getPreRender()
513
      {
514
      return mPreRender;
515
      }
516

    
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518

    
519
    public ObjectLibInterface getInterface()
520
      {
521
      return mInterface;
522
      }
523

    
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525

    
526
    public static void setIconMode(boolean mode)
527
      {
528
      mForcedIconMode = mode;
529
      }
530

    
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532

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

    
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539
// PUBLIC API
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541

    
542
    public ObjectControl(Activity act, ObjectLibInterface actioner)
543
      {
544
      mIsAutomatic = false;
545

    
546
      mLastCubitColor = -1;
547
      mCurrRotSpeed   = 0.0f;
548

    
549
      mLastX = new float[NUM_SPEED_PROBES];
550
      mLastY = new float[NUM_SPEED_PROBES];
551
      mLastT = new long[NUM_SPEED_PROBES];
552
      mFirstIndex =0;
553
      mLastIndex  =0;
554

    
555
      DisplayMetrics dm = new DisplayMetrics();
556
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
557

    
558
      mDensity = dm.densityDpi;
559

    
560
      mPreRender = new ObjectPreRender(act,this,actioner);
561
      mInterface = actioner;
562
      }
563

    
564
///////////////////////////////////////////////////////////////////////////////////////////////////
565

    
566
    public TwistyObjectNode getNode()
567
      {
568
      return mObjectNode;
569
      }
570

    
571
///////////////////////////////////////////////////////////////////////////////////////////////////
572

    
573
    public void createNode(int width, int height)
574
      {
575
      if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
576
      }
577

    
578
///////////////////////////////////////////////////////////////////////////////////////////////////
579

    
580
    public void setScreenSize(int width, int height)
581
      {
582
      mScreenWidth = width;
583
      mScreenHeight= height;
584
      mScreenMin   = Math.min(width,height);
585

    
586
      mPreRender.setScreenSize();
587
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
588
      }
589

    
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591

    
592
    public void setMove(int xmove, int ymove)
593
      {
594
      mMoveX = xmove;
595
      mMoveY = ymove;
596

    
597
      mPreRender.setMove(xmove,ymove);
598
      }
599

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

    
602
    public void onPause()
603
      {
604
      BlockController.onPause();
605
      }
606

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

    
609
    public void onResume()
610
      {
611
      mPointer1 = INVALID_POINTER_ID;
612
      mPointer2 = INVALID_POINTER_ID;
613

    
614
      unlock();
615

    
616
      BlockController.onResume();
617
      }
618

    
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620

    
621
    public void rotateNow(Static4D quat)
622
      {
623
      mTemp.set(quat);
624
      mQuat.set(mTemp);
625
      }
626

    
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628

    
629
    public void scaleNow(float scale)
630
      {
631
      mPreRender.getObject().setObjectRatioNow(scale,mObjectNode.getScale(), mObjectNode.getMinSize() );
632
      }
633

    
634
///////////////////////////////////////////////////////////////////////////////////////////////////
635

    
636
    public void setQuat()
637
      {
638
      mQuat.set(mTemp);
639
      }
640

    
641
///////////////////////////////////////////////////////////////////////////////////////////////////
642

    
643
    public Static4D getQuat()
644
      {
645
      return mQuat;
646
      }
647

    
648
///////////////////////////////////////////////////////////////////////////////////////////////////
649

    
650
    public void preRender()
651
      {
652
      mPreRender.preRender();
653
      }
654

    
655
///////////////////////////////////////////////////////////////////////////////////////////////////
656

    
657
    public void blockEverything(int place)
658
      {
659
      setLock(true);
660
      mPreRender.blockEverything(place);
661
      }
662

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

    
665
    public void blockTouch(int place)
666
      {
667
      setLock(true);
668
      mPreRender.blockTouch(place);
669
      }
670

    
671
///////////////////////////////////////////////////////////////////////////////////////////////////
672

    
673
    public void unblockEverything()
674
      {
675
      unsetLock();
676
      mPreRender.unblockEverything();
677
      }
678

    
679
///////////////////////////////////////////////////////////////////////////////////////////////////
680

    
681
    public void unblockTouch()
682
      {
683
      unsetLock();
684
      mPreRender.unblockTouch();
685
      }
686

    
687
///////////////////////////////////////////////////////////////////////////////////////////////////
688

    
689
    public void unblockUI()
690
      {
691
      mPreRender.unblockUI();
692
      }
693

    
694
///////////////////////////////////////////////////////////////////////////////////////////////////
695

    
696
    public boolean isTouchBlocked()
697
      {
698
      return mPreRender.isTouchBlocked();
699
      }
700

    
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702

    
703
    public boolean isUINotBlocked()
704
      {
705
      return mPreRender.isUINotBlocked();
706
      }
707

    
708
///////////////////////////////////////////////////////////////////////////////////////////////////
709

    
710
    public void initializeObject(int[][] moves)
711
      {
712
      mPreRender.initializeObject(moves);
713
      }
714

    
715
///////////////////////////////////////////////////////////////////////////////////////////////////
716

    
717
    public void changeObject(int ordinal, InputStream jsonStream, InputStream meshStream)
718
      {
719
      mPreRender.changeObject(ordinal, jsonStream, meshStream);
720
      }
721

    
722
///////////////////////////////////////////////////////////////////////////////////////////////////
723

    
724
    public void changeIfDifferent(int ordinal, InputStream jsonStream, InputStream meshStream)
725
      {
726
      TwistyObject object = mPreRender.getObject();
727
      ObjectType old = object==null ? null : object.getObjectType();
728

    
729
      if( old==null || old.ordinal() != ordinal )
730
        {
731
        mPreRender.changeObject(ordinal, jsonStream, meshStream);
732
        }
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/18)