Revision 37a25788
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/object/RubikCube.java | ||
---|---|---|
47 | 47 |
new Static3D(0,0,1) |
48 | 48 |
}; |
49 | 49 |
|
50 |
static final int[] FACE_COLORS = new int[] |
|
50 |
private static final int[] FACE_COLORS = new int[]
|
|
51 | 51 |
{ |
52 | 52 |
0xffffff00, 0xffffffff, // AXIS[0]right (right-YELLOW) AXIS[0]left (left -WHITE) |
53 | 53 |
0xff0000ff, 0xff00ff00, // AXIS[1]right (top -BLUE ) AXIS[1]left (bottom-GREEN) |
src/main/java/org/distorted/object/RubikCubeMovement.java | ||
---|---|---|
25 | 25 |
{ |
26 | 26 |
RubikCubeMovement() |
27 | 27 |
{ |
28 |
super(3,2);
|
|
28 |
super(RubikCube.AXIS,2,0.5f);
|
|
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
35 | 35 |
return (y>x) ? (y>=-x) : (y< -x); |
36 | 36 |
} |
37 | 37 |
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
boolean faceIsVisible(int axis, int lr) |
|
41 |
{ |
|
42 |
return (2*lr-1)*mCamera[axis] > 0.5f; |
|
43 |
} |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
// given precomputed mCamera and mPoint, respectively camera and touch point positions in ScreenSpace, |
|
47 |
// cast this touch point onto the surface defined by the 'face' and write the cast coords to 'output'. |
|
48 |
// Center of the 'face' = (0,0), third coord always +- cubeHalfSize. |
|
49 |
|
|
50 |
void castTouchPointOntoFace(int axis, int lr, float[] output) |
|
51 |
{ |
|
52 |
float diff = mPoint[axis]-mCamera[axis]; |
|
53 |
float ratio= diff!=0.0f ? ((lr-0.5f)-mCamera[axis])/diff : 0.0f; |
|
54 |
|
|
55 |
output[0] = (mPoint[0]-mCamera[0])*ratio + mCamera[0]; |
|
56 |
output[1] = (mPoint[1]-mCamera[1])*ratio + mCamera[1]; |
|
57 |
output[2] = (mPoint[2]-mCamera[2])*ratio + mCamera[2]; |
|
58 |
} |
|
59 |
|
|
60 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 39 |
|
62 | 40 |
void fillPossibleRotations(int axis, int[] output) |
src/main/java/org/distorted/object/RubikObjectMovement.java | ||
---|---|---|
20 | 20 |
package org.distorted.object; |
21 | 21 |
|
22 | 22 |
import org.distorted.library.type.Static2D; |
23 |
import org.distorted.library.type.Static3D; |
|
23 | 24 |
import org.distorted.library.type.Static4D; |
24 | 25 |
|
25 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
26 | 27 |
|
27 | 28 |
public abstract class RubikObjectMovement |
28 | 29 |
{ |
29 |
float[] mPoint, mCamera, mTouch;
|
|
30 |
float[] mTouch; |
|
30 | 31 |
int mRotationVect, mLastTouchedAxis; |
31 | 32 |
|
32 |
private float[] mDiff; |
|
33 |
private float[] mPoint, mCamera, mDiff;
|
|
33 | 34 |
private int mLastTouchedLR; |
34 | 35 |
private int mNumAxis, mNumFacesPerAxis; |
35 | 36 |
private int[] mPossible; |
37 |
private float mDistanceCenterFace; |
|
38 |
private Static3D[] mAxis; |
|
36 | 39 |
|
37 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 41 |
|
39 |
abstract boolean faceIsVisible(int axis, int lr); |
|
40 |
abstract void castTouchPointOntoFace(int axis, int lr, float[] output); |
|
41 | 42 |
abstract boolean isInsideFace(float[] point); |
42 |
abstract void fillPossibleRotations(int axis, int[] output); |
|
43 | 43 |
abstract float fillUpRotationVectAndOffset(float[] vect, int[] possible); |
44 | 44 |
abstract float returnAngle(float[] vect, int[] possible); |
45 |
abstract void fillPossibleRotations(int axis, int[] output); |
|
45 | 46 |
|
46 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | 48 |
|
48 |
RubikObjectMovement(int numAxis, int numFacesPerAxis)
|
|
49 |
RubikObjectMovement(Static3D[] axis, int numFacesPerAxis, float distance)
|
|
49 | 50 |
{ |
50 | 51 |
mPoint = new float[3]; |
51 | 52 |
mCamera= new float[3]; |
52 | 53 |
mDiff = new float[3]; |
53 | 54 |
mTouch = new float[3]; |
54 | 55 |
|
55 |
mNumAxis = numAxis; |
|
56 |
mAxis = axis; |
|
57 |
mNumAxis = mAxis.length; |
|
56 | 58 |
mNumFacesPerAxis = numFacesPerAxis; |
59 |
mDistanceCenterFace = distance; |
|
57 | 60 |
mPossible = new int[mNumAxis-1]; |
58 | 61 |
} |
59 | 62 |
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
private boolean faceIsVisible(Static3D axis, int lr) |
|
66 |
{ |
|
67 |
float castCameraOnAxis = mCamera[0]*axis.get0() + mCamera[1]*axis.get1() + mCamera[2]*axis.get2(); |
|
68 |
return (2*lr-1)*castCameraOnAxis > mDistanceCenterFace; |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
// given precomputed mCamera and mPoint, respectively camera and touch point positions in ScreenSpace, |
|
73 |
// compute point 'output[]' which: |
|
74 |
// 1) lies on a face of the Object, i.e. surface defined by (axis, distance from (0,0,0)) [and this |
|
75 |
// distance is +-mDistanceCenterFace, depending if it is the face on the left or the right end of |
|
76 |
// the axis] (lr=0 or 1, so (2lr-1)*mDistanceCenterFace) |
|
77 |
// 2) is co-linear with mCamera and mPoint |
|
78 |
// |
|
79 |
// output = camera + alpha*(point-camera), where alpha = [dist-axis*camera] / [axis*(point-camera)] |
|
80 |
|
|
81 |
private void castTouchPointOntoFace(Static3D axis, int lr, float[] output) |
|
82 |
{ |
|
83 |
float d0 = mPoint[0]-mCamera[0]; |
|
84 |
float d1 = mPoint[1]-mCamera[1]; |
|
85 |
float d2 = mPoint[2]-mCamera[2]; |
|
86 |
float a0 = axis.get0(); |
|
87 |
float a1 = axis.get1(); |
|
88 |
float a2 = axis.get2(); |
|
89 |
|
|
90 |
float denom = a0*d0 + a1*d1 + a2*d2; |
|
91 |
|
|
92 |
if( denom != 0.0f ) |
|
93 |
{ |
|
94 |
float axisCam = a0*mCamera[0] + a1*mCamera[1] + a2*mCamera[2]; |
|
95 |
float distance = (2*lr-1)*mDistanceCenterFace; |
|
96 |
float alpha = (distance-axisCam)/denom; |
|
97 |
|
|
98 |
output[0] = mCamera[0] + d0*alpha; |
|
99 |
output[1] = mCamera[1] + d1*alpha; |
|
100 |
output[2] = mCamera[2] + d2*alpha; |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
60 | 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 105 |
// PUBLIC API |
62 | 106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
75 | 119 |
{ |
76 | 120 |
for( mLastTouchedLR=0; mLastTouchedLR<mNumFacesPerAxis; mLastTouchedLR++) |
77 | 121 |
{ |
78 |
if( faceIsVisible(mLastTouchedAxis, mLastTouchedLR) )
|
|
122 |
if( faceIsVisible(mAxis[mLastTouchedAxis], mLastTouchedLR) )
|
|
79 | 123 |
{ |
80 |
castTouchPointOntoFace(mLastTouchedAxis, mLastTouchedLR, mTouch);
|
|
124 |
castTouchPointOntoFace(mAxis[mLastTouchedAxis], mLastTouchedLR, mTouch);
|
|
81 | 125 |
|
82 | 126 |
if( isInsideFace(mTouch) ) |
83 | 127 |
{ |
... | ... | |
99 | 143 |
mPoint[1] = rotatedTouchPoint.get1()/RubikObject.OBJECT_SCREEN_RATIO; |
100 | 144 |
mPoint[2] = rotatedTouchPoint.get2()/RubikObject.OBJECT_SCREEN_RATIO; |
101 | 145 |
|
102 |
castTouchPointOntoFace(mLastTouchedAxis, mLastTouchedLR, mDiff);
|
|
146 |
castTouchPointOntoFace(mAxis[mLastTouchedAxis], mLastTouchedLR, mDiff);
|
|
103 | 147 |
|
104 | 148 |
mDiff[0] -= mTouch[0]; |
105 | 149 |
mDiff[1] -= mTouch[1]; |
src/main/java/org/distorted/object/RubikPyraminx.java | ||
---|---|---|
44 | 44 |
private static final float SQ2 = (float)Math.sqrt(2); |
45 | 45 |
private static final float SQ3 = (float)Math.sqrt(3); |
46 | 46 |
|
47 |
private static final Static3D[] AXIS = new Static3D[]
|
|
47 |
static final Static3D[] AXIS = new Static3D[] |
|
48 | 48 |
{ |
49 | 49 |
new Static3D( 0, 1, 0 ), |
50 | 50 |
new Static3D( 0, -1.0f/3, 2*SQ2/3 ), |
src/main/java/org/distorted/object/RubikPyraminxMovement.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
RubikPyraminxMovement() |
32 | 32 |
{ |
33 |
super(4,1); |
|
34 |
} |
|
35 |
|
|
36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
37 |
|
|
38 |
boolean faceIsVisible(int axis, int lr) |
|
39 |
{ |
|
40 |
return mCamera[axis] < -SQ2*SQ3/12; |
|
41 |
} |
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
44 |
// TODO |
|
45 |
|
|
46 |
void castTouchPointOntoFace(int axis, int lr, float[] output) |
|
47 |
{ |
|
48 |
/* |
|
49 |
float diff = mPoint[axis]-mCamera[axis]; |
|
50 |
float ratio= diff!=0.0f ? ((lr-0.5f)-mCamera[axis])/diff : 0.0f; |
|
51 |
|
|
52 |
output[0] = (mPoint[0]-mCamera[0])*ratio + mCamera[0]; |
|
53 |
output[1] = (mPoint[1]-mCamera[1])*ratio + mCamera[1]; |
|
54 |
output[2] = (mPoint[2]-mCamera[2])*ratio + mCamera[2]; |
|
55 |
*/ |
|
33 |
super(RubikPyraminx.AXIS,1,SQ2*SQ3/12); |
|
56 | 34 |
} |
57 | 35 |
|
58 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Progress with object Movement.