Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / ObjectControl.java @ 9276dced

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.lang.ref.WeakReference;
23

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

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

    
32
import org.distorted.objectlib.helpers.MovesFinished;
33
import org.distorted.objectlib.helpers.ObjectStateActioner;
34
import org.distorted.objectlib.helpers.TwistyActivity;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

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

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

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

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

    
55
    private final WeakReference<TwistyActivity> mAct;
56
    private final ObjectStateActioner mActioner;
57
    private final ObjectPreRender mPreRender;
58
    private Movement mMovement;
59
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
60
    private int mScreenWidth, mScreenHeight, mScreenMin;
61

    
62
    private float mRotAngle, mInitDistance;
63
    private float mStartRotX, mStartRotY;
64
    private float mAxisX, mAxisY;
65
    private float mRotationFactor;
66
    private int mLastCubitColor, mLastCubitFace, 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 static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
80
    private static final Static4D mTemp= new Static4D(0,0,0,1);
81

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

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

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

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

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

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

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

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

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

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

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

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

    
137
      long timeDiff = lastTime-firstTime;
138

    
139
      mLastIndex = 0;
140
      mFirstIndex= 0;
141

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

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

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

    
153
      return distInPixels/mDensity;
154
      }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

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

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

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

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

    
188
            if( down )
189
              {
190
              int color = mActioner.getCurrentColor();
191
              mLastCubitFace = mMovement.getTouchedFace();
192
              float[] point = mMovement.getTouchedPoint3D();
193
              mLastCubit = object.getCubit(point);
194
              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
195
              mLastCubitColor = mActioner.cubitIsLocked(object.getObjectType(),mLastCubit);
196
              }
197
            }
198
          }
199
        else
200
          {
201
          final TwistyActivity act = mAct.get();
202
          final boolean locked= act.isLocked();
203
          mDragging           = (!locked || mIsAutomatic);
204
          mBeginningRotation  = false;
205
          mContinuingRotation = false;
206
          if( !mDragging ) mActioner.failedToDrag(act);
207
          }
208
        }
209
      }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

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

    
220
        float angleNow = getAngle(x,y,x2,y2);
221
        float angleDiff = angleNow-mRotAngle;
222
        float sinA =-(float)Math.sin(angleDiff);
223
        float cosA = (float)Math.cos(angleDiff);
224

    
225
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
226
        mTemp.set(dragQuat);
227

    
228
        mRotAngle = angleNow;
229

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

    
242
      mPreRender.setQuatOnNextRender();
243
      mX = x;
244
      mY = y;
245
      }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

    
249
    private void finishRotation()
250
      {
251
      computeCurrentSpeedInInchesPerSecond();
252
      int angle = mPreRender.getObject().computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
253
      mPreRender.finishRotation(angle);
254
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
255

    
256
      if( angle!=0 )
257
        {
258
        TwistyActivity act = mAct.get();
259
        mActioner.onFinishRotation(act,mCurrentAxis,mCurrentRow,angle);
260
        }
261

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

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

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

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

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

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

    
286
      addSpeedProbe(x2,y2);
287
      }
288

    
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

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

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

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

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

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

    
309
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
310

    
311
      TwistyActivity act = mAct.get();
312
      mActioner.onBeginRotation(act);
313

    
314
      addSpeedProbe(x,y);
315

    
316
      mBeginningRotation = false;
317
      mContinuingRotation= true;
318
      }
319

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

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

    
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

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

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

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

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

    
349
      int index2 = event.findPointerIndex(mPointer2);
350

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

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

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

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

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

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

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

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

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

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397

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

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

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

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

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

    
434
      setUpDragOrRotate(true,mX,mY,mode);
435
      }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

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

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

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

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

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

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

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

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

    
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493
// INTERNAL API (for AutomaticControl)
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

    
496
    public ObjectPreRender getPreRender()
497
      {
498
      return mPreRender;
499
      }
500

    
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502
// PUBLIC API
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
    public ObjectControl(TwistyActivity act, ObjectStateActioner actioner)
506
      {
507
      mIsAutomatic = false;
508

    
509
      mLastCubitColor = -1;
510
      mCurrRotSpeed   = 0.0f;
511

    
512
      mLastX = new float[NUM_SPEED_PROBES];
513
      mLastY = new float[NUM_SPEED_PROBES];
514
      mLastT = new long[NUM_SPEED_PROBES];
515
      mFirstIndex =0;
516
      mLastIndex  =0;
517

    
518
      DisplayMetrics dm = new DisplayMetrics();
519
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
520

    
521
      mDensity = dm.densityDpi;
522

    
523
      mPreRender = new ObjectPreRender(act,this,actioner);
524
      mAct = new WeakReference<>(act);
525
      mActioner = actioner;
526
      }
527

    
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529

    
530
    public void setScreenSize(int width, int height)
531
      {
532
      mScreenWidth = width;
533
      mScreenHeight= height;
534
      mScreenMin = Math.min(width, height);
535
      mPreRender.setScreenSize(width);
536
      }
537

    
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539

    
540
    public void initialize()
541
      {
542
      mPointer1 = INVALID_POINTER_ID;
543
      mPointer2 = INVALID_POINTER_ID;
544
      }
545

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

    
548
    public void setQuat()
549
      {
550
      mQuat.set(mTemp);
551
      }
552

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

    
555
    public Static4D getQuat()
556
      {
557
      return mQuat;
558
      }
559

    
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561

    
562
    public void setMovement(Movement movement)
563
      {
564
      mMovement = movement;
565
      }
566

    
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568

    
569
    public void preRender()
570
      {
571
      mPreRender.preRender();
572
      }
573

    
574
///////////////////////////////////////////////////////////////////////////////////////////////////
575

    
576
    public void blockEverything(int place)
577
      {
578
      mPreRender.blockEverything(place);
579
      }
580

    
581
///////////////////////////////////////////////////////////////////////////////////////////////////
582

    
583
    public void blockTouch(int place)
584
      {
585
      mPreRender.blockTouch(place);
586
      }
587

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

    
590
    public void unblockEverything()
591
      {
592
      mPreRender.unblockEverything();
593
      }
594

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

    
597
    public void unblockTouch()
598
      {
599
      mPreRender.unblockTouch();
600
      }
601

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

    
604
    public void unblockUI()
605
      {
606
      mPreRender.unblockUI();
607
      }
608

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

    
611
    public boolean isTouchBlocked()
612
      {
613
      return mPreRender.isTouchBlocked();
614
      }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617

    
618
    public boolean isUINotBlocked()
619
      {
620
      return mPreRender.isUINotBlocked();
621
      }
622

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

    
625
    public void initializeObject(int[][] moves)
626
      {
627
      mPreRender.initializeObject(moves);
628
      }
629

    
630
///////////////////////////////////////////////////////////////////////////////////////////////////
631

    
632
    public void changeObject(ObjectType object)
633
      {
634
      mPreRender.changeObject(object);
635
      }
636

    
637
///////////////////////////////////////////////////////////////////////////////////////////////////
638

    
639
    public void setupObject(ObjectType object, int[][] moves)
640
      {
641
      mPreRender.setupObject(object,moves);
642
      }
643

    
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645

    
646
    public void scrambleObject(int num)
647
      {
648
      mPreRender.scrambleObject(num);
649
      }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652

    
653
    public void solveObject()
654
      {
655
      mPreRender.solveObject();
656
      }
657

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

    
660
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration)
661
      {
662
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
663
      }
664

    
665
///////////////////////////////////////////////////////////////////////////////////////////////////
666

    
667
    public void resetAllTextureMaps()
668
      {
669
      mPreRender.resetAllTextureMaps();
670
      }
671

    
672
///////////////////////////////////////////////////////////////////////////////////////////////////
673

    
674
    public TwistyObject getObject()
675
      {
676
      return mPreRender.getObject();
677
      }
678

    
679
///////////////////////////////////////////////////////////////////////////////////////////////////
680

    
681
    public void savePreferences(SharedPreferences.Editor editor)
682
      {
683
      mPreRender.savePreferences(editor);
684
      }
685

    
686
///////////////////////////////////////////////////////////////////////////////////////////////////
687

    
688
    public void restorePreferences(SharedPreferences preferences)
689
      {
690
      mPreRender.restorePreferences(preferences);
691
      }
692

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

    
695
    public boolean onTouchEvent(MotionEvent event, int mode)
696
      {
697
      int action = event.getActionMasked();
698

    
699
      switch(action)
700
         {
701
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
702
                                               actionDown(mX1, mY1, mode);
703
                                               break;
704
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
705
                                               actionMove(mX1, mY1, mX2, mY2, mode);
706
                                               break;
707
         case MotionEvent.ACTION_UP          : prepareUp(event);
708
                                               actionUp();
709
                                               break;
710
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
711
                                               actionDown2(mX1, mY1, mX2, mY2);
712
                                               break;
713
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
714
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
715
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
716
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
717
                                               break;
718
         }
719

    
720
      return true;
721
      }
722
}
723

    
(7-7/15)