Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objectlib.main;
21

    
22
import java.io.InputStream;
23

    
24
import android.app.Activity;
25
import android.content.SharedPreferences;
26
import android.util.DisplayMetrics;
27
import android.view.MotionEvent;
28

    
29
import org.distorted.library.main.QuatHelper;
30
import org.distorted.library.type.Static4D;
31

    
32
import org.distorted.objectlib.helpers.BlockController;
33
import org.distorted.objectlib.helpers.MovesFinished;
34
import org.distorted.objectlib.helpers.ObjectLibInterface;
35
import org.distorted.objectlib.touchcontrol.TouchControl;
36
import org.distorted.objectlib.touchcontrol.TouchControlShapeChanging;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class ObjectControl
41
{
42
    public static final int NUM_SPEED_PROBES = 10;
43
    public static final int INVALID_POINTER_ID = -1;
44

    
45
    public static final int MODE_ROTATE  = 0;
46
    public static final int MODE_DRAG    = 1;
47
    public static final int MODE_REPLACE = 2;
48

    
49
    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
50
    // given face by SWIPING_SENSITIVITY/2 degrees.
51
    public final static int SWIPING_SENSITIVITY  = 240;
52
    // Moving the finger by 0.3 of an inch will start a Rotation.
53
    public final static float ROTATION_SENSITIVITY = 0.3f;
54

    
55
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
56

    
57
    private final ObjectLibInterface mInterface;
58
    private final ObjectPreRender mPreRender;
59
    private TouchControl mTouchControl, mTouchControlBackup;
60
    private TwistyObjectNode mObjectNode;
61
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
62
    private int mScreenWidth, mScreenHeight, mScreenMin;
63
    private float mMoveX, mMoveY;
64
    private int mLastMode;
65

    
66
    private float mRotAngle, mInitDistance;
67
    private float mStartRotX, mStartRotY;
68
    private float mRotationFactor;
69
    private int mCurrentAxis, mCurrentRow;
70
    private float mCurrentAngle, mCurrRotSpeed;
71
    private final float[] mLastX;
72
    private final float[] mLastY;
73
    private final long[] mLastT;
74
    private int mFirstIndex, mLastIndex;
75
    private final int mDensity;
76

    
77
    private int mPointer1, mPointer2;
78
    private float mX1, mY1, mX2, mY2, mX, mY;
79
    private final boolean mIsAutomatic;
80

    
81
    private boolean mIsLocked, mRemLocked;
82
    private final int[] mBuffer;
83
    private final float[] mAxis;
84
    private int mMeshState, mIconMode;
85
    private boolean mRotateOnCreation;
86

    
87
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
88
    private static final Static4D mTemp= new Static4D(0,0,0,1);
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
    private void addSpeedProbe(float x, float y)
93
      {
94
      long currTime = System.currentTimeMillis();
95
      boolean theSame = mLastIndex==mFirstIndex;
96

    
97
      mLastIndex++;
98
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
99

    
100
      mLastT[mLastIndex] = currTime;
101
      mLastX[mLastIndex] = x;
102
      mLastY[mLastIndex] = y;
103

    
104
      if( mLastIndex==mFirstIndex)
105
        {
106
        mFirstIndex++;
107
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
108
        }
109

    
110
      if( theSame )
111
        {
112
        mLastT[mFirstIndex] = currTime;
113
        mLastX[mFirstIndex] = x;
114
        mLastY[mFirstIndex] = y;
115
        }
116
      }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
    private void computeCurrentSpeedInInchesPerSecond()
121
      {
122
      long firstTime = mLastT[mFirstIndex];
123
      long lastTime  = mLastT[mLastIndex];
124
      float fX = mLastX[mFirstIndex];
125
      float fY = mLastY[mFirstIndex];
126
      float lX = mLastX[mLastIndex];
127
      float lY = mLastY[mLastIndex];
128

    
129
      long timeDiff = lastTime-firstTime;
130

    
131
      mLastIndex = 0;
132
      mFirstIndex= 0;
133

    
134
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX-lX,fY-lY)/timeDiff : 0;
135
      }
136

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

    
139
    private float retFingerDragDistanceInInches(float xd, float yd)
140
      {
141
      float xDist = mScreenWidth*xd;
142
      float yDist = mScreenHeight*yd;
143
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
144

    
145
      return distInPixels/mDensity;
146
      }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
    private void replaceMode(boolean down)
151
      {
152
      mBeginningRotation= false;
153

    
154
      if( down )
155
        {
156
        int cubit = mTouchControl.getTouchedCubit();
157
        int face  = mTouchControl.getTouchedCubitFace();
158
        mInterface.onReplaceModeDown(cubit,face);
159
        }
160
      }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
    private void setUpDragOrRotate(boolean down, float x, float y)
165
      {
166
      if( mLastMode==MODE_DRAG )
167
        {
168
        mDragging           = true;
169
        mBeginningRotation  = false;
170
        mContinuingRotation = false;
171
        }
172
      else
173
        {
174
        CAMERA_POINT.set2( mObjectNode.getCameraDist() );
175
        Static4D touchPoint = new Static4D(x, y, 0, 0);
176
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
177
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
178

    
179
        if( mTouchControl!=null && mTouchControl.objectTouched(rotatedTouchPoint,rotatedCamera) )
180
          {
181
          mDragging           = false;
182
          mContinuingRotation = false;
183

    
184
               if( mLastMode==MODE_ROTATE  ) mBeginningRotation = !mPreRender.isTouchBlocked();
185
          else if( mLastMode==MODE_REPLACE ) replaceMode(down);
186
          }
187
        else
188
          {
189
          mDragging           = (!mIsLocked || mIsAutomatic);
190
          mBeginningRotation  = false;
191
          mContinuingRotation = false;
192
          if( !mDragging ) mInterface.failedToDrag();
193
          }
194
        }
195
      }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
    private void drag(float x, float y)
200
      {
201
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
202
        {
203
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
204
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
205

    
206
        float angleNow = getAngle(x,y,x2,y2);
207
        float angleDiff = angleNow-mRotAngle;
208
        float sinA =-(float)Math.sin(angleDiff);
209
        float cosA = (float)Math.cos(angleDiff);
210

    
211
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
212
        mTemp.set(dragQuat);
213

    
214
        mRotAngle = angleNow;
215

    
216
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
217
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
218
        mInitDistance = distNow;
219
        TwistyObject object = mPreRender.getObject();
220
        if( object!=null ) object.setObjectRatio(distQuot, mObjectNode.getMinSize() );
221
        }
222
      else
223
        {
224
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
225
        mTemp.set(dragQuat);
226
        }
227

    
228
      mPreRender.setQuatOnNextRender();
229
      mX = x;
230
      mY = y;
231
      }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
    private void finishRotation()
236
      {
237
      TwistyObject object = mPreRender.getObject();
238
      int[][] angles = object.getBasicAngles();
239

    
240
      if( mCurrentAxis<angles.length )
241
        {
242
        computeCurrentSpeedInInchesPerSecond();
243
        int basic = angles[mCurrentAxis][mCurrentRow];
244
        int angle = object.computeNearestAngle(basic,mCurrentAngle, mCurrRotSpeed);
245
        mPreRender.finishRotation(angle);
246
        mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
247

    
248
        if( angle!=0 )
249
          {
250
          int realAngle = (angle*basic)/360;
251
          mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
252
          }
253

    
254
        mContinuingRotation = false;
255
        mBeginningRotation  = false;
256
        mDragging           = true;
257
        }
258
      }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

    
262
    private void continueRotation(float x, float y)
263
      {
264
      float dx = x-mStartRotX;
265
      float dy = y-mStartRotY;
266
      float alpha = dx*mAxis[0] + dy*mAxis[1];
267
      float x2 = dx - alpha*mAxis[0];
268
      float y2 = dy - alpha*mAxis[1];
269

    
270
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
271

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

    
275
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
276
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
277
      mPreRender.getObject().continueRotation(mCurrentAngle);
278

    
279
      addSpeedProbe(x2,y2);
280
      }
281

    
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

    
284
    private void beginRotation(float x, float y)
285
      {
286
      mStartRotX = x;
287
      mStartRotY = y;
288

    
289
      TwistyObject object = mPreRender.getObject();
290
      int[] numLayers = object.getNumLayers();
291

    
292
      Static4D touchPoint = new Static4D(x, y, 0, 0);
293
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
294
      mTouchControl.newRotation(mBuffer,rotatedTouchPoint,mQuat);
295

    
296
      mCurrentAxis = mBuffer[0];
297
      mCurrentRow  = mBuffer[1];
298

    
299
      mTouchControl.getCastedRotAxis(mAxis,mQuat,mCurrentAxis);
300
      mRotationFactor = mTouchControl.returnRotationFactor(numLayers,mCurrentRow);
301

    
302
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
303

    
304
      mInterface.onBeginRotation();
305

    
306
      addSpeedProbe(x,y);
307

    
308
      mBeginningRotation = false;
309
      mContinuingRotation= true;
310
      }
311

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

    
314
    private float getAngle(float x1, float y1, float x2, float y2)
315
      {
316
      return (float) Math.atan2(y1-y2, x1-x2);
317
      }
318

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

    
321
    private void prepareDown(MotionEvent event)
322
      {
323
      mPointer1 = event.getPointerId(0);
324
      mX1 = event.getX() - mMoveX;
325
      mY1 = event.getY() + mMoveY;
326
      mPointer2 = INVALID_POINTER_ID;
327
      }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
    private void prepareMove(MotionEvent event)
332
      {
333
      int index1 = event.findPointerIndex(mPointer1);
334

    
335
      if( index1>=0 )
336
        {
337
        mX1 = event.getX(index1) - mMoveX;
338
        mY1 = event.getY(index1) + mMoveY;
339
        }
340

    
341
      int index2 = event.findPointerIndex(mPointer2);
342

    
343
      if( index2>=0 )
344
        {
345
        mX2 = event.getX(index2) - mMoveX;
346
        mY2 = event.getY(index2) + mMoveY;
347
        }
348
      }
349

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

    
352
    private void prepareUp(MotionEvent event)
353
      {
354
      mPointer1 = INVALID_POINTER_ID;
355
      mPointer2 = INVALID_POINTER_ID;
356
      }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

    
360
    private void prepareDown2(MotionEvent event)
361
      {
362
      int index = event.getActionIndex();
363

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

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
    private void prepareUp2(MotionEvent event)
381
      {
382
      int index = event.getActionIndex();
383

    
384
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
385
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
386
      }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
    private void actionMove(float x1, float y1, float x2, float y2)
391
      {
392
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
393
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
394

    
395
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
396
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
397

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

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

    
421
    private void actionDown(float x, float y)
422
      {
423
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
424
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
425

    
426
      setUpDragOrRotate(true,mX,mY);
427
      }
428

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

    
431
    private void actionUp()
432
      {
433
      if( mContinuingRotation )
434
        {
435
        finishRotation();
436
        }
437

    
438
      if( mLastMode==MODE_REPLACE ) mInterface.onReplaceModeUp();
439
      }
440

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

    
443
    private void actionDown2(float x1, float y1, float x2, float y2)
444
      {
445
      mRotAngle = getAngle(x1,-y1, x2,-y2);
446
      mInitDistance = -1;
447

    
448
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
449
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
450

    
451
      if( mBeginningRotation )
452
        {
453
        mContinuingRotation = false;
454
        mBeginningRotation  = false;
455
        mDragging           = true;
456
        }
457
      else if( mContinuingRotation )
458
        {
459
        finishRotation();
460
        }
461
      }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

    
465
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
466
      {
467
      if( p1isUp )
468
        {
469
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
470
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
471
        }
472
      if( p2isUp )
473
        {
474
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
475
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
476
        }
477
      }
478

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480

    
481
    private void switchTouchControl(int oldMode, int newMode)
482
      {
483
      if( newMode==MODE_REPLACE )
484
        {
485
        if( mTouchControlBackup!=null )
486
          {
487
          TouchControl tmp = mTouchControlBackup;
488
          mTouchControlBackup = mTouchControl;
489
          mTouchControl = tmp;
490
          }
491
        else
492
          {
493
          mTouchControlBackup = mTouchControl;
494
          TwistyObject object = getObject();
495
          mTouchControl = new TouchControlShapeChanging(object);
496
          float ratio = object.getObjectRatio();
497
          mTouchControl.setObjectRatio(ratio);
498
          }
499
        }
500
      if( oldMode==MODE_REPLACE )
501
        {
502
        if( mTouchControlBackup!=null )
503
          {
504
          TouchControl tmp = mTouchControlBackup;
505
          mTouchControlBackup = mTouchControl;
506
          mTouchControl = tmp;
507
          }
508
        else
509
          {
510
          mTouchControlBackup = mTouchControl;
511
          TwistyObject object = getObject();
512
          mTouchControl = object.getTouchControl();
513
          float ratio = object.getObjectRatio();
514
          mTouchControl.setObjectRatio(ratio);
515
          }
516
        }
517
      }
518

    
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520

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

    
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528
// INTERNAL API (for AutomaticControl)
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530

    
531
    public ObjectPreRender getPreRender()
532
      {
533
      return mPreRender;
534
      }
535

    
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537

    
538
    public ObjectLibInterface getInterface()
539
      {
540
      return mInterface;
541
      }
542

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544
// PUBLIC API
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546

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

    
551
      mBuffer = new int[2];
552
      mAxis   = new float[2];
553

    
554
      mCurrRotSpeed= 0.0f;
555
      mLastMode    = -1;
556
      mRotateOnCreation = false;
557

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

    
566
      DisplayMetrics dm = new DisplayMetrics();
567
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
568

    
569
      mDensity = dm.densityDpi;
570

    
571
      mPreRender = new ObjectPreRender(act,this,actioner);
572
      mInterface = actioner;
573
      }
574

    
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576

    
577
    public void setRotateOnCreation(boolean rotate)
578
      {
579
      mRotateOnCreation = rotate;
580
      }
581

    
582
///////////////////////////////////////////////////////////////////////////////////////////////////
583

    
584
    public boolean getRotateOnCreation()
585
      {
586
      return mRotateOnCreation;
587
      }
588

    
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590

    
591
    public TwistyObjectNode getNode()
592
      {
593
      return mObjectNode;
594
      }
595

    
596
///////////////////////////////////////////////////////////////////////////////////////////////////
597

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

    
603
///////////////////////////////////////////////////////////////////////////////////////////////////
604

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

    
611
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
612

    
613
      TwistyObject object = mPreRender.getObject();
614

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

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

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

    
629
      mPreRender.setMove(xmove,ymove);
630
      }
631

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

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

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

    
641
    public void onPause()
642
      {
643
      BlockController.onPause();
644
      }
645

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

    
648
    public void onResume()
649
      {
650
      mPointer1 = INVALID_POINTER_ID;
651
      mPointer2 = INVALID_POINTER_ID;
652

    
653
      unlock();
654

    
655
      BlockController.onResume();
656
      }
657

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

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

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

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

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

    
675
    public void setQuat()
676
      {
677
      mQuat.set(mTemp);
678
      }
679

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

    
682
    public Static4D getQuat()
683
      {
684
      return mQuat;
685
      }
686

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

    
689
    public void preRender()
690
      {
691
      mPreRender.preRender();
692
      }
693

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

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

    
702
///////////////////////////////////////////////////////////////////////////////////////////////////
703

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

    
710
///////////////////////////////////////////////////////////////////////////////////////////////////
711

    
712
    public void unblockEverything()
713
      {
714
      unsetLock();
715
      mPreRender.unblockEverything();
716
      }
717

    
718
///////////////////////////////////////////////////////////////////////////////////////////////////
719

    
720
    public void unblockTouch()
721
      {
722
      unsetLock();
723
      mPreRender.unblockTouch();
724
      }
725

    
726
///////////////////////////////////////////////////////////////////////////////////////////////////
727

    
728
    public void unblockUI()
729
      {
730
      mPreRender.unblockUI();
731
      }
732

    
733
///////////////////////////////////////////////////////////////////////////////////////////////////
734

    
735
    public boolean isTouchBlocked()
736
      {
737
      return mPreRender.isTouchBlocked();
738
      }
739

    
740
///////////////////////////////////////////////////////////////////////////////////////////////////
741

    
742
    public boolean isUINotBlocked()
743
      {
744
      return mPreRender.isUINotBlocked();
745
      }
746

    
747
///////////////////////////////////////////////////////////////////////////////////////////////////
748

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

    
754
///////////////////////////////////////////////////////////////////////////////////////////////////
755

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

    
761
///////////////////////////////////////////////////////////////////////////////////////////////////
762

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

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

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

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

    
790
///////////////////////////////////////////////////////////////////////////////////////////////////
791

    
792
    public void solveObject()
793
      {
794
      mPreRender.solveObject();
795
      }
796

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

    
799
    public void solveOnly()
800
      {
801
      mPreRender.solveOnly();
802
      }
803

    
804
///////////////////////////////////////////////////////////////////////////////////////////////////
805

    
806
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
807
      {
808
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
809
      }
810

    
811
///////////////////////////////////////////////////////////////////////////////////////////////////
812

    
813
    public void resetAllTextureMaps()
814
      {
815
      mPreRender.resetAllTextureMaps();
816
      }
817

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

    
820
    public TwistyObject getObject()
821
      {
822
      return mPreRender.getObject();
823
      }
824

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

    
827
    public void savePreferences(SharedPreferences.Editor editor)
828
      {
829
      mPreRender.savePreferences(editor);
830
      }
831

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

    
834
    public void restorePreferences(SharedPreferences preferences)
835
      {
836
      mPreRender.restorePreferences(preferences);
837
      }
838

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

    
841
    public boolean retLocked()
842
      {
843
      return mIsLocked;
844
      }
845

    
846
///////////////////////////////////////////////////////////////////////////////////////////////////
847

    
848
    public void toggleLock()
849
      {
850
      mIsLocked = !mIsLocked;
851
      }
852

    
853
///////////////////////////////////////////////////////////////////////////////////////////////////
854

    
855
    public void unlock()
856
      {
857
      mIsLocked = false;
858
      }
859

    
860
///////////////////////////////////////////////////////////////////////////////////////////////////
861

    
862
    public void setLock(boolean value)
863
      {
864
      mRemLocked = mIsLocked;
865
      mIsLocked = value;
866
      }
867

    
868
///////////////////////////////////////////////////////////////////////////////////////////////////
869

    
870
    public void unsetLock()
871
      {
872
      mIsLocked = mRemLocked;
873
      }
874

    
875
///////////////////////////////////////////////////////////////////////////////////////////////////
876

    
877
    public void setTextureMap(int cubit, int face, int newColor)
878
      {
879
      mPreRender.setTextureMap(cubit,face,newColor);
880
      }
881

    
882
///////////////////////////////////////////////////////////////////////////////////////////////////
883

    
884
    public boolean onTouchEvent(MotionEvent event, int mode)
885
      {
886
      if( mObjectNode==null ) return true;
887

    
888
      int action = event.getActionMasked();
889

    
890
      if( mode!=mLastMode)
891
        {
892
        switchTouchControl(mLastMode,mode);
893
        mLastMode = mode;
894
        }
895

    
896
      switch(action)
897
         {
898
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
899
                                               actionDown(mX1, mY1);
900
                                               break;
901
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
902
                                               actionMove(mX1, mY1, mX2, mY2);
903
                                               break;
904
         case MotionEvent.ACTION_UP          : prepareUp(event);
905
                                               actionUp();
906
                                               break;
907
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
908
                                               actionDown2(mX1, mY1, mX2, mY2);
909
                                               break;
910
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
911
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
912
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
913
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
914
                                               break;
915
         }
916

    
917
      return true;
918
      }
919
}
920

    
(2-2/12)