Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 3d093961

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.Static2D;
31
import org.distorted.library.type.Static4D;
32

    
33
import org.distorted.objectlib.helpers.BlockController;
34
import org.distorted.objectlib.helpers.MovesFinished;
35
import org.distorted.objectlib.helpers.ObjectLibInterface;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

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

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

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

    
56
    private final ObjectLibInterface mInterface;
57
    private final ObjectPreRender mPreRender;
58
    private Movement mMovement;
59
    private TwistyObjectNode mObjectNode;
60
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
61
    private int mScreenWidth, mScreenHeight, mScreenMin;
62
    private float mMoveX, mMoveY;
63
    private float mScale;
64

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

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

    
82
    private boolean mIsLocked, mRemLocked;
83

    
84
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
85
    private static final Static4D mTemp= new Static4D(0,0,0,1);
86

    
87
    private static boolean mForcedIconMode = false;
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
91
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
92

    
93
    private void computeCurrentAxis(Static4D axis)
94
      {
95
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
96

    
97
      mAxisX =result.get0();
98
      mAxisY =result.get1();
99

    
100
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
101
      mAxisX /= len;
102
      mAxisY /= len;
103
      }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
    private void addSpeedProbe(float x, float y)
108
      {
109
      long currTime = System.currentTimeMillis();
110
      boolean theSame = mLastIndex==mFirstIndex;
111

    
112
      mLastIndex++;
113
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
114

    
115
      mLastT[mLastIndex] = currTime;
116
      mLastX[mLastIndex] = x;
117
      mLastY[mLastIndex] = y;
118

    
119
      if( mLastIndex==mFirstIndex)
120
        {
121
        mFirstIndex++;
122
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
123
        }
124

    
125
      if( theSame )
126
        {
127
        mLastT[mFirstIndex] = currTime;
128
        mLastX[mFirstIndex] = x;
129
        mLastY[mFirstIndex] = y;
130
        }
131
      }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
    private void computeCurrentSpeedInInchesPerSecond()
136
      {
137
      long firstTime = mLastT[mFirstIndex];
138
      long lastTime  = mLastT[mLastIndex];
139
      float fX = mLastX[mFirstIndex];
140
      float fY = mLastY[mFirstIndex];
141
      float lX = mLastX[mLastIndex];
142
      float lY = mLastY[mLastIndex];
143

    
144
      long timeDiff = lastTime-firstTime;
145

    
146
      mLastIndex = 0;
147
      mFirstIndex= 0;
148

    
149
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
150
      }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
155
      {
156
      float xDist = mScreenWidth*(xFrom-xTo);
157
      float yDist = mScreenHeight*(yFrom-yTo);
158
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
159

    
160
      return distInPixels/mDensity;
161
      }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
    private void replaceMode(TwistyObject object, boolean down)
166
      {
167
      mBeginningRotation= false;
168

    
169
      if( down )
170
        {
171
        int color = mInterface.getCurrentColor();
172
        float[] point = mMovement.getTouchedPoint3D();
173
        mLastCubit = object.getCubit(point);
174
        mLastCubitColor = mInterface.cubitIsLocked(mLastCubit);
175
        int face;
176

    
177
        if( mLastCubitColor>=0 )
178
          {
179
          face =4;
180
          }
181
        else
182
          {
183
          int touchedFace = mMovement.getTouchedFace();
184
          if( mLastCubit<8 ) face = touchedFace;
185
          else
186
            {
187
            switch(touchedFace)
188
              {
189
              case  0: face = mLastCubit==15 || mLastCubit==18 ? 3 : 5; break;
190
              case  1: face = mLastCubit==13 || mLastCubit==16 ? 3 : 5; break;
191
              case  2: face = mLastCubit==10                   ? 5 : 3; break;
192
              case  3: face = mLastCubit== 8                   ? 3 : 5; break;
193
              case  4: face = mLastCubit== 9                   ? 3 : 5; break;
194
              case  5: face = mLastCubit== 8                   ? 5 : 3; break;
195
              default: face =-1;
196
              }
197
            }
198
          }
199

    
200
        mPreRender.setTextureMap( mLastCubit, face , color );
201
        }
202
      }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
    private void setUpDragOrRotate(boolean down, float x, float y, int mode)
207
      {
208
      if( mode==MODE_DRAG )
209
        {
210
        mDragging           = true;
211
        mBeginningRotation  = false;
212
        mContinuingRotation = false;
213
        }
214
      else
215
        {
216
        TwistyObject object = mPreRender.getObject();
217
        CAMERA_POINT.set2( object==null ? 1.21f : mObjectNode.getCameraDist() );
218

    
219
        Static4D touchPoint = new Static4D(x, y, 0, 0);
220
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
221
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
222

    
223
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
224
          {
225
          mDragging           = false;
226
          mContinuingRotation = false;
227

    
228
          if( mode==MODE_ROTATE )
229
            {
230
            mBeginningRotation= !mPreRender.isTouchBlocked();
231
            }
232
          else if( mode==MODE_REPLACE ) replaceMode(object,down);
233
          }
234
        else
235
          {
236
          mDragging           = (!mIsLocked || mIsAutomatic);
237
          mBeginningRotation  = false;
238
          mContinuingRotation = false;
239
          if( !mDragging ) mInterface.failedToDrag();
240
          }
241
        }
242
      }
243

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

    
246
    private void drag(float x, float y)
247
      {
248
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
249
        {
250
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
251
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
252

    
253
        float angleNow = getAngle(x,y,x2,y2);
254
        float angleDiff = angleNow-mRotAngle;
255
        float sinA =-(float)Math.sin(angleDiff);
256
        float cosA = (float)Math.cos(angleDiff);
257

    
258
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
259
        mTemp.set(dragQuat);
260

    
261
        mRotAngle = angleNow;
262

    
263
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
264
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
265
        mInitDistance = distNow;
266
        TwistyObject object = mPreRender.getObject();
267
        if( object!=null ) object.setObjectRatio(distQuot, mObjectNode.getMinSize() );
268
        }
269
      else
270
        {
271
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
272
        mTemp.set(dragQuat);
273
        }
274

    
275
      mPreRender.setQuatOnNextRender();
276
      mX = x;
277
      mY = y;
278
      }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
    private void finishRotation()
283
      {
284
      TwistyObject object = mPreRender.getObject();
285
      int[] angles = object.getBasicAngle();
286

    
287
      if( mCurrentAxis<angles.length )
288
        {
289
        computeCurrentSpeedInInchesPerSecond();
290

    
291
        int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
292
        mPreRender.finishRotation(angle);
293
        mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
294

    
295
        if( angle!=0 )
296
          {
297
          int basicAngle= angles[mCurrentAxis];
298
          int realAngle = (angle*basicAngle)/360;
299
          mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
300
          }
301

    
302
        mContinuingRotation = false;
303
        mBeginningRotation  = false;
304
        mDragging           = true;
305
        }
306
      }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

    
310
    private void continueRotation(float x, float y)
311
      {
312
      float dx = x-mStartRotX;
313
      float dy = y-mStartRotY;
314
      float alpha = dx*mAxisX + dy*mAxisY;
315
      float x2 = dx - alpha*mAxisX;
316
      float y2 = dy - alpha*mAxisY;
317

    
318
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
319

    
320
      // we have the length of 1D vector 'angle', now the direction:
321
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
322

    
323
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
324
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
325
      mPreRender.getObject().continueRotation(mCurrentAngle);
326

    
327
      addSpeedProbe(x2,y2);
328
      }
329

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

    
332
    private void beginRotation(float x, float y)
333
      {
334
      mStartRotX = x;
335
      mStartRotY = y;
336

    
337
      TwistyObject object = mPreRender.getObject();
338
      int[] numLayers = object.getNumLayers();
339

    
340
      Static4D touchPoint = new Static4D(x, y, 0, 0);
341
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
342
      Static2D res = mMovement.newRotation(rotatedTouchPoint,object.getObjectRatio());
343

    
344
      mCurrentAxis = (int)res.get0();
345
      mCurrentRow  = (int)res.get1();
346

    
347
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
348
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
349

    
350
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
351

    
352
      mInterface.onBeginRotation();
353

    
354
      addSpeedProbe(x,y);
355

    
356
      mBeginningRotation = false;
357
      mContinuingRotation= true;
358
      }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
    private float getAngle(float x1, float y1, float x2, float y2)
363
      {
364
      return (float) Math.atan2(y1-y2, x1-x2);
365
      }
366

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

    
369
    private void prepareDown(MotionEvent event)
370
      {
371
      mPointer1 = event.getPointerId(0);
372
      mX1 = event.getX() - mMoveX;
373
      mY1 = event.getY() + mMoveY;
374
      mPointer2 = INVALID_POINTER_ID;
375
      }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
    private void prepareMove(MotionEvent event)
380
      {
381
      int index1 = event.findPointerIndex(mPointer1);
382

    
383
      if( index1>=0 )
384
        {
385
        mX1 = event.getX(index1) - mMoveX;
386
        mY1 = event.getY(index1) + mMoveY;
387
        }
388

    
389
      int index2 = event.findPointerIndex(mPointer2);
390

    
391
      if( index2>=0 )
392
        {
393
        mX2 = event.getX(index2) - mMoveX;
394
        mY2 = event.getY(index2) + mMoveY;
395
        }
396
      }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
    private void prepareUp(MotionEvent event)
401
      {
402
      mPointer1 = INVALID_POINTER_ID;
403
      mPointer2 = INVALID_POINTER_ID;
404
      }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
    private void prepareDown2(MotionEvent event)
409
      {
410
      int index = event.getActionIndex();
411

    
412
      if( mPointer1==INVALID_POINTER_ID )
413
        {
414
        mPointer1 = event.getPointerId(index);
415
        mX1 = event.getX(index) - mMoveX;
416
        mY1 = event.getY(index) + mMoveY;
417
        }
418
      else if( mPointer2==INVALID_POINTER_ID )
419
        {
420
        mPointer2 = event.getPointerId(index);
421
        mX2 = event.getX(index) - mMoveX;
422
        mY2 = event.getY(index) + mMoveY;
423
        }
424
      }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

    
428
    private void prepareUp2(MotionEvent event)
429
      {
430
      int index = event.getActionIndex();
431

    
432
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
433
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
434
      }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

    
438
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
439
      {
440
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
441
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
442

    
443
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
444
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
445

    
446
      if( mBeginningRotation )
447
        {
448
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
449
          {
450
          beginRotation(x,y);
451
          }
452
        }
453
      else if( mContinuingRotation )
454
        {
455
        continueRotation(x,y);
456
        }
457
      else if( mDragging )
458
        {
459
        drag(x,y);
460
        }
461
      else
462
        {
463
        setUpDragOrRotate(false,x,y,mode);
464
        }
465
      }
466

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

    
469
    private void actionDown(float x, float y, int mode)
470
      {
471
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
472
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
473

    
474
      setUpDragOrRotate(true,mX,mY,mode);
475
      }
476

    
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

    
479
    private void actionUp()
480
      {
481
      if( mContinuingRotation )
482
        {
483
        finishRotation();
484
        }
485

    
486
      if( mLastCubitColor>=0 )
487
        {
488
        mPreRender.setTextureMap( mLastCubit, 4, mLastCubitColor );
489
        mLastCubitColor = -1;
490
        }
491
      }
492

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

    
495
    private void actionDown2(float x1, float y1, float x2, float y2)
496
      {
497
      mRotAngle = getAngle(x1,-y1, x2,-y2);
498
      mInitDistance = -1;
499

    
500
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
501
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
502

    
503
      if( mBeginningRotation )
504
        {
505
        mContinuingRotation = false;
506
        mBeginningRotation  = false;
507
        mDragging           = true;
508
        }
509
      else if( mContinuingRotation )
510
        {
511
        finishRotation();
512
        }
513
      }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516

    
517
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
518
      {
519
      if( p1isUp )
520
        {
521
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
522
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
523
        }
524
      if( p2isUp )
525
        {
526
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
527
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
528
        }
529
      }
530

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

    
533
    void setMovement(Movement movement)
534
      {
535
      mMovement = movement;
536
      }
537

    
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539
// INTERNAL API (for AutomaticControl)
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541

    
542
    public ObjectPreRender getPreRender()
543
      {
544
      return mPreRender;
545
      }
546

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

    
549
    public ObjectLibInterface getInterface()
550
      {
551
      return mInterface;
552
      }
553

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

    
556
    public static void setIconMode(boolean mode)
557
      {
558
      mForcedIconMode = mode;
559
      }
560

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

    
563
    public static boolean isInIconMode()
564
      {
565
      return mForcedIconMode;
566
      }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569
// PUBLIC API
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571

    
572
    public ObjectControl(Activity act, ObjectLibInterface actioner)
573
      {
574
      mIsAutomatic = false;
575

    
576
      mLastCubitColor = -1;
577
      mCurrRotSpeed   = 0.0f;
578
      mScale = 1.0f;
579

    
580
      mLastX = new float[NUM_SPEED_PROBES];
581
      mLastY = new float[NUM_SPEED_PROBES];
582
      mLastT = new long[NUM_SPEED_PROBES];
583
      mFirstIndex =0;
584
      mLastIndex  =0;
585

    
586
      DisplayMetrics dm = new DisplayMetrics();
587
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
588

    
589
      mDensity = dm.densityDpi;
590

    
591
      mPreRender = new ObjectPreRender(act,this,actioner);
592
      mInterface = actioner;
593
      }
594

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

    
597
    public TwistyObjectNode getNode()
598
      {
599
      return mObjectNode;
600
      }
601

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

    
604
    public void createNode(int width, int height)
605
      {
606
      if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
607
      }
608

    
609
///////////////////////////////////////////////////////////////////////////////////////////////////
610

    
611
    public void setScreenSize(int width, int height)
612
      {
613
      mScreenWidth = width;
614
      mScreenHeight= height;
615
      mScreenMin   = Math.min(width,height);
616

    
617
      mPreRender.setScreenSize();
618
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
619
      }
620

    
621
///////////////////////////////////////////////////////////////////////////////////////////////////
622

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

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

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

    
633
    public void setObjectScale(float scale)
634
      {
635
      mScale = scale;
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, InputStream jsonStream, InputStream meshStream)
757
      {
758
      mPreRender.changeObject(ordinal, jsonStream, meshStream);
759
      }
760

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

    
763
    public void changeIfDifferent(int ordinal, InputStream jsonStream, InputStream meshStream)
764
      {
765
      TwistyObject object = mPreRender.getObject();
766
      ObjectType old = object==null ? null : object.getObjectType();
767

    
768
      if( old==null || old.ordinal() != ordinal )
769
        {
770
        mPreRender.changeObject(ordinal, jsonStream, meshStream);
771
        }
772
      }
773

    
774
///////////////////////////////////////////////////////////////////////////////////////////////////
775

    
776
    public void scrambleObject(int num)
777
      {
778
      mPreRender.scrambleObject(num);
779
      }
780

    
781
///////////////////////////////////////////////////////////////////////////////////////////////////
782

    
783
    public void solveObject()
784
      {
785
      mPreRender.solveObject();
786
      }
787

    
788
///////////////////////////////////////////////////////////////////////////////////////////////////
789

    
790
    public void solveOnly()
791
      {
792
      mPreRender.solveOnly();
793
      }
794

    
795
///////////////////////////////////////////////////////////////////////////////////////////////////
796

    
797
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
798
      {
799
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
800
      }
801

    
802
///////////////////////////////////////////////////////////////////////////////////////////////////
803

    
804
    public void resetAllTextureMaps()
805
      {
806
      mPreRender.resetAllTextureMaps();
807
      }
808

    
809
///////////////////////////////////////////////////////////////////////////////////////////////////
810

    
811
    public TwistyObject getObject()
812
      {
813
      return mPreRender.getObject();
814
      }
815

    
816
///////////////////////////////////////////////////////////////////////////////////////////////////
817

    
818
    public void savePreferences(SharedPreferences.Editor editor)
819
      {
820
      mPreRender.savePreferences(editor);
821
      }
822

    
823
///////////////////////////////////////////////////////////////////////////////////////////////////
824

    
825
    public void restorePreferences(SharedPreferences preferences)
826
      {
827
      mPreRender.restorePreferences(preferences);
828
      }
829
///////////////////////////////////////////////////////////////////////////////////////////////////
830

    
831
    public boolean retLocked()
832
      {
833
      return mIsLocked;
834
      }
835

    
836
///////////////////////////////////////////////////////////////////////////////////////////////////
837

    
838
    public void toggleLock()
839
      {
840
      mIsLocked = !mIsLocked;
841
      }
842

    
843
///////////////////////////////////////////////////////////////////////////////////////////////////
844

    
845
    public void unlock()
846
      {
847
      mIsLocked = false;
848
      }
849

    
850
///////////////////////////////////////////////////////////////////////////////////////////////////
851

    
852
    public void setLock(boolean value)
853
      {
854
      mRemLocked = mIsLocked;
855
      mIsLocked = value;
856
      }
857

    
858
///////////////////////////////////////////////////////////////////////////////////////////////////
859

    
860
    public void unsetLock()
861
      {
862
      mIsLocked = mRemLocked;
863
      }
864

    
865
///////////////////////////////////////////////////////////////////////////////////////////////////
866

    
867
    public boolean onTouchEvent(MotionEvent event, int mode)
868
      {
869
      int action = event.getActionMasked();
870

    
871
      switch(action)
872
         {
873
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
874
                                               actionDown(mX1, mY1, mode);
875
                                               break;
876
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
877
                                               actionMove(mX1, mY1, mX2, mY2, mode);
878
                                               break;
879
         case MotionEvent.ACTION_UP          : prepareUp(event);
880
                                               actionUp();
881
                                               break;
882
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
883
                                               actionDown2(mX1, mY1, mX2, mY2);
884
                                               break;
885
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
886
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
887
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
888
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
889
                                               break;
890
         }
891

    
892
      return true;
893
      }
894
}
895

    
(8-8/18)