Project

General

Profile

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

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

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 static org.distorted.objectlib.helpers.OperatingSystemInterface.*;
13

    
14
import android.content.SharedPreferences;
15

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

    
19
import org.distorted.objectlib.helpers.BlockController;
20
import org.distorted.objectlib.helpers.MovesFinished;
21
import org.distorted.objectlib.helpers.ObjectLibInterface;
22
import org.distorted.objectlib.helpers.OperatingSystemInterface;
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

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

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

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

    
48
    private final ObjectLibInterface mInterface;
49
    private final OperatingSystemInterface mOS;
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 float mX1, mY1, mX2, mY2, mX, mY;
70
    private final boolean mIsAutomatic;
71

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

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

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

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

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

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

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

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

    
118
      long timeDiff = lastTime-firstTime;
119

    
120
      mLastIndex = 0;
121
      mFirstIndex= 0;
122

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

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

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

    
134
      return distInPixels/mDensity;
135
      }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

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

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

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

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

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

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

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
    private void drag(float x, float y)
189
      {
190
      if( mOS.isFirstPressed() && mOS.isSecondPressed() )
191
        {
192
        float x2 = (mX2 - mScreenWidth*0.5f)/ mScalingSize;
193
        float y2 = (mScreenHeight*0.5f - mY2)/ mScalingSize;
194

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

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

    
203
        mRotAngle = angleNow;
204

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

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

    
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

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

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

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

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

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

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

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

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

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

    
273
      addSpeedProbe(x2,y2);
274
      }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

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

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

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

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

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

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

    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

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

    
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

    
314
    private void prepareDown()
315
      {
316
      mOS.pressFirst();
317
      mOS.unpressSecond();
318

    
319
      mX1 = mOS.getFirstX() - mMoveX;
320
      mY1 = mOS.getFirstY() + mMoveY;
321
      }
322

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

    
325
    private void prepareMove()
326
      {
327
      if( mOS.isFirstPressed() )
328
        {
329
        mX1 = mOS.getFirstX() - mMoveX;
330
        mY1 = mOS.getFirstY() + mMoveY;
331
        }
332

    
333
      if( mOS.isSecondPressed() )
334
        {
335
        mX2 = mOS.getSecondX() - mMoveX;
336
        mY2 = mOS.getSecondY() + mMoveY;
337
        }
338
      }
339

    
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341

    
342
    private void prepareUp()
343
      {
344
      mOS.unpressFirst();
345
      mOS.unpressSecond();
346
      }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
    private void prepareDown2()
351
      {
352
      if( !mOS.isFirstPressed() )
353
        {
354
        mOS.pressFirst();
355
        mX1 = mOS.getFirstX() - mMoveX;
356
        mY1 = mOS.getFirstY() + mMoveY;
357
        }
358
      else if( !mOS.isSecondPressed() )
359
        {
360
        mOS.pressSecond();
361
        mX2 = mOS.getSecondX() - mMoveX;
362
        mY2 = mOS.getSecondY() + mMoveY;
363
        }
364
      }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
    private void prepareUp2()
369
      {
370
      mOS.upOneOfThem();
371
      }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
    private void actionMove(float x1, float y1, float x2, float y2)
376
      {
377
      float pX,pY;
378

    
379
      if( mOS.isFirstPressed() ) { pX = x1; pY=y1; }
380
      else                       { pX = x2; pY=y2; }
381

    
382
      float x = (pX - mScreenWidth*0.5f)/ mScalingSize;
383
      float y = (mScreenHeight*0.5f -pY)/ mScalingSize;
384

    
385
      if( mBeginningRotation )
386
        {
387
        if( retFingerDragDistanceInInches(mX-x,mY-y) > ROTATION_SENSITIVITY )
388
          {
389
          beginRotation(x,y);
390
          }
391
        }
392
      else if( mContinuingRotation )
393
        {
394
        continueRotation(x,y);
395
        }
396
      else if( mDragging )
397
        {
398
        drag(x,y);
399
        }
400
      else
401
        {
402
        setUpDragOrRotate(false,x,y);
403
        }
404
      }
405

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

    
408
    private void actionDown(float x, float y)
409
      {
410
      mX = (x -  mScreenWidth*0.5f)/ mScalingSize;
411
      mY = (mScreenHeight*0.5f - y)/ mScalingSize;
412

    
413
      setUpDragOrRotate(true,mX,mY);
414
      }
415

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

    
418
    private void actionUp()
419
      {
420
      if( mContinuingRotation )
421
        {
422
        finishRotation();
423
        }
424

    
425
      if( mLastMode==MODE_REPLACE ) mInterface.onReplaceModeUp();
426
      }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

    
430
    private void actionDown2(float x1, float y1, float x2, float y2)
431
      {
432
      mRotAngle = getAngle(x1,-y1, x2,-y2);
433
      mInitDistance = -1;
434

    
435
      mX = (x1 - mScreenWidth*0.5f )/ mScalingSize;
436
      mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
437

    
438
      if( mBeginningRotation )
439
        {
440
        mContinuingRotation = false;
441
        mBeginningRotation  = false;
442
        mDragging           = true;
443
        }
444
      else if( mContinuingRotation )
445
        {
446
        finishRotation();
447
        }
448
      }
449

    
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451

    
452
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
453
      {
454
      if( p1isUp )
455
        {
456
        mX = (x2 -  mScreenWidth*0.5f)/ mScalingSize;
457
        mY = (mScreenHeight*0.5f - y2)/ mScalingSize;
458
        }
459
      if( p2isUp )
460
        {
461
        mX = (x1 -  mScreenWidth*0.5f)/ mScalingSize;
462
        mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
463
        }
464
      }
465

    
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467

    
468
    int getScalingSize()
469
      {
470
      return mScalingSize;
471
      }
472

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

    
475
    void setTouchControl(TwistyObject object)
476
      {
477
      if( mLastMode!=MODE_REPLACE ) mTouchControl = object.getTouchControl();
478
      else                          mTouchControl = new TouchControlShapeChanging(object);
479
      }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482
// INTERNAL API (for AutomaticControl)
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
    public ObjectPreRender getPreRender()
486
      {
487
      return mPreRender;
488
      }
489

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491

    
492
    public ObjectLibInterface getInterface()
493
      {
494
      return mInterface;
495
      }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498
// PUBLIC API
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
    public ObjectControl(ObjectLibInterface actioner, OperatingSystemInterface os)
502
      {
503
      mIsAutomatic = false;
504

    
505
      mBuffer = new int[2];
506
      mAxis   = new float[2];
507

    
508
      mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
509
      mTemp= new Static4D(0,0,0,1);
510

    
511
      mCurrRotSpeed= 0.0f;
512
      mLastMode    = -1;
513
      mRotateOnCreation = false;
514

    
515
      mLastX = new float[NUM_SPEED_PROBES];
516
      mLastY = new float[NUM_SPEED_PROBES];
517
      mLastT = new long[NUM_SPEED_PROBES];
518
      mFirstIndex= 0;
519
      mLastIndex = 0;
520
      mMeshState =-1;
521
      mIconMode  =-1;
522

    
523
      mInterface = actioner;
524
      mOS = os;
525

    
526
      mDensity = mOS.getScreenDensity();
527
      mPreRender = new ObjectPreRender(this,actioner);
528
      }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531

    
532
    public void setRotateOnCreation(boolean rotate)
533
      {
534
      mRotateOnCreation = rotate;
535
      }
536

    
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538

    
539
    public boolean getRotateOnCreation()
540
      {
541
      return mRotateOnCreation;
542
      }
543

    
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545

    
546
    public TwistyObjectNode getNode()
547
      {
548
      return mObjectNode;
549
      }
550

    
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552

    
553
    public void createNode(int width, int height)
554
      {
555
      if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
556
      }
557

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

    
560
    public void setScreenSizeAndScaling(int width, int height, int scaling)
561
      {
562
      mScreenWidth = width;
563
      mScreenHeight= height;
564
      mScalingSize = scaling;
565

    
566
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
567

    
568
      TwistyObject object = mPreRender.getObject();
569

    
570
      if( object!=null )
571
        {
572
        object.setTexture();
573
        object.setNodeSize(mScalingSize);
574
        }
575
      }
576

    
577
///////////////////////////////////////////////////////////////////////////////////////////////////
578

    
579
    public void setObjectMove(int xmove, int ymove)
580
      {
581
      mMoveX = xmove;
582
      mMoveY = ymove;
583

    
584
      mPreRender.setMove(xmove,ymove);
585
      }
586

    
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588

    
589
    public void setObjectScale(float scale)
590
      {
591
      mPreRender.setScale(scale);
592
      }
593

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

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

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

    
603
    public void onResume()
604
      {
605
      mOS.unpressFirst();
606
      mOS.unpressSecond();
607

    
608
      unlock();
609

    
610
      BlockController.onResume();
611
      }
612

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

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

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

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

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

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

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

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

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

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

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

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

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

    
659
    public void unblockRotation()
660
      {
661
      unsetLock();
662
      mPreRender.unblockRotation();
663
      }
664

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

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

    
672
///////////////////////////////////////////////////////////////////////////////////////////////////
673

    
674
    public boolean isScramblingAndSolvingNotBlocked()
675
      {
676
      return mPreRender.isScramblingAndSolvingNotBlocked();
677
      }
678

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

    
681
    public void initializeObject(int[][] moves)
682
      {
683
      mPreRender.initializeObject(moves);
684
      }
685

    
686
///////////////////////////////////////////////////////////////////////////////////////////////////
687

    
688
    public void changeObject(int ordinal, int meshState, int iconMode, InitAssets asset)
689
      {
690
      mPreRender.changeObject(ordinal, meshState, iconMode, asset);
691
      }
692

    
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694

    
695
    public void changeIfDifferent(int ordinal, String newName, int meshState, int iconMode, InitAssets asset)
696
      {
697
      TwistyObject object = mPreRender.getObject();
698
      String oldName = object==null ? "" : object.getShortName();
699

    
700
      if( !oldName.equals(newName) || mMeshState!=meshState || mIconMode!=iconMode )
701
        {
702
        mMeshState = meshState;
703
        mIconMode  = iconMode;
704
        mPreRender.changeObject(ordinal, meshState, iconMode, asset);
705
        }
706
      }
707

    
708
///////////////////////////////////////////////////////////////////////////////////////////////////
709
// if one or more fingers currently touch the screen, and we just pressed the 'scramble' button, do
710
// not scramble - otherwise a kind of a cheat is possible where user touches the screen, starts
711
// scrambling, then lifts the finger and the act of lifting screws the scrambling - no further
712
// scrambles take any effect!
713

    
714
    public boolean scrambleObject(int num)
715
      {
716
      if( !mBeginningRotation && !mContinuingRotation )
717
        {
718
        return mPreRender.scrambleObject(num);
719
        }
720
      return false;
721
      }
722

    
723
///////////////////////////////////////////////////////////////////////////////////////////////////
724
// ditto
725

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

    
735
///////////////////////////////////////////////////////////////////////////////////////////////////
736

    
737
    public void presentObject(int num, int duration)
738
      {
739
      mPreRender.presentObject(num,duration);
740
      }
741

    
742
///////////////////////////////////////////////////////////////////////////////////////////////////
743

    
744
    public void solveObject()
745
      {
746
      mPreRender.solveObject();
747
      }
748

    
749
///////////////////////////////////////////////////////////////////////////////////////////////////
750

    
751
    public void solveOnly()
752
      {
753
      mPreRender.solveOnly();
754
      }
755

    
756
///////////////////////////////////////////////////////////////////////////////////////////////////
757

    
758
    public void resetTextureMapsEffect(int duration)
759
      {
760
      mPreRender.resetTextureMapsEffect(duration);
761
      }
762

    
763
///////////////////////////////////////////////////////////////////////////////////////////////////
764

    
765
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
766
      {
767
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
768
      }
769

    
770
///////////////////////////////////////////////////////////////////////////////////////////////////
771

    
772
    public void resetAllTextureMaps()
773
      {
774
      mPreRender.resetAllTextureMaps();
775
      }
776

    
777
///////////////////////////////////////////////////////////////////////////////////////////////////
778

    
779
    public TwistyObject getObject()
780
      {
781
      return mPreRender.getObject();
782
      }
783

    
784
///////////////////////////////////////////////////////////////////////////////////////////////////
785

    
786
    public void savePreferences(SharedPreferences.Editor editor)
787
      {
788
      mPreRender.savePreferences(editor);
789
      }
790

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

    
793
    public void restorePreferences(SharedPreferences preferences)
794
      {
795
      mPreRender.restorePreferences(preferences);
796
      }
797

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

    
800
    public boolean retLocked()
801
      {
802
      return mIsLocked;
803
      }
804

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

    
807
    public void toggleLock()
808
      {
809
      mIsLocked = !mIsLocked;
810
      }
811

    
812
///////////////////////////////////////////////////////////////////////////////////////////////////
813

    
814
    public void unlock()
815
      {
816
      mIsLocked = false;
817
      }
818

    
819
///////////////////////////////////////////////////////////////////////////////////////////////////
820

    
821
    public void setLock(boolean value)
822
      {
823
      mRemLocked = mIsLocked;
824
      mIsLocked = value;
825
      }
826

    
827
///////////////////////////////////////////////////////////////////////////////////////////////////
828

    
829
    public void unsetLock()
830
      {
831
      mIsLocked = mRemLocked;
832
      }
833

    
834
///////////////////////////////////////////////////////////////////////////////////////////////////
835

    
836
    public void setTextureMap(int cubit, int face, int newColor)
837
      {
838
      mPreRender.setTextureMap(cubit,face,newColor);
839
      }
840

    
841
///////////////////////////////////////////////////////////////////////////////////////////////////
842

    
843
    public boolean onTouchEvent(int mode)
844
      {
845
      if( mode!=MODE_NOTHING )
846
        {
847
        if( mObjectNode==null ) return true;
848

    
849
        if( mode!=mLastMode )
850
          {
851
          TwistyObject object = getObject();
852

    
853
          if( object!=null )
854
            {
855
            mLastMode = mode;
856
            setTouchControl(object);
857
            }
858
          else return true;
859
          }
860

    
861
        int action = mOS.getAction();
862

    
863
        switch(action)
864
          {
865
          case ACTION_DOWN_1: prepareDown();
866
                              actionDown(mX1, mY1);
867
                              break;
868
          case ACTION_MOVE  : prepareMove();
869
                              actionMove(mX1, mY1, mX2, mY2);
870
                              break;
871
          case ACTION_UP_1  : prepareUp();
872
                              actionUp();
873
                              break;
874
          case ACTION_DOWN_2: prepareDown2();
875
                              actionDown2(mX1, mY1, mX2, mY2);
876
                              break;
877
          case ACTION_UP_2  : prepareUp2();
878
                              boolean p1isUp = !mOS.isFirstPressed();
879
                              boolean p2isUp = !mOS.isSecondPressed();
880
                              actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
881
                              break;
882
          }
883
        }
884

    
885
      return true;
886
      }
887
}
888

    
(3-3/11)