Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 2832c2fa

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.main;
11

    
12
import java.io.InputStream;
13

    
14
import android.app.Activity;
15
import android.content.SharedPreferences;
16
import android.util.DisplayMetrics;
17
import android.view.MotionEvent;
18

    
19
import org.distorted.library.main.QuatHelper;
20
import org.distorted.library.type.Static4D;
21

    
22
import org.distorted.objectlib.helpers.BlockController;
23
import org.distorted.objectlib.helpers.MovesFinished;
24
import org.distorted.objectlib.helpers.ObjectLibInterface;
25
import org.distorted.objectlib.touchcontrol.TouchControl;
26
import org.distorted.objectlib.touchcontrol.TouchControlShapeChanging;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class ObjectControl
31
{
32
    public static final int MAX_MOVING_PARTS = 242; // Gigaminx
33
    public static final int MAX_QUATS = 60;         // Gigaminx: 60 quats group.
34

    
35
    public static final int NUM_SPEED_PROBES = 10;
36
    public static final int INVALID_POINTER_ID = -1;
37

    
38
    public static final int MODE_ROTATE  = 0;
39
    public static final int MODE_DRAG    = 1;
40
    public static final int MODE_REPLACE = 2;
41
    public static final int MODE_NOTHING = 3;
42

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

    
49
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
50

    
51
    private final ObjectLibInterface mInterface;
52
    private final ObjectPreRender mPreRender;
53
    private TouchControl mTouchControl;
54
    private TwistyObjectNode mObjectNode;
55
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
56
    private int mScreenWidth, mScreenHeight, mScalingSize;
57
    private float mMoveX, mMoveY;
58
    private int mLastMode;
59

    
60
    private float mRotAngle, mInitDistance;
61
    private float mStartRotX, mStartRotY;
62
    private float mRotationFactor;
63
    private int mCurrentAxis, mCurrentRow;
64
    private float mCurrentAngle, mCurrRotSpeed;
65
    private final float[] mLastX;
66
    private final float[] mLastY;
67
    private final long[] mLastT;
68
    private int mFirstIndex, mLastIndex;
69
    private final int mDensity;
70

    
71
    private int mPointer1, mPointer2;
72
    private float mX1, mY1, mX2, mY2, mX, mY;
73
    private final boolean mIsAutomatic;
74

    
75
    private boolean mIsLocked, mRemLocked;
76
    private final int[] mBuffer;
77
    private final float[] mAxis;
78
    private int mMeshState, mIconMode;
79
    private boolean mRotateOnCreation;
80
    private final Static4D mQuat,mTemp;
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
    private void addSpeedProbe(float x, float y)
85
      {
86
      long currTime = System.currentTimeMillis();
87
      boolean theSame = mLastIndex==mFirstIndex;
88

    
89
      mLastIndex++;
90
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
91

    
92
      mLastT[mLastIndex] = currTime;
93
      mLastX[mLastIndex] = x;
94
      mLastY[mLastIndex] = y;
95

    
96
      if( mLastIndex==mFirstIndex)
97
        {
98
        mFirstIndex++;
99
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
100
        }
101

    
102
      if( theSame )
103
        {
104
        mLastT[mFirstIndex] = currTime;
105
        mLastX[mFirstIndex] = x;
106
        mLastY[mFirstIndex] = y;
107
        }
108
      }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
    private void computeCurrentSpeedInInchesPerSecond()
113
      {
114
      long firstTime = mLastT[mFirstIndex];
115
      long lastTime  = mLastT[mLastIndex];
116
      float fX = mLastX[mFirstIndex];
117
      float fY = mLastY[mFirstIndex];
118
      float lX = mLastX[mLastIndex];
119
      float lY = mLastY[mLastIndex];
120

    
121
      long timeDiff = lastTime-firstTime;
122

    
123
      mLastIndex = 0;
124
      mFirstIndex= 0;
125

    
126
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX-lX,fY-lY)/timeDiff : 0;
127
      }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
    private float retFingerDragDistanceInInches(float xd, float yd)
132
      {
133
      float xDist = mScreenWidth*xd;
134
      float yDist = mScreenHeight*yd;
135
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
136

    
137
      return distInPixels/mDensity;
138
      }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
    private void replaceMode(boolean down)
143
      {
144
      mBeginningRotation= false;
145

    
146
      if( down )
147
        {
148
        int cubit = mTouchControl.getTouchedCubit();
149
        int face  = mTouchControl.getTouchedCubitFace();
150
        mInterface.onReplaceModeDown(cubit,face);
151
        }
152
      }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
    private void setUpDragOrRotate(boolean down, float x, float y)
157
      {
158
      if( mLastMode==MODE_DRAG )
159
        {
160
        mDragging           = true;
161
        mBeginningRotation  = false;
162
        mContinuingRotation = false;
163
        }
164
      else
165
        {
166
        CAMERA_POINT.set2( mObjectNode.getCameraDist() );
167
        Static4D touchPoint = new Static4D(x, y, 0, 0);
168
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
169
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
170

    
171
        if( mTouchControl!=null && mTouchControl.objectTouched(rotatedTouchPoint,rotatedCamera) )
172
          {
173
          mDragging           = false;
174
          mContinuingRotation = false;
175

    
176
               if( mLastMode==MODE_ROTATE  ) mBeginningRotation = !mPreRender.isRotationBlocked();
177
          else if( mLastMode==MODE_REPLACE ) replaceMode(down);
178
          }
179
        else
180
          {
181
          mDragging           = (!mIsLocked || mIsAutomatic);
182
          mBeginningRotation  = false;
183
          mContinuingRotation = false;
184
          if( !mDragging ) mInterface.failedToDrag();
185
          }
186
        }
187
      }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
    private void drag(float x, float y)
192
      {
193
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
194
        {
195
        float x2 = (mX2 - mScreenWidth*0.5f)/ mScalingSize;
196
        float y2 = (mScreenHeight*0.5f - mY2)/ mScalingSize;
197

    
198
        float angleNow = getAngle(x,y,x2,y2);
199
        float angleDiff = angleNow-mRotAngle;
200
        float sinA =-(float)Math.sin(angleDiff);
201
        float cosA = (float)Math.cos(angleDiff);
202

    
203
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
204
        mTemp.set(dragQuat);
205

    
206
        mRotAngle = angleNow;
207

    
208
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
209
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
210
        mInitDistance = distNow;
211
        TwistyObject object = mPreRender.getObject();
212
        if( object!=null )
213
          {
214
          object.setObjectRatio(distQuot, mScalingSize );
215
          float ratio = object.getObjectRatio();
216
          if( mLastMode==MODE_REPLACE ) mTouchControl.setObjectRatio(ratio);
217
          }
218
        }
219
      else
220
        {
221
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
222
        mTemp.set(dragQuat);
223
        }
224

    
225
      mPreRender.setQuatOnNextRender();
226
      mX = x;
227
      mY = y;
228
      }
229

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
    private void finishRotation()
233
      {
234
      TwistyObject object = mPreRender.getObject();
235
      int[][] angles = object.getBasicAngles();
236

    
237
      if( mCurrentAxis<angles.length && mCurrentRow<angles[mCurrentAxis].length )
238
        {
239
        computeCurrentSpeedInInchesPerSecond();
240
        int basic = angles[mCurrentAxis][mCurrentRow];
241
        int angle = object.computeNearestAngle(basic,mCurrentAngle, mCurrRotSpeed);
242
        mPreRender.finishRotation(angle);
243
        mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
244

    
245
        if( angle!=0 )
246
          {
247
          int realAngle = (angle*basic)/360;
248
          mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
249
          }
250

    
251
        mContinuingRotation = false;
252
        mBeginningRotation  = false;
253
        mDragging           = true;
254
        }
255
      }
256

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

    
259
    private void continueRotation(float x, float y)
260
      {
261
      float dx = x-mStartRotX;
262
      float dy = y-mStartRotY;
263
      float alpha = dx*mAxis[0] + dy*mAxis[1];
264
      float x2 = dx - alpha*mAxis[0];
265
      float y2 = dy - alpha*mAxis[1];
266

    
267
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
268

    
269
      // we have the length of 1D vector 'angle', now the direction:
270
      float tmp = mAxis[1]==0 ? -mAxis[0]*y2 : mAxis[1]*x2;
271

    
272
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
273
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
274
      mPreRender.getObject().continueRotation(mCurrentAngle);
275

    
276
      addSpeedProbe(x2,y2);
277
      }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

    
281
    private void beginRotation(float x, float y)
282
      {
283
      mStartRotX = x;
284
      mStartRotY = y;
285

    
286
      TwistyObject object = mPreRender.getObject();
287
      int[] numLayers = object.getNumLayers();
288

    
289
      Static4D touchPoint = new Static4D(x, y, 0, 0);
290
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
291
      mTouchControl.newRotation(mBuffer,rotatedTouchPoint,mQuat);
292

    
293
      mCurrentAxis = mBuffer[0];
294
      mCurrentRow  = mBuffer[1];
295

    
296
      mTouchControl.getCastedRotAxis(mAxis,mQuat,mCurrentAxis);
297
      mRotationFactor = mTouchControl.returnRotationFactor(numLayers,mCurrentRow);
298

    
299
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
300

    
301
      mInterface.onBeginRotation();
302

    
303
      addSpeedProbe(x,y);
304

    
305
      mBeginningRotation = false;
306
      mContinuingRotation= true;
307
      }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
    private float getAngle(float x1, float y1, float x2, float y2)
312
      {
313
      return (float) Math.atan2(y1-y2, x1-x2);
314
      }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
    private void prepareDown(MotionEvent event)
319
      {
320
      mPointer1 = event.getPointerId(0);
321
      mX1 = event.getX() - mMoveX;
322
      mY1 = event.getY() + mMoveY;
323
      mPointer2 = INVALID_POINTER_ID;
324
      }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
    private void prepareMove(MotionEvent event)
329
      {
330
      int index1 = event.findPointerIndex(mPointer1);
331

    
332
      if( index1>=0 )
333
        {
334
        mX1 = event.getX(index1) - mMoveX;
335
        mY1 = event.getY(index1) + mMoveY;
336
        }
337

    
338
      int index2 = event.findPointerIndex(mPointer2);
339

    
340
      if( index2>=0 )
341
        {
342
        mX2 = event.getX(index2) - mMoveX;
343
        mY2 = event.getY(index2) + mMoveY;
344
        }
345
      }
346

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

    
349
    private void prepareUp(MotionEvent event)
350
      {
351
      mPointer1 = INVALID_POINTER_ID;
352
      mPointer2 = INVALID_POINTER_ID;
353
      }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
    private void prepareDown2(MotionEvent event)
358
      {
359
      int index = event.getActionIndex();
360

    
361
      if( mPointer1==INVALID_POINTER_ID )
362
        {
363
        mPointer1 = event.getPointerId(index);
364
        mX1 = event.getX(index) - mMoveX;
365
        mY1 = event.getY(index) + mMoveY;
366
        }
367
      else if( mPointer2==INVALID_POINTER_ID )
368
        {
369
        mPointer2 = event.getPointerId(index);
370
        mX2 = event.getX(index) - mMoveX;
371
        mY2 = event.getY(index) + mMoveY;
372
        }
373
      }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

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

    
381
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
382
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
383
      }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
    private void actionMove(float x1, float y1, float x2, float y2)
388
      {
389
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
390
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
391

    
392
      float x = (pX - mScreenWidth*0.5f)/ mScalingSize;
393
      float y = (mScreenHeight*0.5f -pY)/ mScalingSize;
394

    
395
      if( mBeginningRotation )
396
        {
397
        if( retFingerDragDistanceInInches(mX-x,mY-y) > ROTATION_SENSITIVITY )
398
          {
399
          beginRotation(x,y);
400
          }
401
        }
402
      else if( mContinuingRotation )
403
        {
404
        continueRotation(x,y);
405
        }
406
      else if( mDragging )
407
        {
408
        drag(x,y);
409
        }
410
      else
411
        {
412
        setUpDragOrRotate(false,x,y);
413
        }
414
      }
415

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

    
418
    private void actionDown(float x, float y)
419
      {
420
      mX = (x -  mScreenWidth*0.5f)/ mScalingSize;
421
      mY = (mScreenHeight*0.5f - y)/ mScalingSize;
422

    
423
      setUpDragOrRotate(true,mX,mY);
424
      }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

    
428
    private void actionUp()
429
      {
430
      if( mContinuingRotation )
431
        {
432
        finishRotation();
433
        }
434

    
435
      if( mLastMode==MODE_REPLACE ) mInterface.onReplaceModeUp();
436
      }
437

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439

    
440
    private void actionDown2(float x1, float y1, float x2, float y2)
441
      {
442
      mRotAngle = getAngle(x1,-y1, x2,-y2);
443
      mInitDistance = -1;
444

    
445
      mX = (x1 - mScreenWidth*0.5f )/ mScalingSize;
446
      mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
447

    
448
      if( mBeginningRotation )
449
        {
450
        mContinuingRotation = false;
451
        mBeginningRotation  = false;
452
        mDragging           = true;
453
        }
454
      else if( mContinuingRotation )
455
        {
456
        finishRotation();
457
        }
458
      }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
463
      {
464
      if( p1isUp )
465
        {
466
        mX = (x2 -  mScreenWidth*0.5f)/ mScalingSize;
467
        mY = (mScreenHeight*0.5f - y2)/ mScalingSize;
468
        }
469
      if( p2isUp )
470
        {
471
        mX = (x1 -  mScreenWidth*0.5f)/ mScalingSize;
472
        mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
473
        }
474
      }
475

    
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

    
478
    int getScalingSize()
479
      {
480
      return mScalingSize;
481
      }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
    void setTouchControl(TwistyObject object)
486
      {
487
      if( mLastMode!=MODE_REPLACE ) mTouchControl = object.getTouchControl();
488
      else                          mTouchControl = new TouchControlShapeChanging(object);
489
      }
490

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

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

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

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

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

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

    
515
      mBuffer = new int[2];
516
      mAxis   = new float[2];
517

    
518
      mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
519
      mTemp= new Static4D(0,0,0,1);
520

    
521
      mCurrRotSpeed= 0.0f;
522
      mLastMode    = -1;
523
      mRotateOnCreation = false;
524

    
525
      mLastX = new float[NUM_SPEED_PROBES];
526
      mLastY = new float[NUM_SPEED_PROBES];
527
      mLastT = new long[NUM_SPEED_PROBES];
528
      mFirstIndex= 0;
529
      mLastIndex = 0;
530
      mMeshState =-1;
531
      mIconMode  =-1;
532

    
533
      DisplayMetrics dm = new DisplayMetrics();
534
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
535

    
536
      mDensity = dm.densityDpi;
537

    
538
      mPreRender = new ObjectPreRender(act,this,actioner);
539
      mInterface = actioner;
540
      }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543

    
544
    public void setRotateOnCreation(boolean rotate)
545
      {
546
      mRotateOnCreation = rotate;
547
      }
548

    
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550

    
551
    public boolean getRotateOnCreation()
552
      {
553
      return mRotateOnCreation;
554
      }
555

    
556
///////////////////////////////////////////////////////////////////////////////////////////////////
557

    
558
    public TwistyObjectNode getNode()
559
      {
560
      return mObjectNode;
561
      }
562

    
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564

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

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

    
572
    public void setScreenSizeAndScaling(int width, int height, int scaling)
573
      {
574
      mScreenWidth = width;
575
      mScreenHeight= height;
576
      mScalingSize = scaling;
577

    
578
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
579

    
580
      TwistyObject object = mPreRender.getObject();
581

    
582
      if( object!=null )
583
        {
584
        object.setTexture();
585
        object.setNodeSize(mScalingSize);
586
        }
587
      }
588

    
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590

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

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

    
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600

    
601
    public void setObjectScale(float scale)
602
      {
603
      mPreRender.setScale(scale);
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,mScalingSize );
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 blockTouch(int place)
664
      {
665
      setLock(true);
666
      mPreRender.blockRotation(place);
667
      }
668

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

    
671
    public void unblockRotation()
672
      {
673
      unsetLock();
674
      mPreRender.unblockRotation();
675
      }
676

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

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

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

    
686
    public boolean isScramblingAndSolvingNotBlocked()
687
      {
688
      return mPreRender.isScramblingAndSolvingNotBlocked();
689
      }
690

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

    
693
    public void initializeObject(int[][] moves)
694
      {
695
      mPreRender.initializeObject(moves);
696
      }
697

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

    
700
    public void changeObject(int ordinal, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
701
      {
702
      mPreRender.changeObject(ordinal, meshState, iconMode, jsonStream, meshStream);
703
      }
704

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

    
707
    public void changeIfDifferent(int ordinal, String newName, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
708
      {
709
      TwistyObject object = mPreRender.getObject();
710
      String oldName = object==null ? "" : object.getShortName();
711

    
712
      if( !oldName.equals(newName) || mMeshState!=meshState || mIconMode!=iconMode )
713
        {
714
        mMeshState = meshState;
715
        mIconMode  = iconMode;
716
        mPreRender.changeObject(ordinal, meshState, iconMode, jsonStream, meshStream);
717
        }
718
      }
719

    
720
///////////////////////////////////////////////////////////////////////////////////////////////////
721
// if one or more fingers currently touch the screen, and we just pressed the 'scramble' button, do
722
// not scramble - otherwise a kind of a cheat is possible where user touches the screen, starts
723
// scrambling, then lifts the finger and the act of lifting screws the scrambling - no further
724
// scrambles take any effect!
725

    
726
    public boolean scrambleObject(int num)
727
      {
728
      if( !mBeginningRotation && !mContinuingRotation )
729
        {
730
        return mPreRender.scrambleObject(num);
731
        }
732
      return false;
733
      }
734

    
735
///////////////////////////////////////////////////////////////////////////////////////////////////
736
// ditto
737

    
738
    public boolean fastScrambleObject(int duration, int num)
739
      {
740
      if( !mBeginningRotation && !mContinuingRotation )
741
        {
742
        return mPreRender.fastScrambleObject(duration,num);
743
        }
744
      return false;
745
      }
746

    
747
///////////////////////////////////////////////////////////////////////////////////////////////////
748

    
749
    public void presentObject(int num, int duration)
750
      {
751
      mPreRender.presentObject(num,duration);
752
      }
753

    
754
///////////////////////////////////////////////////////////////////////////////////////////////////
755

    
756
    public void solveObject()
757
      {
758
      mPreRender.solveObject();
759
      }
760

    
761
///////////////////////////////////////////////////////////////////////////////////////////////////
762

    
763
    public void solveOnly()
764
      {
765
      mPreRender.solveOnly();
766
      }
767

    
768
///////////////////////////////////////////////////////////////////////////////////////////////////
769

    
770
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
771
      {
772
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
773
      }
774

    
775
///////////////////////////////////////////////////////////////////////////////////////////////////
776

    
777
    public void resetAllTextureMaps()
778
      {
779
      mPreRender.resetAllTextureMaps();
780
      }
781

    
782
///////////////////////////////////////////////////////////////////////////////////////////////////
783

    
784
    public TwistyObject getObject()
785
      {
786
      return mPreRender.getObject();
787
      }
788

    
789
///////////////////////////////////////////////////////////////////////////////////////////////////
790

    
791
    public void savePreferences(SharedPreferences.Editor editor)
792
      {
793
      mPreRender.savePreferences(editor);
794
      }
795

    
796
///////////////////////////////////////////////////////////////////////////////////////////////////
797

    
798
    public void restorePreferences(SharedPreferences preferences)
799
      {
800
      mPreRender.restorePreferences(preferences);
801
      }
802

    
803
///////////////////////////////////////////////////////////////////////////////////////////////////
804

    
805
    public boolean retLocked()
806
      {
807
      return mIsLocked;
808
      }
809

    
810
///////////////////////////////////////////////////////////////////////////////////////////////////
811

    
812
    public void toggleLock()
813
      {
814
      mIsLocked = !mIsLocked;
815
      }
816

    
817
///////////////////////////////////////////////////////////////////////////////////////////////////
818

    
819
    public void unlock()
820
      {
821
      mIsLocked = false;
822
      }
823

    
824
///////////////////////////////////////////////////////////////////////////////////////////////////
825

    
826
    public void setLock(boolean value)
827
      {
828
      mRemLocked = mIsLocked;
829
      mIsLocked = value;
830
      }
831

    
832
///////////////////////////////////////////////////////////////////////////////////////////////////
833

    
834
    public void unsetLock()
835
      {
836
      mIsLocked = mRemLocked;
837
      }
838

    
839
///////////////////////////////////////////////////////////////////////////////////////////////////
840

    
841
    public void setTextureMap(int cubit, int face, int newColor)
842
      {
843
      mPreRender.setTextureMap(cubit,face,newColor);
844
      }
845

    
846
///////////////////////////////////////////////////////////////////////////////////////////////////
847

    
848
    public boolean onTouchEvent(MotionEvent event, int mode)
849
      {
850
      if( mode!=MODE_NOTHING )
851
        {
852
        if( mObjectNode==null ) return true;
853

    
854
        int action = event.getActionMasked();
855

    
856
        if( mode!=mLastMode )
857
          {
858
          TwistyObject object = getObject();
859

    
860
          if( object!=null )
861
            {
862
            mLastMode = mode;
863
            setTouchControl(object);
864
            }
865
          else return true;
866
          }
867

    
868
        switch(action)
869
          {
870
          case MotionEvent.ACTION_DOWN        : prepareDown(event);
871
                                                actionDown(mX1, mY1);
872
                                                break;
873
          case MotionEvent.ACTION_MOVE        : prepareMove(event);
874
                                                actionMove(mX1, mY1, mX2, mY2);
875
                                                break;
876
          case MotionEvent.ACTION_UP          : prepareUp(event);
877
                                                actionUp();
878
                                                break;
879
          case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
880
                                                actionDown2(mX1, mY1, mX2, mY2);
881
                                                break;
882
          case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
883
                                                boolean p1isUp = mPointer1==INVALID_POINTER_ID;
884
                                                boolean p2isUp = mPointer2==INVALID_POINTER_ID;
885
                                                actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
886
                                                break;
887
          }
888
        }
889

    
890
      return true;
891
      }
892
}
893

    
(3-3/9)