Project

General

Profile

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

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

1 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 b3fff6fb Leszek Koltunski
import android.app.Activity;
23 9276dced Leszek Koltunski
import android.content.SharedPreferences;
24 880beeea Leszek Koltunski
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 2fca02cf Leszek Koltunski
import org.distorted.objectlib.helpers.BlockController;
32 9276dced Leszek Koltunski
import org.distorted.objectlib.helpers.MovesFinished;
33 b3fff6fb Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectLibInterface;
34 880beeea Leszek Koltunski
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 b3fff6fb Leszek Koltunski
    private final ObjectLibInterface mInterface;
55 880beeea Leszek Koltunski
    private final ObjectPreRender mPreRender;
56
    private Movement mMovement;
57
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
58
    private int mScreenWidth, mScreenHeight, mScreenMin;
59 72d6857c Leszek Koltunski
    private float mMoveX, mMoveY;
60 880beeea Leszek Koltunski
61
    private float mRotAngle, mInitDistance;
62
    private float mStartRotX, mStartRotY;
63
    private float mAxisX, mAxisY;
64
    private float mRotationFactor;
65 a57e6870 Leszek Koltunski
    private int mLastCubitColor, mLastCubit;
66 880beeea Leszek Koltunski
    private int mCurrentAxis, mCurrentRow;
67
    private float mCurrentAngle, mCurrRotSpeed;
68
    private final float[] mLastX;
69
    private final float[] mLastY;
70
    private final long[] mLastT;
71
    private int mFirstIndex, mLastIndex;
72
    private final int mDensity;
73
74
    private int mPointer1, mPointer2;
75
    private float mX1, mY1, mX2, mY2, mX, mY;
76 046104f5 Leszek Koltunski
    private final boolean mIsAutomatic;
77 880beeea Leszek Koltunski
78 b9956428 Leszek Koltunski
    private boolean mIsLocked, mRemLocked;
79
80 880beeea Leszek Koltunski
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
81
    private static final Static4D mTemp= new Static4D(0,0,0,1);
82
83 568d4698 Leszek Koltunski
    private static boolean mForcedIconMode = false, mForcedCreateMesh = false;
84 2289cab1 Leszek Koltunski
85 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
86
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
87
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
88
89
    private void computeCurrentAxis(Static4D axis)
90
      {
91
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
92
93
      mAxisX =result.get0();
94
      mAxisY =result.get1();
95
96
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
97
      mAxisX /= len;
98
      mAxisY /= len;
99
      }
100
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
103
    private void addSpeedProbe(float x, float y)
104
      {
105
      long currTime = System.currentTimeMillis();
106
      boolean theSame = mLastIndex==mFirstIndex;
107
108
      mLastIndex++;
109
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
110
111
      mLastT[mLastIndex] = currTime;
112
      mLastX[mLastIndex] = x;
113
      mLastY[mLastIndex] = y;
114
115
      if( mLastIndex==mFirstIndex)
116
        {
117
        mFirstIndex++;
118
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
119
        }
120
121
      if( theSame )
122
        {
123
        mLastT[mFirstIndex] = currTime;
124
        mLastX[mFirstIndex] = x;
125
        mLastY[mFirstIndex] = y;
126
        }
127
      }
128
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130
131
    private void computeCurrentSpeedInInchesPerSecond()
132
      {
133
      long firstTime = mLastT[mFirstIndex];
134
      long lastTime  = mLastT[mLastIndex];
135
      float fX = mLastX[mFirstIndex];
136
      float fY = mLastY[mFirstIndex];
137
      float lX = mLastX[mLastIndex];
138
      float lY = mLastY[mLastIndex];
139
140
      long timeDiff = lastTime-firstTime;
141
142
      mLastIndex = 0;
143
      mFirstIndex= 0;
144
145
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
146
      }
147
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149
150
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
151
      {
152
      float xDist = mScreenWidth*(xFrom-xTo);
153
      float yDist = mScreenHeight*(yFrom-yTo);
154
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
155
156
      return distInPixels/mDensity;
157
      }
158
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
161
    private void setUpDragOrRotate(boolean down, float x, float y, int mode)
162
      {
163
      if( mode==MODE_DRAG )
164
        {
165
        mDragging           = true;
166
        mBeginningRotation  = false;
167
        mContinuingRotation = false;
168
        }
169
      else
170
        {
171
        TwistyObject object = mPreRender.getObject();
172
        CAMERA_POINT.set2( object==null ? 1.21f : object.getCameraDist() );
173
174
        Static4D touchPoint = new Static4D(x, y, 0, 0);
175
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
176
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
177
178
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
179
          {
180
          mDragging           = false;
181
          mContinuingRotation = false;
182
183
          if( mode==MODE_ROTATE )
184
            {
185
            mBeginningRotation= !mPreRender.isTouchBlocked();
186
            }
187
          else if( mode==MODE_REPLACE )
188
            {
189
            mBeginningRotation= false;
190
191
            if( down )
192
              {
193 b3fff6fb Leszek Koltunski
              int color = mInterface.getCurrentColor();
194 880beeea Leszek Koltunski
              float[] point = mMovement.getTouchedPoint3D();
195
              mLastCubit = object.getCubit(point);
196 b3fff6fb Leszek Koltunski
              mLastCubitColor = mInterface.cubitIsLocked(object.getObjectType(),mLastCubit);
197 a57e6870 Leszek Koltunski
              mPreRender.setTextureMap( mLastCubit, mLastCubitColor>=0 ? 4 : mMovement.getTouchedFace(), color );
198 880beeea Leszek Koltunski
              }
199
            }
200
          }
201
        else
202
          {
203 b9956428 Leszek Koltunski
          mDragging           = (!mIsLocked || mIsAutomatic);
204 880beeea Leszek Koltunski
          mBeginningRotation  = false;
205
          mContinuingRotation = false;
206 b3fff6fb Leszek Koltunski
          if( !mDragging ) mInterface.failedToDrag();
207 880beeea Leszek Koltunski
          }
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 2df35810 Leszek Koltunski
      TwistyObject object = mPreRender.getObject();
253
      int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
254 880beeea Leszek Koltunski
      mPreRender.finishRotation(angle);
255
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
256
257
      if( angle!=0 )
258
        {
259 2df35810 Leszek Koltunski
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
260
        int realAngle = (angle*basicAngle)/360;
261 b3fff6fb Leszek Koltunski
        mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
262 880beeea Leszek Koltunski
        }
263
264
      mContinuingRotation = false;
265
      mBeginningRotation  = false;
266
      mDragging           = true;
267
      }
268
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
271
    private void continueRotation(float x, float y)
272
      {
273
      float dx = x-mStartRotX;
274
      float dy = y-mStartRotY;
275
      float alpha = dx*mAxisX + dy*mAxisY;
276
      float x2 = dx - alpha*mAxisX;
277
      float y2 = dy - alpha*mAxisY;
278
279
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
280
281
      // we have the length of 1D vector 'angle', now the direction:
282
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
283
284
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
285
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
286
      mPreRender.getObject().continueRotation(mCurrentAngle);
287
288
      addSpeedProbe(x2,y2);
289
      }
290
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292
293
    private void beginRotation(float x, float y)
294
      {
295
      mStartRotX = x;
296
      mStartRotY = y;
297
298
      TwistyObject object = mPreRender.getObject();
299 a57e6870 Leszek Koltunski
      int[] numLayers = object.getNumLayers();
300 880beeea Leszek Koltunski
301
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
302
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
303
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
304
305
      mCurrentAxis = (int)res.get0();
306
      mCurrentRow  = (int)res.get1();
307
308
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
309
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
310
311
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
312
313 b3fff6fb Leszek Koltunski
      mInterface.onBeginRotation();
314 880beeea Leszek Koltunski
315
      addSpeedProbe(x,y);
316
317
      mBeginningRotation = false;
318
      mContinuingRotation= true;
319
      }
320
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
323
    private float getAngle(float x1, float y1, float x2, float y2)
324
      {
325
      return (float) Math.atan2(y1-y2, x1-x2);
326
      }
327
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
330
    private void prepareDown(MotionEvent event)
331
      {
332
      mPointer1 = event.getPointerId(0);
333 72d6857c Leszek Koltunski
      mX1 = event.getX() - mMoveX;
334
      mY1 = event.getY() + mMoveY;
335 880beeea Leszek Koltunski
      mPointer2 = INVALID_POINTER_ID;
336
      }
337
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339
340
    private void prepareMove(MotionEvent event)
341
      {
342
      int index1 = event.findPointerIndex(mPointer1);
343
344
      if( index1>=0 )
345
        {
346 72d6857c Leszek Koltunski
        mX1 = event.getX(index1) - mMoveX;
347
        mY1 = event.getY(index1) + mMoveY;
348 880beeea Leszek Koltunski
        }
349
350
      int index2 = event.findPointerIndex(mPointer2);
351
352
      if( index2>=0 )
353
        {
354 72d6857c Leszek Koltunski
        mX2 = event.getX(index2) - mMoveX;
355
        mY2 = event.getY(index2) + mMoveY;
356 880beeea Leszek Koltunski
        }
357
      }
358
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
361
    private void prepareUp(MotionEvent event)
362
      {
363
      mPointer1 = INVALID_POINTER_ID;
364
      mPointer2 = INVALID_POINTER_ID;
365
      }
366
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
369
    private void prepareDown2(MotionEvent event)
370
      {
371
      int index = event.getActionIndex();
372
373
      if( mPointer1==INVALID_POINTER_ID )
374
        {
375
        mPointer1 = event.getPointerId(index);
376 72d6857c Leszek Koltunski
        mX1 = event.getX(index) - mMoveX;
377
        mY1 = event.getY(index) + mMoveY;
378 880beeea Leszek Koltunski
        }
379
      else if( mPointer2==INVALID_POINTER_ID )
380
        {
381
        mPointer2 = event.getPointerId(index);
382 72d6857c Leszek Koltunski
        mX2 = event.getX(index) - mMoveX;
383
        mY2 = event.getY(index) + mMoveY;
384 880beeea Leszek Koltunski
        }
385
      }
386
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388
389
    private void prepareUp2(MotionEvent event)
390
      {
391
      int index = event.getActionIndex();
392
393
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
394
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
395
      }
396
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398
399
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
400
      {
401
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
402
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
403
404
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
405
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
406
407
      if( mBeginningRotation )
408
        {
409
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
410
          {
411
          beginRotation(x,y);
412
          }
413
        }
414
      else if( mContinuingRotation )
415
        {
416
        continueRotation(x,y);
417
        }
418
      else if( mDragging )
419
        {
420
        drag(x,y);
421
        }
422
      else
423
        {
424
        setUpDragOrRotate(false,x,y,mode);
425
        }
426
      }
427
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429
430
    private void actionDown(float x, float y, int mode)
431
      {
432
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
433
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
434
435
      setUpDragOrRotate(true,mX,mY,mode);
436
      }
437
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439
440
    private void actionUp()
441
      {
442
      if( mContinuingRotation )
443
        {
444
        finishRotation();
445
        }
446
447
      if( mLastCubitColor>=0 )
448
        {
449 a57e6870 Leszek Koltunski
        mPreRender.setTextureMap( mLastCubit, 4, mLastCubitColor );
450 880beeea Leszek Koltunski
        mLastCubitColor = -1;
451
        }
452
      }
453
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455
456
    private void actionDown2(float x1, float y1, float x2, float y2)
457
      {
458
      mRotAngle = getAngle(x1,-y1, x2,-y2);
459
      mInitDistance = -1;
460
461
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
462
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
463
464
      if( mBeginningRotation )
465
        {
466
        mContinuingRotation = false;
467
        mBeginningRotation  = false;
468
        mDragging           = true;
469
        }
470
      else if( mContinuingRotation )
471
        {
472
        finishRotation();
473
        }
474
      }
475
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477
478
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
479
      {
480
      if( p1isUp )
481
        {
482
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
483
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
484
        }
485
      if( p2isUp )
486
        {
487
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
488
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
489
        }
490
      }
491
492 9276dced Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
493
// INTERNAL API (for AutomaticControl)
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495
496
    public ObjectPreRender getPreRender()
497
      {
498
      return mPreRender;
499
      }
500
501 b3fff6fb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
502
503
    public ObjectLibInterface getInterface()
504
      {
505
      return mInterface;
506
      }
507
508 2289cab1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
509
510 568d4698 Leszek Koltunski
    public static void setIconMode(boolean mode)
511 2289cab1 Leszek Koltunski
      {
512 568d4698 Leszek Koltunski
      mForcedIconMode = mode;
513
      }
514
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516
517
    public static void setForcedMesh(boolean mode)
518
      {
519
      mForcedCreateMesh = mode;
520 2289cab1 Leszek Koltunski
      }
521
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523
524
    public static boolean isInIconMode()
525
      {
526
      return mForcedIconMode;
527
      }
528
529 568d4698 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
530
531
    public static boolean isInCreateMesh()
532
      {
533
      return mForcedCreateMesh;
534
      }
535
536 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
537
// PUBLIC API
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539
540 b3fff6fb Leszek Koltunski
    public ObjectControl(Activity act, ObjectLibInterface actioner)
541 880beeea Leszek Koltunski
      {
542
      mIsAutomatic = false;
543
544
      mLastCubitColor = -1;
545
      mCurrRotSpeed   = 0.0f;
546
547
      mLastX = new float[NUM_SPEED_PROBES];
548
      mLastY = new float[NUM_SPEED_PROBES];
549
      mLastT = new long[NUM_SPEED_PROBES];
550
      mFirstIndex =0;
551
      mLastIndex  =0;
552
553
      DisplayMetrics dm = new DisplayMetrics();
554
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
555
556
      mDensity = dm.densityDpi;
557
558 15e5214c Leszek Koltunski
      mPreRender = new ObjectPreRender(act,this,actioner);
559 b3fff6fb Leszek Koltunski
      mInterface = actioner;
560 880beeea Leszek Koltunski
      }
561
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563
564
    public void setScreenSize(int width, int height)
565
      {
566
      mScreenWidth = width;
567
      mScreenHeight= height;
568 e7daa161 Leszek Koltunski
      mScreenMin = Math.min(width,height);
569
      mPreRender.setScreenSize(width,height);
570 880beeea Leszek Koltunski
      }
571
572 ecf3d6e3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
573
574
    public void setMove(int xmove, int ymove)
575
      {
576 72d6857c Leszek Koltunski
      mMoveX = xmove;
577
      mMoveY = ymove;
578
579
      mPreRender.setMove(xmove,ymove);
580 ecf3d6e3 Leszek Koltunski
      }
581
582 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
583
584 2fca02cf Leszek Koltunski
    public void onPause()
585
      {
586
      BlockController.onPause();
587
      }
588
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590
591
    public void onResume()
592 880beeea Leszek Koltunski
      {
593
      mPointer1 = INVALID_POINTER_ID;
594
      mPointer2 = INVALID_POINTER_ID;
595 b9956428 Leszek Koltunski
596
      unlock();
597 2fca02cf Leszek Koltunski
598
      BlockController.onResume();
599 880beeea Leszek Koltunski
      }
600
601 2289cab1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
602
603
    public void rotateNow(Static4D quat)
604
      {
605
      mTemp.set(quat);
606
      mQuat.set(mTemp);
607
      }
608
609 ee6bb8d7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
610
611
    public void scaleNow(float scale)
612
      {
613
      mPreRender.getObject().setObjectRatioNow(scale);
614
      }
615
616 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
617
618
    public void setQuat()
619
      {
620
      mQuat.set(mTemp);
621
      }
622
623
///////////////////////////////////////////////////////////////////////////////////////////////////
624
625
    public Static4D getQuat()
626
      {
627
      return mQuat;
628
      }
629
630
///////////////////////////////////////////////////////////////////////////////////////////////////
631
632
    public void setMovement(Movement movement)
633
      {
634
      mMovement = movement;
635
      }
636
637
///////////////////////////////////////////////////////////////////////////////////////////////////
638
639 9276dced Leszek Koltunski
    public void preRender()
640 880beeea Leszek Koltunski
      {
641 9276dced Leszek Koltunski
      mPreRender.preRender();
642
      }
643
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645
646
    public void blockEverything(int place)
647
      {
648 b9956428 Leszek Koltunski
      setLock(true);
649 9276dced Leszek Koltunski
      mPreRender.blockEverything(place);
650
      }
651
652
///////////////////////////////////////////////////////////////////////////////////////////////////
653
654
    public void blockTouch(int place)
655
      {
656 b9956428 Leszek Koltunski
      setLock(true);
657 9276dced Leszek Koltunski
      mPreRender.blockTouch(place);
658
      }
659
660
///////////////////////////////////////////////////////////////////////////////////////////////////
661
662
    public void unblockEverything()
663
      {
664 b9956428 Leszek Koltunski
      unsetLock();
665 9276dced Leszek Koltunski
      mPreRender.unblockEverything();
666
      }
667
668
///////////////////////////////////////////////////////////////////////////////////////////////////
669
670
    public void unblockTouch()
671
      {
672 b9956428 Leszek Koltunski
      unsetLock();
673 9276dced Leszek Koltunski
      mPreRender.unblockTouch();
674
      }
675
676
///////////////////////////////////////////////////////////////////////////////////////////////////
677
678
    public void unblockUI()
679
      {
680
      mPreRender.unblockUI();
681
      }
682
683
///////////////////////////////////////////////////////////////////////////////////////////////////
684
685
    public boolean isTouchBlocked()
686
      {
687
      return mPreRender.isTouchBlocked();
688
      }
689
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691
692
    public boolean isUINotBlocked()
693
      {
694
      return mPreRender.isUINotBlocked();
695
      }
696
697
///////////////////////////////////////////////////////////////////////////////////////////////////
698
699
    public void initializeObject(int[][] moves)
700
      {
701
      mPreRender.initializeObject(moves);
702
      }
703
704
///////////////////////////////////////////////////////////////////////////////////////////////////
705
706
    public void changeObject(ObjectType object)
707
      {
708
      mPreRender.changeObject(object);
709
      }
710
711 568d4698 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
712
713
    public void recreateObject()
714
      {
715
      mPreRender.recreateObject();
716
      }
717
718 9276dced Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
719
720
    public void scrambleObject(int num)
721
      {
722
      mPreRender.scrambleObject(num);
723
      }
724
725
///////////////////////////////////////////////////////////////////////////////////////////////////
726
727
    public void solveObject()
728
      {
729
      mPreRender.solveObject();
730
      }
731
732 17d623f1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
733
734
    public void solveOnly()
735
      {
736
      mPreRender.solveOnly();
737
      }
738
739 9276dced Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
740
741 2df35810 Leszek Koltunski
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
742 9276dced Leszek Koltunski
      {
743
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
744
      }
745
746
///////////////////////////////////////////////////////////////////////////////////////////////////
747
748
    public void resetAllTextureMaps()
749
      {
750
      mPreRender.resetAllTextureMaps();
751
      }
752
753
///////////////////////////////////////////////////////////////////////////////////////////////////
754
755
    public TwistyObject getObject()
756
      {
757
      return mPreRender.getObject();
758
      }
759
760
///////////////////////////////////////////////////////////////////////////////////////////////////
761
762
    public void savePreferences(SharedPreferences.Editor editor)
763
      {
764
      mPreRender.savePreferences(editor);
765
      }
766
767
///////////////////////////////////////////////////////////////////////////////////////////////////
768
769
    public void restorePreferences(SharedPreferences preferences)
770
      {
771
      mPreRender.restorePreferences(preferences);
772 880beeea Leszek Koltunski
      }
773 b9956428 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
774
775 81141862 Leszek Koltunski
    public boolean retLocked()
776 b9956428 Leszek Koltunski
      {
777
      return mIsLocked;
778
      }
779
780
///////////////////////////////////////////////////////////////////////////////////////////////////
781
782 81141862 Leszek Koltunski
    public void toggleLock()
783 b9956428 Leszek Koltunski
      {
784
      mIsLocked = !mIsLocked;
785
      }
786
787
///////////////////////////////////////////////////////////////////////////////////////////////////
788
789 81141862 Leszek Koltunski
    public void unlock()
790
      {
791
      mIsLocked = false;
792
      }
793 b9956428 Leszek Koltunski
794
///////////////////////////////////////////////////////////////////////////////////////////////////
795
796 81141862 Leszek Koltunski
    public void setLock(boolean value)
797
      {
798
      mRemLocked = mIsLocked;
799
      mIsLocked = value;
800
      }
801 b9956428 Leszek Koltunski
802
///////////////////////////////////////////////////////////////////////////////////////////////////
803
804 81141862 Leszek Koltunski
    public void unsetLock()
805
      {
806
      mIsLocked = mRemLocked;
807
      }
808 880beeea Leszek Koltunski
809
///////////////////////////////////////////////////////////////////////////////////////////////////
810
811
    public boolean onTouchEvent(MotionEvent event, int mode)
812
      {
813
      int action = event.getActionMasked();
814
815
      switch(action)
816
         {
817
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
818
                                               actionDown(mX1, mY1, mode);
819
                                               break;
820
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
821
                                               actionMove(mX1, mY1, mX2, mY2, mode);
822
                                               break;
823
         case MotionEvent.ACTION_UP          : prepareUp(event);
824
                                               actionUp();
825
                                               break;
826
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
827
                                               actionDown2(mX1, mY1, mX2, mY2);
828
                                               break;
829
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
830
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
831
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
832
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
833
                                               break;
834
         }
835
836
      return true;
837
      }
838
}