Revision 11fa413d
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/main/ObjectControl.java | ||
---|---|---|
33 | 33 |
import org.distorted.objectlib.helpers.MovesFinished; |
34 | 34 |
import org.distorted.objectlib.helpers.ObjectLibInterface; |
35 | 35 |
import org.distorted.objectlib.touchcontrol.TouchControl; |
36 |
import org.distorted.objectlib.touchcontrol.TouchControlShapeChanging; |
|
36 | 37 |
|
37 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 39 |
|
... | ... | |
55 | 56 |
|
56 | 57 |
private final ObjectLibInterface mInterface; |
57 | 58 |
private final ObjectPreRender mPreRender; |
58 |
private TouchControl mTouchControl; |
|
59 |
private TouchControl mTouchControl, mTouchControlBackup;
|
|
59 | 60 |
private TwistyObjectNode mObjectNode; |
60 | 61 |
private boolean mDragging, mBeginningRotation, mContinuingRotation; |
61 | 62 |
private int mScreenWidth, mScreenHeight, mScreenMin; |
62 | 63 |
private float mMoveX, mMoveY; |
64 |
private int mLastMode; |
|
63 | 65 |
|
64 | 66 |
private float mRotAngle, mInitDistance; |
65 | 67 |
private float mStartRotX, mStartRotY; |
66 | 68 |
private float mRotationFactor; |
67 |
private int mLastCubitColor, mLastCubit; |
|
68 | 69 |
private int mCurrentAxis, mCurrentRow; |
69 | 70 |
private float mCurrentAngle, mCurrRotSpeed; |
70 | 71 |
private final float[] mLastX; |
... | ... | |
152 | 153 |
|
153 | 154 |
if( down ) |
154 | 155 |
{ |
155 |
int color = mInterface.getCurrentColor(); |
|
156 |
float[] point = mTouchControl.getTouchedPoint3D(); |
|
157 |
TwistyObject object = mPreRender.getObject(); |
|
158 |
mLastCubit = object.getCubit(point); |
|
159 |
mLastCubitColor = mInterface.cubitIsLocked(mLastCubit); |
|
160 |
int face; |
|
161 |
|
|
162 |
if( mLastCubitColor>=0 ) |
|
163 |
{ |
|
164 |
face =4; |
|
165 |
} |
|
166 |
else |
|
167 |
{ |
|
168 |
int touchedFace = mTouchControl.getTouchedFace(); |
|
169 |
if( mLastCubit<8 ) face = touchedFace; |
|
170 |
else |
|
171 |
{ |
|
172 |
switch(touchedFace) |
|
173 |
{ |
|
174 |
case 0: face = mLastCubit==15 || mLastCubit==18 ? 3 : 5; break; |
|
175 |
case 1: face = mLastCubit==13 || mLastCubit==16 ? 3 : 5; break; |
|
176 |
case 2: face = mLastCubit==10 ? 5 : 3; break; |
|
177 |
case 3: face = mLastCubit== 8 ? 3 : 5; break; |
|
178 |
case 4: face = mLastCubit== 9 ? 3 : 5; break; |
|
179 |
case 5: face = mLastCubit== 8 ? 5 : 3; break; |
|
180 |
default: face =-1; |
|
181 |
} |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
mPreRender.setTextureMap( mLastCubit, face , color ); |
|
156 |
int cubit = mTouchControl.getTouchedCubit(); |
|
157 |
int face = mTouchControl.getTouchedCubitFace(); |
|
158 |
mInterface.onReplaceModeDown(cubit,face); |
|
186 | 159 |
} |
187 | 160 |
} |
188 | 161 |
|
189 | 162 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
190 | 163 |
|
191 |
private void setUpDragOrRotate(boolean down, float x, float y, int mode)
|
|
164 |
private void setUpDragOrRotate(boolean down, float x, float y) |
|
192 | 165 |
{ |
193 |
if( mode==MODE_DRAG ) |
|
166 |
if( mLastMode==MODE_DRAG )
|
|
194 | 167 |
{ |
195 | 168 |
mDragging = true; |
196 | 169 |
mBeginningRotation = false; |
... | ... | |
208 | 181 |
mDragging = false; |
209 | 182 |
mContinuingRotation = false; |
210 | 183 |
|
211 |
if( mode==MODE_ROTATE ) mBeginningRotation = !mPreRender.isTouchBlocked(); |
|
212 |
else if( mode==MODE_REPLACE ) replaceMode(down); |
|
184 |
if( mLastMode==MODE_ROTATE ) mBeginningRotation = !mPreRender.isTouchBlocked();
|
|
185 |
else if( mLastMode==MODE_REPLACE ) replaceMode(down);
|
|
213 | 186 |
} |
214 | 187 |
else |
215 | 188 |
{ |
... | ... | |
415 | 388 |
|
416 | 389 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
417 | 390 |
|
418 |
private void actionMove(float x1, float y1, float x2, float y2, int mode)
|
|
391 |
private void actionMove(float x1, float y1, float x2, float y2) |
|
419 | 392 |
{ |
420 | 393 |
float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2; |
421 | 394 |
float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2; |
... | ... | |
440 | 413 |
} |
441 | 414 |
else |
442 | 415 |
{ |
443 |
setUpDragOrRotate(false,x,y,mode);
|
|
416 |
setUpDragOrRotate(false,x,y); |
|
444 | 417 |
} |
445 | 418 |
} |
446 | 419 |
|
447 | 420 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
448 | 421 |
|
449 |
private void actionDown(float x, float y, int mode)
|
|
422 |
private void actionDown(float x, float y) |
|
450 | 423 |
{ |
451 | 424 |
mX = (x - mScreenWidth*0.5f)/mScreenMin; |
452 | 425 |
mY = (mScreenHeight*0.5f - y)/mScreenMin; |
453 | 426 |
|
454 |
setUpDragOrRotate(true,mX,mY,mode);
|
|
427 |
setUpDragOrRotate(true,mX,mY); |
|
455 | 428 |
} |
456 | 429 |
|
457 | 430 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
463 | 436 |
finishRotation(); |
464 | 437 |
} |
465 | 438 |
|
466 |
if( mLastCubitColor>=0 ) |
|
467 |
{ |
|
468 |
mPreRender.setTextureMap( mLastCubit, 4, mLastCubitColor ); |
|
469 |
mLastCubitColor = -1; |
|
470 |
} |
|
439 |
if( mLastMode==MODE_REPLACE ) mInterface.onReplaceModeUp(); |
|
471 | 440 |
} |
472 | 441 |
|
473 | 442 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
510 | 479 |
|
511 | 480 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
512 | 481 |
|
513 |
void setMovement(TouchControl touchControl)
|
|
482 |
void setTouchControl(TwistyObject object)
|
|
514 | 483 |
{ |
515 |
mTouchControl = touchControl; |
|
484 |
if( mLastMode!=MODE_REPLACE ) mTouchControl = object.getTouchControl(); |
|
485 |
else mTouchControl = new TouchControlShapeChanging(object); |
|
516 | 486 |
} |
517 | 487 |
|
518 | 488 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
556 | 526 |
mBuffer = new int[2]; |
557 | 527 |
mAxis = new float[2]; |
558 | 528 |
|
559 |
mLastCubitColor = -1;
|
|
560 |
mCurrRotSpeed = 0.0f;
|
|
529 |
mCurrRotSpeed= 0.0f;
|
|
530 |
mLastMode = -1;
|
|
561 | 531 |
|
562 | 532 |
mLastX = new float[NUM_SPEED_PROBES]; |
563 | 533 |
mLastY = new float[NUM_SPEED_PROBES]; |
... | ... | |
850 | 820 |
mIsLocked = mRemLocked; |
851 | 821 |
} |
852 | 822 |
|
823 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
824 |
|
|
825 |
public void setTextureMap(int cubit, int face, int newColor) |
|
826 |
{ |
|
827 |
mPreRender.setTextureMap(cubit,face,newColor); |
|
828 |
} |
|
829 |
|
|
830 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
831 |
|
|
832 |
private void switchTouchControl(int oldMode, int newMode) |
|
833 |
{ |
|
834 |
if( newMode==MODE_REPLACE ) |
|
835 |
{ |
|
836 |
if( mTouchControlBackup!=null ) |
|
837 |
{ |
|
838 |
TouchControl tmp = mTouchControlBackup; |
|
839 |
mTouchControlBackup = mTouchControl; |
|
840 |
mTouchControl = tmp; |
|
841 |
} |
|
842 |
else |
|
843 |
{ |
|
844 |
mTouchControlBackup = mTouchControl; |
|
845 |
TwistyObject object = getObject(); |
|
846 |
mTouchControl = new TouchControlShapeChanging(object); |
|
847 |
float ratio = object.getObjectRatio(); |
|
848 |
mTouchControl.setObjectRatio(ratio); |
|
849 |
} |
|
850 |
} |
|
851 |
if( oldMode==MODE_REPLACE ) |
|
852 |
{ |
|
853 |
if( mTouchControlBackup!=null ) |
|
854 |
{ |
|
855 |
TouchControl tmp = mTouchControlBackup; |
|
856 |
mTouchControlBackup = mTouchControl; |
|
857 |
mTouchControl = tmp; |
|
858 |
} |
|
859 |
else |
|
860 |
{ |
|
861 |
mTouchControlBackup = mTouchControl; |
|
862 |
TwistyObject object = getObject(); |
|
863 |
mTouchControl = object.getTouchControl(); |
|
864 |
float ratio = object.getObjectRatio(); |
|
865 |
mTouchControl.setObjectRatio(ratio); |
|
866 |
} |
|
867 |
} |
|
868 |
} |
|
869 |
|
|
853 | 870 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
854 | 871 |
|
855 | 872 |
public boolean onTouchEvent(MotionEvent event, int mode) |
856 | 873 |
{ |
857 | 874 |
int action = event.getActionMasked(); |
858 | 875 |
|
876 |
if( mode!=mLastMode) |
|
877 |
{ |
|
878 |
switchTouchControl(mLastMode,mode); |
|
879 |
mLastMode = mode; |
|
880 |
} |
|
881 |
|
|
859 | 882 |
switch(action) |
860 | 883 |
{ |
861 | 884 |
case MotionEvent.ACTION_DOWN : prepareDown(event); |
862 |
actionDown(mX1, mY1, mode);
|
|
885 |
actionDown(mX1, mY1); |
|
863 | 886 |
break; |
864 | 887 |
case MotionEvent.ACTION_MOVE : prepareMove(event); |
865 |
actionMove(mX1, mY1, mX2, mY2, mode);
|
|
888 |
actionMove(mX1, mY1, mX2, mY2); |
|
866 | 889 |
break; |
867 | 890 |
case MotionEvent.ACTION_UP : prepareUp(event); |
868 | 891 |
actionUp(); |
Also available in: Unified diff
Make the ShapeChanging the default TouchControl during MODE_REPLACE.