Revision bb11be2a
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/objects/TwistyMegaminx.java | ||
---|---|---|
35 | 35 |
import org.distorted.main.R; |
36 | 36 |
import org.distorted.main.RubikSurfaceView; |
37 | 37 |
|
38 |
import static org.distorted.helpers.FactoryCubit.COS18; |
|
39 |
import static org.distorted.helpers.FactoryCubit.COS54; |
|
40 |
import static org.distorted.helpers.FactoryCubit.SIN18; |
|
41 |
import static org.distorted.helpers.FactoryCubit.SIN54; |
|
42 |
|
|
43 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 39 |
|
45 | 40 |
public class TwistyMegaminx extends TwistyMinx |
... | ... | |
54 | 49 |
private static MeshBase[] mCenterMeshes, mCornerMeshes; |
55 | 50 |
private static MeshBase[][] mEdgeMeshes; |
56 | 51 |
|
52 |
private static final float[][] STICKERS = new float[][] |
|
53 |
{ |
|
54 |
{ -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f }, |
|
55 |
{ -0.5f, -0.0914315f, 0.5f, -0.4163512f, 0.5f, 0.4163512f, -0.5f, 0.0914315f }, |
|
56 |
{ -0.49233657f, -0.18006028f, 0.49233657f, -0.5f, 0.49233657f, 0.5f, -0.49233657f, 0.18006028f }, |
|
57 |
{ -0.3002273f, -0.30490047f, 0.3002273f, -0.5f, 0.3002273f, 0.5f, -0.3002273f, 0.30490047f }, |
|
58 |
{ -0.29389262f, 0.4045085f, -0.47552824f, -0.1545085f, 0.0f, -0.5f, 0.47552824f, -0.1545085f, 0.29389262f, 0.4045085f } |
|
59 |
}; |
|
60 |
|
|
57 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
58 | 62 |
|
59 | 63 |
TwistyMegaminx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh, |
... | ... | |
96 | 100 |
{ |
97 | 101 |
float[] cuts = new float[numLayers-1]; |
98 | 102 |
float D = numLayers*MovementMinx.DIST3D; |
99 |
float E = 2*C1; // 2*cos(36 deg)
|
|
103 |
float E = 2*SIN54;
|
|
100 | 104 |
float X = 2*D*E/(1+2*E); // height of the 'upper' part of a dodecahedron, i.e. put it on a table, |
101 | 105 |
// its height is then D*2*DIST3D, it has one 'lower' part of height X, one |
102 | 106 |
// 'middle' part of height Y and one upper part of height X again. |
... | ... | |
266 | 270 |
return QUAT_CENTER_INDICES[center]; |
267 | 271 |
} |
268 | 272 |
|
273 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
274 |
|
|
275 |
MeshBase createEdgeMesh(int numLayers, float width, float height) |
|
276 |
{ |
|
277 |
double W = width/2; |
|
278 |
double X = height*SIN_HALFD; |
|
279 |
double Y = height*SIN18/COS18; |
|
280 |
double Z = height*COS_HALFD; |
|
281 |
|
|
282 |
double[][] vertices = new double[][] |
|
283 |
{ |
|
284 |
{ 0.0, W , 0.0 }, |
|
285 |
{ X, W+Y , -Z }, |
|
286 |
{ 0.0, W+2*Y ,-2*Z }, |
|
287 |
{ -X, W+Y , -Z }, |
|
288 |
{ 0.0, -W , 0.0 }, |
|
289 |
{ X,-W-Y , -Z }, |
|
290 |
{ 0.0,-W-2*Y ,-2*Z }, |
|
291 |
{ -X,-W-Y , -Z }, |
|
292 |
}; |
|
293 |
|
|
294 |
int[][] vertIndexes = new int[][] |
|
295 |
{ |
|
296 |
{4,5,1,0}, |
|
297 |
{7,4,0,3}, |
|
298 |
{7,6,2,3}, |
|
299 |
{6,5,1,2}, |
|
300 |
{0,1,2,3}, |
|
301 |
{4,5,6,7} |
|
302 |
}; |
|
303 |
|
|
304 |
int N = numLayers<=5 ? 5 : 3; |
|
305 |
|
|
306 |
float[][] bands = new float[][] |
|
307 |
{ |
|
308 |
{0.04f,34,0.2f,0.2f,N,0,0}, |
|
309 |
{0.00f, 0,0.3f,0.2f,2,0,0} |
|
310 |
}; |
|
311 |
int[] bandIndexes = new int[] { 0,0,1,1,1,1}; |
|
312 |
float[][] corners = new float[][] { {0.04f,0.10f} }; |
|
313 |
int[] cornerIndexes = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 }; |
|
314 |
float[][] centers = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} }; |
|
315 |
int[] centerIndexes = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 }; |
|
316 |
|
|
317 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
318 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
319 |
|
|
320 |
return factory.createRoundedSolid(vertices, vertIndexes, |
|
321 |
bands, bandIndexes, |
|
322 |
corners, cornerIndexes, |
|
323 |
centers, centerIndexes, |
|
324 |
getNumCubitFaces() ); |
|
325 |
} |
|
326 |
|
|
327 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
328 |
|
|
329 |
MeshBase createCenterMesh(int numLayers, float width) |
|
330 |
{ |
|
331 |
final double V = 0.83; // ?? |
|
332 |
final double ANGLE = V*Math.PI; |
|
333 |
final double cosA = Math.cos(ANGLE); |
|
334 |
final double sinA = Math.sin(ANGLE); |
|
335 |
|
|
336 |
float R = 0.5f*width/COS54; |
|
337 |
float X1 = R*COS54; |
|
338 |
float Y1 = R*SIN54; |
|
339 |
float X2 = R*COS18; |
|
340 |
float Y2 = R*SIN18; |
|
341 |
|
|
342 |
double[][] vertices = new double[][] |
|
343 |
{ |
|
344 |
{-X1,+Y1*sinA, Y1*cosA}, |
|
345 |
{-X2,-Y2*sinA,-Y2*cosA}, |
|
346 |
{0.0f,-R*sinA, -R*cosA}, |
|
347 |
{+X2,-Y2*sinA,-Y2*cosA}, |
|
348 |
{+X1,+Y1*sinA, Y1*cosA} |
|
349 |
}; |
|
350 |
|
|
351 |
int[][] vertIndexes = new int[][] |
|
352 |
{ |
|
353 |
{0,1,2,3,4}, |
|
354 |
{0,1,2,3,4} |
|
355 |
}; |
|
356 |
|
|
357 |
int N = numLayers==3 ? 4 : 3; |
|
358 |
|
|
359 |
float[][] bands = new float[][] |
|
360 |
{ |
|
361 |
{0.04f,45, R/3,0.2f,N,0,0}, |
|
362 |
{0.00f, 0, R/3,0.2f,2,0,0} |
|
363 |
}; |
|
364 |
int[] bandIndexes = new int[] { 0,1 }; |
|
365 |
float[][] corners = new float[][] { {0.04f,0.10f} }; |
|
366 |
int[] cornerIndexes = new int[] { -1,-1,-1,-1, -1 }; |
|
367 |
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} }; |
|
368 |
int[] centerIndexes = new int[] { -1,-1,-1,-1, -1 }; |
|
369 |
|
|
370 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
371 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
372 |
|
|
373 |
return factory.createRoundedSolid(vertices, vertIndexes, |
|
374 |
bands, bandIndexes, |
|
375 |
corners, cornerIndexes, |
|
376 |
centers, centerIndexes, |
|
377 |
getNumCubitFaces() ); |
|
378 |
} |
|
379 |
|
|
269 | 380 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
270 | 381 |
|
271 | 382 |
MeshBase createCubitMesh(int cubit, int numLayers) |
... | ... | |
299 | 410 |
float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f); |
300 | 411 |
float width = (numLayers/3.0f)*2*MEGA_D + 2*type*height*SIN18/COS18; |
301 | 412 |
|
302 |
mEdgeMeshes[index][type] = FactoryCubit.getInstance().createMegaminxEdgeMesh(numLayers,width,height);
|
|
413 |
mEdgeMeshes[index][type] = createEdgeMesh(numLayers,width,height);
|
|
303 | 414 |
} |
304 | 415 |
|
305 | 416 |
mesh = mEdgeMeshes[index][type].copy(true); |
... | ... | |
309 | 420 |
if( mCenterMeshes[index]==null ) |
310 | 421 |
{ |
311 | 422 |
float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18); |
312 |
mCenterMeshes[index] = FactoryCubit.getInstance().createMegaminxCenterMesh(numLayers,width);
|
|
423 |
mCenterMeshes[index] = createCenterMesh(numLayers,width);
|
|
313 | 424 |
} |
314 | 425 |
|
315 | 426 |
mesh = mCenterMeshes[index].copy(true); |
... | ... | |
412 | 523 |
{ |
413 | 524 |
int COLORS = FACE_COLORS.length; |
414 | 525 |
float R,S; |
415 |
float[] vertices;
|
|
526 |
int index,variant = face/COLORS;
|
|
416 | 527 |
|
417 |
int variant = face/COLORS; |
|
418 |
|
|
419 |
if( variant==0 ) |
|
420 |
{ |
|
421 |
R = 0.080f; |
|
422 |
S = 0.10f; |
|
423 |
vertices = new float[] { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f }; |
|
424 |
} |
|
528 |
if( variant==0 ) { R = 0.08f; S = 0.10f; index = 0; } |
|
425 | 529 |
else |
426 | 530 |
{ |
427 | 531 |
int numLayers = getNumLayers(); |
428 |
float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f); |
|
429 |
float W = height*SIN18/COS18; |
|
430 |
float width = (numLayers/3.0f)*2*MEGA_D + 2*(variant-1)*W; |
|
431 | 532 |
|
432 | 533 |
if( variant < (numLayers+1)/2 ) |
433 | 534 |
{ |
434 |
float X1 = 0.5f*height; |
|
435 |
float Y1 = 0.5f*width; |
|
436 |
float Y2 = 0.5f*width + W; |
|
437 |
|
|
438 |
R = 0.045f; |
|
439 |
S = 0.055f; |
|
440 |
vertices = new float[] { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 }; |
|
441 |
} |
|
442 |
else |
|
443 |
{ |
|
444 |
float Z = 0.5f; |
|
445 |
float X1 = Z*COS54; |
|
446 |
float Y1 = Z*SIN54; |
|
447 |
float X2 = Z*COS18; |
|
448 |
float Y2 = Z*SIN18; |
|
449 |
|
|
450 |
R = 0.09f; |
|
451 |
S = 0.08f; |
|
452 |
vertices = new float[] { -X1,+Y1, -X2,-Y2, 0.0f,-Z, +X2,-Y2, +X1,+Y1 }; |
|
535 |
if( numLayers==3 ) { R = 0.12f; S = 0.12f; index = 1; } |
|
536 |
else |
|
537 |
{ |
|
538 |
if( variant==1 ) { R = 0.12f; S = 0.12f; index = 2; } |
|
539 |
else { R = 0.08f; S = 0.08f; index = 3; } |
|
540 |
} |
|
453 | 541 |
} |
542 |
else { R = 0.10f; S = 0.07f; index = 4; } |
|
454 | 543 |
} |
455 | 544 |
|
456 | 545 |
FactorySticker factory = FactorySticker.getInstance(); |
457 |
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
|
|
546 |
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[index], S, FACE_COLORS[face%COLORS], R);
|
|
458 | 547 |
} |
459 | 548 |
|
460 | 549 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
New cubit engine: finish converting Kilominx & Megaminx.