Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 8e66157b

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.effects.BaseEffect;
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.helpers.OperatingSystemInterface;
24
import org.distorted.objectlib.touchcontrol.TouchControl;
25
import org.distorted.objectlib.touchcontrol.TouchControlShapeChanging;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

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

    
34
    public static final int NUM_SPEED_PROBES = 10;
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 OperatingSystemInterface mOS;
51
    private final ObjectPreRender mPreRender;
52
    private TouchControl mTouchControl;
53
    private TwistyObjectNode mObjectNode;
54
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
55
    private int mScreenWidth, mScreenHeight, mScalingSize;
56
    private float mMoveX, mMoveY;
57
    private int mLastMode;
58

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

    
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( mOS.isFirstPressed() && mOS.isSecondPressed() )
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()
316
      {
317
      mOS.pressFirst();
318
      mOS.unpressSecond();
319

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

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

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

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

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

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

    
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350

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

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

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

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

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

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

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

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

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408

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

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

    
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418

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

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

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

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

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

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

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

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

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

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

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

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

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

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

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492

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

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499
// PUBLIC API
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

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

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

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

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

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

    
524
      mInterface = actioner;
525
      mOS = os;
526

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

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

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

    
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539

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

    
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546

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

    
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553

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

    
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560

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

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

    
569
      TwistyObject object = mPreRender.getObject();
570

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

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

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

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

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

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

    
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596

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

    
602
///////////////////////////////////////////////////////////////////////////////////////////////////
603

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

    
609
      unlock();
610

    
611
      BlockController.onResume();
612
      }
613

    
614
///////////////////////////////////////////////////////////////////////////////////////////////////
615

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

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

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

    
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630

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

    
636
///////////////////////////////////////////////////////////////////////////////////////////////////
637

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

    
643
///////////////////////////////////////////////////////////////////////////////////////////////////
644

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

    
650
///////////////////////////////////////////////////////////////////////////////////////////////////
651

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

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

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

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

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

    
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674

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

    
680
///////////////////////////////////////////////////////////////////////////////////////////////////
681

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

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

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

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

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

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

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

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

    
724
///////////////////////////////////////////////////////////////////////////////////////////////////
725
// ditto
726

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

    
736
///////////////////////////////////////////////////////////////////////////////////////////////////
737

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

    
743
///////////////////////////////////////////////////////////////////////////////////////////////////
744

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

    
750
///////////////////////////////////////////////////////////////////////////////////////////////////
751

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

    
757
///////////////////////////////////////////////////////////////////////////////////////////////////
758

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

    
764
///////////////////////////////////////////////////////////////////////////////////////////////////
765

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

    
771
///////////////////////////////////////////////////////////////////////////////////////////////////
772

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

    
778
///////////////////////////////////////////////////////////////////////////////////////////////////
779

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

    
785
///////////////////////////////////////////////////////////////////////////////////////////////////
786

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

    
791
      for( int i=0; i< BaseEffect.Type.LENGTH; i++ )
792
        {
793
        BaseEffect.Type.getType(i).savePreferences(editor);
794
        }
795
      }
796

    
797
///////////////////////////////////////////////////////////////////////////////////////////////////
798

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

    
803
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
804
        {
805
        BaseEffect.Type.getType(i).restorePreferences(preferences);
806
        }
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(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 = mOS.getAction();
873

    
874
        switch(action)
875
          {
876
          case ACTION_DOWN_1: prepareDown();
877
                              actionDown(mX1, mY1);
878
                              break;
879
          case ACTION_MOVE  : prepareMove();
880
                              actionMove(mX1, mY1, mX2, mY2);
881
                              break;
882
          case ACTION_UP_1  : prepareUp();
883
                              actionUp();
884
                              break;
885
          case ACTION_DOWN_2: prepareDown2();
886
                              actionDown2(mX1, mY1, mX2, mY2);
887
                              break;
888
          case ACTION_UP_2  : prepareUp2();
889
                              boolean p1isUp = !mOS.isFirstPressed();
890
                              boolean p2isUp = !mOS.isSecondPressed();
891
                              actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
892
                              break;
893
          }
894
        }
895

    
896
      return true;
897
      }
898
}
899

    
(3-3/11)