Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 594bbce0

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 android.app.Activity;
23
import android.content.SharedPreferences;
24
import android.util.DisplayMetrics;
25
import android.view.MotionEvent;
26

    
27
import org.distorted.library.main.QuatHelper;
28
import org.distorted.library.type.Static2D;
29
import org.distorted.library.type.Static4D;
30

    
31
import org.distorted.objectlib.helpers.BlockController;
32
import org.distorted.objectlib.helpers.MovesFinished;
33
import org.distorted.objectlib.helpers.ObjectLibInterface;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

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

    
42
    public static final int MODE_ROTATE  = 0;
43
    public static final int MODE_DRAG    = 1;
44
    public static final int MODE_REPLACE = 2;
45

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

    
52
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
53

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

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

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

    
79
    private boolean mIsLocked, mRemLocked;
80

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

    
84
    private static boolean mForcedIconMode = false;
85
    private static boolean mForcedDmeshMode= false;
86
    private static boolean mForcedJsonMode = false;
87

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

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

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

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

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

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

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

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

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

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

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

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

    
143
      long timeDiff = lastTime-firstTime;
144

    
145
      mLastIndex = 0;
146
      mFirstIndex= 0;
147

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

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

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

    
159
      return distInPixels/mDensity;
160
      }
161

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

    
164
    private void setUpDragOrRotate(boolean down, float x, float y, int mode)
165
      {
166
      if( mode==MODE_DRAG )
167
        {
168
        mDragging           = true;
169
        mBeginningRotation  = false;
170
        mContinuingRotation = false;
171
        }
172
      else
173
        {
174
        TwistyObject object = mPreRender.getObject();
175
        CAMERA_POINT.set2( object==null ? 1.21f : mObjectNode.getCameraDist() );
176

    
177
        Static4D touchPoint = new Static4D(x, y, 0, 0);
178
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
179
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
180

    
181
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
182
          {
183
          mDragging           = false;
184
          mContinuingRotation = false;
185

    
186
          if( mode==MODE_ROTATE )
187
            {
188
            mBeginningRotation= !mPreRender.isTouchBlocked();
189
            }
190
          else if( mode==MODE_REPLACE )
191
            {
192
            mBeginningRotation= false;
193

    
194
            if( down )
195
              {
196
              int color = mInterface.getCurrentColor();
197
              float[] point = mMovement.getTouchedPoint3D();
198
              mLastCubit = object.getCubit(point);
199
              mLastCubitColor = mInterface.cubitIsLocked(object.getObjectType(),mLastCubit);
200
              mPreRender.setTextureMap( mLastCubit, mLastCubitColor>=0 ? 4 : mMovement.getTouchedFace(), color );
201
              }
202
            }
203
          }
204
        else
205
          {
206
          mDragging           = (!mIsLocked || mIsAutomatic);
207
          mBeginningRotation  = false;
208
          mContinuingRotation = false;
209
          if( !mDragging ) mInterface.failedToDrag();
210
          }
211
        }
212
      }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
    private void drag(float x, float y)
217
      {
218
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
219
        {
220
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
221
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
222

    
223
        float angleNow = getAngle(x,y,x2,y2);
224
        float angleDiff = angleNow-mRotAngle;
225
        float sinA =-(float)Math.sin(angleDiff);
226
        float cosA = (float)Math.cos(angleDiff);
227

    
228
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
229
        mTemp.set(dragQuat);
230

    
231
        mRotAngle = angleNow;
232

    
233
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
234
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
235
        mInitDistance = distNow;
236
        TwistyObject object = mPreRender.getObject();
237
        if( object!=null ) object.setObjectRatio(distQuot,mObjectNode.getScaleFactor() );
238
        }
239
      else
240
        {
241
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
242
        mTemp.set(dragQuat);
243
        }
244

    
245
      mPreRender.setQuatOnNextRender();
246
      mX = x;
247
      mY = y;
248
      }
249

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

    
252
    private void finishRotation()
253
      {
254
      computeCurrentSpeedInInchesPerSecond();
255
      TwistyObject object = mPreRender.getObject();
256
      int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
257
      mPreRender.finishRotation(angle);
258
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
259

    
260
      if( angle!=0 )
261
        {
262
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
263
        int realAngle = (angle*basicAngle)/360;
264
        mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
265
        }
266

    
267
      mContinuingRotation = false;
268
      mBeginningRotation  = false;
269
      mDragging           = true;
270
      }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

    
274
    private void continueRotation(float x, float y)
275
      {
276
      float dx = x-mStartRotX;
277
      float dy = y-mStartRotY;
278
      float alpha = dx*mAxisX + dy*mAxisY;
279
      float x2 = dx - alpha*mAxisX;
280
      float y2 = dy - alpha*mAxisY;
281

    
282
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
283

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

    
287
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
288
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
289
      mPreRender.getObject().continueRotation(mCurrentAngle);
290

    
291
      addSpeedProbe(x2,y2);
292
      }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
    private void beginRotation(float x, float y)
297
      {
298
      mStartRotX = x;
299
      mStartRotY = y;
300

    
301
      TwistyObject object = mPreRender.getObject();
302
      int[] numLayers = object.getNumLayers();
303

    
304
      Static4D touchPoint = new Static4D(x, y, 0, 0);
305
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
306
      Static2D res = mMovement.newRotation(rotatedTouchPoint,object.getObjectRatio());
307

    
308
      mCurrentAxis = (int)res.get0();
309
      mCurrentRow  = (int)res.get1();
310

    
311
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
312
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
313

    
314
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
315

    
316
      mInterface.onBeginRotation();
317

    
318
      addSpeedProbe(x,y);
319

    
320
      mBeginningRotation = false;
321
      mContinuingRotation= true;
322
      }
323

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

    
326
    private float getAngle(float x1, float y1, float x2, float y2)
327
      {
328
      return (float) Math.atan2(y1-y2, x1-x2);
329
      }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
    private void prepareDown(MotionEvent event)
334
      {
335
      mPointer1 = event.getPointerId(0);
336
      mX1 = event.getX() - mMoveX;
337
      mY1 = event.getY() + mMoveY;
338
      mPointer2 = INVALID_POINTER_ID;
339
      }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

    
343
    private void prepareMove(MotionEvent event)
344
      {
345
      int index1 = event.findPointerIndex(mPointer1);
346

    
347
      if( index1>=0 )
348
        {
349
        mX1 = event.getX(index1) - mMoveX;
350
        mY1 = event.getY(index1) + mMoveY;
351
        }
352

    
353
      int index2 = event.findPointerIndex(mPointer2);
354

    
355
      if( index2>=0 )
356
        {
357
        mX2 = event.getX(index2) - mMoveX;
358
        mY2 = event.getY(index2) + mMoveY;
359
        }
360
      }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
    private void prepareUp(MotionEvent event)
365
      {
366
      mPointer1 = INVALID_POINTER_ID;
367
      mPointer2 = INVALID_POINTER_ID;
368
      }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
    private void prepareDown2(MotionEvent event)
373
      {
374
      int index = event.getActionIndex();
375

    
376
      if( mPointer1==INVALID_POINTER_ID )
377
        {
378
        mPointer1 = event.getPointerId(index);
379
        mX1 = event.getX(index) - mMoveX;
380
        mY1 = event.getY(index) + mMoveY;
381
        }
382
      else if( mPointer2==INVALID_POINTER_ID )
383
        {
384
        mPointer2 = event.getPointerId(index);
385
        mX2 = event.getX(index) - mMoveX;
386
        mY2 = event.getY(index) + mMoveY;
387
        }
388
      }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
    private void prepareUp2(MotionEvent event)
393
      {
394
      int index = event.getActionIndex();
395

    
396
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
397
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
398
      }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

    
402
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
403
      {
404
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
405
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
406

    
407
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
408
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
409

    
410
      if( mBeginningRotation )
411
        {
412
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
413
          {
414
          beginRotation(x,y);
415
          }
416
        }
417
      else if( mContinuingRotation )
418
        {
419
        continueRotation(x,y);
420
        }
421
      else if( mDragging )
422
        {
423
        drag(x,y);
424
        }
425
      else
426
        {
427
        setUpDragOrRotate(false,x,y,mode);
428
        }
429
      }
430

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

    
433
    private void actionDown(float x, float y, int mode)
434
      {
435
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
436
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
437

    
438
      setUpDragOrRotate(true,mX,mY,mode);
439
      }
440

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

    
443
    private void actionUp()
444
      {
445
      if( mContinuingRotation )
446
        {
447
        finishRotation();
448
        }
449

    
450
      if( mLastCubitColor>=0 )
451
        {
452
        mPreRender.setTextureMap( mLastCubit, 4, mLastCubitColor );
453
        mLastCubitColor = -1;
454
        }
455
      }
456

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

    
459
    private void actionDown2(float x1, float y1, float x2, float y2)
460
      {
461
      mRotAngle = getAngle(x1,-y1, x2,-y2);
462
      mInitDistance = -1;
463

    
464
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
465
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
466

    
467
      if( mBeginningRotation )
468
        {
469
        mContinuingRotation = false;
470
        mBeginningRotation  = false;
471
        mDragging           = true;
472
        }
473
      else if( mContinuingRotation )
474
        {
475
        finishRotation();
476
        }
477
      }
478

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

    
481
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
482
      {
483
      if( p1isUp )
484
        {
485
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
486
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
487
        }
488
      if( p2isUp )
489
        {
490
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
491
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
492
        }
493
      }
494

    
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496

    
497
    void setMovement(Movement movement)
498
      {
499
      mMovement = movement;
500
      }
501

    
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503
// INTERNAL API (for AutomaticControl)
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505

    
506
    public ObjectPreRender getPreRender()
507
      {
508
      return mPreRender;
509
      }
510

    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

    
513
    public ObjectLibInterface getInterface()
514
      {
515
      return mInterface;
516
      }
517

    
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519

    
520
    public static void setIconMode(boolean mode)
521
      {
522
      mForcedIconMode = mode;
523
      }
524

    
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526

    
527
    public static void setDmeshMode(boolean mode)
528
      {
529
      mForcedDmeshMode = mode;
530
      }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533

    
534
    public static void setJsonMode(boolean mode)
535
      {
536
      mForcedJsonMode = mode;
537
      }
538

    
539
///////////////////////////////////////////////////////////////////////////////////////////////////
540

    
541
    public static boolean isInIconMode()
542
      {
543
      return mForcedIconMode;
544
      }
545

    
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547

    
548
    public static boolean isInDmeshMode()
549
      {
550
      return mForcedDmeshMode;
551
      }
552

    
553
///////////////////////////////////////////////////////////////////////////////////////////////////
554

    
555
    public static boolean isInJsonMode()
556
      {
557
      return mForcedJsonMode;
558
      }
559

    
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561
// PUBLIC API
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563

    
564
    public ObjectControl(Activity act, ObjectLibInterface actioner)
565
      {
566
      mIsAutomatic = false;
567

    
568
      mLastCubitColor = -1;
569
      mCurrRotSpeed   = 0.0f;
570

    
571
      mLastX = new float[NUM_SPEED_PROBES];
572
      mLastY = new float[NUM_SPEED_PROBES];
573
      mLastT = new long[NUM_SPEED_PROBES];
574
      mFirstIndex =0;
575
      mLastIndex  =0;
576

    
577
      DisplayMetrics dm = new DisplayMetrics();
578
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
579

    
580
      mDensity = dm.densityDpi;
581

    
582
      mPreRender = new ObjectPreRender(act,this,actioner);
583
      mInterface = actioner;
584
      }
585

    
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587

    
588
    public TwistyObjectNode getNode()
589
      {
590
      return mObjectNode;
591
      }
592

    
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594

    
595
    public void createNode(int width, int height)
596
      {
597
      if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
598
      }
599

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601

    
602
    public void setScreenSize(int width, int height)
603
      {
604
      mScreenWidth = width;
605
      mScreenHeight= height;
606
      mScreenMin   = Math.min(width,height);
607

    
608
      mPreRender.setScreenSize();
609
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
610
      }
611

    
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613

    
614
    public void setMove(int xmove, int ymove)
615
      {
616
      mMoveX = xmove;
617
      mMoveY = ymove;
618

    
619
      mPreRender.setMove(xmove,ymove);
620
      }
621

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

    
624
    public void onPause()
625
      {
626
      BlockController.onPause();
627
      }
628

    
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630

    
631
    public void onResume()
632
      {
633
      mPointer1 = INVALID_POINTER_ID;
634
      mPointer2 = INVALID_POINTER_ID;
635

    
636
      unlock();
637

    
638
      BlockController.onResume();
639
      }
640

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

    
643
    public void rotateNow(Static4D quat)
644
      {
645
      mTemp.set(quat);
646
      mQuat.set(mTemp);
647
      }
648

    
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650

    
651
    public void scaleNow(float scale)
652
      {
653
      mPreRender.getObject().setObjectRatioNow(scale,mObjectNode.getScaleFactor());
654
      }
655

    
656
///////////////////////////////////////////////////////////////////////////////////////////////////
657

    
658
    public void setQuat()
659
      {
660
      mQuat.set(mTemp);
661
      }
662

    
663
///////////////////////////////////////////////////////////////////////////////////////////////////
664

    
665
    public Static4D getQuat()
666
      {
667
      return mQuat;
668
      }
669

    
670
///////////////////////////////////////////////////////////////////////////////////////////////////
671

    
672
    public void preRender()
673
      {
674
      mPreRender.preRender();
675
      }
676

    
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678

    
679
    public void blockEverything(int place)
680
      {
681
      setLock(true);
682
      mPreRender.blockEverything(place);
683
      }
684

    
685
///////////////////////////////////////////////////////////////////////////////////////////////////
686

    
687
    public void blockTouch(int place)
688
      {
689
      setLock(true);
690
      mPreRender.blockTouch(place);
691
      }
692

    
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694

    
695
    public void unblockEverything()
696
      {
697
      unsetLock();
698
      mPreRender.unblockEverything();
699
      }
700

    
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702

    
703
    public void unblockTouch()
704
      {
705
      unsetLock();
706
      mPreRender.unblockTouch();
707
      }
708

    
709
///////////////////////////////////////////////////////////////////////////////////////////////////
710

    
711
    public void unblockUI()
712
      {
713
      mPreRender.unblockUI();
714
      }
715

    
716
///////////////////////////////////////////////////////////////////////////////////////////////////
717

    
718
    public boolean isTouchBlocked()
719
      {
720
      return mPreRender.isTouchBlocked();
721
      }
722

    
723
///////////////////////////////////////////////////////////////////////////////////////////////////
724

    
725
    public boolean isUINotBlocked()
726
      {
727
      return mPreRender.isUINotBlocked();
728
      }
729

    
730
///////////////////////////////////////////////////////////////////////////////////////////////////
731

    
732
    public void initializeObject(int[][] moves)
733
      {
734
      mPreRender.initializeObject(moves);
735
      }
736

    
737
///////////////////////////////////////////////////////////////////////////////////////////////////
738

    
739
    public void changeObject(ObjectType newObject)
740
      {
741
      mPreRender.changeObject(newObject);
742
      }
743

    
744
///////////////////////////////////////////////////////////////////////////////////////////////////
745

    
746
    public void recreateObject()
747
      {
748
      mPreRender.recreateObject();
749
      }
750

    
751
///////////////////////////////////////////////////////////////////////////////////////////////////
752

    
753
    public void scrambleObject(int num)
754
      {
755
      mPreRender.scrambleObject(num);
756
      }
757

    
758
///////////////////////////////////////////////////////////////////////////////////////////////////
759

    
760
    public void solveObject()
761
      {
762
      mPreRender.solveObject();
763
      }
764

    
765
///////////////////////////////////////////////////////////////////////////////////////////////////
766

    
767
    public void solveOnly()
768
      {
769
      mPreRender.solveOnly();
770
      }
771

    
772
///////////////////////////////////////////////////////////////////////////////////////////////////
773

    
774
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
775
      {
776
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
777
      }
778

    
779
///////////////////////////////////////////////////////////////////////////////////////////////////
780

    
781
    public void resetAllTextureMaps()
782
      {
783
      mPreRender.resetAllTextureMaps();
784
      }
785

    
786
///////////////////////////////////////////////////////////////////////////////////////////////////
787

    
788
    public TwistyObject getObject()
789
      {
790
      return mPreRender.getObject();
791
      }
792

    
793
///////////////////////////////////////////////////////////////////////////////////////////////////
794

    
795
    public void savePreferences(SharedPreferences.Editor editor)
796
      {
797
      mPreRender.savePreferences(editor);
798
      }
799

    
800
///////////////////////////////////////////////////////////////////////////////////////////////////
801

    
802
    public void restorePreferences(SharedPreferences preferences)
803
      {
804
      mPreRender.restorePreferences(preferences);
805
      }
806
///////////////////////////////////////////////////////////////////////////////////////////////////
807

    
808
    public boolean retLocked()
809
      {
810
      return mIsLocked;
811
      }
812

    
813
///////////////////////////////////////////////////////////////////////////////////////////////////
814

    
815
    public void toggleLock()
816
      {
817
      mIsLocked = !mIsLocked;
818
      }
819

    
820
///////////////////////////////////////////////////////////////////////////////////////////////////
821

    
822
    public void unlock()
823
      {
824
      mIsLocked = false;
825
      }
826

    
827
///////////////////////////////////////////////////////////////////////////////////////////////////
828

    
829
    public void setLock(boolean value)
830
      {
831
      mRemLocked = mIsLocked;
832
      mIsLocked = value;
833
      }
834

    
835
///////////////////////////////////////////////////////////////////////////////////////////////////
836

    
837
    public void unsetLock()
838
      {
839
      mIsLocked = mRemLocked;
840
      }
841

    
842
///////////////////////////////////////////////////////////////////////////////////////////////////
843

    
844
    public boolean onTouchEvent(MotionEvent event, int mode)
845
      {
846
      int action = event.getActionMasked();
847

    
848
      switch(action)
849
         {
850
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
851
                                               actionDown(mX1, mY1, mode);
852
                                               break;
853
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
854
                                               actionMove(mX1, mY1, mX2, mY2, mode);
855
                                               break;
856
         case MotionEvent.ACTION_UP          : prepareUp(event);
857
                                               actionUp();
858
                                               break;
859
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
860
                                               actionDown2(mX1, mY1, mX2, mY2);
861
                                               break;
862
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
863
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
864
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
865
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
866
                                               break;
867
         }
868

    
869
      return true;
870
      }
871
}
872

    
(8-8/18)