Revision 967c1d17
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objects/Movement12.java | ||
---|---|---|
30 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
31 | 31 |
// Dodecahedral objects: map the 2D swipes of user's fingers to 3D rotations |
32 | 32 |
|
33 |
abstract class Movement12 extends Movement
|
|
33 |
class Movement12 extends Movement |
|
34 | 34 |
{ |
35 | 35 |
static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5); |
36 | 36 |
static final float DIST2D = (SIN54/COS54)/2; |
... | ... | |
53 | 53 |
|
54 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 55 |
|
56 |
Movement12(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, int size) |
|
56 |
Movement12(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, int size, int type, int[] numEnabled, int[][][] enabled)
|
|
57 | 57 |
{ |
58 |
super(rotAxis, FACE_AXIS, cuts,rotatable,DIST3D, size); |
|
58 |
super(rotAxis, FACE_AXIS, cuts,rotatable,DIST3D, size, type, numEnabled, enabled);
|
|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
111 | 111 |
} |
112 | 112 |
|
113 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
114 |
// Return 1,2,3,4,5 - the vertex of the pentagon to which point 'point' is the closest, if the |
|
115 |
// 'point' is inside the pentagon - or 0 otherwise. |
|
114 |
|
|
115 |
int returnPart(int type, int face, float[] point) |
|
116 |
{ |
|
117 |
switch(type) |
|
118 |
{ |
|
119 |
case TYPE_SPLIT_EDGE : return partEdge(point,face); |
|
120 |
case TYPE_SPLIT_CORNER: return partCorner(point,face); |
|
121 |
default : return 0; |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
126 |
// Return 0,1,2,3,4 - the vertex of the pentagon to which point 'point' is the closest, if the |
|
127 |
// 'point' is inside the pentagon - or -1 otherwise. |
|
116 | 128 |
// The 'first' vertex is the one we meet the first when we rotate clockwise starting from 12:00. |
117 | 129 |
// This vertex makes angle 'returnAngle()' with the line coming out upwards from the center of the |
118 | 130 |
// pentagon. |
119 | 131 |
// Distance from the center to a vertex of the pentagon = 1/(6*COS54) |
120 | 132 |
|
121 |
int returnPartOfThePentagon(float[] point, int face)
|
|
133 |
int partEdge(float[] point, int face)
|
|
122 | 134 |
{ |
123 | 135 |
float angle = returnAngle(face); |
124 | 136 |
float A = (float)(Math.PI/5); |
125 | 137 |
|
126 | 138 |
for(int i=0; i<5; i++) |
127 | 139 |
{ |
128 |
if( isOnTheLeft(point, DIST2D, (9-2*i)*A-angle) ) return 0;
|
|
140 |
if( isOnTheLeft(point, DIST2D, (9-2*i)*A-angle) ) return -1;
|
|
129 | 141 |
} |
130 | 142 |
|
131 | 143 |
if( isOnTheLeft(point, 0, 2.5f*A-angle) ) |
132 | 144 |
{ |
133 | 145 |
if( isOnTheLeft(point, 0, 3.5f*A-angle) ) |
134 | 146 |
{ |
135 |
return isOnTheLeft(point, 0, 5.5f*A-angle) ? 4 : 5;
|
|
147 |
return isOnTheLeft(point, 0, 5.5f*A-angle) ? 3 : 4;
|
|
136 | 148 |
} |
137 |
else return 1;
|
|
149 |
else return 0;
|
|
138 | 150 |
} |
139 | 151 |
else |
140 | 152 |
{ |
141 | 153 |
if( isOnTheLeft(point, 0, 4.5f*A-angle) ) |
142 | 154 |
{ |
143 |
return 3;
|
|
155 |
return 2;
|
|
144 | 156 |
} |
145 | 157 |
else |
146 | 158 |
{ |
147 |
return isOnTheLeft(point, 0, 6.5f*A-angle) ? 2 : 1;
|
|
159 |
return isOnTheLeft(point, 0, 6.5f*A-angle) ? 1 : 0;
|
|
148 | 160 |
} |
149 | 161 |
} |
150 | 162 |
} |
151 | 163 |
|
164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
165 |
// TODO - no such object yet |
|
166 |
|
|
167 |
int partCorner(float[] point, int face) |
|
168 |
{ |
|
169 |
return 0; |
|
170 |
} |
|
171 |
|
|
152 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
153 | 173 |
|
154 | 174 |
boolean isInsideFace(int face, float[] p) |
155 | 175 |
{ |
156 |
return returnPartOfThePentagon(p,face) > 0; |
|
176 |
float angle = returnAngle(face); |
|
177 |
float A = (float)(Math.PI/5); |
|
178 |
|
|
179 |
for(int i=0; i<5; i++) |
|
180 |
{ |
|
181 |
if( isOnTheLeft(p, DIST2D, (9-2*i)*A-angle) ) return false; |
|
182 |
} |
|
183 |
|
|
184 |
return true; |
|
157 | 185 |
} |
158 | 186 |
} |
Also available in: Unified diff
Do away with the last method in the object Movement classes. Remove the object Movement classes altogether.
From now on the implementation of a TwistyPuzzle is 100% data, no code at all.
Next step: make the implementation a (generated?) (XML?) file.