Revision 5e06e92f
Added by Leszek Koltunski over 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 SQ3 = (float)Math.sqrt(3); |
|
45 | 44 |
private static final float SQ5 = (float)Math.sqrt(5); |
46 | 45 |
|
47 | 46 |
private static final Static1D RADIUS = new Static1D(1); |
... | ... | |
65 | 64 |
public static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle) |
66 | 65 |
public static final float DIHEDRAL1= (float)(Math.acos(-SQ5/5)*180/Math.PI); |
67 | 66 |
public static final float DIHEDRAL2= (float)((180/Math.PI)*Math.asin((2*SIN54*SIN54-1)/COS54) - 90); |
68 |
public static final float MINX_SC = 0.5f; |
|
69 |
|
|
70 | 67 |
|
71 | 68 |
private static final double[] mBuffer = new double[3]; |
72 | 69 |
private static final double[] mQuat1 = new double[4]; |
... | ... | |
391 | 388 |
return new MeshJoined(meshes); |
392 | 389 |
} |
393 | 390 |
|
394 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
395 |
|
|
396 |
MeshBase createFacesKilominxCenter() |
|
397 |
{ |
|
398 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
399 |
|
|
400 |
float X1= 0.5f*SIN54; |
|
401 |
float Y1= 0.5f*SIN_HALFD; |
|
402 |
float Y2= Y1 - 0.5f*COS54; |
|
403 |
float H = 0.5f* SIN54 /COS54 ; |
|
404 |
float X2= MINX_SC*H* SIN_HALFD; |
|
405 |
float Y3= MINX_SC*H/(2*COS_HALFD); |
|
406 |
float Y4= MINX_SC*H*(1/(2*COS_HALFD) - COS_HALFD); |
|
407 |
|
|
408 |
float[] vertices0 = { -X1, Y2, 0, -Y1, X1, Y2, 0, Y1 }; |
|
409 |
float[] bands0 = computeBands(0.04f,17,0.3f,0.2f,5); |
|
410 |
float[] vertices1 = { -X2, Y4, 0, -Y3, X2, Y4, 0, Y3 }; |
|
411 |
float[] bands1 = computeBands(0.00f, 0,0.25f,0.5f,2); |
|
412 |
|
|
413 |
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1); |
|
414 |
meshes[0].setEffectAssociation(0, 1,0); |
|
415 |
meshes[1] = meshes[0].copy(true); |
|
416 |
meshes[1].setEffectAssociation(0, 2,0); |
|
417 |
meshes[2] = meshes[0].copy(true); |
|
418 |
meshes[2].setEffectAssociation(0, 4,0); |
|
419 |
meshes[3] = new MeshPolygon(vertices1, bands1, 0, 0); |
|
420 |
meshes[3].setEffectAssociation(0, 8,0); |
|
421 |
meshes[4] = meshes[3].copy(true); |
|
422 |
meshes[4].setEffectAssociation(0,16,0); |
|
423 |
meshes[5] = meshes[3].copy(true); |
|
424 |
meshes[5].setEffectAssociation(0,32,0); |
|
425 |
|
|
426 |
return new MeshJoined(meshes); |
|
427 |
} |
|
428 |
|
|
429 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
430 |
|
|
431 |
MeshBase createFacesMinxCorner(int numLayers) |
|
432 |
{ |
|
433 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
434 |
|
|
435 |
float Y = COS54/(2*SIN54); |
|
436 |
|
|
437 |
float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y }; |
|
438 |
|
|
439 |
int numBands0 = numLayers==3 ? 5 : 3; |
|
440 |
int numBands1 = numLayers==3 ? 2 : 2; |
|
441 |
float h = numLayers==3 ? 0.04f : 0.03f; |
|
442 |
int e = numLayers==3 ? 4 : 1; |
|
443 |
|
|
444 |
float[] bands0 = computeBands(h ,34,0.3f,0.2f, numBands0); |
|
445 |
float[] bands1 = computeBands(0.00f,34,0.3f,0.2f, numBands1); |
|
446 |
|
|
447 |
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1); |
|
448 |
meshes[0].setEffectAssociation(0, 1,0); |
|
449 |
meshes[1] = meshes[0].copy(true); |
|
450 |
meshes[1].setEffectAssociation(0, 2,0); |
|
451 |
meshes[2] = meshes[0].copy(true); |
|
452 |
meshes[2].setEffectAssociation(0, 4,0); |
|
453 |
meshes[3] = new MeshPolygon(vertices0, bands1, 1, e); |
|
454 |
meshes[3].setEffectAssociation(0, 8,0); |
|
455 |
meshes[4] = meshes[3].copy(true); |
|
456 |
meshes[4].setEffectAssociation(0,16,0); |
|
457 |
meshes[5] = meshes[3].copy(true); |
|
458 |
meshes[5].setEffectAssociation(0,32,0); |
|
459 |
|
|
460 |
return new MeshJoined(meshes); |
|
461 |
} |
|
462 |
|
|
463 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
464 |
|
|
465 |
MeshBase createFacesKilominxEdge(int numLayers, float width, float height) |
|
466 |
{ |
|
467 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
468 |
|
|
469 |
float D = height/COS18; |
|
470 |
float W = D*SIN18; |
|
471 |
float X1 = height/2; |
|
472 |
float Y1 = width/2; |
|
473 |
float Y2 = (width+W)/2; |
|
474 |
float X3 = D*SIN54; |
|
475 |
float Y3 = D*COS54; |
|
476 |
float X4 = height*SIN_HALFD; |
|
477 |
float Y4 = height*COS_HALFD; |
|
478 |
|
|
479 |
float[] vertices0 = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 }; |
|
480 |
float[] vertices1 = { -X1,-Y2, X1, -Y2, X1, Y2+W,-X1, Y2 }; |
|
481 |
float[] vertices2 = { -X3, 0.0f, 0.0f, -Y3, X3, 0.0f, 0.0f, Y3 }; |
|
482 |
float[] vertices3 = { -X4, 0.0f, 0.0f, -Y4, X4, 0.0f, 0.0f, Y4 }; |
|
483 |
|
|
484 |
int numBands0 = numLayers<=5 ? 5 : 3; |
|
485 |
int numBands1 = numLayers<=5 ? 3 : 2; |
|
486 |
float h = numLayers<=5 ? 0.03f : 0.03f; |
|
487 |
|
|
488 |
float[] bands0 = computeBands(h ,34,0.2f,0.2f,numBands0); |
|
489 |
float[] bands1 = computeBands(0.01f,34,0.3f,0.2f,numBands1); |
|
490 |
|
|
491 |
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1); |
|
492 |
meshes[0].setEffectAssociation(0, 1,0); |
|
493 |
meshes[1] = meshes[0].copy(true); |
|
494 |
meshes[1].setEffectAssociation(0, 2,0); |
|
495 |
meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0); |
|
496 |
meshes[2].setEffectAssociation(0, 4,0); |
|
497 |
meshes[3] = meshes[2].copy(true); |
|
498 |
meshes[3].setEffectAssociation(0, 8,0); |
|
499 |
meshes[4] = new MeshPolygon(vertices2, bands1, 0, 0); |
|
500 |
meshes[4].setEffectAssociation(0,16,0); |
|
501 |
meshes[5] = new MeshPolygon(vertices3, bands1, 0, 0); |
|
502 |
meshes[5].setEffectAssociation(0,32,0); |
|
503 |
|
|
504 |
return new MeshJoined(meshes); |
|
505 |
} |
|
506 |
|
|
507 | 391 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
508 | 392 |
|
509 | 393 |
MeshBase createFacesMegaminxEdge(int numLayers, float width, float height) |
... | ... | |
718 | 602 |
return effect; |
719 | 603 |
} |
720 | 604 |
|
721 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
722 |
|
|
723 |
VertexEffect[] createVertexEffectsKilominxCenter(float width) |
|
724 |
{ |
|
725 |
VertexEffect[] effect = new VertexEffect[11]; |
|
726 |
|
|
727 |
float H = 0.5f*(SIN54/COS54); |
|
728 |
float Y1= 0.5f*SIN_HALFD; |
|
729 |
float Y2= H/(2*COS_HALFD); |
|
730 |
float cos18 = (float)(Math.sqrt(1- SIN18 * SIN18)); |
|
731 |
float LEN = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f); |
|
732 |
|
|
733 |
Static3D axisZ = new Static3D(0.0f , 0.0f , 1.0f); |
|
734 |
Static3D axisY = new Static3D(0.0f , 1.0f , 0.0f); |
|
735 |
Static3D axisA = new Static3D(-SIN18, cos18, 0.0f); |
|
736 |
Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H* SIN_HALFD /(COS_HALFD*LEN)); |
|
737 |
|
|
738 |
Static3D move1 = new Static3D(0,-Y1,0); |
|
739 |
Static3D move2 = new Static3D(0,-Y2,0); |
|
740 |
Static3D move3 = new Static3D(0.5f*cos18,0.5f*SIN18,0); |
|
741 |
Static3D center= new Static3D(0.0f, 0.0f, 0.0f); |
|
742 |
|
|
743 |
Static1D angle1 = new Static1D(54); |
|
744 |
Static1D angle2 = new Static1D(DIHEDRAL1/2+18); |
|
745 |
Static1D angle3 = new Static1D(90); |
|
746 |
Static1D angle4 = new Static1D(120); |
|
747 |
Static1D angle5 = new Static1D(240); |
|
748 |
Static1D angle6 = new Static1D(90-DIHEDRAL1/2); |
|
749 |
|
|
750 |
effect[0] = new VertexEffectMove(move1); |
|
751 |
effect[1] = new VertexEffectScale(1/MINX_SC); |
|
752 |
effect[2] = new VertexEffectMove(move2); |
|
753 |
effect[3] = new VertexEffectRotate(angle1, axisZ, center); |
|
754 |
effect[4] = new VertexEffectRotate(angle2, axisZ, center); |
|
755 |
effect[5] = new VertexEffectRotate(angle3, axisA, center); |
|
756 |
effect[6] = new VertexEffectMove(move3); |
|
757 |
effect[7] = new VertexEffectRotate(angle4, axisC, center); |
|
758 |
effect[8] = new VertexEffectRotate(angle5, axisC, center); |
|
759 |
effect[9] = new VertexEffectRotate(angle6, axisY, center); |
|
760 |
effect[10]= new VertexEffectScale(width/0.5f); |
|
761 |
|
|
762 |
effect[0].setMeshAssociation( 7,-1); // meshes 0,1,2 |
|
763 |
effect[1].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
764 |
effect[2].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
765 |
effect[3].setMeshAssociation( 7,-1); // meshes 0,1,2 |
|
766 |
effect[4].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
767 |
effect[5].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
768 |
effect[6].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
769 |
effect[7].setMeshAssociation(18,-1); // meshes 1,4 |
|
770 |
effect[8].setMeshAssociation(36,-1); // meshes 2,5 |
|
771 |
|
|
772 |
return effect; |
|
773 |
} |
|
774 |
|
|
775 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
776 |
|
|
777 |
VertexEffect[] createVertexEffectsMinxCorner(float width) |
|
778 |
{ |
|
779 |
VertexEffect[] effect = new VertexEffect[9]; |
|
780 |
|
|
781 |
float Y = COS54/(2*SIN54); |
|
782 |
|
|
783 |
float sinA = (2*SIN54*SIN54-1)/COS54; |
|
784 |
float cosA = (float)Math.sqrt(1-sinA*sinA); |
|
785 |
float LEN = 0.5f/SIN54; |
|
786 |
float scale= width/LEN; |
|
787 |
|
|
788 |
Static3D axisA = new Static3D( SIN54, COS54, 0.0f); |
|
789 |
Static3D axisB = new Static3D(-SIN54, COS54, 0.0f); |
|
790 |
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f); |
|
791 |
|
|
792 |
Static3D centerU = new Static3D( 0.0f, Y, 0.0f); |
|
793 |
Static3D centerD = new Static3D( 0.0f,-Y, 0.0f); |
|
794 |
|
|
795 |
Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN ); |
|
796 |
Static3D move2= new Static3D(0.0f, Y , 0.0f ); |
|
797 |
|
|
798 |
Static1D angleD = new Static1D(DIHEDRAL1); |
|
799 |
Static1D angleE = new Static1D(360-DIHEDRAL1); |
|
800 |
Static1D angleF = new Static1D(DIHEDRAL2); |
|
801 |
|
|
802 |
effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) ); |
|
803 |
effect[1] = new VertexEffectRotate(angleE, axisA, centerU); |
|
804 |
effect[2] = new VertexEffectRotate(angleD, axisB, centerU); |
|
805 |
effect[3] = new VertexEffectMove(move1); |
|
806 |
effect[4] = new VertexEffectRotate(angleE, axisA, centerD); |
|
807 |
effect[5] = new VertexEffectRotate(angleD, axisB, centerD); |
|
808 |
effect[6] = new VertexEffectRotate(angleF, axisX, centerD); |
|
809 |
effect[7] = new VertexEffectMove(move2); |
|
810 |
effect[8] = new VertexEffectScale(scale); |
|
811 |
|
|
812 |
effect[0].setMeshAssociation( 3,-1); // meshes 0,1 |
|
813 |
effect[1].setMeshAssociation( 16,-1); // mesh 4 |
|
814 |
effect[2].setMeshAssociation( 32,-1); // mesh 5 |
|
815 |
effect[3].setMeshAssociation( 56,-1); // meshes 3,4,5 |
|
816 |
effect[4].setMeshAssociation( 1,-1); // mesh 0 |
|
817 |
effect[5].setMeshAssociation( 2,-1); // mesh 1 |
|
818 |
|
|
819 |
return effect; |
|
820 |
} |
|
821 |
|
|
822 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
823 |
|
|
824 |
VertexEffect[] createVertexEffectsKilominxEdge(float width, float height, boolean left) |
|
825 |
{ |
|
826 |
VertexEffect[] effect = new VertexEffect[11 + (left ? 0:1)]; |
|
827 |
|
|
828 |
float D = height/COS18; |
|
829 |
float W = D*SIN18; |
|
830 |
float X1 = height/2; |
|
831 |
float Y1 = width/2; |
|
832 |
float Y2 = (width+W)/2; |
|
833 |
float Y3 = D*COS54; |
|
834 |
float Y4 = height*COS_HALFD; |
|
835 |
float Z = 2*height*COS_HALFD; |
|
836 |
float alpha = 90-DIHEDRAL1/2; |
|
837 |
|
|
838 |
Static1D angle1 = new Static1D(alpha); |
|
839 |
Static1D angle2 = new Static1D(180-alpha); |
|
840 |
Static1D angle3 = new Static1D(DIHEDRAL2); |
|
841 |
Static1D angle4 = new Static1D(90); |
|
842 |
|
|
843 |
Static3D move1 = new Static3D(+X1,-Y1,0); |
|
844 |
Static3D move2 = new Static3D(-X1,-Y2+W,-Z); |
|
845 |
Static3D move3 = new Static3D(0,+Y3,0); |
|
846 |
Static3D move4 = new Static3D(0,-Y4-width,0); |
|
847 |
Static3D scale = new Static3D(+1,+1,-1); |
|
848 |
|
|
849 |
Static3D axisXplus = new Static3D(+1, 0, 0); |
|
850 |
Static3D axisYplus = new Static3D( 0,+1, 0); |
|
851 |
|
|
852 |
Static3D center1= new Static3D( 0, 0, 0); |
|
853 |
Static3D center2= new Static3D( 0, 0,-Z); |
|
854 |
Static3D center3= new Static3D( 0,-width, 0); |
|
855 |
|
|
856 |
effect[ 0] = new VertexEffectMove(move1); |
|
857 |
effect[ 1] = new VertexEffectMove(move2); |
|
858 |
effect[ 2] = new VertexEffectMove(move3); |
|
859 |
effect[ 3] = new VertexEffectMove(move4); |
|
860 |
effect[ 4] = new VertexEffectScale(scale); |
|
861 |
effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1); |
|
862 |
effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1); |
|
863 |
effect[ 7] = new VertexEffectRotate(angle1, axisYplus , center2); |
|
864 |
effect[ 8] = new VertexEffectRotate(angle2, axisYplus , center2); |
|
865 |
effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center1); |
|
866 |
effect[10] = new VertexEffectRotate(angle4, axisXplus , center3); |
|
867 |
|
|
868 |
if( !left ) |
|
869 |
{ |
|
870 |
Static3D scale1 = new Static3D(+1,-1,+1); |
|
871 |
effect[11] = new VertexEffectScale(scale1); |
|
872 |
} |
|
873 |
|
|
874 |
effect[ 0].setMeshAssociation( 3,-1); // meshes 0,1 |
|
875 |
effect[ 1].setMeshAssociation(12,-1); // meshes 2,3 |
|
876 |
effect[ 2].setMeshAssociation(16,-1); // mesh 4 |
|
877 |
effect[ 3].setMeshAssociation(32,-1); // mesh 5 |
|
878 |
effect[ 4].setMeshAssociation( 2,-1); // mesh 1 |
|
879 |
effect[ 5].setMeshAssociation( 1,-1); // mesh 0 |
|
880 |
effect[ 6].setMeshAssociation( 2,-1); // mesh 1 |
|
881 |
effect[ 7].setMeshAssociation( 4,-1); // mesh 2 |
|
882 |
effect[ 8].setMeshAssociation( 8,-1); // mesh 3 |
|
883 |
effect[ 9].setMeshAssociation(16,-1); // mesh 4 |
|
884 |
effect[10].setMeshAssociation(32,-1); // mesh 5 |
|
885 |
|
|
886 |
return effect; |
|
887 |
} |
|
888 |
|
|
889 | 605 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
890 | 606 |
|
891 | 607 |
VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height) |
... | ... | |
1114 | 830 |
return mesh; |
1115 | 831 |
} |
1116 | 832 |
|
1117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1118 |
|
|
1119 |
public MeshBase createKilominxCenterMesh(float width) |
|
1120 |
{ |
|
1121 |
MeshBase mesh = createFacesKilominxCenter(); |
|
1122 |
VertexEffect[] effects = createVertexEffectsKilominxCenter(width); |
|
1123 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1124 |
|
|
1125 |
float A = (2*SQ3/3)* SIN54; |
|
1126 |
float B = 0.4f; |
|
1127 |
float X = SIN_HALFD * SIN54 *COS54 ; |
|
1128 |
float Y = SIN54 * SIN54 - 0.5f; |
|
1129 |
float Z = COS_HALFD* SIN54 *COS54 ; |
|
1130 |
|
|
1131 |
Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B); |
|
1132 |
|
|
1133 |
Static3D[] vertices = new Static3D[4]; |
|
1134 |
vertices[0] = new Static3D( 0.0f, 0.0f, 0.0f); |
|
1135 |
vertices[1] = new Static3D( 0.0f,-0.5f, 0.0f); |
|
1136 |
vertices[2] = new Static3D(-X , Y ,-Z ); |
|
1137 |
vertices[3] = new Static3D(+X , Y ,-Z ); |
|
1138 |
|
|
1139 |
roundCorners(mesh,center,vertices,0.03f,0.10f); |
|
1140 |
|
|
1141 |
mesh.mergeEffComponents(); |
|
1142 |
|
|
1143 |
return mesh; |
|
1144 |
} |
|
1145 |
|
|
1146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1147 |
// numLayers==3 --> index=0; numLayers=5 --> index=1 ... |
|
1148 |
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc |
|
1149 |
|
|
1150 |
public MeshBase createKilominxEdgeMesh(int numLayers, float width, float height, boolean left) |
|
1151 |
{ |
|
1152 |
MeshBase mesh = createFacesKilominxEdge(numLayers,width,height); |
|
1153 |
VertexEffect[] effects = createVertexEffectsKilominxEdge(width,height,left); |
|
1154 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1155 |
|
|
1156 |
// round... |
|
1157 |
|
|
1158 |
mesh.mergeEffComponents(); |
|
1159 |
|
|
1160 |
return mesh; |
|
1161 |
} |
|
1162 |
|
|
1163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1164 |
|
|
1165 |
public MeshBase createMinxCornerMesh(int numLayers, float width) |
|
1166 |
{ |
|
1167 |
MeshBase mesh = createFacesMinxCorner(numLayers); |
|
1168 |
VertexEffect[] effects = createVertexEffectsMinxCorner(width); |
|
1169 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1170 |
|
|
1171 |
float A = (2*SQ3/3)* SIN54; |
|
1172 |
float B = 0.4f; |
|
1173 |
/* |
|
1174 |
float X = SIN_HALFD* SIN54 * COS54; |
|
1175 |
float Y = SIN54 * SIN54 - 0.5f; |
|
1176 |
float Z = COS_HALFD* SIN54 * COS54; |
|
1177 |
float S = 2*width; |
|
1178 |
*/ |
|
1179 |
Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B); |
|
1180 |
Static3D[] vertices = new Static3D[1]; |
|
1181 |
vertices[0] = new Static3D( 0.0f, 0.0f , 0.0f); |
|
1182 |
/* |
|
1183 |
vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f); |
|
1184 |
vertices[2] = new Static3D(-X*S , Y*S ,-Z*S ); |
|
1185 |
vertices[3] = new Static3D(+X*S , Y*S ,-Z*S ); |
|
1186 |
*/ |
|
1187 |
roundCorners(mesh,center,vertices,0.04f,0.10f); |
|
1188 |
|
|
1189 |
mesh.mergeEffComponents(); |
|
1190 |
|
|
1191 |
return mesh; |
|
1192 |
} |
|
1193 |
|
|
1194 | 833 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1195 | 834 |
// numLayers==3 --> index=0; numLayers=5 --> index=1 ... |
1196 | 835 |
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc |
... | ... | |
1278 | 917 |
return mesh; |
1279 | 918 |
} |
1280 | 919 |
|
1281 |
|
|
1282 |
|
|
1283 |
|
|
1284 | 920 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1285 | 921 |
|
1286 | 922 |
private boolean areColinear(double[][] vertices, int index1, int index2, int index3) |
... | ... | |
1899 | 1535 |
|
1900 | 1536 |
mNewFaceTransf.add(newT); |
1901 | 1537 |
} |
1538 |
|
|
1539 |
printStickerCoords(); |
|
1902 | 1540 |
} |
1903 | 1541 |
|
1904 | 1542 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyBandaged2Bar.java | ||
---|---|---|
69 | 69 |
super(size, quat, texture, mesh, effects, moves, ObjectList.BAN2, res, scrWidth); |
70 | 70 |
} |
71 | 71 |
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
int getNumCubitTypes(int numLayers) |
|
75 |
{ |
|
76 |
return 2; |
|
77 |
} |
|
78 |
|
|
79 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
80 | 73 |
|
81 | 74 |
float[][] getPositions() |
src/main/java/org/distorted/objects/TwistyKilominx.java | ||
---|---|---|
37 | 37 |
|
38 | 38 |
import static org.distorted.helpers.FactoryCubit.COS18; |
39 | 39 |
import static org.distorted.helpers.FactoryCubit.COS54; |
40 |
import static org.distorted.helpers.FactoryCubit.COS_HALFD; |
|
40 | 41 |
import static org.distorted.helpers.FactoryCubit.SIN18; |
41 | 42 |
import static org.distorted.helpers.FactoryCubit.SIN54; |
43 |
import static org.distorted.helpers.FactoryCubit.SIN_HALFD; |
|
42 | 44 |
|
43 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 46 |
|
... | ... | |
323 | 325 |
} |
324 | 326 |
} |
325 | 327 |
|
328 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
329 |
|
|
330 |
private MeshBase createCenterMesh(float width) |
|
331 |
{ |
|
332 |
double X = width*COS18*SIN_HALFD; |
|
333 |
double Y = width*SIN18; |
|
334 |
double Z = width*COS18*COS_HALFD; |
|
335 |
double H = width*(SIN54/COS54); |
|
336 |
double H3= H/COS_HALFD; |
|
337 |
double X3= H*SIN_HALFD; |
|
338 |
double Z3= H*COS_HALFD;; |
|
339 |
double C = 1/(COS54*Math.sqrt(2-2*SIN18)); |
|
340 |
|
|
341 |
double[][] vertices = new double[][] |
|
342 |
{ |
|
343 |
{ 0.0, 0.0 , 0.0 }, |
|
344 |
{ X, Y , -Z }, |
|
345 |
{ 0.0,C*2*Y ,-2*C*Z }, |
|
346 |
{ -X, Y , -Z }, |
|
347 |
{ 0.0,-width, 0.0 }, |
|
348 |
{ X3,-width, -Z3 }, |
|
349 |
{ 0.0,-width, -H3 }, |
|
350 |
{ -X3,-width, -Z3 } |
|
351 |
}; |
|
352 |
|
|
353 |
int[][] vertIndexes = new int[][] |
|
354 |
{ |
|
355 |
{4,5,1,0}, |
|
356 |
{7,4,0,3}, |
|
357 |
{0,1,2,3}, |
|
358 |
{7,6,2,3}, |
|
359 |
{6,5,1,2}, |
|
360 |
{4,5,6,7} |
|
361 |
}; |
|
362 |
|
|
363 |
float[][] bands = new float[][] |
|
364 |
{ |
|
365 |
{0.04f,17,0.3f,0.2f,5,1,1}, |
|
366 |
{0.00f, 0,0.0f,0.5f,2,0,0} |
|
367 |
}; |
|
368 |
|
|
369 |
float A = (2*SQ3/3)*SIN54; |
|
370 |
float B = 0.4f; |
|
371 |
|
|
372 |
int[] bandIndexes = new int[] { 0,0,0,1,1,1}; |
|
373 |
float[][] corners = new float[][] { {0.03f,0.10f} }; |
|
374 |
int[] cornerIndexes = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 }; |
|
375 |
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} }; |
|
376 |
int[] centerIndexes = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 }; |
|
377 |
|
|
378 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
379 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
380 |
|
|
381 |
return factory.createRoundedSolid(vertices, vertIndexes, |
|
382 |
bands, bandIndexes, |
|
383 |
corners, cornerIndexes, |
|
384 |
centers, centerIndexes, |
|
385 |
getNumCubitFaces() ); |
|
386 |
} |
|
387 |
|
|
388 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
389 |
|
|
390 |
private MeshBase createEdgeMesh(int numLayers, float width, float height, boolean left) |
|
391 |
{ |
|
392 |
double X = height*SIN_HALFD; |
|
393 |
double Y = height*SIN18/COS18; |
|
394 |
double Z = height*COS_HALFD; |
|
395 |
|
|
396 |
double[][] vertices = new double[][] |
|
397 |
{ |
|
398 |
{ 0.0, 0.0 , 0.0 }, |
|
399 |
{ X, Y , -Z }, |
|
400 |
{ 0.0, 2*Y ,-2*Z }, |
|
401 |
{ -X, Y , -Z }, |
|
402 |
{ 0.0, -width, 0.0 }, |
|
403 |
{ X, -width, -Z }, |
|
404 |
{ 0.0, -width,-2*Z }, |
|
405 |
{ -X, -width, -Z }, |
|
406 |
}; |
|
407 |
|
|
408 |
int[][] vertIndexes = new int[][] |
|
409 |
{ |
|
410 |
{4,5,1,0}, |
|
411 |
{7,4,0,3}, |
|
412 |
{7,6,2,3}, |
|
413 |
{6,5,1,2}, |
|
414 |
{0,1,2,3}, |
|
415 |
{4,5,6,7} |
|
416 |
}; |
|
417 |
|
|
418 |
if( !left ) |
|
419 |
{ |
|
420 |
int tmp, len = vertices.length; |
|
421 |
for(int i=0; i<len; i++) vertices[i][1] = -vertices[i][1]; |
|
422 |
|
|
423 |
len = vertIndexes.length; |
|
424 |
for(int i=0; i<len; i++) |
|
425 |
{ |
|
426 |
tmp = vertIndexes[i][0]; |
|
427 |
vertIndexes[i][0] = vertIndexes[i][3]; |
|
428 |
vertIndexes[i][3] = tmp; |
|
429 |
|
|
430 |
tmp = vertIndexes[i][1]; |
|
431 |
vertIndexes[i][1] = vertIndexes[i][2]; |
|
432 |
vertIndexes[i][2] = tmp; |
|
433 |
} |
|
434 |
} |
|
435 |
|
|
436 |
int numBands0 = numLayers<=5 ? 5 : 3; |
|
437 |
int numBands1 = numLayers<=5 ? 3 : 2; |
|
438 |
|
|
439 |
float[][] bands = new float[][] |
|
440 |
{ |
|
441 |
{0.04f,34,0.2f,0.2f,numBands0,1,1}, |
|
442 |
{0.00f, 0,0.0f,0.0f,numBands1,0,0} |
|
443 |
}; |
|
444 |
int[] bandIndexes = new int[] { 0,0,1,1,1,1}; |
|
445 |
float[][] corners = new float[][] { {0.04f,0.10f} }; |
|
446 |
int[] cornerIndexes = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 }; |
|
447 |
float[][] centers = new float[][] { {0.0f, -width/2, (float)(-2*Z)} }; |
|
448 |
int[] centerIndexes = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 }; |
|
449 |
|
|
450 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
451 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
452 |
|
|
453 |
return factory.createRoundedSolid(vertices, vertIndexes, |
|
454 |
bands, bandIndexes, |
|
455 |
corners, cornerIndexes, |
|
456 |
centers, centerIndexes, |
|
457 |
getNumCubitFaces() ); |
|
458 |
} |
|
459 |
|
|
326 | 460 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
327 | 461 |
|
328 | 462 |
MeshBase createCubitMesh(int cubit, int numLayers) |
... | ... | |
349 | 483 |
if( mCornerMeshes[indexCornerEdge]==null ) |
350 | 484 |
{ |
351 | 485 |
float width = (numLayers/3.0f)/(numLayers-1); |
352 |
mCornerMeshes[indexCornerEdge] = FactoryCubit.getInstance().createMinxCornerMesh(numLayers,width);
|
|
486 |
mCornerMeshes[indexCornerEdge] = createCornerMesh(numLayers,width);
|
|
353 | 487 |
} |
354 | 488 |
mesh = mCornerMeshes[indexCornerEdge].copy(true); |
355 | 489 |
} |
... | ... | |
363 | 497 |
float height= tmp*COS18; |
364 | 498 |
float width = tmp + (type/2)*tmp*SIN18; |
365 | 499 |
|
366 |
mEdgeMeshes[indexCornerEdge][type] = FactoryCubit.getInstance().createKilominxEdgeMesh(numLayers,width,height, (type%2)==0 );
|
|
500 |
mEdgeMeshes[indexCornerEdge][type] = createEdgeMesh(numLayers,width,height, (type%2)==0 );
|
|
367 | 501 |
} |
368 | 502 |
|
369 | 503 |
mesh = mEdgeMeshes[indexCornerEdge][type].copy(true); |
... | ... | |
375 | 509 |
if( mCenterMeshes[indexCenter]==null ) |
376 | 510 |
{ |
377 | 511 |
float width = (1+0.5f*(numLayers-3)*SIN18)*(numLayers/3.0f)/(numLayers-1); |
378 |
mCenterMeshes[indexCenter] = FactoryCubit.getInstance().createKilominxCenterMesh(width);
|
|
512 |
mCenterMeshes[indexCenter] = createCenterMesh(width);
|
|
379 | 513 |
} |
380 | 514 |
|
381 | 515 |
mesh = mCenterMeshes[indexCenter].copy(true); |
... | ... | |
487 | 621 |
int variant = face/COLORS; |
488 | 622 |
int numLayers = getNumLayers(); |
489 | 623 |
|
490 |
if( variant == (numLayers-1)/2 || numLayers==3 ) |
|
624 |
if( variant == (numLayers-1)/2 || numLayers==3 ) // center
|
|
491 | 625 |
{ |
492 |
float S = 0.07f; |
|
493 |
float R = 0.09f; |
|
494 |
|
|
495 |
float A = 0.86f; |
|
496 |
float X1= (SQ5+1)/8; |
|
497 |
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4); |
|
498 |
float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8); |
|
626 |
float R = 0.10f; |
|
627 |
float S = 0.09f; |
|
628 |
float A = 0.87f; |
|
629 |
float[] vertices = { -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f }; |
|
499 | 630 |
|
500 |
float[] vertices = { -X1, Y2, 0, -A*Y1, X1, Y2, 0, Y1 }; |
|
631 |
float cx = vertices[2]; |
|
632 |
float cy = vertices[3]; |
|
633 |
vertices[2] *= A; |
|
634 |
vertices[3] *= A; |
|
501 | 635 |
|
502 | 636 |
FactorySticker factory = FactorySticker.getInstance(); |
503 | 637 |
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%NUM_FACES], R); |
504 |
|
|
505 |
float MID = TEXTURE_HEIGHT*0.5f; |
|
506 |
float WID = TEXTURE_HEIGHT*0.1f; |
|
507 |
float HEI = TEXTURE_HEIGHT*(0.47f+Y1); |
|
508 |
canvas.drawLine(left+MID-WID,top+HEI,left+MID+WID,top+HEI,paint); |
|
638 |
canvas.drawCircle(left+(0.5f+cx)*TEXTURE_HEIGHT, top+(0.5f-cy)*TEXTURE_HEIGHT, 0.05f*TEXTURE_HEIGHT, paint); |
|
509 | 639 |
} |
510 |
else if( variant==0 ) |
|
640 |
else if( variant==0 ) // corner
|
|
511 | 641 |
{ |
512 |
float Y = COS54/(2*SIN54); |
|
513 |
float R = 0.09f; |
|
514 |
float S = 0.09f; |
|
515 |
float[] vertices = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y }; |
|
642 |
float R = 0.10f; |
|
643 |
float S = 0.11f; |
|
644 |
float[] vertices = { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f }; |
|
516 | 645 |
|
517 | 646 |
FactorySticker factory = FactorySticker.getInstance(); |
518 | 647 |
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R); |
519 | 648 |
} |
520 |
else |
|
649 |
else // edge
|
|
521 | 650 |
{ |
522 |
float R = 0.07f; |
|
523 |
float S = 0.07f; |
|
524 |
|
|
525 |
float tmp = (numLayers/3.0f)/(numLayers-1); |
|
526 |
float height= tmp*COS18; |
|
527 |
float width = tmp + (variant-1)*tmp*SIN18; |
|
528 |
float D = height/COS18; |
|
529 |
float W = D*SIN18; |
|
530 |
float X1 = height/2; |
|
531 |
float Y1 = width/2; |
|
532 |
float[] vertices = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 }; |
|
651 |
float R = 0.10f; |
|
652 |
float S = 0.10f; |
|
653 |
float[] vertices = { -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f }; |
|
533 | 654 |
|
534 | 655 |
FactorySticker factory = FactorySticker.getInstance(); |
535 | 656 |
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R); |
src/main/java/org/distorted/objects/TwistyMegaminx.java | ||
---|---|---|
286 | 286 |
if( mCornerMeshes[index]==null ) |
287 | 287 |
{ |
288 | 288 |
float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1)); |
289 |
mCornerMeshes[index] = FactoryCubit.getInstance().createMinxCornerMesh(numLayers, width);
|
|
289 |
mCornerMeshes[index] = createCornerMesh(numLayers, width);
|
|
290 | 290 |
} |
291 | 291 |
mesh = mCornerMeshes[index].copy(true); |
292 | 292 |
} |
... | ... | |
418 | 418 |
|
419 | 419 |
if( variant==0 ) |
420 | 420 |
{ |
421 |
float Y = COS54/(2*SIN54); |
|
422 |
R = 0.070f; |
|
423 |
S = 0.08f; |
|
424 |
vertices = new float[] { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y }; |
|
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 }; |
|
425 | 424 |
} |
426 | 425 |
else |
427 | 426 |
{ |
... | ... | |
436 | 435 |
float Y1 = 0.5f*width; |
437 | 436 |
float Y2 = 0.5f*width + W; |
438 | 437 |
|
439 |
R = 0.05f; |
|
440 |
S = 0.06f;
|
|
438 |
R = 0.045f;
|
|
439 |
S = 0.055f;
|
|
441 | 440 |
vertices = new float[] { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 }; |
442 | 441 |
} |
443 | 442 |
else |
... | ... | |
448 | 447 |
float X2 = Z*COS18; |
449 | 448 |
float Y2 = Z*SIN18; |
450 | 449 |
|
451 |
R = 0.10f;
|
|
450 |
R = 0.09f;
|
|
452 | 451 |
S = 0.08f; |
453 | 452 |
vertices = new float[] { -X1,+Y1, -X2,-Y2, 0.0f,-Z, +X2,-Y2, +X1,+Y1 }; |
454 | 453 |
} |
src/main/java/org/distorted/objects/TwistyMinx.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.content.res.Resources; |
23 | 23 |
|
24 |
import org.distorted.helpers.FactoryCubit; |
|
24 | 25 |
import org.distorted.library.main.DistortedEffects; |
25 | 26 |
import org.distorted.library.main.DistortedTexture; |
27 |
import org.distorted.library.mesh.MeshBase; |
|
26 | 28 |
import org.distorted.library.mesh.MeshSquare; |
27 | 29 |
import org.distorted.library.type.Static3D; |
28 | 30 |
import org.distorted.library.type.Static4D; |
29 | 31 |
|
30 | 32 |
import java.util.Random; |
31 | 33 |
|
34 |
import static org.distorted.helpers.FactoryCubit.COS18; |
|
35 |
import static org.distorted.helpers.FactoryCubit.COS_HALFD; |
|
36 |
import static org.distorted.helpers.FactoryCubit.SIN18; |
|
37 |
import static org.distorted.helpers.FactoryCubit.SIN54; |
|
38 |
import static org.distorted.helpers.FactoryCubit.SIN_HALFD; |
|
39 |
|
|
32 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 | 41 |
|
34 | 42 |
abstract class TwistyMinx extends TwistyObject |
... | ... | |
376 | 384 |
return chances; |
377 | 385 |
} |
378 | 386 |
|
387 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
388 |
|
|
389 |
MeshBase createCornerMesh(int numLayers, float width) |
|
390 |
{ |
|
391 |
float A = (2*SQ3/3)*SIN54; |
|
392 |
float B = 0.4f; |
|
393 |
int N = numLayers==3 ? 5 : 3; |
|
394 |
int E = numLayers==3 ? 4 : 1; |
|
395 |
|
|
396 |
double X = width*COS18*SIN_HALFD; |
|
397 |
double Y = width*SIN18; |
|
398 |
double Z = width*COS18*COS_HALFD; |
|
399 |
|
|
400 |
double[][] vertices = new double[][] |
|
401 |
{ |
|
402 |
{ 0.0, 0.0 , 0.0 }, |
|
403 |
{ X, Y , -Z }, |
|
404 |
{ 0.0, 2*Y ,-2*Z }, |
|
405 |
{ -X, Y , -Z }, |
|
406 |
{ 0.0, 0.0-width, 0.0 }, |
|
407 |
{ X, Y-width, -Z }, |
|
408 |
{ 0.0, 2*Y-width,-2*Z }, |
|
409 |
{ -X, Y-width, -Z }, |
|
410 |
}; |
|
411 |
|
|
412 |
int[][] vertIndexes = new int[][] |
|
413 |
{ |
|
414 |
{4,5,1,0}, |
|
415 |
{7,4,0,3}, |
|
416 |
{0,1,2,3}, |
|
417 |
{4,5,6,7}, |
|
418 |
{6,5,1,2}, |
|
419 |
{7,6,2,3} |
|
420 |
}; |
|
421 |
|
|
422 |
float[][] bands = new float[][] |
|
423 |
{ |
|
424 |
{0.04f,34,0.3f,0.2f, N, 1, 1}, |
|
425 |
{0.00f, 0,0.0f,0.0f, 2, 1, E} |
|
426 |
}; |
|
427 |
int[] bandIndexes = new int[] { 0,0,0,1,1,1}; |
|
428 |
float[][] corners = new float[][] { {0.04f,0.10f} }; |
|
429 |
int[] cornerIndexes = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 }; |
|
430 |
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} }; |
|
431 |
int[] centerIndexes = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 }; |
|
432 |
|
|
433 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
434 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
435 |
|
|
436 |
return factory.createRoundedSolid(vertices, vertIndexes, |
|
437 |
bands, bandIndexes, |
|
438 |
corners, cornerIndexes, |
|
439 |
centers, centerIndexes, |
|
440 |
getNumCubitFaces() ); |
|
441 |
} |
|
442 |
|
|
379 | 443 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
380 | 444 |
// PUBLIC API |
381 | 445 |
|
Also available in: Unified diff
New cubit engine: convert Kiliminx & some Megaminx.