Revision 86c73a69
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
---|---|---|
46 | 46 |
// Moving the finger from the middle of the vertical screen to the right edge will rotate a |
47 | 47 |
// given face by SWIPING_SENSITIVITY/2 degrees. |
48 | 48 |
private final static int SWIPING_SENSITIVITY = 240; |
49 |
|
|
50 | 49 |
// Moving the finger by 1/12 the distance of min(scrWidth,scrHeight) will start a Rotation. |
51 | 50 |
private final static int ROTATION_SENSITIVITY = 12; |
52 |
|
|
53 | 51 |
// Every 1/12 the distance of min(scrWidth,scrHeight) the direction of cube rotation will reset. |
54 | 52 |
private final static int DIRECTION_SENSITIVITY= 12; |
55 | 53 |
|
54 |
private final Static4D CAMERA_POINT = new Static4D(0, 0, RubikRenderer.CAMERA_DISTANCE, 0); |
|
55 |
|
|
56 | 56 |
private RubikRenderer mRenderer; |
57 | 57 |
private RubikCubeMovement mMovement; |
58 | 58 |
|
... | ... | |
351 | 351 |
case MotionEvent.ACTION_DOWN: mX = x; |
352 | 352 |
mY = y; |
353 | 353 |
|
354 |
if( mMovement.faceTouched(mQuatAccumulated, x, y) ) |
|
354 |
Static4D touchPoint1 = new Static4D(x, y, 0, 0); |
|
355 |
Static4D rotatedTouchPoint1= rotateVectorByInvertedQuat(touchPoint1, mQuatAccumulated); |
|
356 |
Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuatAccumulated); |
|
357 |
|
|
358 |
if( mMovement.faceTouched(rotatedTouchPoint1, rotatedCamera) ) |
|
355 | 359 |
{ |
356 | 360 |
mDragging = false; |
357 | 361 |
mBeginningRotation = mRenderer.canRotate(); |
... | ... | |
383 | 387 |
{ |
384 | 388 |
if( (mX-x)*(mX-x)+(mY-y)*(mY-y) > 1.0f/(ROTATION_SENSITIVITY*ROTATION_SENSITIVITY) ) |
385 | 389 |
{ |
386 |
Static2D rot = mMovement.newRotation(mQuatAccumulated, x, y); |
|
390 |
Static4D touchPoint2 = new Static4D(x, y, 0, 0); |
|
391 |
Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuatAccumulated); |
|
392 |
|
|
393 |
Static2D rot = mMovement.newRotation(rotatedTouchPoint2); |
|
387 | 394 |
RubikCube cube = mRenderer.getCube(); |
388 | 395 |
|
389 | 396 |
cube.addNewRotation( (int)rot.get1(), (int)(cube.getSize()*rot.get2()) ); |
... | ... | |
394 | 401 |
} |
395 | 402 |
else if( mContinuingRotation ) |
396 | 403 |
{ |
397 |
float angle = mMovement.continueRotation(mQuatAccumulated, x, y); |
|
404 |
Static4D touchPoint3 = new Static4D(x, y, 0, 0); |
|
405 |
Static4D rotatedTouchPoint3= rotateVectorByInvertedQuat(touchPoint3, mQuatAccumulated); |
|
406 |
|
|
407 |
float angle = mMovement.continueRotation(rotatedTouchPoint3); |
|
398 | 408 |
mRenderer.getCube().continueRotation(SWIPING_SENSITIVITY*angle); |
399 | 409 |
} |
400 | 410 |
break; |
Also available in: Unified diff
Movement.