Project

General

Profile

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

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

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
    private int mLastCubitColor, mLastCubitFace, mLastCubit;
66
    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 2289cab1 Leszek Koltunski
    private static boolean mForcedIconMode;
84
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
              mLastCubitFace = mMovement.getTouchedFace();
195
              float[] point = mMovement.getTouchedPoint3D();
196
              mLastCubit = object.getCubit(point);
197
              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
198 b3fff6fb Leszek Koltunski
              mLastCubitColor = mInterface.cubitIsLocked(object.getObjectType(),mLastCubit);
199 880beeea Leszek Koltunski
              }
200
            }
201
          }
202
        else
203
          {
204 b9956428 Leszek Koltunski
          mDragging           = (!mIsLocked || mIsAutomatic);
205 880beeea Leszek Koltunski
          mBeginningRotation  = false;
206
          mContinuingRotation = false;
207 b3fff6fb Leszek Koltunski
          if( !mDragging ) mInterface.failedToDrag();
208 880beeea Leszek Koltunski
          }
209
        }
210
      }
211
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
214
    private void drag(float x, float y)
215
      {
216
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
217
        {
218
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
219
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
220
221
        float angleNow = getAngle(x,y,x2,y2);
222
        float angleDiff = angleNow-mRotAngle;
223
        float sinA =-(float)Math.sin(angleDiff);
224
        float cosA = (float)Math.cos(angleDiff);
225
226
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
227
        mTemp.set(dragQuat);
228
229
        mRotAngle = angleNow;
230
231
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
232
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
233
        mInitDistance = distNow;
234
        TwistyObject object = mPreRender.getObject();
235
        if( object!=null ) object.setObjectRatio(distQuot);
236
        }
237
      else
238
        {
239
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
240
        mTemp.set(dragQuat);
241
        }
242
243
      mPreRender.setQuatOnNextRender();
244
      mX = x;
245
      mY = y;
246
      }
247
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249
250
    private void finishRotation()
251
      {
252
      computeCurrentSpeedInInchesPerSecond();
253 2df35810 Leszek Koltunski
      TwistyObject object = mPreRender.getObject();
254
      int angle = object.computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
255 880beeea Leszek Koltunski
      mPreRender.finishRotation(angle);
256
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
257
258
      if( angle!=0 )
259
        {
260 2df35810 Leszek Koltunski
        int basicAngle= object.getBasicAngle()[mCurrentAxis];
261
        int realAngle = (angle*basicAngle)/360;
262 b3fff6fb Leszek Koltunski
        mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
263 880beeea Leszek Koltunski
        }
264
265
      mContinuingRotation = false;
266
      mBeginningRotation  = false;
267
      mDragging           = true;
268
      }
269
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271
272
    private void continueRotation(float x, float y)
273
      {
274
      float dx = x-mStartRotX;
275
      float dy = y-mStartRotY;
276
      float alpha = dx*mAxisX + dy*mAxisY;
277
      float x2 = dx - alpha*mAxisX;
278
      float y2 = dy - alpha*mAxisY;
279
280
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
281
282
      // we have the length of 1D vector 'angle', now the direction:
283
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
284
285
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
286
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
287
      mPreRender.getObject().continueRotation(mCurrentAngle);
288
289
      addSpeedProbe(x2,y2);
290
      }
291
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293
294
    private void beginRotation(float x, float y)
295
      {
296
      mStartRotX = x;
297
      mStartRotY = y;
298
299
      TwistyObject object = mPreRender.getObject();
300
      int numLayers = object.getNumLayers();
301
302
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
303
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
304
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
305
306
      mCurrentAxis = (int)res.get0();
307
      mCurrentRow  = (int)res.get1();
308
309
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
310
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
311
312
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
313
314 b3fff6fb Leszek Koltunski
      mInterface.onBeginRotation();
315 880beeea Leszek Koltunski
316
      addSpeedProbe(x,y);
317
318
      mBeginningRotation = false;
319
      mContinuingRotation= true;
320
      }
321
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323
324
    private float getAngle(float x1, float y1, float x2, float y2)
325
      {
326
      return (float) Math.atan2(y1-y2, x1-x2);
327
      }
328
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
331
    private void prepareDown(MotionEvent event)
332
      {
333
      mPointer1 = event.getPointerId(0);
334 72d6857c Leszek Koltunski
      mX1 = event.getX() - mMoveX;
335
      mY1 = event.getY() + mMoveY;
336 880beeea Leszek Koltunski
      mPointer2 = INVALID_POINTER_ID;
337
      }
338
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340
341
    private void prepareMove(MotionEvent event)
342
      {
343
      int index1 = event.findPointerIndex(mPointer1);
344
345
      if( index1>=0 )
346
        {
347 72d6857c Leszek Koltunski
        mX1 = event.getX(index1) - mMoveX;
348
        mY1 = event.getY(index1) + mMoveY;
349 880beeea Leszek Koltunski
        }
350
351
      int index2 = event.findPointerIndex(mPointer2);
352
353
      if( index2>=0 )
354
        {
355 72d6857c Leszek Koltunski
        mX2 = event.getX(index2) - mMoveX;
356
        mY2 = event.getY(index2) + mMoveY;
357 880beeea Leszek Koltunski
        }
358
      }
359
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361
362
    private void prepareUp(MotionEvent event)
363
      {
364
      mPointer1 = INVALID_POINTER_ID;
365
      mPointer2 = INVALID_POINTER_ID;
366
      }
367
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369
370
    private void prepareDown2(MotionEvent event)
371
      {
372
      int index = event.getActionIndex();
373
374
      if( mPointer1==INVALID_POINTER_ID )
375
        {
376
        mPointer1 = event.getPointerId(index);
377 72d6857c Leszek Koltunski
        mX1 = event.getX(index) - mMoveX;
378
        mY1 = event.getY(index) + mMoveY;
379 880beeea Leszek Koltunski
        }
380
      else if( mPointer2==INVALID_POINTER_ID )
381
        {
382
        mPointer2 = event.getPointerId(index);
383 72d6857c Leszek Koltunski
        mX2 = event.getX(index) - mMoveX;
384
        mY2 = event.getY(index) + mMoveY;
385 880beeea Leszek Koltunski
        }
386
      }
387
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
390
    private void prepareUp2(MotionEvent event)
391
      {
392
      int index = event.getActionIndex();
393
394
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
395
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
396
      }
397
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399
400
    private void actionMove(float x1, float y1, float x2, float y2, int mode)
401
      {
402
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
403
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
404
405
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
406
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
407
408
      if( mBeginningRotation )
409
        {
410
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
411
          {
412
          beginRotation(x,y);
413
          }
414
        }
415
      else if( mContinuingRotation )
416
        {
417
        continueRotation(x,y);
418
        }
419
      else if( mDragging )
420
        {
421
        drag(x,y);
422
        }
423
      else
424
        {
425
        setUpDragOrRotate(false,x,y,mode);
426
        }
427
      }
428
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430
431
    private void actionDown(float x, float y, int mode)
432
      {
433
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
434
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
435
436
      setUpDragOrRotate(true,mX,mY,mode);
437
      }
438
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440
441
    private void actionUp()
442
      {
443
      if( mContinuingRotation )
444
        {
445
        finishRotation();
446
        }
447
448
      if( mLastCubitColor>=0 )
449
        {
450
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
451
        mLastCubitColor = -1;
452
        }
453
      }
454
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456
457
    private void actionDown2(float x1, float y1, float x2, float y2)
458
      {
459
      mRotAngle = getAngle(x1,-y1, x2,-y2);
460
      mInitDistance = -1;
461
462
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
463
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
464
465
      if( mBeginningRotation )
466
        {
467
        mContinuingRotation = false;
468
        mBeginningRotation  = false;
469
        mDragging           = true;
470
        }
471
      else if( mContinuingRotation )
472
        {
473
        finishRotation();
474
        }
475
      }
476
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478
479
    private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
480
      {
481
      if( p1isUp )
482
        {
483
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
484
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
485
        }
486
      if( p2isUp )
487
        {
488
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
489
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
490
        }
491
      }
492
493 9276dced Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
494
// INTERNAL API (for AutomaticControl)
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496
497
    public ObjectPreRender getPreRender()
498
      {
499
      return mPreRender;
500
      }
501
502 b3fff6fb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
503
504
    public ObjectLibInterface getInterface()
505
      {
506
      return mInterface;
507
      }
508
509 2289cab1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
510
511
    public static void setIconMode()
512
      {
513
      mForcedIconMode = true;
514
      }
515
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
518
    public static boolean isInIconMode()
519
      {
520
      return mForcedIconMode;
521
      }
522
523 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
524
// PUBLIC API
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526
527 b3fff6fb Leszek Koltunski
    public ObjectControl(Activity act, ObjectLibInterface actioner)
528 880beeea Leszek Koltunski
      {
529
      mIsAutomatic = false;
530 2289cab1 Leszek Koltunski
      mForcedIconMode = false;
531 880beeea Leszek Koltunski
532
      mLastCubitColor = -1;
533
      mCurrRotSpeed   = 0.0f;
534
535
      mLastX = new float[NUM_SPEED_PROBES];
536
      mLastY = new float[NUM_SPEED_PROBES];
537
      mLastT = new long[NUM_SPEED_PROBES];
538
      mFirstIndex =0;
539
      mLastIndex  =0;
540
541
      DisplayMetrics dm = new DisplayMetrics();
542
      act.getWindowManager().getDefaultDisplay().getMetrics(dm);
543
544
      mDensity = dm.densityDpi;
545
546 15e5214c Leszek Koltunski
      mPreRender = new ObjectPreRender(act,this,actioner);
547 b3fff6fb Leszek Koltunski
      mInterface = actioner;
548 880beeea Leszek Koltunski
      }
549
550
///////////////////////////////////////////////////////////////////////////////////////////////////
551
552
    public void setScreenSize(int width, int height)
553
      {
554
      mScreenWidth = width;
555
      mScreenHeight= height;
556
      mScreenMin = Math.min(width, height);
557 9276dced Leszek Koltunski
      mPreRender.setScreenSize(width);
558 880beeea Leszek Koltunski
      }
559
560 ecf3d6e3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
561
562
    public void setMove(int xmove, int ymove)
563
      {
564 72d6857c Leszek Koltunski
      mMoveX = xmove;
565
      mMoveY = ymove;
566
567
      mPreRender.setMove(xmove,ymove);
568 ecf3d6e3 Leszek Koltunski
      }
569
570 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
571
572 2fca02cf Leszek Koltunski
    public void onPause()
573
      {
574
      BlockController.onPause();
575
      }
576
577
///////////////////////////////////////////////////////////////////////////////////////////////////
578
579
    public void onResume()
580 880beeea Leszek Koltunski
      {
581
      mPointer1 = INVALID_POINTER_ID;
582
      mPointer2 = INVALID_POINTER_ID;
583 b9956428 Leszek Koltunski
584
      unlock();
585 2fca02cf Leszek Koltunski
586
      BlockController.onResume();
587 880beeea Leszek Koltunski
      }
588
589 2289cab1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
590
591
    public void rotateNow(Static4D quat)
592
      {
593
      mTemp.set(quat);
594
      mQuat.set(mTemp);
595
      }
596
597 ee6bb8d7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
598
599
    public void scaleNow(float scale)
600
      {
601
      mPreRender.getObject().setObjectRatioNow(scale);
602
      }
603
604 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
605
606
    public void setQuat()
607
      {
608
      mQuat.set(mTemp);
609
      }
610
611
///////////////////////////////////////////////////////////////////////////////////////////////////
612
613
    public Static4D getQuat()
614
      {
615
      return mQuat;
616
      }
617
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619
620
    public void setMovement(Movement movement)
621
      {
622
      mMovement = movement;
623
      }
624
625
///////////////////////////////////////////////////////////////////////////////////////////////////
626
627 9276dced Leszek Koltunski
    public void preRender()
628 880beeea Leszek Koltunski
      {
629 9276dced Leszek Koltunski
      mPreRender.preRender();
630
      }
631
632
///////////////////////////////////////////////////////////////////////////////////////////////////
633
634
    public void blockEverything(int place)
635
      {
636 b9956428 Leszek Koltunski
      setLock(true);
637 9276dced Leszek Koltunski
      mPreRender.blockEverything(place);
638
      }
639
640
///////////////////////////////////////////////////////////////////////////////////////////////////
641
642
    public void blockTouch(int place)
643
      {
644 b9956428 Leszek Koltunski
      setLock(true);
645 9276dced Leszek Koltunski
      mPreRender.blockTouch(place);
646
      }
647
648
///////////////////////////////////////////////////////////////////////////////////////////////////
649
650
    public void unblockEverything()
651
      {
652 b9956428 Leszek Koltunski
      unsetLock();
653 9276dced Leszek Koltunski
      mPreRender.unblockEverything();
654
      }
655
656
///////////////////////////////////////////////////////////////////////////////////////////////////
657
658
    public void unblockTouch()
659
      {
660 b9956428 Leszek Koltunski
      unsetLock();
661 9276dced Leszek Koltunski
      mPreRender.unblockTouch();
662
      }
663
664
///////////////////////////////////////////////////////////////////////////////////////////////////
665
666
    public void unblockUI()
667
      {
668
      mPreRender.unblockUI();
669
      }
670
671
///////////////////////////////////////////////////////////////////////////////////////////////////
672
673
    public boolean isTouchBlocked()
674
      {
675
      return mPreRender.isTouchBlocked();
676
      }
677
678
///////////////////////////////////////////////////////////////////////////////////////////////////
679
680
    public boolean isUINotBlocked()
681
      {
682
      return mPreRender.isUINotBlocked();
683
      }
684
685
///////////////////////////////////////////////////////////////////////////////////////////////////
686
687
    public void initializeObject(int[][] moves)
688
      {
689
      mPreRender.initializeObject(moves);
690
      }
691
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693
694
    public void changeObject(ObjectType object)
695
      {
696
      mPreRender.changeObject(object);
697
      }
698
699
///////////////////////////////////////////////////////////////////////////////////////////////////
700
701
    public void scrambleObject(int num)
702
      {
703
      mPreRender.scrambleObject(num);
704
      }
705
706
///////////////////////////////////////////////////////////////////////////////////////////////////
707
708
    public void solveObject()
709
      {
710
      mPreRender.solveObject();
711
      }
712
713 17d623f1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
714
715
    public void solveOnly()
716
      {
717
      mPreRender.solveOnly();
718
      }
719
720 9276dced Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
721
722 2df35810 Leszek Koltunski
    public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
723 9276dced Leszek Koltunski
      {
724
      mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
725
      }
726
727
///////////////////////////////////////////////////////////////////////////////////////////////////
728
729
    public void resetAllTextureMaps()
730
      {
731
      mPreRender.resetAllTextureMaps();
732
      }
733
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735
736
    public TwistyObject getObject()
737
      {
738
      return mPreRender.getObject();
739
      }
740
741
///////////////////////////////////////////////////////////////////////////////////////////////////
742
743
    public void savePreferences(SharedPreferences.Editor editor)
744
      {
745
      mPreRender.savePreferences(editor);
746
      }
747
748
///////////////////////////////////////////////////////////////////////////////////////////////////
749
750
    public void restorePreferences(SharedPreferences preferences)
751
      {
752
      mPreRender.restorePreferences(preferences);
753 880beeea Leszek Koltunski
      }
754 b9956428 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
755
756 81141862 Leszek Koltunski
    public boolean retLocked()
757 b9956428 Leszek Koltunski
      {
758
      return mIsLocked;
759
      }
760
761
///////////////////////////////////////////////////////////////////////////////////////////////////
762
763 81141862 Leszek Koltunski
    public void toggleLock()
764 b9956428 Leszek Koltunski
      {
765
      mIsLocked = !mIsLocked;
766
      }
767
768
///////////////////////////////////////////////////////////////////////////////////////////////////
769
770 81141862 Leszek Koltunski
    public void unlock()
771
      {
772
      mIsLocked = false;
773
      }
774 b9956428 Leszek Koltunski
775
///////////////////////////////////////////////////////////////////////////////////////////////////
776
777 81141862 Leszek Koltunski
    public void setLock(boolean value)
778
      {
779
      mRemLocked = mIsLocked;
780
      mIsLocked = value;
781
      }
782 b9956428 Leszek Koltunski
783
///////////////////////////////////////////////////////////////////////////////////////////////////
784
785 81141862 Leszek Koltunski
    public void unsetLock()
786
      {
787
      mIsLocked = mRemLocked;
788
      }
789 880beeea Leszek Koltunski
790
///////////////////////////////////////////////////////////////////////////////////////////////////
791
792
    public boolean onTouchEvent(MotionEvent event, int mode)
793
      {
794
      int action = event.getActionMasked();
795
796
      switch(action)
797
         {
798
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
799
                                               actionDown(mX1, mY1, mode);
800
                                               break;
801
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
802
                                               actionMove(mX1, mY1, mX2, mY2, mode);
803
                                               break;
804
         case MotionEvent.ACTION_UP          : prepareUp(event);
805
                                               actionUp();
806
                                               break;
807
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
808
                                               actionDown2(mX1, mY1, mX2, mY2);
809
                                               break;
810
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
811
                                               boolean p1isUp = mPointer1==INVALID_POINTER_ID;
812
                                               boolean p2isUp = mPointer2==INVALID_POINTER_ID;
813
                                               actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
814
                                               break;
815
         }
816
817
      return true;
818
      }
819
}