Revision a64e07d0
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objects/FactoryCubit.java | ||
---|---|---|
31 | 31 |
import org.distorted.library.type.Static3D; |
32 | 32 |
import org.distorted.library.type.Static4D; |
33 | 33 |
|
34 |
import static org.distorted.objects.TwistyMegaminx.MEGA_D; |
|
35 |
|
|
34 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
35 | 37 |
|
36 | 38 |
class FactoryCubit |
... | ... | |
48 | 50 |
static final float SIN54 = (SQ5+1)/4; // sin(54 deg) |
49 | 51 |
static final float COS54 = (float)(Math.sqrt(10-2*SQ5)/4); // cos(54 deg) |
50 | 52 |
|
51 |
static final float MINX_C0 = (SQ5-1)/4; |
|
52 |
static final float MINX_C4 = (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
|
|
53 |
static final float MINX_C5 = (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
|
|
54 |
static final float MINX_SC = 0.5f; |
|
53 |
static final float MINX_C0 = (SQ5-1)/4;
|
|
54 |
static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
|
|
55 |
static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
|
|
56 |
static final float MINX_SC = 0.5f;
|
|
55 | 57 |
|
56 | 58 |
private static final int IVY_N = 8; |
57 | 59 |
|
... | ... | |
686 | 688 |
|
687 | 689 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
688 | 690 |
|
689 |
MeshBase createFacesMinxCorner()
|
|
691 |
MeshBase createFacesKilominxCorner()
|
|
690 | 692 |
{ |
691 | 693 |
MeshBase[] meshes = new MeshPolygon[6]; |
692 | 694 |
|
... | ... | |
694 | 696 |
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4); |
695 | 697 |
float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8); |
696 | 698 |
float H = 0.5f* SIN54 /COS54 ; |
697 |
float X2= MINX_SC*H*MINX_C5;
|
|
698 |
float Y3= MINX_SC*H/(2*MINX_C4);
|
|
699 |
float Y4= MINX_SC*H*(1/(2*MINX_C4) - MINX_C4);
|
|
699 |
float X2= MINX_SC*H* SIN_HALFD;
|
|
700 |
float Y3= MINX_SC*H/(2*COS_HALFD);
|
|
701 |
float Y4= MINX_SC*H*(1/(2*COS_HALFD) - COS_HALFD);
|
|
700 | 702 |
|
701 | 703 |
float[] vertices0 = { -X1, Y2, 0, -Y1, X1, Y2, 0, Y1 }; |
702 | 704 |
float[] bands0 = computeBands(0.04f,17,0.3f,0.2f,5); |
... | ... | |
719 | 721 |
return new MeshJoined(meshes); |
720 | 722 |
} |
721 | 723 |
|
724 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
725 |
|
|
726 |
MeshBase createFacesMegaminxCorner() |
|
727 |
{ |
|
728 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
729 |
|
|
730 |
float Y = COS54/(2*SIN54); |
|
731 |
|
|
732 |
float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y }; |
|
733 |
float[] bands0 = computeBands(0.04f,34,0.3f,0.2f,5); |
|
734 |
float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2); |
|
735 |
|
|
736 |
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1); |
|
737 |
meshes[0].setEffectAssociation(0, 1,0); |
|
738 |
meshes[1] = meshes[0].copy(true); |
|
739 |
meshes[1].setEffectAssociation(0, 2,0); |
|
740 |
meshes[2] = meshes[0].copy(true); |
|
741 |
meshes[2].setEffectAssociation(0, 4,0); |
|
742 |
meshes[3] = new MeshPolygon(vertices0, bands1, 1, 4); |
|
743 |
meshes[3].setEffectAssociation(0, 8,0); |
|
744 |
meshes[4] = meshes[3].copy(true); |
|
745 |
meshes[4].setEffectAssociation(0,16,0); |
|
746 |
meshes[5] = meshes[3].copy(true); |
|
747 |
meshes[5].setEffectAssociation(0,32,0); |
|
748 |
|
|
749 |
return new MeshJoined(meshes); |
|
750 |
} |
|
751 |
|
|
722 | 752 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
723 | 753 |
// EFFECTS |
724 | 754 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1218 | 1248 |
|
1219 | 1249 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1220 | 1250 |
|
1221 |
VertexEffect[] createVertexEffectsMinxCorner()
|
|
1251 |
VertexEffect[] createVertexEffectsKilominxCorner()
|
|
1222 | 1252 |
{ |
1223 | 1253 |
VertexEffect[] effect = new VertexEffect[10]; |
1224 | 1254 |
|
1225 | 1255 |
float H = 0.5f*(SIN54 /COS54 ); |
1226 | 1256 |
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4); |
1227 |
float Y2= H/(2*MINX_C4);
|
|
1257 |
float Y2= H/(2*COS_HALFD);
|
|
1228 | 1258 |
float A = (float)(Math.acos(-SQ5/5)*180/Math.PI); // dihedral angle of a dedecahedron in degrees |
1229 | 1259 |
float sin18 = MINX_C0; |
1230 | 1260 |
float cos18 = (float)(Math.sqrt(1-MINX_C0*MINX_C0)); |
1231 |
float LEN = (float)Math.sqrt(H*H/(MINX_C4*MINX_C4) + 0.25f);
|
|
1261 |
float LEN = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f);
|
|
1232 | 1262 |
|
1233 | 1263 |
Static3D axisZ = new Static3D(0.0f , 0.0f , 1.0f); |
1234 | 1264 |
Static3D axisY = new Static3D(0.0f , 1.0f , 0.0f); |
1235 | 1265 |
Static3D axisA = new Static3D(-sin18, cos18, 0.0f); |
1236 |
Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H*MINX_C5/(MINX_C4*LEN));
|
|
1266 |
Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H* SIN_HALFD /(COS_HALFD*LEN));
|
|
1237 | 1267 |
|
1238 | 1268 |
Static3D move1 = new Static3D(0,-Y1,0); |
1239 | 1269 |
Static3D move2 = new Static3D(0,-Y2,0); |
... | ... | |
1271 | 1301 |
return effect; |
1272 | 1302 |
} |
1273 | 1303 |
|
1304 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1305 |
|
|
1306 |
VertexEffect[] createVertexEffectsMegaminxCorner(int numLayers) |
|
1307 |
{ |
|
1308 |
VertexEffect[] effect = new VertexEffect[9]; |
|
1309 |
|
|
1310 |
float Y = COS54/(2*SIN54); |
|
1311 |
float A = (float)(Math.acos(-SQ5/5)*180/Math.PI); // dihedral angle of a dedecahedron in degrees |
|
1312 |
|
|
1313 |
float sinA = (2*SIN54*SIN54-1)/COS54; |
|
1314 |
float cosA = (float)Math.sqrt(1-sinA*sinA); |
|
1315 |
float LEN = 0.5f/SIN54; |
|
1316 |
float scale= 2*SIN54*(0.5f-MEGA_D)/(0.5f*(numLayers-1)); |
|
1317 |
|
|
1318 |
Static3D axisA = new Static3D( SIN54, COS54, 0.0f); |
|
1319 |
Static3D axisB = new Static3D(-SIN54, COS54, 0.0f); |
|
1320 |
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f); |
|
1321 |
|
|
1322 |
Static3D centerU = new Static3D( 0.0f, Y, 0.0f); |
|
1323 |
Static3D centerD = new Static3D( 0.0f,-Y, 0.0f); |
|
1324 |
|
|
1325 |
Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN ); |
|
1326 |
Static3D move2= new Static3D(0.0f, Y , 0.0f ); |
|
1327 |
|
|
1328 |
Static1D angleD = new Static1D(A); |
|
1329 |
Static1D angleE = new Static1D(360-A); |
|
1330 |
Static1D angleF = new Static1D( (float)((180/Math.PI)*Math.asin(sinA) - 90) ); |
|
1331 |
|
|
1332 |
effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) ); |
|
1333 |
effect[1] = new VertexEffectRotate(angleE, axisA, centerU); |
|
1334 |
effect[2] = new VertexEffectRotate(angleD, axisB, centerU); |
|
1335 |
effect[3] = new VertexEffectMove(move1); |
|
1336 |
effect[4] = new VertexEffectRotate(angleE, axisA, centerD); |
|
1337 |
effect[5] = new VertexEffectRotate(angleD, axisB, centerD); |
|
1338 |
effect[6] = new VertexEffectRotate(angleF, axisX, centerD); |
|
1339 |
effect[7] = new VertexEffectMove(move2); |
|
1340 |
effect[8] = new VertexEffectScale(scale); |
|
1341 |
|
|
1342 |
effect[0].setMeshAssociation( 3,-1); // meshes 0,1 |
|
1343 |
effect[1].setMeshAssociation( 16,-1); // mesh 4 |
|
1344 |
effect[2].setMeshAssociation( 32,-1); // mesh 5 |
|
1345 |
effect[3].setMeshAssociation( 56,-1); // meshes 3,4,5 |
|
1346 |
effect[4].setMeshAssociation( 1,-1); // mesh 0 |
|
1347 |
effect[5].setMeshAssociation( 2,-1); // mesh 1 |
|
1348 |
|
|
1349 |
return effect; |
|
1350 |
} |
|
1351 |
|
|
1274 | 1352 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1275 | 1353 |
// OBJECTS |
1276 | 1354 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1626 | 1704 |
|
1627 | 1705 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1628 | 1706 |
|
1629 |
MeshBase createMinxCornerMesh()
|
|
1707 |
MeshBase createKilominxCornerMesh()
|
|
1630 | 1708 |
{ |
1631 |
MeshBase mesh = createFacesMinxCorner();
|
|
1632 |
VertexEffect[] effects = createVertexEffectsMinxCorner();
|
|
1709 |
MeshBase mesh = createFacesKilominxCorner();
|
|
1710 |
VertexEffect[] effects = createVertexEffectsKilominxCorner();
|
|
1633 | 1711 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
1634 | 1712 |
|
1635 | 1713 |
float A = (2*SQ3/3)* SIN54; |
1636 | 1714 |
float B = 0.4f; |
1637 |
float X = MINX_C5* SIN54 *COS54 ;
|
|
1715 |
float X = SIN_HALFD * SIN54 *COS54 ;
|
|
1638 | 1716 |
float Y = SIN54 * SIN54 - 0.5f; |
1639 |
float Z = MINX_C4* SIN54 *COS54 ;
|
|
1717 |
float Z = COS_HALFD* SIN54 *COS54 ;
|
|
1640 | 1718 |
|
1641 | 1719 |
Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B); |
1642 | 1720 |
|
... | ... | |
1650 | 1728 |
|
1651 | 1729 |
mesh.mergeEffComponents(); |
1652 | 1730 |
|
1731 |
return mesh; |
|
1732 |
} |
|
1733 |
|
|
1734 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1735 |
|
|
1736 |
MeshBase createMegaminxCornerMesh(int numLayers) |
|
1737 |
{ |
|
1738 |
MeshBase mesh = createFacesMegaminxCorner(); |
|
1739 |
VertexEffect[] effects = createVertexEffectsMegaminxCorner(numLayers); |
|
1740 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1741 |
|
|
1742 |
float A = (2*SQ3/3)* SIN54; |
|
1743 |
float B = 0.4f; |
|
1744 |
float X = SIN_HALFD* SIN54 * COS54; |
|
1745 |
float Y = SIN54 * SIN54 - 0.5f; |
|
1746 |
float Z = COS_HALFD* SIN54 * COS54; |
|
1747 |
float S = 2*SIN54*(0.5f-MEGA_D)/(0.5f*(numLayers-1)); |
|
1748 |
|
|
1749 |
Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B); |
|
1750 |
|
|
1751 |
Static3D[] vertices = new Static3D[4]; |
|
1752 |
vertices[0] = new Static3D( 0.0f, 0.0f , 0.0f); |
|
1753 |
vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f); |
|
1754 |
vertices[2] = new Static3D(-X*S , Y*S ,-Z*S ); |
|
1755 |
vertices[3] = new Static3D(+X*S , Y*S ,-Z*S ); |
|
1756 |
|
|
1757 |
roundCorners(mesh,center,vertices,0.04f,0.10f); |
|
1758 |
|
|
1759 |
mesh.mergeEffComponents(); |
|
1760 |
|
|
1653 | 1761 |
return mesh; |
1654 | 1762 |
} |
1655 | 1763 |
} |
Also available in: Unified diff
Beginnings of Megaminx & Gigaminx