Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 4c2c0f44

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
      Static4D touchPoint = new Static4D(x, y, 0, 0);
289
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
290

    
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
      if( object.beginNewRotation( mCurrentAxis, mCurrentRow ) )
300
        {
301
        mInterface.onBeginRotation();
302
        addSpeedProbe(x,y);
303
        mBeginningRotation = false;
304
        mContinuingRotation= true;
305
        }
306
      }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

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

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

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

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

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

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

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

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

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

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

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

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

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

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

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

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

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

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

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

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

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

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

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

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

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

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

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

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

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

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

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

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

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

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

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

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

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

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

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

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

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507
// PUBLIC API
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509

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

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

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

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

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

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

    
535
      mDensity = dm.densityDpi;
536

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

    
541
///////////////////////////////////////////////////////////////////////////////////////////////////
542

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

    
548
///////////////////////////////////////////////////////////////////////////////////////////////////
549

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

    
555
///////////////////////////////////////////////////////////////////////////////////////////////////
556

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

    
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563

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

    
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570

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

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

    
579
      TwistyObject object = mPreRender.getObject();
580

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

    
588
///////////////////////////////////////////////////////////////////////////////////////////////////
589

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

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

    
598
///////////////////////////////////////////////////////////////////////////////////////////////////
599

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

    
605
///////////////////////////////////////////////////////////////////////////////////////////////////
606

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

    
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613

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

    
619
      unlock();
620

    
621
      BlockController.onResume();
622
      }
623

    
624
///////////////////////////////////////////////////////////////////////////////////////////////////
625

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

    
632
///////////////////////////////////////////////////////////////////////////////////////////////////
633

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

    
639
///////////////////////////////////////////////////////////////////////////////////////////////////
640

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

    
646
///////////////////////////////////////////////////////////////////////////////////////////////////
647

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

    
653
///////////////////////////////////////////////////////////////////////////////////////////////////
654

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

    
660
///////////////////////////////////////////////////////////////////////////////////////////////////
661

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

    
668
///////////////////////////////////////////////////////////////////////////////////////////////////
669

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

    
676
///////////////////////////////////////////////////////////////////////////////////////////////////
677

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

    
683
///////////////////////////////////////////////////////////////////////////////////////////////////
684

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

    
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691

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

    
697
///////////////////////////////////////////////////////////////////////////////////////////////////
698

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

    
704
///////////////////////////////////////////////////////////////////////////////////////////////////
705

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

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

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

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

    
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735
// ditto
736

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

    
746
///////////////////////////////////////////////////////////////////////////////////////////////////
747

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

    
753
///////////////////////////////////////////////////////////////////////////////////////////////////
754

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

    
760
///////////////////////////////////////////////////////////////////////////////////////////////////
761

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

    
767
///////////////////////////////////////////////////////////////////////////////////////////////////
768

    
769
    public void resetTextureMapsEffect(int duration)
770
      {
771
      mPreRender.resetTextureMapsEffect(duration);
772
      }
773

    
774
///////////////////////////////////////////////////////////////////////////////////////////////////
775

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

    
781
///////////////////////////////////////////////////////////////////////////////////////////////////
782

    
783
    public void resetAllTextureMaps()
784
      {
785
      mPreRender.resetAllTextureMaps();
786
      }
787

    
788
///////////////////////////////////////////////////////////////////////////////////////////////////
789

    
790
    public TwistyObject getObject()
791
      {
792
      return mPreRender.getObject();
793
      }
794

    
795
///////////////////////////////////////////////////////////////////////////////////////////////////
796

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

    
802
///////////////////////////////////////////////////////////////////////////////////////////////////
803

    
804
    public void restorePreferences(SharedPreferences preferences)
805
      {
806
      mPreRender.restorePreferences(preferences);
807
      }
808

    
809
///////////////////////////////////////////////////////////////////////////////////////////////////
810

    
811
    public boolean retLocked()
812
      {
813
      return mIsLocked;
814
      }
815

    
816
///////////////////////////////////////////////////////////////////////////////////////////////////
817

    
818
    public void toggleLock()
819
      {
820
      mIsLocked = !mIsLocked;
821
      }
822

    
823
///////////////////////////////////////////////////////////////////////////////////////////////////
824

    
825
    public void unlock()
826
      {
827
      mIsLocked = false;
828
      }
829

    
830
///////////////////////////////////////////////////////////////////////////////////////////////////
831

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

    
838
///////////////////////////////////////////////////////////////////////////////////////////////////
839

    
840
    public void unsetLock()
841
      {
842
      mIsLocked = mRemLocked;
843
      }
844

    
845
///////////////////////////////////////////////////////////////////////////////////////////////////
846

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

    
852
///////////////////////////////////////////////////////////////////////////////////////////////////
853

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

    
860
        if( mode!=mLastMode )
861
          {
862
          TwistyObject object = getObject();
863

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

    
872
        int action = event.getActionMasked();
873

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

    
896
      return true;
897
      }
898
}
899

    
(2-2/10)