Revision ee39837d
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
459 | 459 |
mStartRotX = x; |
460 | 460 |
mStartRotY = y; |
461 | 461 |
|
462 |
TwistyObject object = mPreRender.getObject(); |
|
463 |
int size = object.getSize(); |
|
464 |
|
|
462 | 465 |
Static4D touchPoint2 = new Static4D(x, y, 0, 0); |
463 | 466 |
Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuat); |
464 |
|
|
465 |
Static2D res = mMovement.newRotation(rotatedTouchPoint2); |
|
466 |
TwistyObject object = mPreRender.getObject(); |
|
467 |
Static2D res = mMovement.newRotation(size,rotatedTouchPoint2); |
|
467 | 468 |
|
468 | 469 |
mCurrentAxis = (int)res.get0(); |
469 |
float offset = res.get1(); |
|
470 |
mCurrentRow = object.computeRowFromOffset(offset); |
|
470 |
mCurrentRow = (int)res.get1(); |
|
471 | 471 |
|
472 | 472 |
computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) ); |
473 |
mRotationFactor = object.returnRotationFactor(offset);
|
|
473 |
mRotationFactor = mMovement.returnRotationFactor(size,mCurrentRow);
|
|
474 | 474 |
|
475 | 475 |
object.beginNewRotation( mCurrentAxis, mCurrentRow ); |
476 | 476 |
|
src/main/java/org/distorted/objects/Movement.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
public abstract class Movement |
29 | 29 |
{ |
30 |
static final float SQ2 = (float)Math.sqrt(2); |
|
31 |
static final float SQ3 = (float)Math.sqrt(3); |
|
32 |
static final float SQ6 = (float)Math.sqrt(6); |
|
33 |
|
|
30 | 34 |
private int mLastTouchedFace, mNumFaceAxis; |
31 | 35 |
private float[] mPoint, mCamera, mTouch; |
32 | 36 |
private float[] mPoint2D, mMove2D; |
... | ... | |
40 | 44 |
|
41 | 45 |
abstract boolean isInsideFace(int face, float[] point); |
42 | 46 |
abstract void computeEnabledAxis(int face, float[] touchPoint, int[] enabledAxis); |
47 |
abstract int computeRowFromOffset(int face, int size, float offset); |
|
48 |
public abstract float returnRotationFactor(int size, int row); |
|
43 | 49 |
|
44 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 | 51 |
|
... | ... | |
60 | 66 |
mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces |
61 | 67 |
mDistanceCenterFace2D = distance2D; // distance from the center of a face to its edge |
62 | 68 |
|
63 |
// mCastedRotAxis[1][2]{0,1} are the 2D coords of the 2nd rotAxis cast onto the face defined by the |
|
64 |
// 1st faceAxis. |
|
69 |
computeCastedAxis(rotAxis); |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
// mCastedRotAxis[1][2]{0,1} are the 2D coords of the 2nd rotAxis cast onto the face defined by the |
|
74 |
// 1st faceAxis. |
|
75 |
|
|
76 |
private void computeCastedAxis(Static3D[] rotAxis) |
|
77 |
{ |
|
65 | 78 |
mCastedRotAxis = new float[mNumFaceAxis][rotAxis.length][2]; |
66 | 79 |
mCastedRotAxis4D = new Static4D[mNumFaceAxis][rotAxis.length]; |
67 | 80 |
|
... | ... | |
79 | 92 |
convertTo2Dcoords( mPoint, mFaceAxis[face], mCastedRotAxis[face][casted]); |
80 | 93 |
normalize2D(mCastedRotAxis[face][casted]); |
81 | 94 |
|
82 |
fx = faceAxis[face].get0();
|
|
83 |
fy = faceAxis[face].get1();
|
|
84 |
fz = faceAxis[face].get2();
|
|
95 |
fx = mFaceAxis[face].get0();
|
|
96 |
fy = mFaceAxis[face].get1();
|
|
97 |
fz = mFaceAxis[face].get2();
|
|
85 | 98 |
f = mPoint[0]*fx + mPoint[1]*fy + mPoint[2]*fz; |
86 | 99 |
mCastedRotAxis4D[face][casted] = new Static4D( mPoint[0]-f*fx, mPoint[1]-f*fy, mPoint[2]-f*fz, 0); |
87 | 100 |
} |
... | ... | |
263 | 276 |
|
264 | 277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
265 | 278 |
|
266 |
public Static2D newRotation(Static4D rotatedTouchPoint) |
|
279 |
public Static2D newRotation(int size, Static4D rotatedTouchPoint)
|
|
267 | 280 |
{ |
268 | 281 |
float objectRatio = TwistyObject.getObjectRatio(); |
269 | 282 |
|
... | ... | |
280 | 293 |
computeEnabledAxis(mLastTouchedFace, mPoint2D, mEnabledRotAxis); |
281 | 294 |
int rotIndex = computeRotationIndex(mLastTouchedFace, mMove2D, mEnabledRotAxis); |
282 | 295 |
float offset = computeOffset(mPoint2D, mCastedRotAxis[mLastTouchedFace][rotIndex]); |
296 |
int row = computeRowFromOffset(mLastTouchedFace,size,offset); |
|
283 | 297 |
|
284 |
return new Static2D(rotIndex,offset);
|
|
298 |
return new Static2D(rotIndex,row);
|
|
285 | 299 |
} |
286 | 300 |
|
287 | 301 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/MovementCube.java | ||
---|---|---|
42 | 42 |
super(TwistyCube.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D); |
43 | 43 |
} |
44 | 44 |
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
int computeRowFromOffset(int face, int size, float offset) |
|
48 |
{ |
|
49 |
return (int)(size*offset); |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
public float returnRotationFactor(int size, int row) |
|
55 |
{ |
|
56 |
return 1.0f; |
|
57 |
} |
|
58 |
|
|
45 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 60 |
|
47 | 61 |
boolean isInsideFace(int face, float[] p) |
src/main/java/org/distorted/objects/MovementDiamond.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
class MovementDiamond extends Movement |
27 | 27 |
{ |
28 |
private static final float SQ3 = (float)Math.sqrt(3); |
|
29 |
private static final float SQ6 = (float)Math.sqrt(6); |
|
30 |
|
|
31 | 28 |
static final float DIST3D = SQ6/6; |
32 | 29 |
static final float DIST2D = SQ3/6; |
33 | 30 |
|
... | ... | |
46 | 43 |
super(TwistyDiamond.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D); |
47 | 44 |
} |
48 | 45 |
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
// We have either one of the four faces (1,3,4,6) which, when the retAxis are cast onto it, they |
|
48 |
// point the right way (and so the triangle then spans from offset=-SQ3/6 to offset=+SQ3/3 with |
|
49 |
// midpoint at SQ3/12) or one of the other face when the cast rotAxis are the wrong way round (and |
|
50 |
// the triangle spans then from 0 to SQ3/2 with midpoint at SQ3/4). |
|
51 |
|
|
52 |
int computeRowFromOffset(int face, int size, float offset) |
|
53 |
{ |
|
54 |
if( face==1 || face==3 || face==4 || face==6 ) |
|
55 |
{ |
|
56 |
return offset<SQ3/12 ? 0:1; |
|
57 |
} |
|
58 |
else |
|
59 |
{ |
|
60 |
return offset<SQ3/4 ? 0:1; |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
public float returnRotationFactor(int size, int row) |
|
67 |
{ |
|
68 |
return 1.0f; |
|
69 |
} |
|
70 |
|
|
49 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
50 | 72 |
|
51 | 73 |
boolean isInsideFace(int face, float[] p) |
... | ... | |
62 | 84 |
{ |
63 | 85 |
enabled[0] = 3; |
64 | 86 |
|
65 |
switch(face) |
|
87 |
switch(face/2)
|
|
66 | 88 |
{ |
67 |
case 0: |
|
68 |
case 1: enabled[1]=1; enabled[2]=2; enabled[3]=3; |
|
69 |
break; |
|
70 |
case 2: |
|
71 |
case 3: enabled[1]=0; enabled[2]=2; enabled[3]=3; |
|
72 |
break; |
|
73 |
case 4: |
|
74 |
case 5: enabled[1]=0; enabled[2]=1; enabled[3]=3; |
|
75 |
break; |
|
76 |
case 6: |
|
77 |
case 7: enabled[1]=0; enabled[2]=1; enabled[3]=2; |
|
78 |
break; |
|
89 |
case 0: enabled[1]=1; enabled[2]=2; enabled[3]=3; break; |
|
90 |
case 1: enabled[1]=0; enabled[2]=2; enabled[3]=3; break; |
|
91 |
case 2: enabled[1]=0; enabled[2]=1; enabled[3]=3; break; |
|
92 |
case 3: enabled[1]=0; enabled[2]=1; enabled[3]=2; break; |
|
79 | 93 |
} |
80 | 94 |
} |
81 | 95 |
} |
src/main/java/org/distorted/objects/MovementDino.java | ||
---|---|---|
42 | 42 |
super(TwistyDino.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D); |
43 | 43 |
} |
44 | 44 |
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
int computeRowFromOffset(int face, int size, float offset) |
|
48 |
{ |
|
49 |
return offset<DIST2D ? 0:2; |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
public float returnRotationFactor(int size, int row) |
|
55 |
{ |
|
56 |
return 1.0f; |
|
57 |
} |
|
58 |
|
|
45 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 60 |
// _____________ |
47 | 61 |
// | \ 0 / | |
src/main/java/org/distorted/objects/MovementHelicopter.java | ||
---|---|---|
42 | 42 |
super(TwistyHelicopter.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D); |
43 | 43 |
} |
44 | 44 |
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
int computeRowFromOffset(int face, int size, float offset) |
|
48 |
{ |
|
49 |
return offset<DIST2D ? 0:2; |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
public float returnRotationFactor(int size, int row) |
|
55 |
{ |
|
56 |
return 1.0f; |
|
57 |
} |
|
58 |
|
|
45 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 60 |
// _____________ |
47 | 61 |
// | | | |
src/main/java/org/distorted/objects/MovementPyraminx.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
class MovementPyraminx extends Movement |
27 | 27 |
{ |
28 |
private static final float SQ2 = (float)Math.sqrt(2); |
|
29 |
private static final float SQ3 = (float)Math.sqrt(3); |
|
30 |
private static final float SQ6 = (float)Math.sqrt(6); |
|
31 |
|
|
32 | 28 |
static final float DIST3D = SQ6/12; |
33 | 29 |
static final float DIST2D = SQ3/6; |
34 | 30 |
|
... | ... | |
47 | 43 |
super(TwistyPyraminx.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D); |
48 | 44 |
} |
49 | 45 |
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
int computeRowFromOffset(int face, int size, float offset) |
|
49 |
{ |
|
50 |
return (int)(size*offset/(SQ6/3)); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
public float returnRotationFactor(int size, int row) |
|
56 |
{ |
|
57 |
return ((float)size)/(size-row); |
|
58 |
} |
|
59 |
|
|
50 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 61 |
|
52 | 62 |
boolean isInsideFace(int face, float[] p) |
src/main/java/org/distorted/objects/MovementSkewb.java | ||
---|---|---|
42 | 42 |
super(TwistySkewb.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D); |
43 | 43 |
} |
44 | 44 |
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
int computeRowFromOffset(int face, int size, float offset) |
|
48 |
{ |
|
49 |
return offset<DIST2D ? 0:1; |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
public float returnRotationFactor(int size, int row) |
|
55 |
{ |
|
56 |
return 1.0f; |
|
57 |
} |
|
58 |
|
|
45 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 60 |
// _____________ |
47 | 61 |
// | \ 0 / | |
src/main/java/org/distorted/objects/TwistyCube.java | ||
---|---|---|
390 | 390 |
return 4; |
391 | 391 |
} |
392 | 392 |
|
393 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
394 |
|
|
395 |
public int computeRowFromOffset(float offset) |
|
396 |
{ |
|
397 |
return (int)(getSize()*offset); |
|
398 |
} |
|
399 |
|
|
400 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
401 |
|
|
402 |
public float returnRotationFactor(float offset) |
|
403 |
{ |
|
404 |
return 1.0f; |
|
405 |
} |
|
406 |
|
|
407 | 393 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
408 | 394 |
|
409 | 395 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
src/main/java/org/distorted/objects/TwistyDiamond.java | ||
---|---|---|
558 | 558 |
return 3; |
559 | 559 |
} |
560 | 560 |
|
561 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
562 |
|
|
563 |
public int computeRowFromOffset(float offset) |
|
564 |
{ |
|
565 |
return offset<SQ3/12 ? 0:1; |
|
566 |
} |
|
567 |
|
|
568 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
569 |
|
|
570 |
public float returnRotationFactor(float offset) |
|
571 |
{ |
|
572 |
return 1.0f; |
|
573 |
} |
|
574 |
|
|
575 | 561 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
576 | 562 |
|
577 | 563 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
src/main/java/org/distorted/objects/TwistyDino.java | ||
---|---|---|
413 | 413 |
return 3; |
414 | 414 |
} |
415 | 415 |
|
416 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
417 |
|
|
418 |
public int computeRowFromOffset(float offset) |
|
419 |
{ |
|
420 |
return offset<0.5f ? 0:2; |
|
421 |
} |
|
422 |
|
|
423 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
424 |
|
|
425 |
public float returnRotationFactor(float offset) |
|
426 |
{ |
|
427 |
return 1.0f; |
|
428 |
} |
|
429 |
|
|
430 | 416 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
431 | 417 |
|
432 | 418 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
src/main/java/org/distorted/objects/TwistyHelicopter.java | ||
---|---|---|
621 | 621 |
return 2; |
622 | 622 |
} |
623 | 623 |
|
624 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
625 |
|
|
626 |
public int computeRowFromOffset(float offset) |
|
627 |
{ |
|
628 |
return offset<0.166f ? 0:2; |
|
629 |
} |
|
630 |
|
|
631 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
632 |
|
|
633 |
public float returnRotationFactor(float offset) |
|
634 |
{ |
|
635 |
return 1.0f; |
|
636 |
} |
|
637 |
|
|
638 | 624 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
639 | 625 |
|
640 | 626 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
src/main/java/org/distorted/objects/TwistyObject.java | ||
---|---|---|
710 | 710 |
public abstract boolean isSolved(); |
711 | 711 |
public abstract Static3D[] getRotationAxis(); |
712 | 712 |
public abstract int getBasicAngle(); |
713 |
public abstract int computeRowFromOffset(float offset); |
|
714 |
public abstract float returnRotationFactor(float offset); |
|
715 | 713 |
public abstract String retObjectString(); |
716 | 714 |
public abstract int randomizeNewRotAxis(Random rnd, int oldRotAxis); |
717 | 715 |
public abstract int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis); |
src/main/java/org/distorted/objects/TwistyPyraminx.java | ||
---|---|---|
492 | 492 |
return 3; |
493 | 493 |
} |
494 | 494 |
|
495 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
496 |
|
|
497 |
public int computeRowFromOffset(float offset) |
|
498 |
{ |
|
499 |
return (int)(getSize()*offset/(SQ6/3)); |
|
500 |
} |
|
501 |
|
|
502 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
503 |
|
|
504 |
public float returnRotationFactor(float offset) |
|
505 |
{ |
|
506 |
int size = getSize(); |
|
507 |
int row = (int)(size*offset/(SQ3/2)); |
|
508 |
|
|
509 |
return ((float)size)/(size-row); |
|
510 |
} |
|
511 |
|
|
512 | 495 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
513 | 496 |
|
514 | 497 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
src/main/java/org/distorted/objects/TwistySkewb.java | ||
---|---|---|
565 | 565 |
return 3; |
566 | 566 |
} |
567 | 567 |
|
568 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
569 |
|
|
570 |
public int computeRowFromOffset(float offset) |
|
571 |
{ |
|
572 |
return offset<0.25f ? 0:1; |
|
573 |
} |
|
574 |
|
|
575 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
576 |
|
|
577 |
public float returnRotationFactor(float offset) |
|
578 |
{ |
|
579 |
return 1.0f; |
|
580 |
} |
|
581 |
|
|
582 | 568 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
583 | 569 |
|
584 | 570 |
public int randomizeNewRotAxis(Random rnd, int oldRotAxis) |
Also available in: Unified diff
Progress with the Diamond. Everything working except for the isSolved(): turns out the center cubits can end up rotated along the face by multitudes of 120 degrees.