Project

General

Profile

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

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

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 android.app.Activity;
13
import android.content.SharedPreferences;
14
import android.util.DisplayMetrics;
15
import android.view.MotionEvent;
16

    
17
import org.distorted.library.main.QuatHelper;
18
import org.distorted.library.type.Static4D;
19

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

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

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

    
33
    public static final int NUM_SPEED_PROBES = 10;
34
    public static final int INVALID_POINTER_ID = -1;
35

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

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

    
47
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
48

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

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

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

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

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

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

    
87
      mLastIndex++;
88
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
89

    
90
      mLastT[mLastIndex] = currTime;
91
      mLastX[mLastIndex] = x;
92
      mLastY[mLastIndex] = y;
93

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

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

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

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

    
119
      long timeDiff = lastTime-firstTime;
120

    
121
      mLastIndex = 0;
122
      mFirstIndex= 0;
123

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

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

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

    
135
      return distInPixels/mDensity;
136
      }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
    private void replaceMode(boolean down)
141
      {
142
      mBeginningRotation= false;
143

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

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

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

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

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

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

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

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

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

    
204
        mRotAngle = angleNow;
205

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

    
223
      mPreRender.setQuatOnNextRender();
224
      mX = x;
225
      mY = y;
226
      }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

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

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

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

    
249
        mContinuingRotation = false;
250
        mBeginningRotation  = false;
251
        mDragging           = true;
252
        }
253
      }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

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

    
265
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
266

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

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

    
274
      addSpeedProbe(x2,y2);
275
      }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

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

    
284
      TwistyObject object = mPreRender.getObject();
285
      int[] numLayers = object.getNumLayers();
286
      Static4D touchPoint = new Static4D(x, y, 0, 0);
287
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
288

    
289
      mTouchControl.newRotation(mBuffer,rotatedTouchPoint,mQuat);
290

    
291
      mCurrentAxis = mBuffer[0];
292
      mCurrentRow  = mBuffer[1];
293

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

    
297
      if( object.beginNewRotation( mCurrentAxis, mCurrentRow ) )
298
        {
299
        mInterface.onBeginRotation();
300
        addSpeedProbe(x,y);
301
        mBeginningRotation = false;
302
        mContinuingRotation= true;
303
        }
304
      }
305

    
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307

    
308
    private float getAngle(float x1, float y1, float x2, float y2)
309
      {
310
      return (float) Math.atan2(y1-y2, x1-x2);
311
      }
312

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

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

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

    
325
    private void prepareMove(MotionEvent event)
326
      {
327
      int index1 = event.findPointerIndex(mPointer1);
328

    
329
      if( index1>=0 )
330
        {
331
        mX1 = event.getX(index1) - mMoveX;
332
        mY1 = event.getY(index1) + mMoveY;
333
        }
334

    
335
      int index2 = event.findPointerIndex(mPointer2);
336

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

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

    
346
    private void prepareUp(MotionEvent event)
347
      {
348
      mPointer1 = INVALID_POINTER_ID;
349
      mPointer2 = INVALID_POINTER_ID;
350
      }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
    private void prepareDown2(MotionEvent event)
355
      {
356
      int index = event.getActionIndex();
357

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

    
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

    
374
    private void prepareUp2(MotionEvent event)
375
      {
376
      int index = event.getActionIndex();
377

    
378
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
379
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
380
      }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
    private void actionMove(float x1, float y1, float x2, float y2)
385
      {
386
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
387
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
388

    
389
      float x = (pX - mScreenWidth*0.5f)/ mScalingSize;
390
      float y = (mScreenHeight*0.5f -pY)/ mScalingSize;
391

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

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

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

    
420
      setUpDragOrRotate(true,mX,mY);
421
      }
422

    
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424

    
425
    private void actionUp()
426
      {
427
      if( mContinuingRotation )
428
        {
429
        finishRotation();
430
        }
431

    
432
      if( mLastMode==MODE_REPLACE ) mInterface.onReplaceModeUp();
433
      }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
    private void actionDown2(float x1, float y1, float x2, float y2)
438
      {
439
      mRotAngle = getAngle(x1,-y1, x2,-y2);
440
      mInitDistance = -1;
441

    
442
      mX = (x1 - mScreenWidth*0.5f )/ mScalingSize;
443
      mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
444

    
445
      if( mBeginningRotation )
446
        {
447
        mContinuingRotation = false;
448
        mBeginningRotation  = false;
449
        mDragging           = true;
450
        }
451
      else if( mContinuingRotation )
452
        {
453
        finishRotation();
454
        }
455
      }
456

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

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

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

    
475
    int getScalingSize()
476
      {
477
      return mScalingSize;
478
      }
479

    
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

    
482
    void setTouchControl(TwistyObject object)
483
      {
484
      if( mLastMode!=MODE_REPLACE ) mTouchControl = object.getTouchControl();
485
      else                          mTouchControl = new TouchControlShapeChanging(object);
486
      }
487

    
488
///////////////////////////////////////////////////////////////////////////////////////////////////
489
// INTERNAL API (for AutomaticControl)
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491

    
492
    public ObjectPreRender getPreRender()
493
      {
494
      return mPreRender;
495
      }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
    public ObjectLibInterface getInterface()
500
      {
501
      return mInterface;
502
      }
503

    
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505
// PUBLIC API
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507

    
508
    public ObjectControl(Activity act, ObjectLibInterface actioner)
509
      {
510
      mIsAutomatic = false;
511

    
512
      mBuffer = new int[2];
513
      mAxis   = new float[2];
514

    
515
      mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
516
      mTemp= new Static4D(0,0,0,1);
517

    
518
      mCurrRotSpeed= 0.0f;
519
      mLastMode    = -1;
520
      mRotateOnCreation = false;
521

    
522
      mLastX = new float[NUM_SPEED_PROBES];
523
      mLastY = new float[NUM_SPEED_PROBES];
524
      mLastT = new long[NUM_SPEED_PROBES];
525
      mFirstIndex= 0;
526
      mLastIndex = 0;
527
      mMeshState =-1;
528
      mIconMode  =-1;
529

    
530
      DisplayMetrics dm = new DisplayMetrics();
531
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
532

    
533
      mDensity = dm.densityDpi;
534

    
535
      mPreRender = new ObjectPreRender(act,this,actioner);
536
      mInterface = actioner;
537
      }
538

    
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540

    
541
    public void setRotateOnCreation(boolean rotate)
542
      {
543
      mRotateOnCreation = rotate;
544
      }
545

    
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547

    
548
    public boolean getRotateOnCreation()
549
      {
550
      return mRotateOnCreation;
551
      }
552

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

    
555
    public TwistyObjectNode getNode()
556
      {
557
      return mObjectNode;
558
      }
559

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

    
562
    public void createNode(int width, int height)
563
      {
564
      if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
565
      }
566

    
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568

    
569
    public void setScreenSizeAndScaling(int width, int height, int scaling)
570
      {
571
      mScreenWidth = width;
572
      mScreenHeight= height;
573
      mScalingSize = scaling;
574

    
575
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
576

    
577
      TwistyObject object = mPreRender.getObject();
578

    
579
      if( object!=null )
580
        {
581
        object.setTexture();
582
        object.setNodeSize(mScalingSize);
583
        }
584
      }
585

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

    
588
    public void setObjectMove(int xmove, int ymove)
589
      {
590
      mMoveX = xmove;
591
      mMoveY = ymove;
592

    
593
      mPreRender.setMove(xmove,ymove);
594
      }
595

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

    
598
    public void setObjectScale(float scale)
599
      {
600
      mPreRender.setScale(scale);
601
      }
602

    
603
///////////////////////////////////////////////////////////////////////////////////////////////////
604

    
605
    public void onPause()
606
      {
607
      BlockController.onPause();
608
      }
609

    
610
///////////////////////////////////////////////////////////////////////////////////////////////////
611

    
612
    public void onResume()
613
      {
614
      mPointer1 = INVALID_POINTER_ID;
615
      mPointer2 = INVALID_POINTER_ID;
616

    
617
      unlock();
618

    
619
      BlockController.onResume();
620
      }
621

    
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623

    
624
    public void rotateNow(Static4D quat)
625
      {
626
      mTemp.set(quat);
627
      mQuat.set(mTemp);
628
      }
629

    
630
///////////////////////////////////////////////////////////////////////////////////////////////////
631

    
632
    public void scaleNow(float scale)
633
      {
634
      mPreRender.getObject().setObjectRatioNow(scale,mScalingSize );
635
      }
636

    
637
///////////////////////////////////////////////////////////////////////////////////////////////////
638

    
639
    public void setQuat()
640
      {
641
      mQuat.set(mTemp);
642
      }
643

    
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645

    
646
    public Static4D getQuat()
647
      {
648
      return mQuat;
649
      }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652

    
653
    public void preRender()
654
      {
655
      mPreRender.preRender();
656
      }
657

    
658
///////////////////////////////////////////////////////////////////////////////////////////////////
659

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

    
666
///////////////////////////////////////////////////////////////////////////////////////////////////
667

    
668
    public void unblockRotation()
669
      {
670
      unsetLock();
671
      mPreRender.unblockRotation();
672
      }
673

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

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

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

    
683
    public boolean isScramblingAndSolvingNotBlocked()
684
      {
685
      return mPreRender.isScramblingAndSolvingNotBlocked();
686
      }
687

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

    
690
    public void initializeObject(int[][] moves)
691
      {
692
      mPreRender.initializeObject(moves);
693
      }
694

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

    
697
    public void changeObject(int ordinal, int meshState, int iconMode, InitAssets asset)
698
      {
699
      mPreRender.changeObject(ordinal, meshState, iconMode, asset);
700
      }
701

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

    
704
    public void changeIfDifferent(int ordinal, String newName, int meshState, int iconMode, InitAssets asset)
705
      {
706
      TwistyObject object = mPreRender.getObject();
707
      String oldName = object==null ? "" : object.getShortName();
708

    
709
      if( !oldName.equals(newName) || mMeshState!=meshState || mIconMode!=iconMode )
710
        {
711
        mMeshState = meshState;
712
        mIconMode  = iconMode;
713
        mPreRender.changeObject(ordinal, meshState, iconMode, asset);
714
        }
715
      }
716

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

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

    
732
///////////////////////////////////////////////////////////////////////////////////////////////////
733
// ditto
734

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

    
744
///////////////////////////////////////////////////////////////////////////////////////////////////
745

    
746
    public void presentObject(int num, int duration)
747
      {
748
      mPreRender.presentObject(num,duration);
749
      }
750

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

    
753
    public void solveObject()
754
      {
755
      mPreRender.solveObject();
756
      }
757

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

    
760
    public void solveOnly()
761
      {
762
      mPreRender.solveOnly();
763
      }
764

    
765
///////////////////////////////////////////////////////////////////////////////////////////////////
766

    
767
    public void resetTextureMapsEffect(int duration)
768
      {
769
      mPreRender.resetTextureMapsEffect(duration);
770
      }
771

    
772
///////////////////////////////////////////////////////////////////////////////////////////////////
773

    
774
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
775
      {
776
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
777
      }
778

    
779
///////////////////////////////////////////////////////////////////////////////////////////////////
780

    
781
    public void resetAllTextureMaps()
782
      {
783
      mPreRender.resetAllTextureMaps();
784
      }
785

    
786
///////////////////////////////////////////////////////////////////////////////////////////////////
787

    
788
    public TwistyObject getObject()
789
      {
790
      return mPreRender.getObject();
791
      }
792

    
793
///////////////////////////////////////////////////////////////////////////////////////////////////
794

    
795
    public void savePreferences(SharedPreferences.Editor editor)
796
      {
797
      mPreRender.savePreferences(editor);
798
      }
799

    
800
///////////////////////////////////////////////////////////////////////////////////////////////////
801

    
802
    public void restorePreferences(SharedPreferences preferences)
803
      {
804
      mPreRender.restorePreferences(preferences);
805
      }
806

    
807
///////////////////////////////////////////////////////////////////////////////////////////////////
808

    
809
    public boolean retLocked()
810
      {
811
      return mIsLocked;
812
      }
813

    
814
///////////////////////////////////////////////////////////////////////////////////////////////////
815

    
816
    public void toggleLock()
817
      {
818
      mIsLocked = !mIsLocked;
819
      }
820

    
821
///////////////////////////////////////////////////////////////////////////////////////////////////
822

    
823
    public void unlock()
824
      {
825
      mIsLocked = false;
826
      }
827

    
828
///////////////////////////////////////////////////////////////////////////////////////////////////
829

    
830
    public void setLock(boolean value)
831
      {
832
      mRemLocked = mIsLocked;
833
      mIsLocked = value;
834
      }
835

    
836
///////////////////////////////////////////////////////////////////////////////////////////////////
837

    
838
    public void unsetLock()
839
      {
840
      mIsLocked = mRemLocked;
841
      }
842

    
843
///////////////////////////////////////////////////////////////////////////////////////////////////
844

    
845
    public void setTextureMap(int cubit, int face, int newColor)
846
      {
847
      mPreRender.setTextureMap(cubit,face,newColor);
848
      }
849

    
850
///////////////////////////////////////////////////////////////////////////////////////////////////
851

    
852
    public boolean onTouchEvent(MotionEvent event, int mode)
853
      {
854
      if( mode!=MODE_NOTHING )
855
        {
856
        if( mObjectNode==null ) return true;
857

    
858
        if( mode!=mLastMode )
859
          {
860
          TwistyObject object = getObject();
861

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

    
870
        int action = event.getActionMasked();
871

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

    
894
      return true;
895
      }
896
}
897

    
(3-3/11)