Revision ead91342
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/objects/TwistyMegaminx.java | ||
---|---|---|
44 | 44 |
{ |
45 | 45 |
static final float MEGA_D = 0.04f; |
46 | 46 |
|
47 |
private static final int NUM_CORNERS = 20; |
|
48 |
private static final int NUM_CENTERS = 12; |
|
49 |
private static final int NUM_EDGES = 30; |
|
50 |
|
|
51 |
// the five vertices that form a given face. Order: the same as colors |
|
52 |
// of the faces in TwistyMinx. |
|
53 |
private static final int[][] mCenterMap = |
|
54 |
{ |
|
55 |
{ 0, 12, 4, 14, 2}, |
|
56 |
{ 0, 2, 18, 6, 16}, |
|
57 |
{ 6, 18, 11, 19, 7}, |
|
58 |
{ 3, 15, 9, 11, 19}, |
|
59 |
{ 4, 5, 15, 9, 14}, |
|
60 |
{ 1, 13, 5, 15, 3}, |
|
61 |
{ 1, 3, 19, 7, 17}, |
|
62 |
{10, 16, 6, 7, 17}, |
|
63 |
{ 0, 12, 8, 10, 16}, |
|
64 |
{ 8, 13, 5, 4, 12}, |
|
65 |
{ 1, 13, 8, 10, 17}, |
|
66 |
{ 2, 14, 9, 11, 18}, |
|
67 |
}; |
|
68 |
|
|
69 |
// the quadruple ( vertex1, vertex2, face1, face2 ) defining an edge. |
|
70 |
// In fact the 2 vertices already define it, the faces only provide easy |
|
71 |
// way to get to know the colors. Order: arbitrary. Face1 arbitrarily on |
|
72 |
// the 'left' or right of vector vertex1 --> vertex2, according to Quat. |
|
73 |
private static final int[][] mEdgeMap = |
|
74 |
{ |
|
75 |
{ 0, 12, 0, 8}, |
|
76 |
{ 12, 4, 0, 9}, |
|
77 |
{ 4, 14, 0, 4}, |
|
78 |
{ 14, 2, 0, 11}, |
|
79 |
{ 2, 0, 0, 1}, |
|
80 |
{ 14, 9, 4, 11}, |
|
81 |
{ 9, 11, 3, 11}, |
|
82 |
{ 11, 18, 2, 11}, |
|
83 |
{ 18, 2, 1, 11}, |
|
84 |
{ 18, 6, 1, 2}, |
|
85 |
{ 6, 16, 1, 7}, |
|
86 |
{ 16, 0, 8, 1}, |
|
87 |
{ 16, 10, 7, 8}, |
|
88 |
{ 10, 8, 10, 8}, |
|
89 |
{ 8, 12, 9, 8}, |
|
90 |
{ 8, 13, 9, 10}, |
|
91 |
{ 13, 5, 9, 5}, |
|
92 |
{ 5, 4, 9, 4}, |
|
93 |
{ 5, 15, 5, 4}, |
|
94 |
{ 15, 9, 3, 4}, |
|
95 |
{ 11, 19, 2, 3}, |
|
96 |
{ 19, 7, 2, 6}, |
|
97 |
{ 7, 6, 2, 7}, |
|
98 |
{ 7, 17, 7, 6}, |
|
99 |
{ 17, 10, 7, 10}, |
|
100 |
{ 17, 1, 10, 6}, |
|
101 |
{ 1, 3, 5, 6}, |
|
102 |
{ 3, 19, 3, 6}, |
|
103 |
{ 1, 13, 10, 5}, |
|
104 |
{ 3, 15, 3, 5}, |
|
105 |
}; |
|
106 |
|
|
107 |
|
|
108 | 47 |
private static final int[] QUAT_EDGE_INDICES = |
109 | 48 |
{ |
110 | 49 |
56, 40, 43, 59, 0, 55, 10, 17, 25, 49, |
... | ... | |
117 | 56 |
16, 18, 22, 1, 20, 13, 14, 15, 0, 12, 2, 3 |
118 | 57 |
}; |
119 | 58 |
|
120 |
private static final float[][] mCenterCoords = new float[NUM_CENTERS][3]; |
|
121 |
|
|
122 |
static |
|
123 |
{ |
|
124 |
for(int center=0; center<NUM_CENTERS; center++) |
|
125 |
{ |
|
126 |
int[] map = mCenterMap[center]; |
|
127 |
|
|
128 |
float x = CORNERS[map[0]][0] + |
|
129 |
CORNERS[map[1]][0] + |
|
130 |
CORNERS[map[2]][0] + |
|
131 |
CORNERS[map[3]][0] + |
|
132 |
CORNERS[map[4]][0] ; |
|
133 |
|
|
134 |
float y = CORNERS[map[0]][1] + |
|
135 |
CORNERS[map[1]][1] + |
|
136 |
CORNERS[map[2]][1] + |
|
137 |
CORNERS[map[3]][1] + |
|
138 |
CORNERS[map[4]][1] ; |
|
139 |
|
|
140 |
float z = CORNERS[map[0]][2] + |
|
141 |
CORNERS[map[1]][2] + |
|
142 |
CORNERS[map[2]][2] + |
|
143 |
CORNERS[map[3]][2] + |
|
144 |
CORNERS[map[4]][2] ; |
|
145 |
|
|
146 |
mCenterCoords[center][0] = x/5; |
|
147 |
mCenterCoords[center][1] = y/5; |
|
148 |
mCenterCoords[center][2] = z/5; |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 | 59 |
private static MeshBase[] mCenterMeshes, mCornerMeshes; |
153 | 60 |
private static MeshBase[][] mEdgeMeshes; |
154 | 61 |
|
155 |
private static final Static4D[] mBasicCornerV, mCurrCornerV; |
|
156 |
|
|
157 |
static |
|
158 |
{ |
|
159 |
mBasicCornerV = new Static4D[3]; |
|
160 |
mCurrCornerV = new Static4D[3]; |
|
161 |
|
|
162 |
mBasicCornerV[0] = new Static4D( (SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f ); |
|
163 |
mBasicCornerV[1] = new Static4D(-(SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f ); |
|
164 |
mBasicCornerV[2] = new Static4D( 0, -0.500f, 0.0f, 0.0f ); |
|
165 |
} |
|
166 |
|
|
167 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
168 | 63 |
|
169 | 64 |
TwistyMegaminx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh, |
... | ... | |
259 | 154 |
} |
260 | 155 |
else |
261 | 156 |
{ |
262 |
float E = 2.0f*(numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
|
|
157 |
float E = 2.0f*D*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
|
|
263 | 158 |
int N = (numCubitsPerCorner-1)/3; |
264 | 159 |
int block = (part-1) % N; |
265 | 160 |
int index = (part-1) / N; |
266 | 161 |
Static4D pri = mCurrCornerV[index]; |
267 | 162 |
Static4D sec = mCurrCornerV[(index+2)%3]; |
268 | 163 |
|
269 |
int multP = (block % ((numLayers-3)/2)) + 1; |
|
270 |
int multS = (block / ((numLayers-3)/2)); |
|
164 |
int layers= (numLayers-5)/2; |
|
165 |
int multP = (block % layers) + 1; |
|
166 |
int multS = (block / layers); |
|
271 | 167 |
|
272 | 168 |
return new float[] { |
273 | 169 |
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E, |
... | ... | |
289 | 185 |
|
290 | 186 |
private float[] computeEdge(int numLayers, int edge, int part) |
291 | 187 |
{ |
292 |
float corr = numLayers/3.0f;
|
|
188 |
float D = numLayers/3.0f;
|
|
293 | 189 |
|
294 | 190 |
float[] c1 = CORNERS[ mEdgeMap[edge][0] ]; |
295 | 191 |
float[] c2 = CORNERS[ mEdgeMap[edge][1] ]; |
296 |
float x = corr * (c1[0]+c2[0]) / 2;
|
|
297 |
float y = corr * (c1[1]+c2[1]) / 2;
|
|
298 |
float z = corr * (c1[2]+c2[2]) / 2;
|
|
192 |
float x = D * (c1[0]+c2[0]) / 2;
|
|
193 |
float y = D * (c1[1]+c2[1]) / 2;
|
|
194 |
float z = D * (c1[2]+c2[2]) / 2;
|
|
299 | 195 |
|
300 | 196 |
if( part==0 ) |
301 | 197 |
{ |
... | ... | |
307 | 203 |
int dir = (part+1)%2; |
308 | 204 |
float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ]; |
309 | 205 |
|
310 |
float vX = corr*center[0] - x;
|
|
311 |
float vY = corr*center[1] - y;
|
|
312 |
float vZ = corr*center[2] - z;
|
|
206 |
float vX = D*center[0] - x;
|
|
207 |
float vY = D*center[1] - y;
|
|
208 |
float vZ = D*center[2] - z;
|
|
313 | 209 |
|
314 |
float len = (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
|
315 |
float A = mult*corr*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f)/len;
|
|
210 |
float A = mult*D*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
|
|
211 |
A /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
|
316 | 212 |
|
317 | 213 |
return new float[] { x+A*vX, y+A*vY, z+A*vZ }; |
318 | 214 |
} |
Also available in: Unified diff
Progress with any size Kilominx.