Project

General

Profile

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

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

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.MovesFinished;
32
import org.distorted.objectlib.helpers.ObjectLibInterface;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

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

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

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

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

    
53
    private final ObjectLibInterface mInterface;
54
    private final ObjectPreRender mPreRender;
55
    private Movement mMovement;
56
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
57
    private int mScreenWidth, mScreenHeight, mScreenMin;
58

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

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

    
76
    private boolean mIsLocked, mRemLocked;
77

    
78
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
79
    private static final Static4D mTemp= new Static4D(0,0,0,1);
80

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

    
85
    private void computeCurrentAxis(Static4D axis)
86
      {
87
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
88

    
89
      mAxisX =result.get0();
90
      mAxisY =result.get1();
91

    
92
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
93
      mAxisX /= len;
94
      mAxisY /= len;
95
      }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
    private void addSpeedProbe(float x, float y)
100
      {
101
      long currTime = System.currentTimeMillis();
102
      boolean theSame = mLastIndex==mFirstIndex;
103

    
104
      mLastIndex++;
105
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
106

    
107
      mLastT[mLastIndex] = currTime;
108
      mLastX[mLastIndex] = x;
109
      mLastY[mLastIndex] = y;
110

    
111
      if( mLastIndex==mFirstIndex)
112
        {
113
        mFirstIndex++;
114
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
115
        }
116

    
117
      if( theSame )
118
        {
119
        mLastT[mFirstIndex] = currTime;
120
        mLastX[mFirstIndex] = x;
121
        mLastY[mFirstIndex] = y;
122
        }
123
      }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
    private void computeCurrentSpeedInInchesPerSecond()
128
      {
129
      long firstTime = mLastT[mFirstIndex];
130
      long lastTime  = mLastT[mLastIndex];
131
      float fX = mLastX[mFirstIndex];
132
      float fY = mLastY[mFirstIndex];
133
      float lX = mLastX[mLastIndex];
134
      float lY = mLastY[mLastIndex];
135

    
136
      long timeDiff = lastTime-firstTime;
137

    
138
      mLastIndex = 0;
139
      mFirstIndex= 0;
140

    
141
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
142
      }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
147
      {
148
      float xDist = mScreenWidth*(xFrom-xTo);
149
      float yDist = mScreenHeight*(yFrom-yTo);
150
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
151

    
152
      return distInPixels/mDensity;
153
      }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
    private void setUpDragOrRotate(boolean down, float x, float y, int mode)
158
      {
159
      if( mode==MODE_DRAG )
160
        {
161
        mDragging           = true;
162
        mBeginningRotation  = false;
163
        mContinuingRotation = false;
164
        }
165
      else
166
        {
167
        TwistyObject object = mPreRender.getObject();
168
        CAMERA_POINT.set2( object==null ? 1.21f : object.getCameraDist() );
169

    
170
        Static4D touchPoint = new Static4D(x, y, 0, 0);
171
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
172
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
173

    
174
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
175
          {
176
          mDragging           = false;
177
          mContinuingRotation = false;
178

    
179
          if( mode==MODE_ROTATE )
180
            {
181
            mBeginningRotation= !mPreRender.isTouchBlocked();
182
            }
183
          else if( mode==MODE_REPLACE )
184
            {
185
            mBeginningRotation= false;
186

    
187
            if( down )
188
              {
189
              int color = mInterface.getCurrentColor();
190
              mLastCubitFace = mMovement.getTouchedFace();
191
              float[] point = mMovement.getTouchedPoint3D();
192
              mLastCubit = object.getCubit(point);
193
              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
194
              mLastCubitColor = mInterface.cubitIsLocked(object.getObjectType(),mLastCubit);
195
              }
196
            }
197
          }
198
        else
199
          {
200
          mDragging           = (!mIsLocked || mIsAutomatic);
201
          mBeginningRotation  = false;
202
          mContinuingRotation = false;
203
          if( !mDragging ) mInterface.failedToDrag();
204
          }
205
        }
206
      }
207

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

    
210
    private void drag(float x, float y)
211
      {
212
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
213
        {
214
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
215
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
216

    
217
        float angleNow = getAngle(x,y,x2,y2);
218
        float angleDiff = angleNow-mRotAngle;
219
        float sinA =-(float)Math.sin(angleDiff);
220
        float cosA = (float)Math.cos(angleDiff);
221

    
222
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
223
        mTemp.set(dragQuat);
224

    
225
        mRotAngle = angleNow;
226

    
227
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
228
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
229
        mInitDistance = distNow;
230
        TwistyObject object = mPreRender.getObject();
231
        if( object!=null ) object.setObjectRatio(distQuot);
232
        }
233
      else
234
        {
235
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
236
        mTemp.set(dragQuat);
237
        }
238

    
239
      mPreRender.setQuatOnNextRender();
240
      mX = x;
241
      mY = y;
242
      }
243

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

    
246
    private void finishRotation()
247
      {
248
      computeCurrentSpeedInInchesPerSecond();
249
      TwistyObject object = mPreRender.getObject();
250
      int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
251
      mPreRender.finishRotation(angle);
252
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
253

    
254
      if( angle!=0 )
255
        {
256
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
257
        int realAngle = (angle*basicAngle)/360;
258
        mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
259
        }
260

    
261
      mContinuingRotation = false;
262
      mBeginningRotation  = false;
263
      mDragging           = true;
264
      }
265

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

    
268
    private void continueRotation(float x, float y)
269
      {
270
      float dx = x-mStartRotX;
271
      float dy = y-mStartRotY;
272
      float alpha = dx*mAxisX + dy*mAxisY;
273
      float x2 = dx - alpha*mAxisX;
274
      float y2 = dy - alpha*mAxisY;
275

    
276
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
277

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

    
281
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
282
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
283
      mPreRender.getObject().continueRotation(mCurrentAngle);
284

    
285
      addSpeedProbe(x2,y2);
286
      }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

    
290
    private void beginRotation(float x, float y)
291
      {
292
      mStartRotX = x;
293
      mStartRotY = y;
294

    
295
      TwistyObject object = mPreRender.getObject();
296
      int numLayers = object.getNumLayers();
297

    
298
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
299
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
300
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
301

    
302
      mCurrentAxis = (int)res.get0();
303
      mCurrentRow  = (int)res.get1();
304

    
305
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
306
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
307

    
308
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
309

    
310
      mInterface.onBeginRotation();
311

    
312
      addSpeedProbe(x,y);
313

    
314
      mBeginningRotation = false;
315
      mContinuingRotation= true;
316
      }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

    
320
    private float getAngle(float x1, float y1, float x2, float y2)
321
      {
322
      return (float) Math.atan2(y1-y2, x1-x2);
323
      }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
    private void prepareDown(MotionEvent event)
328
      {
329
      mPointer1 = event.getPointerId(0);
330
      mX1 = event.getX();
331
      mY1 = event.getY();
332
      mPointer2 = INVALID_POINTER_ID;
333
      }
334

    
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

    
337
    private void prepareMove(MotionEvent event)
338
      {
339
      int index1 = event.findPointerIndex(mPointer1);
340

    
341
      if( index1>=0 )
342
        {
343
        mX1 = event.getX(index1);
344
        mY1 = event.getY(index1);
345
        }
346

    
347
      int index2 = event.findPointerIndex(mPointer2);
348

    
349
      if( index2>=0 )
350
        {
351
        mX2 = event.getX(index2);
352
        mY2 = event.getY(index2);
353
        }
354
      }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
    private void prepareUp(MotionEvent event)
359
      {
360
      mPointer1 = INVALID_POINTER_ID;
361
      mPointer2 = INVALID_POINTER_ID;
362
      }
363

    
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365

    
366
    private void prepareDown2(MotionEvent event)
367
      {
368
      int index = event.getActionIndex();
369

    
370
      if( mPointer1==INVALID_POINTER_ID )
371
        {
372
        mPointer1 = event.getPointerId(index);
373
        mX1 = event.getX(index);
374
        mY1 = event.getY(index);
375
        }
376
      else if( mPointer2==INVALID_POINTER_ID )
377
        {
378
        mPointer2 = event.getPointerId(index);
379
        mX2 = event.getX(index);
380
        mY2 = event.getY(index);
381
        }
382
      }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
    private void prepareUp2(MotionEvent event)
387
      {
388
      int index = event.getActionIndex();
389

    
390
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
391
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
392
      }
393

    
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395

    
396
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
397
      {
398
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
399
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
400

    
401
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
402
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
403

    
404
      if( mBeginningRotation )
405
        {
406
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
407
          {
408
          beginRotation(x,y);
409
          }
410
        }
411
      else if( mContinuingRotation )
412
        {
413
        continueRotation(x,y);
414
        }
415
      else if( mDragging )
416
        {
417
        drag(x,y);
418
        }
419
      else
420
        {
421
        setUpDragOrRotate(false,x,y,mode);
422
        }
423
      }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
    private void actionDown(float x, float y, int mode)
428
      {
429
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
430
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
431

    
432
      setUpDragOrRotate(true,mX,mY,mode);
433
      }
434

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

    
437
    private void actionUp()
438
      {
439
      if( mContinuingRotation )
440
        {
441
        finishRotation();
442
        }
443

    
444
      if( mLastCubitColor>=0 )
445
        {
446
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
447
        mLastCubitColor = -1;
448
        }
449
      }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

    
453
    private void actionDown2(float x1, float y1, float x2, float y2)
454
      {
455
      mRotAngle = getAngle(x1,-y1, x2,-y2);
456
      mInitDistance = -1;
457

    
458
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
459
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
460

    
461
      if( mBeginningRotation )
462
        {
463
        mContinuingRotation = false;
464
        mBeginningRotation  = false;
465
        mDragging           = true;
466
        }
467
      else if( mContinuingRotation )
468
        {
469
        finishRotation();
470
        }
471
      }
472

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

    
475
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
476
      {
477
      if( p1isUp )
478
        {
479
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
480
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
481
        }
482
      if( p2isUp )
483
        {
484
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
485
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
486
        }
487
      }
488

    
489

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491
// INTERNAL API (for AutomaticControl)
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

    
494
    public ObjectPreRender getPreRender()
495
      {
496
      return mPreRender;
497
      }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

    
501
    public ObjectLibInterface getInterface()
502
      {
503
      return mInterface;
504
      }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507
// PUBLIC API
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509

    
510
    public ObjectControl(Activity act, ObjectLibInterface actioner)
511
      {
512
      mIsAutomatic = false;
513

    
514
      mLastCubitColor = -1;
515
      mCurrRotSpeed   = 0.0f;
516

    
517
      mLastX = new float[NUM_SPEED_PROBES];
518
      mLastY = new float[NUM_SPEED_PROBES];
519
      mLastT = new long[NUM_SPEED_PROBES];
520
      mFirstIndex =0;
521
      mLastIndex  =0;
522

    
523
      DisplayMetrics dm = new DisplayMetrics();
524
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
525

    
526
      mDensity = dm.densityDpi;
527

    
528
      mPreRender = new ObjectPreRender(act,this,actioner);
529
      mInterface = actioner;
530
      }
531

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

    
534
    public void setScreenSize(int width, int height)
535
      {
536
      mScreenWidth = width;
537
      mScreenHeight= height;
538
      mScreenMin = Math.min(width, height);
539
      mPreRender.setScreenSize(width);
540
      }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543

    
544
    public void initialize()
545
      {
546
      mPointer1 = INVALID_POINTER_ID;
547
      mPointer2 = INVALID_POINTER_ID;
548

    
549
      unlock();
550
      }
551

    
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553

    
554
    public void setQuat()
555
      {
556
      mQuat.set(mTemp);
557
      }
558

    
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560

    
561
    public Static4D getQuat()
562
      {
563
      return mQuat;
564
      }
565

    
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567

    
568
    public void setMovement(Movement movement)
569
      {
570
      mMovement = movement;
571
      }
572

    
573
///////////////////////////////////////////////////////////////////////////////////////////////////
574

    
575
    public void preRender()
576
      {
577
      mPreRender.preRender();
578
      }
579

    
580
///////////////////////////////////////////////////////////////////////////////////////////////////
581

    
582
    public void blockEverything(int place)
583
      {
584
      setLock(true);
585
      mPreRender.blockEverything(place);
586
      }
587

    
588
///////////////////////////////////////////////////////////////////////////////////////////////////
589

    
590
    public void blockTouch(int place)
591
      {
592
      setLock(true);
593
      mPreRender.blockTouch(place);
594
      }
595

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

    
598
    public void unblockEverything()
599
      {
600
      unsetLock();
601
      mPreRender.unblockEverything();
602
      }
603

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

    
606
    public void unblockTouch()
607
      {
608
      unsetLock();
609
      mPreRender.unblockTouch();
610
      }
611

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

    
614
    public void unblockUI()
615
      {
616
      mPreRender.unblockUI();
617
      }
618

    
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620

    
621
    public boolean isTouchBlocked()
622
      {
623
      return mPreRender.isTouchBlocked();
624
      }
625

    
626
///////////////////////////////////////////////////////////////////////////////////////////////////
627

    
628
    public boolean isUINotBlocked()
629
      {
630
      return mPreRender.isUINotBlocked();
631
      }
632

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

    
635
    public void initializeObject(int[][] moves)
636
      {
637
      mPreRender.initializeObject(moves);
638
      }
639

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

    
642
    public void changeObject(ObjectType object)
643
      {
644
      mPreRender.changeObject(object);
645
      }
646

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

    
649
    public void setupObject(ObjectType object, int[][] moves)
650
      {
651
      mPreRender.setupObject(object,moves);
652
      }
653

    
654
///////////////////////////////////////////////////////////////////////////////////////////////////
655

    
656
    public void scrambleObject(int num)
657
      {
658
      mPreRender.scrambleObject(num);
659
      }
660

    
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662

    
663
    public void solveObject()
664
      {
665
      mPreRender.solveObject();
666
      }
667

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

    
670
    public void solveOnly()
671
      {
672
      mPreRender.solveOnly();
673
      }
674

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

    
677
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
678
      {
679
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
680
      }
681

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

    
684
    public void resetAllTextureMaps()
685
      {
686
      mPreRender.resetAllTextureMaps();
687
      }
688

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

    
691
    public TwistyObject getObject()
692
      {
693
      return mPreRender.getObject();
694
      }
695

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

    
698
    public void savePreferences(SharedPreferences.Editor editor)
699
      {
700
      mPreRender.savePreferences(editor);
701
      }
702

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

    
705
    public void restorePreferences(SharedPreferences preferences)
706
      {
707
      mPreRender.restorePreferences(preferences);
708
      }
709
///////////////////////////////////////////////////////////////////////////////////////////////////
710

    
711
  public boolean retLocked()
712
      {
713
      return mIsLocked;
714
      }
715

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

    
718
  public void toggleLock()
719
      {
720
      mIsLocked = !mIsLocked;
721
      }
722

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

    
725
  public void unlock()
726
    {
727
    mIsLocked = false;
728
    }
729

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

    
732
  public void setLock(boolean value)
733
    {
734
    mRemLocked = mIsLocked;
735
    mIsLocked = value;
736
    }
737

    
738
///////////////////////////////////////////////////////////////////////////////////////////////////
739

    
740
  public void unsetLock()
741
    {
742
    mIsLocked = mRemLocked;
743
    }
744

    
745
///////////////////////////////////////////////////////////////////////////////////////////////////
746

    
747
    public boolean onTouchEvent(MotionEvent event, int mode)
748
      {
749
      int action = event.getActionMasked();
750

    
751
      switch(action)
752
         {
753
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
754
                                               actionDown(mX1, mY1, mode);
755
                                               break;
756
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
757
                                               actionMove(mX1, mY1, mX2, mY2, mode);
758
                                               break;
759
         case MotionEvent.ACTION_UP          : prepareUp(event);
760
                                               actionUp();
761
                                               break;
762
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
763
                                               actionDown2(mX1, mY1, mX2, mY2);
764
                                               break;
765
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
766
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
767
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
768
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
769
                                               break;
770
         }
771

    
772
      return true;
773
      }
774
}
775

    
(7-7/15)