Revision bb11be2a
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/helpers/FactoryCubit.java | ||
---|---|---|
41 | 41 |
public class FactoryCubit |
42 | 42 |
{ |
43 | 43 |
private static final float SQ2 = (float)Math.sqrt(2); |
44 |
private static final float SQ5 = (float)Math.sqrt(5); |
|
45 |
|
|
46 | 44 |
private static final Static1D RADIUS = new Static1D(1); |
47 | 45 |
private static FactoryCubit mThis; |
48 | 46 |
|
... | ... | |
55 | 53 |
// REX |
56 | 54 |
public static final float REX_D = 0.2f; |
57 | 55 |
|
58 |
// KILO / MEGAMINX |
|
59 |
public static final float SIN54 = (SQ5+1)/4; |
|
60 |
public static final float COS54 = (float)(Math.sqrt(10-2*SQ5)/4); |
|
61 |
public static final float SIN18 = (SQ5-1)/4; |
|
62 |
public static final float COS18 = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5)); |
|
63 |
public static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle) |
|
64 |
public static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle) |
|
65 |
public static final float DIHEDRAL1= (float)(Math.acos(-SQ5/5)*180/Math.PI); |
|
66 |
public static final float DIHEDRAL2= (float)((180/Math.PI)*Math.asin((2*SIN54*SIN54-1)/COS54) - 90); |
|
67 |
|
|
68 | 56 |
private static final double[] mBuffer = new double[3]; |
69 | 57 |
private static final double[] mQuat1 = new double[4]; |
70 | 58 |
private static final double[] mQuat2 = new double[4]; |
... | ... | |
388 | 376 |
return new MeshJoined(meshes); |
389 | 377 |
} |
390 | 378 |
|
391 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
392 |
|
|
393 |
MeshBase createFacesMegaminxEdge(int numLayers, float width, float height) |
|
394 |
{ |
|
395 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
396 |
|
|
397 |
float D = height/COS18; |
|
398 |
float W = D*SIN18; |
|
399 |
|
|
400 |
float Y1 = 0.5f*width; |
|
401 |
float Y2 = 0.5f*width + W; |
|
402 |
float Y3 = 0.5f*width + 2*W; |
|
403 |
float X2 = D*SIN54; |
|
404 |
float X1 = 0.5f*height; |
|
405 |
float Y4 = D*COS54; |
|
406 |
|
|
407 |
float[] vertices0 = { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 }; |
|
408 |
float[] vertices1 = { -X1, Y3, -X1, -Y3, X1, -Y2, X1, Y2 }; |
|
409 |
float[] vertices2 = { -X2, 0.0f, 0.0f, -Y4, X2, 0.0f, 0.0f, Y4 }; |
|
410 |
|
|
411 |
int numBands0 = numLayers==3 ? 5 : 3; |
|
412 |
int numBands1 = numLayers==3 ? 2 : 2; |
|
413 |
float h = numLayers==3 ? 0.03f : 0.03f; |
|
414 |
|
|
415 |
float[] bands0 = computeBands(h ,34,0.2f,0.2f,numBands0); |
|
416 |
float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,numBands1); |
|
417 |
|
|
418 |
meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0); |
|
419 |
meshes[0].setEffectAssociation(0, 1,0); |
|
420 |
meshes[1] = meshes[0].copy(true); |
|
421 |
meshes[1].setEffectAssociation(0, 2,0); |
|
422 |
meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0); |
|
423 |
meshes[2].setEffectAssociation(0, 4,0); |
|
424 |
meshes[3] = meshes[2].copy(true); |
|
425 |
meshes[3].setEffectAssociation(0, 8,0); |
|
426 |
meshes[4] = new MeshPolygon(vertices2, bands1, 0, 0); |
|
427 |
meshes[4].setEffectAssociation(0,16,0); |
|
428 |
meshes[5] = meshes[4].copy(true); |
|
429 |
meshes[5].setEffectAssociation(0,32,0); |
|
430 |
|
|
431 |
return new MeshJoined(meshes); |
|
432 |
} |
|
433 |
|
|
434 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
435 |
|
|
436 |
MeshBase createFacesMegaminxCenter(int numLayers) |
|
437 |
{ |
|
438 |
MeshBase[] meshes = new MeshPolygon[2]; |
|
439 |
|
|
440 |
float R = 0.5f; |
|
441 |
float X1 = R*COS54; |
|
442 |
float Y1 = R*SIN54; |
|
443 |
float X2 = R*COS18; |
|
444 |
float Y2 = R*SIN18; |
|
445 |
|
|
446 |
float[] vertices0 = { -X1,+Y1, -X2,-Y2, 0.0f,-R, +X2,-Y2, +X1,+Y1 }; |
|
447 |
|
|
448 |
int numBands0 = numLayers==3 ? 4 : 3; |
|
449 |
int numBands1 = numLayers==3 ? 2 : 2; |
|
450 |
float h = numLayers==3 ? 0.04f : 0.04f; |
|
451 |
|
|
452 |
float[] bands0 = computeBands( h ,45, R/3,0.2f, numBands0); |
|
453 |
float[] bands1 = computeBands( 0.00f,34, R/3,0.2f, numBands1); |
|
454 |
|
|
455 |
meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0); |
|
456 |
meshes[0].setEffectAssociation(0,1,0); |
|
457 |
meshes[1] = new MeshPolygon(vertices0, bands1, 0, 0); |
|
458 |
meshes[1].setEffectAssociation(0,2,0); |
|
459 |
|
|
460 |
return new MeshJoined(meshes); |
|
461 |
} |
|
462 |
|
|
463 | 379 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
464 | 380 |
|
465 | 381 |
private float[] createVertices(int A, int B) |
... | ... | |
602 | 518 |
return effect; |
603 | 519 |
} |
604 | 520 |
|
605 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
606 |
|
|
607 |
VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height) |
|
608 |
{ |
|
609 |
VertexEffect[] effect = new VertexEffect[11]; |
|
610 |
|
|
611 |
float X = 0.5f*height; |
|
612 |
float Y = height*(COS54/COS18) + width*0.5f; |
|
613 |
float Z = 2*height*COS_HALFD; |
|
614 |
|
|
615 |
float alpha = 90-DIHEDRAL1/2; |
|
616 |
float beta = DIHEDRAL2; |
|
617 |
|
|
618 |
Static1D angle1 = new Static1D(alpha); |
|
619 |
Static1D angle2 = new Static1D(180-alpha); |
|
620 |
Static1D angle3 = new Static1D(beta); |
|
621 |
|
|
622 |
Static3D move1 = new Static3D(X,0,0); |
|
623 |
Static3D move2 = new Static3D(X,0,-Z); |
|
624 |
Static3D move3 = new Static3D(0,+Y,0); |
|
625 |
Static3D move4 = new Static3D(0,-Y,0); |
|
626 |
Static3D scale = new Static3D(+1,+1,-1); |
|
627 |
|
|
628 |
Static3D axisXplus = new Static3D(+1, 0, 0); |
|
629 |
Static3D axisXminus= new Static3D(-1, 0, 0); |
|
630 |
Static3D axisYplus = new Static3D( 0,+1, 0); |
|
631 |
Static3D axisYminus= new Static3D( 0,-1, 0); |
|
632 |
|
|
633 |
Static3D center1= new Static3D( 0, 0, 0); |
|
634 |
Static3D center2= new Static3D( 0, 0,-Z); |
|
635 |
Static3D center3= new Static3D( 0,+width*0.5f, 0); |
|
636 |
Static3D center4= new Static3D( 0,-width*0.5f, 0); |
|
637 |
|
|
638 |
effect[ 0] = new VertexEffectMove(move1); |
|
639 |
effect[ 1] = new VertexEffectMove(move2); |
|
640 |
effect[ 2] = new VertexEffectMove(move3); |
|
641 |
effect[ 3] = new VertexEffectMove(move4); |
|
642 |
effect[ 4] = new VertexEffectScale(scale); |
|
643 |
effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1); |
|
644 |
effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1); |
|
645 |
effect[ 7] = new VertexEffectRotate(angle1, axisYminus, center2); |
|
646 |
effect[ 8] = new VertexEffectRotate(angle2, axisYminus, center2); |
|
647 |
effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center3); |
|
648 |
effect[10] = new VertexEffectRotate(angle3, axisXminus, center4); |
|
649 |
|
|
650 |
effect[ 0].setMeshAssociation( 3,-1); // meshes 0,1 |
|
651 |
effect[ 1].setMeshAssociation(12,-1); // meshes 2,3 |
|
652 |
effect[ 2].setMeshAssociation(16,-1); // mesh 4 |
|
653 |
effect[ 3].setMeshAssociation(32,-1); // mesh 5 |
|
654 |
effect[ 4].setMeshAssociation( 2,-1); // mesh 1 |
|
655 |
effect[ 5].setMeshAssociation( 1,-1); // mesh 0 |
|
656 |
effect[ 6].setMeshAssociation( 2,-1); // mesh 1 |
|
657 |
effect[ 7].setMeshAssociation( 4,-1); // mesh 2 |
|
658 |
effect[ 8].setMeshAssociation( 8,-1); // mesh 3 |
|
659 |
effect[ 9].setMeshAssociation(16,-1); // mesh 4 |
|
660 |
effect[10].setMeshAssociation(32,-1); // mesh 5 |
|
661 |
|
|
662 |
return effect; |
|
663 |
} |
|
664 |
|
|
665 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
666 |
|
|
667 |
VertexEffect[] createVertexEffectsMegaminxCenter(float width) |
|
668 |
{ |
|
669 |
VertexEffect[] effect = new VertexEffect[2]; |
|
670 |
|
|
671 |
Static1D angle = new Static1D(DIHEDRAL2); |
|
672 |
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f); |
|
673 |
Static3D center= new Static3D( 0, 0, 0); |
|
674 |
|
|
675 |
effect[0] = new VertexEffectScale(width/COS54); |
|
676 |
effect[1] = new VertexEffectRotate(angle, axisX, center); |
|
677 |
|
|
678 |
return effect; |
|
679 |
} |
|
680 |
|
|
681 | 521 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
682 | 522 |
|
683 | 523 |
VertexEffect[] createCuboidEffects(int[] dimensions) |
... | ... | |
830 | 670 |
return mesh; |
831 | 671 |
} |
832 | 672 |
|
833 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
834 |
// numLayers==3 --> index=0; numLayers=5 --> index=1 ... |
|
835 |
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc |
|
836 |
|
|
837 |
public MeshBase createMegaminxEdgeMesh(int numLayers, float width, float height) |
|
838 |
{ |
|
839 |
MeshBase mesh = createFacesMegaminxEdge(numLayers,width,height); |
|
840 |
VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height); |
|
841 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
842 |
|
|
843 |
mesh.mergeEffComponents(); |
|
844 |
|
|
845 |
return mesh; |
|
846 |
} |
|
847 |
|
|
848 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
849 |
|
|
850 |
public MeshBase createMegaminxCenterMesh(int numLayers, float width) |
|
851 |
{ |
|
852 |
MeshBase mesh = createFacesMegaminxCenter(numLayers); |
|
853 |
VertexEffect[] effects = createVertexEffectsMegaminxCenter(width); |
|
854 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
855 |
|
|
856 |
mesh.mergeEffComponents(); |
|
857 |
mesh.addEmptyTexComponent(); |
|
858 |
mesh.addEmptyTexComponent(); |
|
859 |
mesh.addEmptyTexComponent(); |
|
860 |
mesh.addEmptyTexComponent(); |
|
861 |
|
|
862 |
return mesh; |
|
863 |
} |
|
864 |
|
|
865 | 673 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
866 | 674 |
|
867 | 675 |
public MeshBase createCuboidMesh(int[] dimensions) |
... | ... | |
1535 | 1343 |
|
1536 | 1344 |
mNewFaceTransf.add(newT); |
1537 | 1345 |
} |
1538 |
|
|
1539 |
printStickerCoords(); |
|
1540 | 1346 |
} |
1541 | 1347 |
|
1542 | 1348 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
New cubit engine: finish converting Kilominx & Megaminx.