1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.objectlib.main;
|
11
|
|
12
|
import android.content.SharedPreferences;
|
13
|
import android.view.MotionEvent;
|
14
|
|
15
|
import org.distorted.library.main.QuatHelper;
|
16
|
import org.distorted.library.type.Static4D;
|
17
|
|
18
|
import org.distorted.objectlib.helpers.BlockController;
|
19
|
import org.distorted.objectlib.helpers.MovesFinished;
|
20
|
import org.distorted.objectlib.helpers.ObjectLibInterface;
|
21
|
import org.distorted.objectlib.touchcontrol.TouchControl;
|
22
|
import org.distorted.objectlib.touchcontrol.TouchControlShapeChanging;
|
23
|
|
24
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25
|
|
26
|
public class ObjectControl
|
27
|
{
|
28
|
public static final int MAX_MOVING_PARTS = 242; // Gigaminx
|
29
|
public static final int MAX_QUATS = 60; // Gigaminx: 60 quats group.
|
30
|
|
31
|
public static final int NUM_SPEED_PROBES = 10;
|
32
|
public static final int INVALID_POINTER_ID = -1;
|
33
|
|
34
|
public static final int MODE_ROTATE = 0;
|
35
|
public static final int MODE_DRAG = 1;
|
36
|
public static final int MODE_REPLACE = 2;
|
37
|
public static final int MODE_NOTHING = 3;
|
38
|
|
39
|
// Moving the finger from the middle of the vertical screen to the right edge will rotate a
|
40
|
// given face by SWIPING_SENSITIVITY/2 degrees.
|
41
|
public final static int SWIPING_SENSITIVITY = 240;
|
42
|
// Moving the finger by 0.3 of an inch will start a Rotation.
|
43
|
public final static float ROTATION_SENSITIVITY = 0.3f;
|
44
|
|
45
|
private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
|
46
|
|
47
|
private final ObjectLibInterface mInterface;
|
48
|
private final ObjectPreRender mPreRender;
|
49
|
private TouchControl mTouchControl;
|
50
|
private TwistyObjectNode mObjectNode;
|
51
|
private boolean mDragging, mBeginningRotation, mContinuingRotation;
|
52
|
private int mScreenWidth, mScreenHeight, mScalingSize;
|
53
|
private float mMoveX, mMoveY;
|
54
|
private int mLastMode;
|
55
|
|
56
|
private float mRotAngle, mInitDistance;
|
57
|
private float mStartRotX, mStartRotY;
|
58
|
private float mRotationFactor;
|
59
|
private int mCurrentAxis, mCurrentRow;
|
60
|
private float mCurrentAngle, mCurrRotSpeed;
|
61
|
private final float[] mLastX;
|
62
|
private final float[] mLastY;
|
63
|
private final long[] mLastT;
|
64
|
private int mFirstIndex, mLastIndex;
|
65
|
private final int mDensity;
|
66
|
|
67
|
private int mPointer1, mPointer2;
|
68
|
private float mX1, mY1, mX2, mY2, mX, mY;
|
69
|
private final boolean mIsAutomatic;
|
70
|
|
71
|
private boolean mIsLocked, mRemLocked;
|
72
|
private final int[] mBuffer;
|
73
|
private final float[] mAxis;
|
74
|
private int mMeshState, mIconMode;
|
75
|
private boolean mRotateOnCreation;
|
76
|
private final Static4D mQuat,mTemp;
|
77
|
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
|
80
|
private void addSpeedProbe(float x, float y)
|
81
|
{
|
82
|
long currTime = System.currentTimeMillis();
|
83
|
boolean theSame = mLastIndex==mFirstIndex;
|
84
|
|
85
|
mLastIndex++;
|
86
|
if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
|
87
|
|
88
|
mLastT[mLastIndex] = currTime;
|
89
|
mLastX[mLastIndex] = x;
|
90
|
mLastY[mLastIndex] = y;
|
91
|
|
92
|
if( mLastIndex==mFirstIndex)
|
93
|
{
|
94
|
mFirstIndex++;
|
95
|
if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
|
96
|
}
|
97
|
|
98
|
if( theSame )
|
99
|
{
|
100
|
mLastT[mFirstIndex] = currTime;
|
101
|
mLastX[mFirstIndex] = x;
|
102
|
mLastY[mFirstIndex] = y;
|
103
|
}
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
private void computeCurrentSpeedInInchesPerSecond()
|
109
|
{
|
110
|
long firstTime = mLastT[mFirstIndex];
|
111
|
long lastTime = mLastT[mLastIndex];
|
112
|
float fX = mLastX[mFirstIndex];
|
113
|
float fY = mLastY[mFirstIndex];
|
114
|
float lX = mLastX[mLastIndex];
|
115
|
float lY = mLastY[mLastIndex];
|
116
|
|
117
|
long timeDiff = lastTime-firstTime;
|
118
|
|
119
|
mLastIndex = 0;
|
120
|
mFirstIndex= 0;
|
121
|
|
122
|
mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX-lX,fY-lY)/timeDiff : 0;
|
123
|
}
|
124
|
|
125
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126
|
|
127
|
private float retFingerDragDistanceInInches(float xd, float yd)
|
128
|
{
|
129
|
float xDist = mScreenWidth*xd;
|
130
|
float yDist = mScreenHeight*yd;
|
131
|
float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
|
132
|
|
133
|
return distInPixels/mDensity;
|
134
|
}
|
135
|
|
136
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
137
|
|
138
|
private void replaceMode(boolean down)
|
139
|
{
|
140
|
mBeginningRotation= false;
|
141
|
|
142
|
if( down )
|
143
|
{
|
144
|
int cubit = mTouchControl.getTouchedCubit();
|
145
|
int face = mTouchControl.getTouchedCubitFace();
|
146
|
mInterface.onReplaceModeDown(cubit,face);
|
147
|
}
|
148
|
}
|
149
|
|
150
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151
|
|
152
|
private void setUpDragOrRotate(boolean down, float x, float y)
|
153
|
{
|
154
|
if( mLastMode==MODE_DRAG )
|
155
|
{
|
156
|
mDragging = true;
|
157
|
mBeginningRotation = false;
|
158
|
mContinuingRotation = false;
|
159
|
}
|
160
|
else
|
161
|
{
|
162
|
CAMERA_POINT.set2( mObjectNode.getCameraDist() );
|
163
|
Static4D touchPoint = new Static4D(x, y, 0, 0);
|
164
|
Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
|
165
|
Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
|
166
|
|
167
|
if( mTouchControl!=null && mTouchControl.objectTouched(rotatedTouchPoint,rotatedCamera) )
|
168
|
{
|
169
|
mDragging = false;
|
170
|
mContinuingRotation = false;
|
171
|
|
172
|
if( mLastMode==MODE_ROTATE ) mBeginningRotation = !mPreRender.isRotationBlocked();
|
173
|
else if( mLastMode==MODE_REPLACE ) replaceMode(down);
|
174
|
}
|
175
|
else
|
176
|
{
|
177
|
mDragging = (!mIsLocked || mIsAutomatic);
|
178
|
mBeginningRotation = false;
|
179
|
mContinuingRotation = false;
|
180
|
if( !mDragging ) mInterface.failedToDrag();
|
181
|
}
|
182
|
}
|
183
|
}
|
184
|
|
185
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186
|
|
187
|
private void drag(float x, float y)
|
188
|
{
|
189
|
if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
|
190
|
{
|
191
|
float x2 = (mX2 - mScreenWidth*0.5f)/ mScalingSize;
|
192
|
float y2 = (mScreenHeight*0.5f - mY2)/ mScalingSize;
|
193
|
|
194
|
float angleNow = getAngle(x,y,x2,y2);
|
195
|
float angleDiff = angleNow-mRotAngle;
|
196
|
float sinA =-(float)Math.sin(angleDiff);
|
197
|
float cosA = (float)Math.cos(angleDiff);
|
198
|
|
199
|
Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
|
200
|
mTemp.set(dragQuat);
|
201
|
|
202
|
mRotAngle = angleNow;
|
203
|
|
204
|
float distNow = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
|
205
|
float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
|
206
|
mInitDistance = distNow;
|
207
|
TwistyObject object = mPreRender.getObject();
|
208
|
if( object!=null )
|
209
|
{
|
210
|
object.setObjectRatio(distQuot, mScalingSize );
|
211
|
float ratio = object.getObjectRatio();
|
212
|
if( mLastMode==MODE_REPLACE ) mTouchControl.setObjectRatio(ratio);
|
213
|
}
|
214
|
}
|
215
|
else
|
216
|
{
|
217
|
Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
|
218
|
mTemp.set(dragQuat);
|
219
|
}
|
220
|
|
221
|
mPreRender.setQuatOnNextRender();
|
222
|
mX = x;
|
223
|
mY = y;
|
224
|
}
|
225
|
|
226
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
227
|
|
228
|
private void finishRotation()
|
229
|
{
|
230
|
TwistyObject object = mPreRender.getObject();
|
231
|
int[][] angles = object.getBasicAngles();
|
232
|
|
233
|
if( mCurrentAxis<angles.length && mCurrentRow<angles[mCurrentAxis].length )
|
234
|
{
|
235
|
computeCurrentSpeedInInchesPerSecond();
|
236
|
int basic = angles[mCurrentAxis][mCurrentRow];
|
237
|
int angle = object.computeNearestAngle(basic,mCurrentAngle, mCurrRotSpeed);
|
238
|
mPreRender.finishRotation(angle);
|
239
|
mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
|
240
|
|
241
|
if( angle!=0 )
|
242
|
{
|
243
|
int realAngle = (angle*basic)/360;
|
244
|
mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
|
245
|
}
|
246
|
|
247
|
mContinuingRotation = false;
|
248
|
mBeginningRotation = false;
|
249
|
mDragging = true;
|
250
|
}
|
251
|
}
|
252
|
|
253
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
254
|
|
255
|
private void continueRotation(float x, float y)
|
256
|
{
|
257
|
float dx = x-mStartRotX;
|
258
|
float dy = y-mStartRotY;
|
259
|
float alpha = dx*mAxis[0] + dy*mAxis[1];
|
260
|
float x2 = dx - alpha*mAxis[0];
|
261
|
float y2 = dy - alpha*mAxis[1];
|
262
|
|
263
|
float len = (float)Math.sqrt(x2*x2 + y2*y2);
|
264
|
|
265
|
// we have the length of 1D vector 'angle', now the direction:
|
266
|
float tmp = mAxis[1]==0 ? -mAxis[0]*y2 : mAxis[1]*x2;
|
267
|
|
268
|
float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
|
269
|
mCurrentAngle = SWIPING_SENSITIVITY*angle;
|
270
|
mPreRender.getObject().continueRotation(mCurrentAngle);
|
271
|
|
272
|
addSpeedProbe(x2,y2);
|
273
|
}
|
274
|
|
275
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
276
|
|
277
|
private void beginRotation(float x, float y)
|
278
|
{
|
279
|
mStartRotX = x;
|
280
|
mStartRotY = y;
|
281
|
|
282
|
TwistyObject object = mPreRender.getObject();
|
283
|
int[] numLayers = object.getNumLayers();
|
284
|
Static4D touchPoint = new Static4D(x, y, 0, 0);
|
285
|
Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
|
286
|
|
287
|
mTouchControl.newRotation(mBuffer,rotatedTouchPoint,mQuat);
|
288
|
|
289
|
mCurrentAxis = mBuffer[0];
|
290
|
mCurrentRow = mBuffer[1];
|
291
|
|
292
|
mTouchControl.getCastedRotAxis(mAxis,mQuat,mCurrentAxis);
|
293
|
mRotationFactor = mTouchControl.returnRotationFactor(numLayers,mCurrentRow);
|
294
|
|
295
|
if( object.beginNewRotation( mCurrentAxis, mCurrentRow ) )
|
296
|
{
|
297
|
mInterface.onBeginRotation();
|
298
|
addSpeedProbe(x,y);
|
299
|
mBeginningRotation = false;
|
300
|
mContinuingRotation= true;
|
301
|
}
|
302
|
}
|
303
|
|
304
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
305
|
|
306
|
private float getAngle(float x1, float y1, float x2, float y2)
|
307
|
{
|
308
|
return (float) Math.atan2(y1-y2, x1-x2);
|
309
|
}
|
310
|
|
311
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
312
|
|
313
|
private void prepareDown(MotionEvent event)
|
314
|
{
|
315
|
mPointer1 = event.getPointerId(0);
|
316
|
mX1 = event.getX() - mMoveX;
|
317
|
mY1 = event.getY() + mMoveY;
|
318
|
mPointer2 = INVALID_POINTER_ID;
|
319
|
}
|
320
|
|
321
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
322
|
|
323
|
private void prepareMove(MotionEvent event)
|
324
|
{
|
325
|
int index1 = event.findPointerIndex(mPointer1);
|
326
|
|
327
|
if( index1>=0 )
|
328
|
{
|
329
|
mX1 = event.getX(index1) - mMoveX;
|
330
|
mY1 = event.getY(index1) + mMoveY;
|
331
|
}
|
332
|
|
333
|
int index2 = event.findPointerIndex(mPointer2);
|
334
|
|
335
|
if( index2>=0 )
|
336
|
{
|
337
|
mX2 = event.getX(index2) - mMoveX;
|
338
|
mY2 = event.getY(index2) + mMoveY;
|
339
|
}
|
340
|
}
|
341
|
|
342
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
343
|
|
344
|
private void prepareUp(MotionEvent event)
|
345
|
{
|
346
|
mPointer1 = INVALID_POINTER_ID;
|
347
|
mPointer2 = INVALID_POINTER_ID;
|
348
|
}
|
349
|
|
350
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
351
|
|
352
|
private void prepareDown2(MotionEvent event)
|
353
|
{
|
354
|
int index = event.getActionIndex();
|
355
|
|
356
|
if( mPointer1==INVALID_POINTER_ID )
|
357
|
{
|
358
|
mPointer1 = event.getPointerId(index);
|
359
|
mX1 = event.getX(index) - mMoveX;
|
360
|
mY1 = event.getY(index) + mMoveY;
|
361
|
}
|
362
|
else if( mPointer2==INVALID_POINTER_ID )
|
363
|
{
|
364
|
mPointer2 = event.getPointerId(index);
|
365
|
mX2 = event.getX(index) - mMoveX;
|
366
|
mY2 = event.getY(index) + mMoveY;
|
367
|
}
|
368
|
}
|
369
|
|
370
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
371
|
|
372
|
private void prepareUp2(MotionEvent event)
|
373
|
{
|
374
|
int index = event.getActionIndex();
|
375
|
|
376
|
if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
|
377
|
else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
|
378
|
}
|
379
|
|
380
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
381
|
|
382
|
private void actionMove(float x1, float y1, float x2, float y2)
|
383
|
{
|
384
|
float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
|
385
|
float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
|
386
|
|
387
|
float x = (pX - mScreenWidth*0.5f)/ mScalingSize;
|
388
|
float y = (mScreenHeight*0.5f -pY)/ mScalingSize;
|
389
|
|
390
|
if( mBeginningRotation )
|
391
|
{
|
392
|
if( retFingerDragDistanceInInches(mX-x,mY-y) > ROTATION_SENSITIVITY )
|
393
|
{
|
394
|
beginRotation(x,y);
|
395
|
}
|
396
|
}
|
397
|
else if( mContinuingRotation )
|
398
|
{
|
399
|
continueRotation(x,y);
|
400
|
}
|
401
|
else if( mDragging )
|
402
|
{
|
403
|
drag(x,y);
|
404
|
}
|
405
|
else
|
406
|
{
|
407
|
setUpDragOrRotate(false,x,y);
|
408
|
}
|
409
|
}
|
410
|
|
411
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
412
|
|
413
|
private void actionDown(float x, float y)
|
414
|
{
|
415
|
mX = (x - mScreenWidth*0.5f)/ mScalingSize;
|
416
|
mY = (mScreenHeight*0.5f - y)/ mScalingSize;
|
417
|
|
418
|
setUpDragOrRotate(true,mX,mY);
|
419
|
}
|
420
|
|
421
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
422
|
|
423
|
private void actionUp()
|
424
|
{
|
425
|
if( mContinuingRotation )
|
426
|
{
|
427
|
finishRotation();
|
428
|
}
|
429
|
|
430
|
if( mLastMode==MODE_REPLACE ) mInterface.onReplaceModeUp();
|
431
|
}
|
432
|
|
433
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434
|
|
435
|
private void actionDown2(float x1, float y1, float x2, float y2)
|
436
|
{
|
437
|
mRotAngle = getAngle(x1,-y1, x2,-y2);
|
438
|
mInitDistance = -1;
|
439
|
|
440
|
mX = (x1 - mScreenWidth*0.5f )/ mScalingSize;
|
441
|
mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
|
442
|
|
443
|
if( mBeginningRotation )
|
444
|
{
|
445
|
mContinuingRotation = false;
|
446
|
mBeginningRotation = false;
|
447
|
mDragging = true;
|
448
|
}
|
449
|
else if( mContinuingRotation )
|
450
|
{
|
451
|
finishRotation();
|
452
|
}
|
453
|
}
|
454
|
|
455
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
456
|
|
457
|
private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
|
458
|
{
|
459
|
if( p1isUp )
|
460
|
{
|
461
|
mX = (x2 - mScreenWidth*0.5f)/ mScalingSize;
|
462
|
mY = (mScreenHeight*0.5f - y2)/ mScalingSize;
|
463
|
}
|
464
|
if( p2isUp )
|
465
|
{
|
466
|
mX = (x1 - mScreenWidth*0.5f)/ mScalingSize;
|
467
|
mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
|
468
|
}
|
469
|
}
|
470
|
|
471
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
472
|
|
473
|
int getScalingSize()
|
474
|
{
|
475
|
return mScalingSize;
|
476
|
}
|
477
|
|
478
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
479
|
|
480
|
void setTouchControl(TwistyObject object)
|
481
|
{
|
482
|
if( mLastMode!=MODE_REPLACE ) mTouchControl = object.getTouchControl();
|
483
|
else mTouchControl = new TouchControlShapeChanging(object);
|
484
|
}
|
485
|
|
486
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
487
|
// INTERNAL API (for AutomaticControl)
|
488
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
489
|
|
490
|
public ObjectPreRender getPreRender()
|
491
|
{
|
492
|
return mPreRender;
|
493
|
}
|
494
|
|
495
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
496
|
|
497
|
public ObjectLibInterface getInterface()
|
498
|
{
|
499
|
return mInterface;
|
500
|
}
|
501
|
|
502
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
503
|
// PUBLIC API
|
504
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
505
|
|
506
|
public ObjectControl(ObjectLibInterface actioner)
|
507
|
{
|
508
|
mIsAutomatic = false;
|
509
|
|
510
|
mBuffer = new int[2];
|
511
|
mAxis = new float[2];
|
512
|
|
513
|
mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
|
514
|
mTemp= new Static4D(0,0,0,1);
|
515
|
|
516
|
mCurrRotSpeed= 0.0f;
|
517
|
mLastMode = -1;
|
518
|
mRotateOnCreation = false;
|
519
|
|
520
|
mLastX = new float[NUM_SPEED_PROBES];
|
521
|
mLastY = new float[NUM_SPEED_PROBES];
|
522
|
mLastT = new long[NUM_SPEED_PROBES];
|
523
|
mFirstIndex= 0;
|
524
|
mLastIndex = 0;
|
525
|
mMeshState =-1;
|
526
|
mIconMode =-1;
|
527
|
|
528
|
mDensity = actioner.getScreenDensity();
|
529
|
|
530
|
mPreRender = new ObjectPreRender(this,actioner);
|
531
|
mInterface = actioner;
|
532
|
}
|
533
|
|
534
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
535
|
|
536
|
public void setRotateOnCreation(boolean rotate)
|
537
|
{
|
538
|
mRotateOnCreation = rotate;
|
539
|
}
|
540
|
|
541
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
542
|
|
543
|
public boolean getRotateOnCreation()
|
544
|
{
|
545
|
return mRotateOnCreation;
|
546
|
}
|
547
|
|
548
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
549
|
|
550
|
public TwistyObjectNode getNode()
|
551
|
{
|
552
|
return mObjectNode;
|
553
|
}
|
554
|
|
555
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
556
|
|
557
|
public void createNode(int width, int height)
|
558
|
{
|
559
|
if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
|
560
|
}
|
561
|
|
562
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
563
|
|
564
|
public void setScreenSizeAndScaling(int width, int height, int scaling)
|
565
|
{
|
566
|
mScreenWidth = width;
|
567
|
mScreenHeight= height;
|
568
|
mScalingSize = scaling;
|
569
|
|
570
|
if( mObjectNode!=null ) mObjectNode.setSize(width,height);
|
571
|
|
572
|
TwistyObject object = mPreRender.getObject();
|
573
|
|
574
|
if( object!=null )
|
575
|
{
|
576
|
object.setTexture();
|
577
|
object.setNodeSize(mScalingSize);
|
578
|
}
|
579
|
}
|
580
|
|
581
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
582
|
|
583
|
public void setObjectMove(int xmove, int ymove)
|
584
|
{
|
585
|
mMoveX = xmove;
|
586
|
mMoveY = ymove;
|
587
|
|
588
|
mPreRender.setMove(xmove,ymove);
|
589
|
}
|
590
|
|
591
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
592
|
|
593
|
public void setObjectScale(float scale)
|
594
|
{
|
595
|
mPreRender.setScale(scale);
|
596
|
}
|
597
|
|
598
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
599
|
|
600
|
public void onPause()
|
601
|
{
|
602
|
BlockController.onPause();
|
603
|
}
|
604
|
|
605
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
606
|
|
607
|
public void onResume()
|
608
|
{
|
609
|
mPointer1 = INVALID_POINTER_ID;
|
610
|
mPointer2 = INVALID_POINTER_ID;
|
611
|
|
612
|
unlock();
|
613
|
|
614
|
BlockController.onResume();
|
615
|
}
|
616
|
|
617
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
618
|
|
619
|
public void rotateNow(Static4D quat)
|
620
|
{
|
621
|
mTemp.set(quat);
|
622
|
mQuat.set(mTemp);
|
623
|
}
|
624
|
|
625
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
626
|
|
627
|
public void scaleNow(float scale)
|
628
|
{
|
629
|
mPreRender.getObject().setObjectRatioNow(scale,mScalingSize );
|
630
|
}
|
631
|
|
632
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
633
|
|
634
|
public void setQuat()
|
635
|
{
|
636
|
mQuat.set(mTemp);
|
637
|
}
|
638
|
|
639
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
640
|
|
641
|
public Static4D getQuat()
|
642
|
{
|
643
|
return mQuat;
|
644
|
}
|
645
|
|
646
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
647
|
|
648
|
public void preRender()
|
649
|
{
|
650
|
mPreRender.preRender();
|
651
|
}
|
652
|
|
653
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
654
|
|
655
|
public void blockTouch(int place)
|
656
|
{
|
657
|
setLock(true);
|
658
|
mPreRender.blockRotation(place);
|
659
|
}
|
660
|
|
661
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
662
|
|
663
|
public void unblockRotation()
|
664
|
{
|
665
|
unsetLock();
|
666
|
mPreRender.unblockRotation();
|
667
|
}
|
668
|
|
669
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
670
|
|
671
|
public void unblockEverything()
|
672
|
{
|
673
|
mPreRender.unblockEverything();
|
674
|
}
|
675
|
|
676
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
677
|
|
678
|
public boolean isScramblingAndSolvingNotBlocked()
|
679
|
{
|
680
|
return mPreRender.isScramblingAndSolvingNotBlocked();
|
681
|
}
|
682
|
|
683
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
684
|
|
685
|
public void initializeObject(int[][] moves)
|
686
|
{
|
687
|
mPreRender.initializeObject(moves);
|
688
|
}
|
689
|
|
690
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
691
|
|
692
|
public void changeObject(int ordinal, int meshState, int iconMode, InitAssets asset)
|
693
|
{
|
694
|
mPreRender.changeObject(ordinal, meshState, iconMode, asset);
|
695
|
}
|
696
|
|
697
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
698
|
|
699
|
public void changeIfDifferent(int ordinal, String newName, int meshState, int iconMode, InitAssets asset)
|
700
|
{
|
701
|
TwistyObject object = mPreRender.getObject();
|
702
|
String oldName = object==null ? "" : object.getShortName();
|
703
|
|
704
|
if( !oldName.equals(newName) || mMeshState!=meshState || mIconMode!=iconMode )
|
705
|
{
|
706
|
mMeshState = meshState;
|
707
|
mIconMode = iconMode;
|
708
|
mPreRender.changeObject(ordinal, meshState, iconMode, asset);
|
709
|
}
|
710
|
}
|
711
|
|
712
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
713
|
// if one or more fingers currently touch the screen, and we just pressed the 'scramble' button, do
|
714
|
// not scramble - otherwise a kind of a cheat is possible where user touches the screen, starts
|
715
|
// scrambling, then lifts the finger and the act of lifting screws the scrambling - no further
|
716
|
// scrambles take any effect!
|
717
|
|
718
|
public boolean scrambleObject(int num)
|
719
|
{
|
720
|
if( !mBeginningRotation && !mContinuingRotation )
|
721
|
{
|
722
|
return mPreRender.scrambleObject(num);
|
723
|
}
|
724
|
return false;
|
725
|
}
|
726
|
|
727
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
728
|
// ditto
|
729
|
|
730
|
public boolean fastScrambleObject(int duration, int num)
|
731
|
{
|
732
|
if( !mBeginningRotation && !mContinuingRotation )
|
733
|
{
|
734
|
return mPreRender.fastScrambleObject(duration,num);
|
735
|
}
|
736
|
return false;
|
737
|
}
|
738
|
|
739
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
740
|
|
741
|
public void presentObject(int num, int duration)
|
742
|
{
|
743
|
mPreRender.presentObject(num,duration);
|
744
|
}
|
745
|
|
746
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
747
|
|
748
|
public void solveObject()
|
749
|
{
|
750
|
mPreRender.solveObject();
|
751
|
}
|
752
|
|
753
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
754
|
|
755
|
public void solveOnly()
|
756
|
{
|
757
|
mPreRender.solveOnly();
|
758
|
}
|
759
|
|
760
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
761
|
|
762
|
public void resetTextureMapsEffect(int duration)
|
763
|
{
|
764
|
mPreRender.resetTextureMapsEffect(duration);
|
765
|
}
|
766
|
|
767
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
768
|
|
769
|
public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
|
770
|
{
|
771
|
mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
|
772
|
}
|
773
|
|
774
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
775
|
|
776
|
public void resetAllTextureMaps()
|
777
|
{
|
778
|
mPreRender.resetAllTextureMaps();
|
779
|
}
|
780
|
|
781
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
782
|
|
783
|
public TwistyObject getObject()
|
784
|
{
|
785
|
return mPreRender.getObject();
|
786
|
}
|
787
|
|
788
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
789
|
|
790
|
public void savePreferences(SharedPreferences.Editor editor)
|
791
|
{
|
792
|
mPreRender.savePreferences(editor);
|
793
|
}
|
794
|
|
795
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
796
|
|
797
|
public void restorePreferences(SharedPreferences preferences)
|
798
|
{
|
799
|
mPreRender.restorePreferences(preferences);
|
800
|
}
|
801
|
|
802
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
803
|
|
804
|
public boolean retLocked()
|
805
|
{
|
806
|
return mIsLocked;
|
807
|
}
|
808
|
|
809
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
810
|
|
811
|
public void toggleLock()
|
812
|
{
|
813
|
mIsLocked = !mIsLocked;
|
814
|
}
|
815
|
|
816
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
817
|
|
818
|
public void unlock()
|
819
|
{
|
820
|
mIsLocked = false;
|
821
|
}
|
822
|
|
823
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
824
|
|
825
|
public void setLock(boolean value)
|
826
|
{
|
827
|
mRemLocked = mIsLocked;
|
828
|
mIsLocked = value;
|
829
|
}
|
830
|
|
831
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
832
|
|
833
|
public void unsetLock()
|
834
|
{
|
835
|
mIsLocked = mRemLocked;
|
836
|
}
|
837
|
|
838
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
839
|
|
840
|
public void setTextureMap(int cubit, int face, int newColor)
|
841
|
{
|
842
|
mPreRender.setTextureMap(cubit,face,newColor);
|
843
|
}
|
844
|
|
845
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
846
|
|
847
|
public boolean onTouchEvent(MotionEvent event, int mode)
|
848
|
{
|
849
|
if( mode!=MODE_NOTHING )
|
850
|
{
|
851
|
if( mObjectNode==null ) return true;
|
852
|
|
853
|
if( mode!=mLastMode )
|
854
|
{
|
855
|
TwistyObject object = getObject();
|
856
|
|
857
|
if( object!=null )
|
858
|
{
|
859
|
mLastMode = mode;
|
860
|
setTouchControl(object);
|
861
|
}
|
862
|
else return true;
|
863
|
}
|
864
|
|
865
|
int action = event.getActionMasked();
|
866
|
|
867
|
switch(action)
|
868
|
{
|
869
|
case MotionEvent.ACTION_DOWN : prepareDown(event);
|
870
|
actionDown(mX1, mY1);
|
871
|
break;
|
872
|
case MotionEvent.ACTION_MOVE : prepareMove(event);
|
873
|
actionMove(mX1, mY1, mX2, mY2);
|
874
|
break;
|
875
|
case MotionEvent.ACTION_UP : prepareUp(event);
|
876
|
actionUp();
|
877
|
break;
|
878
|
case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
|
879
|
actionDown2(mX1, mY1, mX2, mY2);
|
880
|
break;
|
881
|
case MotionEvent.ACTION_POINTER_UP : prepareUp2(event);
|
882
|
boolean p1isUp = mPointer1==INVALID_POINTER_ID;
|
883
|
boolean p2isUp = mPointer2==INVALID_POINTER_ID;
|
884
|
actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
|
885
|
break;
|
886
|
}
|
887
|
}
|
888
|
|
889
|
return true;
|
890
|
}
|
891
|
}
|
892
|
|