Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.main;
11

    
12
import java.io.InputStream;
13

    
14
import android.app.Activity;
15
import android.content.SharedPreferences;
16
import android.util.DisplayMetrics;
17
import android.view.MotionEvent;
18

    
19
import org.distorted.library.main.QuatHelper;
20
import org.distorted.library.type.Static4D;
21

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

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

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

    
35
    public static final int NUM_SPEED_PROBES = 10;
36
    public static final int INVALID_POINTER_ID = -1;
37

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

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

    
49
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
50

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

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

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

    
75
    private boolean mIsLocked, mRemLocked;
76
    private final int[] mBuffer;
77
    private final float[] mAxis;
78
    private int mMeshState, mIconMode;
79
    private boolean mRotateOnCreation;
80

    
81
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
82
    private static final Static4D mTemp= new Static4D(0,0,0,1);
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
    private void addSpeedProbe(float x, float y)
87
      {
88
      long currTime = System.currentTimeMillis();
89
      boolean theSame = mLastIndex==mFirstIndex;
90

    
91
      mLastIndex++;
92
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
93

    
94
      mLastT[mLastIndex] = currTime;
95
      mLastX[mLastIndex] = x;
96
      mLastY[mLastIndex] = y;
97

    
98
      if( mLastIndex==mFirstIndex)
99
        {
100
        mFirstIndex++;
101
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
102
        }
103

    
104
      if( theSame )
105
        {
106
        mLastT[mFirstIndex] = currTime;
107
        mLastX[mFirstIndex] = x;
108
        mLastY[mFirstIndex] = y;
109
        }
110
      }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
    private void computeCurrentSpeedInInchesPerSecond()
115
      {
116
      long firstTime = mLastT[mFirstIndex];
117
      long lastTime  = mLastT[mLastIndex];
118
      float fX = mLastX[mFirstIndex];
119
      float fY = mLastY[mFirstIndex];
120
      float lX = mLastX[mLastIndex];
121
      float lY = mLastY[mLastIndex];
122

    
123
      long timeDiff = lastTime-firstTime;
124

    
125
      mLastIndex = 0;
126
      mFirstIndex= 0;
127

    
128
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX-lX,fY-lY)/timeDiff : 0;
129
      }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
    private float retFingerDragDistanceInInches(float xd, float yd)
134
      {
135
      float xDist = mScreenWidth*xd;
136
      float yDist = mScreenHeight*yd;
137
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
138

    
139
      return distInPixels/mDensity;
140
      }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
    private void replaceMode(boolean down)
145
      {
146
      mBeginningRotation= false;
147

    
148
      if( down )
149
        {
150
        int cubit = mTouchControl.getTouchedCubit();
151
        int face  = mTouchControl.getTouchedCubitFace();
152
        mInterface.onReplaceModeDown(cubit,face);
153
        }
154
      }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

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

    
173
        if( mTouchControl!=null && mTouchControl.objectTouched(rotatedTouchPoint,rotatedCamera) )
174
          {
175
          mDragging           = false;
176
          mContinuingRotation = false;
177

    
178
               if( mLastMode==MODE_ROTATE  ) mBeginningRotation = !mPreRender.isTouchBlocked();
179
          else if( mLastMode==MODE_REPLACE ) replaceMode(down);
180
          }
181
        else
182
          {
183
          mDragging           = (!mIsLocked || mIsAutomatic);
184
          mBeginningRotation  = false;
185
          mContinuingRotation = false;
186
          if( !mDragging ) mInterface.failedToDrag();
187
          }
188
        }
189
      }
190

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

    
193
    private void drag(float x, float y)
194
      {
195
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
196
        {
197
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
198
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
199

    
200
        float angleNow = getAngle(x,y,x2,y2);
201
        float angleDiff = angleNow-mRotAngle;
202
        float sinA =-(float)Math.sin(angleDiff);
203
        float cosA = (float)Math.cos(angleDiff);
204

    
205
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
206
        mTemp.set(dragQuat);
207

    
208
        mRotAngle = angleNow;
209

    
210
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
211
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
212
        mInitDistance = distNow;
213
        TwistyObject object = mPreRender.getObject();
214
        if( object!=null ) object.setObjectRatio(distQuot, mObjectNode.getMinSize() );
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

    
286
      Static4D touchPoint = new Static4D(x, y, 0, 0);
287
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
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
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
297

    
298
      mInterface.onBeginRotation();
299

    
300
      addSpeedProbe(x,y);
301

    
302
      mBeginningRotation = false;
303
      mContinuingRotation= true;
304
      }
305

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
475
    private void switchTouchControl(int oldMode, int newMode)
476
      {
477
      if( newMode==MODE_REPLACE )
478
        {
479
        if( mTouchControlBackup!=null )
480
          {
481
          TouchControl tmp = mTouchControlBackup;
482
          mTouchControlBackup = mTouchControl;
483
          mTouchControl = tmp;
484
          }
485
        else
486
          {
487
          TwistyObject object = getObject();
488

    
489
          if( object!=null )
490
            {
491
            mTouchControlBackup = mTouchControl;
492
            mTouchControl = new TouchControlShapeChanging(object);
493
            float ratio = object.getObjectRatio();
494
            mTouchControl.setObjectRatio(ratio);
495
            }
496
          }
497
        }
498
      if( oldMode==MODE_REPLACE )
499
        {
500
        if( mTouchControlBackup!=null )
501
          {
502
          TouchControl tmp = mTouchControlBackup;
503
          mTouchControlBackup = mTouchControl;
504
          mTouchControl = tmp;
505
          }
506
        else
507
          {
508
          TwistyObject object = getObject();
509

    
510
          if( object!=null )
511
            {
512
            mTouchControlBackup = mTouchControl;
513
            mTouchControl = object.getTouchControl();
514
            float ratio = object.getObjectRatio();
515
            mTouchControl.setObjectRatio(ratio);
516
            }
517
          }
518
        }
519
      }
520

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

    
523
    void setTouchControl(TwistyObject object)
524
      {
525
      if( mLastMode!=MODE_REPLACE )  mTouchControl = object.getTouchControl();
526
      else                           mTouchControl = new TouchControlShapeChanging(object);
527
      }
528

    
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530
// INTERNAL API (for AutomaticControl)
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532

    
533
    public ObjectPreRender getPreRender()
534
      {
535
      return mPreRender;
536
      }
537

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

    
540
    public ObjectLibInterface getInterface()
541
      {
542
      return mInterface;
543
      }
544

    
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546
// PUBLIC API
547
///////////////////////////////////////////////////////////////////////////////////////////////////
548

    
549
    public ObjectControl(Activity act, ObjectLibInterface actioner)
550
      {
551
      mIsAutomatic = false;
552

    
553
      mBuffer = new int[2];
554
      mAxis   = new float[2];
555

    
556
      mCurrRotSpeed= 0.0f;
557
      mLastMode    = -1;
558
      mRotateOnCreation = false;
559

    
560
      mLastX = new float[NUM_SPEED_PROBES];
561
      mLastY = new float[NUM_SPEED_PROBES];
562
      mLastT = new long[NUM_SPEED_PROBES];
563
      mFirstIndex= 0;
564
      mLastIndex = 0;
565
      mMeshState =-1;
566
      mIconMode  =-1;
567

    
568
      DisplayMetrics dm = new DisplayMetrics();
569
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
570

    
571
      mDensity = dm.densityDpi;
572

    
573
      mPreRender = new ObjectPreRender(act,this,actioner);
574
      mInterface = actioner;
575
      }
576

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

    
579
    public void setRotateOnCreation(boolean rotate)
580
      {
581
      mRotateOnCreation = rotate;
582
      }
583

    
584
///////////////////////////////////////////////////////////////////////////////////////////////////
585

    
586
    public boolean getRotateOnCreation()
587
      {
588
      return mRotateOnCreation;
589
      }
590

    
591
///////////////////////////////////////////////////////////////////////////////////////////////////
592

    
593
    public TwistyObjectNode getNode()
594
      {
595
      return mObjectNode;
596
      }
597

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

    
600
    public void createNode(int width, int height)
601
      {
602
      if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
603
      }
604

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

    
607
    public void setScreenSize(int width, int height)
608
      {
609
      mScreenWidth = width;
610
      mScreenHeight= height;
611
      mScreenMin   = Math.min(width,height);
612

    
613
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
614

    
615
      TwistyObject object = mPreRender.getObject();
616

    
617
      if( object!=null )
618
        {
619
        object.setTexture();
620
        object.setNodeSize(mScreenMin);
621
        }
622
      }
623

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

    
626
    public void setObjectMove(int xmove, int ymove)
627
      {
628
      mMoveX = xmove;
629
      mMoveY = ymove;
630

    
631
      mPreRender.setMove(xmove,ymove);
632
      }
633

    
634
///////////////////////////////////////////////////////////////////////////////////////////////////
635

    
636
    public void setObjectScale(float scale)
637
      {
638
      mPreRender.setScale(scale);
639
      }
640

    
641
///////////////////////////////////////////////////////////////////////////////////////////////////
642

    
643
    public void onPause()
644
      {
645
      BlockController.onPause();
646
      }
647

    
648
///////////////////////////////////////////////////////////////////////////////////////////////////
649

    
650
    public void onResume()
651
      {
652
      mPointer1 = INVALID_POINTER_ID;
653
      mPointer2 = INVALID_POINTER_ID;
654

    
655
      unlock();
656

    
657
      BlockController.onResume();
658
      }
659

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

    
662
    public void rotateNow(Static4D quat)
663
      {
664
      mTemp.set(quat);
665
      mQuat.set(mTemp);
666
      }
667

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

    
670
    public void scaleNow(float scale)
671
      {
672
      mPreRender.getObject().setObjectRatioNow(scale,mObjectNode.getMinSize() );
673
      }
674

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

    
677
    public void setQuat()
678
      {
679
      mQuat.set(mTemp);
680
      }
681

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

    
684
    public Static4D getQuat()
685
      {
686
      return mQuat;
687
      }
688

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

    
691
    public void preRender()
692
      {
693
      mPreRender.preRender();
694
      }
695

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

    
698
    public void blockEverything(int place)
699
      {
700
      setLock(true);
701
      mPreRender.blockEverything(place);
702
      }
703

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

    
706
    public void blockTouch(int place)
707
      {
708
      setLock(true);
709
      mPreRender.blockTouch(place);
710
      }
711

    
712
///////////////////////////////////////////////////////////////////////////////////////////////////
713

    
714
    public void unblockEverything()
715
      {
716
      unsetLock();
717
      mPreRender.unblockEverything();
718
      }
719

    
720
///////////////////////////////////////////////////////////////////////////////////////////////////
721

    
722
    public void unblockTouch()
723
      {
724
      unsetLock();
725
      mPreRender.unblockTouch();
726
      }
727

    
728
///////////////////////////////////////////////////////////////////////////////////////////////////
729

    
730
    public void unblockUI()
731
      {
732
      mPreRender.unblockUI();
733
      }
734

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

    
737
    public boolean isTouchBlocked()
738
      {
739
      return mPreRender.isTouchBlocked();
740
      }
741

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

    
744
    public boolean isUINotBlocked()
745
      {
746
      return mPreRender.isUINotBlocked();
747
      }
748

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

    
751
    public void initializeObject(int[][] moves)
752
      {
753
      mPreRender.initializeObject(moves);
754
      }
755

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

    
758
    public void changeObject(int ordinal, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
759
      {
760
      mPreRender.changeObject(ordinal, meshState, iconMode, jsonStream, meshStream);
761
      }
762

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

    
765
    public void changeIfDifferent(int ordinal, String oldName, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
766
      {
767
      TwistyObject object = mPreRender.getObject();
768
      String newName = object==null ? "" : object.getShortName();
769

    
770
      if( !oldName.equals(newName) || mMeshState!=meshState || mIconMode!=iconMode )
771
        {
772
        mMeshState = meshState;
773
        mIconMode  = iconMode;
774
        mPreRender.changeObject(ordinal, meshState, iconMode, jsonStream, meshStream);
775
        }
776
      }
777

    
778
///////////////////////////////////////////////////////////////////////////////////////////////////
779
// if one or more fingers currently touch the screen, and we just pressed the 'scramble' button, do
780
// not scramble - otherwise a kind of a cheat is possible where user touches the screen, starts
781
// scrambling, then lifts the finger and the act of lifting screws the scrambling - no further
782
// scrambles take any effect!
783

    
784
    public void scrambleObject(int num)
785
      {
786
      if( !mBeginningRotation && !mContinuingRotation )
787
        {
788
        mPreRender.scrambleObject(num);
789
        }
790
      }
791

    
792
///////////////////////////////////////////////////////////////////////////////////////////////////
793
// ditto
794

    
795
    public void fastScrambleObject(int num)
796
      {
797
      if( !mBeginningRotation && !mContinuingRotation )
798
        {
799
        mPreRender.fastScrambleObject(num);
800
        }
801
      }
802

    
803
///////////////////////////////////////////////////////////////////////////////////////////////////
804

    
805
    public void solveObject()
806
      {
807
      mPreRender.solveObject();
808
      }
809

    
810
///////////////////////////////////////////////////////////////////////////////////////////////////
811

    
812
    public void solveOnly()
813
      {
814
      mPreRender.solveOnly();
815
      }
816

    
817
///////////////////////////////////////////////////////////////////////////////////////////////////
818

    
819
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
820
      {
821
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
822
      }
823

    
824
///////////////////////////////////////////////////////////////////////////////////////////////////
825

    
826
    public void resetAllTextureMaps()
827
      {
828
      mPreRender.resetAllTextureMaps();
829
      }
830

    
831
///////////////////////////////////////////////////////////////////////////////////////////////////
832

    
833
    public TwistyObject getObject()
834
      {
835
      return mPreRender.getObject();
836
      }
837

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

    
840
    public void savePreferences(SharedPreferences.Editor editor)
841
      {
842
      mPreRender.savePreferences(editor);
843
      }
844

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

    
847
    public void restorePreferences(SharedPreferences preferences)
848
      {
849
      mPreRender.restorePreferences(preferences);
850
      }
851

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

    
854
    public boolean retLocked()
855
      {
856
      return mIsLocked;
857
      }
858

    
859
///////////////////////////////////////////////////////////////////////////////////////////////////
860

    
861
    public void toggleLock()
862
      {
863
      mIsLocked = !mIsLocked;
864
      }
865

    
866
///////////////////////////////////////////////////////////////////////////////////////////////////
867

    
868
    public void unlock()
869
      {
870
      mIsLocked = false;
871
      }
872

    
873
///////////////////////////////////////////////////////////////////////////////////////////////////
874

    
875
    public void setLock(boolean value)
876
      {
877
      mRemLocked = mIsLocked;
878
      mIsLocked = value;
879
      }
880

    
881
///////////////////////////////////////////////////////////////////////////////////////////////////
882

    
883
    public void unsetLock()
884
      {
885
      mIsLocked = mRemLocked;
886
      }
887

    
888
///////////////////////////////////////////////////////////////////////////////////////////////////
889

    
890
    public void setTextureMap(int cubit, int face, int newColor)
891
      {
892
      mPreRender.setTextureMap(cubit,face,newColor);
893
      }
894

    
895
///////////////////////////////////////////////////////////////////////////////////////////////////
896

    
897
    public boolean onTouchEvent(MotionEvent event, int mode)
898
      {
899
      if( mode!=MODE_NOTHING )
900
        {
901
        if( mObjectNode==null ) return true;
902

    
903
        int action = event.getActionMasked();
904

    
905
        if( mode!=mLastMode)
906
          {
907
          switchTouchControl(mLastMode,mode);
908
          mLastMode = mode;
909
          }
910

    
911
        switch(action)
912
          {
913
          case MotionEvent.ACTION_DOWN        : prepareDown(event);
914
                                                actionDown(mX1, mY1);
915
                                                break;
916
          case MotionEvent.ACTION_MOVE        : prepareMove(event);
917
                                                actionMove(mX1, mY1, mX2, mY2);
918
                                                break;
919
          case MotionEvent.ACTION_UP          : prepareUp(event);
920
                                                actionUp();
921
                                                break;
922
          case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
923
                                                actionDown2(mX1, mY1, mX2, mY2);
924
                                                break;
925
          case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
926
                                                boolean p1isUp = mPointer1==INVALID_POINTER_ID;
927
                                                boolean p2isUp = mPointer2==INVALID_POINTER_ID;
928
                                                actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
929
                                                break;
930
          }
931
        }
932

    
933
      return true;
934
      }
935
}
936

    
(3-3/13)