Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 97a6aa87

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,fY,lX,lY)/timeDiff : 0;
135
      }
136

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

    
139
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
140
      {
141
      float xDist = mScreenWidth*(xFrom-xTo);
142
      float yDist = mScreenHeight*(yFrom-yTo);
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

    
244
        int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
245
        mPreRender.finishRotation(angle);
246
        mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
247

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

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

    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

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

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

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

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

    
280
      addSpeedProbe(x2,y2);
281
      }
282

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

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

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

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

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

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

    
303
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
304

    
305
      mInterface.onBeginRotation();
306

    
307
      addSpeedProbe(x,y);
308

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

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

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

    
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

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

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

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

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

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

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

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

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

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

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

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

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

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

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

    
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390

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

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

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

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

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

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

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

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

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

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

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

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

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

    
464
///////////////////////////////////////////////////////////////////////////////////////////////////
465

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

    
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

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

    
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521

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

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

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

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

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

    
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545
// PUBLIC API
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547

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

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

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

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

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

    
570
      mDensity = dm.densityDpi;
571

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

    
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577

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

    
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584

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

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

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

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

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

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

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

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

    
614
      TwistyObject object = mPreRender.getObject();
615

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

    
623
///////////////////////////////////////////////////////////////////////////////////////////////////
624

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

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

    
633
///////////////////////////////////////////////////////////////////////////////////////////////////
634

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

    
640
///////////////////////////////////////////////////////////////////////////////////////////////////
641

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

    
647
///////////////////////////////////////////////////////////////////////////////////////////////////
648

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

    
654
      unlock();
655

    
656
      BlockController.onResume();
657
      }
658

    
659
///////////////////////////////////////////////////////////////////////////////////////////////////
660

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

    
667
///////////////////////////////////////////////////////////////////////////////////////////////////
668

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

    
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675

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

    
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682

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

    
688
///////////////////////////////////////////////////////////////////////////////////////////////////
689

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

    
695
///////////////////////////////////////////////////////////////////////////////////////////////////
696

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

    
703
///////////////////////////////////////////////////////////////////////////////////////////////////
704

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

    
711
///////////////////////////////////////////////////////////////////////////////////////////////////
712

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

    
719
///////////////////////////////////////////////////////////////////////////////////////////////////
720

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

    
727
///////////////////////////////////////////////////////////////////////////////////////////////////
728

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

    
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735

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

    
741
///////////////////////////////////////////////////////////////////////////////////////////////////
742

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

    
748
///////////////////////////////////////////////////////////////////////////////////////////////////
749

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

    
755
///////////////////////////////////////////////////////////////////////////////////////////////////
756

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

    
762
///////////////////////////////////////////////////////////////////////////////////////////////////
763

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
826
///////////////////////////////////////////////////////////////////////////////////////////////////
827

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

    
833
///////////////////////////////////////////////////////////////////////////////////////////////////
834

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

    
840
///////////////////////////////////////////////////////////////////////////////////////////////////
841

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

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

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

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

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

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

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

    
869
///////////////////////////////////////////////////////////////////////////////////////////////////
870

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

    
876
///////////////////////////////////////////////////////////////////////////////////////////////////
877

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

    
883
///////////////////////////////////////////////////////////////////////////////////////////////////
884

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

    
889
      int action = event.getActionMasked();
890

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

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

    
918
      return true;
919
      }
920
}
921

    
(2-2/12)