Project

General

Profile

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

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

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 org.distorted.library.main.QuatHelper;
15
import org.distorted.library.type.Static4D;
16

    
17
import org.distorted.objectlib.effects.BaseEffect;
18
import org.distorted.objectlib.helpers.BlockController;
19
import org.distorted.objectlib.helpers.MovesFinished;
20
import org.distorted.objectlib.helpers.ObjectLibInterface;
21
import org.distorted.objectlib.helpers.OperatingSystemInterface;
22
import org.distorted.objectlib.touchcontrol.TouchControl;
23
import org.distorted.objectlib.touchcontrol.TouchControlShapeChanging;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

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

    
32
    public static final int NUM_SPEED_PROBES = 10;
33

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

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

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

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

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

    
68
    private float mX1, mY1, mX2, mY2, mX, mY;
69
    private final boolean mIsAutomatic;
70

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

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

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

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

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

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

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

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

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

    
117
      long timeDiff = lastTime-firstTime;
118

    
119
      mLastIndex = 0;
120
      mFirstIndex= 0;
121

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

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

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

    
133
      return distInPixels/mDensity;
134
      }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

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

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

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

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

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

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

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

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

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

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

    
202
        mRotAngle = angleNow;
203

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

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

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

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

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

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

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

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

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

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

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

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

    
272
      addSpeedProbe(x2,y2);
273
      }
274

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

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

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

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

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

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

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

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

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

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

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

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

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
    private void prepareMove()
325
      {
326
      int index1 = mOS.getFirstPointerIndex();
327

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

    
334
      int index2 = mOS.getSecondPointerIndex();
335

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

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

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

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

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

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

    
371
    private void prepareUp2()
372
      {
373
      mOS.upOneOfThem();
374
      }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

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

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

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

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

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

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

    
416
      setUpDragOrRotate(true,mX,mY);
417
      }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

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

    
428
      if( mLastMode==MODE_REPLACE ) mInterface.onReplaceModeUp();
429
      }
430

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432

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

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

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

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

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

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470

    
471
    int getScalingSize()
472
      {
473
      return mScalingSize;
474
      }
475

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

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

    
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485
// INTERNAL API (for AutomaticControl)
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487

    
488
    public ObjectPreRender getPreRender()
489
      {
490
      return mPreRender;
491
      }
492

    
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

    
495
    public ObjectLibInterface getInterface()
496
      {
497
      return mInterface;
498
      }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501
// PUBLIC API
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

    
504
    public ObjectControl(OperatingSystemInterface os)
505
      {
506
      mIsAutomatic = false;
507

    
508
      mBuffer = new int[2];
509
      mAxis   = new float[2];
510

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

    
514
      mCurrRotSpeed= 0.0f;
515
      mLastMode    = -1;
516
      mRotateOnCreation = false;
517

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

    
526
      mInterface = os.getInterface();
527
      mOS = os;
528

    
529
      mDensity = mOS.getScreenDensity();
530
      mPreRender = new ObjectPreRender(this,mInterface);
531
      }
532

    
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534

    
535
    public void setRotateOnCreation(boolean rotate)
536
      {
537
      mRotateOnCreation = rotate;
538
      }
539

    
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541

    
542
    public boolean getRotateOnCreation()
543
      {
544
      return mRotateOnCreation;
545
      }
546

    
547
///////////////////////////////////////////////////////////////////////////////////////////////////
548

    
549
    public TwistyObjectNode getNode()
550
      {
551
      return mObjectNode;
552
      }
553

    
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555

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

    
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562

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

    
569
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
570

    
571
      TwistyObject object = mPreRender.getObject();
572

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

    
580
///////////////////////////////////////////////////////////////////////////////////////////////////
581

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

    
587
      mPreRender.setMove(xmove,ymove);
588
      }
589

    
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591

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

    
597
///////////////////////////////////////////////////////////////////////////////////////////////////
598

    
599
    public void onPause()
600
      {
601
      BlockController.onPause();
602
      }
603

    
604
///////////////////////////////////////////////////////////////////////////////////////////////////
605

    
606
    public void onResume()
607
      {
608
      mOS.unpressFirst();
609
      mOS.unpressSecond();
610

    
611
      unlock();
612

    
613
      BlockController.onResume();
614
      }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617

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

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

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

    
631
///////////////////////////////////////////////////////////////////////////////////////////////////
632

    
633
    public void setQuat()
634
      {
635
      mQuat.set(mTemp);
636
      }
637

    
638
///////////////////////////////////////////////////////////////////////////////////////////////////
639

    
640
    public Static4D getQuat()
641
      {
642
      return mQuat;
643
      }
644

    
645
///////////////////////////////////////////////////////////////////////////////////////////////////
646

    
647
    public void preRender()
648
      {
649
      mPreRender.preRender();
650
      }
651

    
652
///////////////////////////////////////////////////////////////////////////////////////////////////
653

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

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

    
662
    public void unblockRotation()
663
      {
664
      unsetLock();
665
      mPreRender.unblockRotation();
666
      }
667

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

    
670
    public void unblockEverything()
671
      {
672
      mPreRender.unblockEverything();
673
      }
674

    
675
///////////////////////////////////////////////////////////////////////////////////////////////////
676

    
677
    public boolean isScramblingAndSolvingNotBlocked()
678
      {
679
      return mPreRender.isScramblingAndSolvingNotBlocked();
680
      }
681

    
682
///////////////////////////////////////////////////////////////////////////////////////////////////
683

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

    
689
///////////////////////////////////////////////////////////////////////////////////////////////////
690

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

    
696
///////////////////////////////////////////////////////////////////////////////////////////////////
697

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

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

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

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

    
726
///////////////////////////////////////////////////////////////////////////////////////////////////
727
// ditto
728

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

    
738
///////////////////////////////////////////////////////////////////////////////////////////////////
739

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

    
745
///////////////////////////////////////////////////////////////////////////////////////////////////
746

    
747
    public void solveObject()
748
      {
749
      mPreRender.solveObject();
750
      }
751

    
752
///////////////////////////////////////////////////////////////////////////////////////////////////
753

    
754
    public void solveOnly()
755
      {
756
      mPreRender.solveOnly();
757
      }
758

    
759
///////////////////////////////////////////////////////////////////////////////////////////////////
760

    
761
    public void resetTextureMapsEffect(int duration)
762
      {
763
      mPreRender.resetTextureMapsEffect(duration);
764
      }
765

    
766
///////////////////////////////////////////////////////////////////////////////////////////////////
767

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

    
773
///////////////////////////////////////////////////////////////////////////////////////////////////
774

    
775
    public void resetAllTextureMaps()
776
      {
777
      mPreRender.resetAllTextureMaps();
778
      }
779

    
780
///////////////////////////////////////////////////////////////////////////////////////////////////
781

    
782
    public TwistyObject getObject()
783
      {
784
      return mPreRender.getObject();
785
      }
786

    
787
///////////////////////////////////////////////////////////////////////////////////////////////////
788

    
789
    public OperatingSystemInterface getOS()
790
      {
791
      return mOS;
792
      }
793

    
794
///////////////////////////////////////////////////////////////////////////////////////////////////
795

    
796
    public void savePreferences()
797
      {
798
      mPreRender.savePreferences(mOS);
799

    
800
      for( int i=0; i< BaseEffect.Type.LENGTH; i++ )
801
        {
802
        BaseEffect.Type.getType(i).savePreferences(mOS);
803
        }
804
      }
805

    
806
///////////////////////////////////////////////////////////////////////////////////////////////////
807

    
808
    public void restorePreferences()
809
      {
810
      mPreRender.restorePreferences(mOS);
811

    
812
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
813
        {
814
        BaseEffect.Type.getType(i).restorePreferences(mOS);
815
        }
816
      }
817

    
818
///////////////////////////////////////////////////////////////////////////////////////////////////
819

    
820
    public boolean retLocked()
821
      {
822
      return mIsLocked;
823
      }
824

    
825
///////////////////////////////////////////////////////////////////////////////////////////////////
826

    
827
    public void toggleLock()
828
      {
829
      mIsLocked = !mIsLocked;
830
      }
831

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

    
834
    public void unlock()
835
      {
836
      mIsLocked = false;
837
      }
838

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

    
841
    public void setLock(boolean value)
842
      {
843
      mRemLocked = mIsLocked;
844
      mIsLocked = value;
845
      }
846

    
847
///////////////////////////////////////////////////////////////////////////////////////////////////
848

    
849
    public void unsetLock()
850
      {
851
      mIsLocked = mRemLocked;
852
      }
853

    
854
///////////////////////////////////////////////////////////////////////////////////////////////////
855

    
856
    public void setTextureMap(int cubit, int face, int newColor)
857
      {
858
      mPreRender.setTextureMap(cubit,face,newColor);
859
      }
860

    
861
///////////////////////////////////////////////////////////////////////////////////////////////////
862

    
863
    public boolean onTouchEvent(int mode)
864
      {
865
      if( mode!=MODE_NOTHING )
866
        {
867
        if( mObjectNode==null ) return true;
868

    
869
        if( mode!=mLastMode )
870
          {
871
          TwistyObject object = getObject();
872

    
873
          if( object!=null )
874
            {
875
            mLastMode = mode;
876
            setTouchControl(object);
877
            }
878
          else return true;
879
          }
880

    
881
        int action = mOS.getAction();
882

    
883
        switch(action)
884
          {
885
          case ACTION_DOWN_1: prepareDown();
886
                              actionDown(mX1, mY1);
887
                              break;
888
          case ACTION_MOVE  : prepareMove();
889
                              actionMove(mX1, mY1, mX2, mY2);
890
                              break;
891
          case ACTION_UP_1  : prepareUp();
892
                              actionUp();
893
                              break;
894
          case ACTION_DOWN_2: prepareDown2();
895
                              actionDown2(mX1, mY1, mX2, mY2);
896
                              break;
897
          case ACTION_UP_2  : prepareUp2();
898
                              boolean p1isUp = !mOS.isFirstPressed();
899
                              boolean p2isUp = !mOS.isSecondPressed();
900
                              actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
901
                              break;
902
          }
903
        }
904

    
905
      return true;
906
      }
907
}
908

    
(3-3/11)