Revision b3d28a81
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/examples/meshfile/FactoryCubit.java | ||
---|---|---|
47 | 47 |
private static final float REX_D = 0.2f; |
48 | 48 |
private static final int REX_N = 5; |
49 | 49 |
|
50 |
static final float MINX_C0 = (SQ5-1)/4; |
|
51 |
static final float MINX_C1 = (SQ5+1)/4; // sin(54 deg)
|
|
52 |
static final float MINX_C3 = (float)(Math.sqrt(10-2*SQ5)/4); // cos(54 deg)
|
|
53 |
static final float MINX_C4 = (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
|
|
54 |
static final float MINX_C5 = (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
|
|
50 |
static final float MINX_C0 = (SQ5-1)/4;
|
|
51 |
static final float SIN54 = (SQ5+1)/4; // sin(54 deg)
|
|
52 |
static final float COS54 = (float)(Math.sqrt(10-2*SQ5)/4); // cos(54 deg)
|
|
53 |
static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
|
|
54 |
static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
|
|
55 | 55 |
|
56 | 56 |
private static final Static1D RADIUS = new Static1D(1); |
57 | 57 |
|
... | ... | |
734 | 734 |
|
735 | 735 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
736 | 736 |
|
737 |
MeshBase createFacesMinxCorner()
|
|
737 |
MeshBase createFacesKilominxCorner()
|
|
738 | 738 |
{ |
739 | 739 |
MeshBase[] meshes = new MeshPolygon[6]; |
740 | 740 |
|
741 | 741 |
float X1= (SQ5+1)/8; |
742 | 742 |
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4); |
743 | 743 |
float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8); |
744 |
float H = 0.5f*MINX_C1/MINX_C3;
|
|
745 |
float X2= H*MINX_C5;
|
|
746 |
float Y3= H/(2*MINX_C4);
|
|
747 |
float Y4= H*(1/(2*MINX_C4) - MINX_C4);
|
|
744 |
float H = 0.5f* SIN54 / COS54;
|
|
745 |
float X2= H*SIN_HALFD;
|
|
746 |
float Y3= H/(2*COS_HALFD);
|
|
747 |
float Y4= H*(1/(2*COS_HALFD) - COS_HALFD);
|
|
748 | 748 |
|
749 | 749 |
float[] vertices0 = { -X1, Y2, 0, -Y1, X1, Y2, 0, Y1 }; |
750 | 750 |
float[] bands0 = computeBands(0.03f,39,0.3f,0.2f,5); |
... | ... | |
767 | 767 |
return new MeshJoined(meshes); |
768 | 768 |
} |
769 | 769 |
|
770 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
771 |
|
|
772 |
MeshBase createFacesMegaminxCorner() |
|
773 |
{ |
|
774 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
775 |
|
|
776 |
float Y = COS54/(2*SIN54); |
|
777 |
|
|
778 |
float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y }; |
|
779 |
float[] bands0 = computeBands(0.04f,34,0.3f,0.2f,5); |
|
780 |
float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2); |
|
781 |
|
|
782 |
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1); |
|
783 |
meshes[0].setEffectAssociation(0, 1,0); |
|
784 |
meshes[1] = meshes[0].copy(true); |
|
785 |
meshes[1].setEffectAssociation(0, 2,0); |
|
786 |
meshes[2] = meshes[0].copy(true); |
|
787 |
meshes[2].setEffectAssociation(0, 4,0); |
|
788 |
meshes[3] = new MeshPolygon(vertices0, bands1, 1, 4); |
|
789 |
meshes[3].setEffectAssociation(0, 8,0); |
|
790 |
meshes[4] = meshes[3].copy(true); |
|
791 |
meshes[4].setEffectAssociation(0,16,0); |
|
792 |
meshes[5] = meshes[3].copy(true); |
|
793 |
meshes[5].setEffectAssociation(0,32,0); |
|
794 |
|
|
795 |
return new MeshJoined(meshes); |
|
796 |
} |
|
797 |
|
|
770 | 798 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
771 | 799 |
// EFFECTS |
772 | 800 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1266 | 1294 |
|
1267 | 1295 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1268 | 1296 |
|
1269 |
VertexEffect[] createVertexEffectsMinxCorner()
|
|
1297 |
VertexEffect[] createVertexEffectsKilominxCorner()
|
|
1270 | 1298 |
{ |
1271 | 1299 |
VertexEffect[] effect = new VertexEffect[9]; |
1272 | 1300 |
|
1273 |
float H = 0.5f*(MINX_C1/MINX_C3);
|
|
1301 |
float H = 0.5f*(SIN54 / COS54);
|
|
1274 | 1302 |
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4); |
1275 |
float Y2= H/(2*MINX_C4);
|
|
1303 |
float Y2= H/(2*COS_HALFD);
|
|
1276 | 1304 |
float A = (float)(Math.acos(-SQ5/5)*180/Math.PI); // dihedral angle of a dedecahedron in degrees |
1277 | 1305 |
float sin18 = MINX_C0; |
1278 | 1306 |
float cos18 = (float)(Math.sqrt(1-MINX_C0*MINX_C0)); |
1279 |
float LEN = (float)Math.sqrt(H*H/(MINX_C4*MINX_C4) + 0.25f);
|
|
1307 |
float LEN = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f);
|
|
1280 | 1308 |
|
1281 | 1309 |
Static3D axisZ = new Static3D(0.0f , 0.0f , 1.0f); |
1282 | 1310 |
Static3D axisY = new Static3D(0.0f , 1.0f , 0.0f); |
1283 | 1311 |
Static3D axisA = new Static3D(-sin18, cos18, 0.0f); |
1284 |
Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H*MINX_C5/(MINX_C4*LEN));
|
|
1312 |
Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H*SIN_HALFD/(COS_HALFD*LEN));
|
|
1285 | 1313 |
|
1286 | 1314 |
Static3D move1 = new Static3D(0,-Y1,0); |
1287 | 1315 |
Static3D move2 = new Static3D(0,-Y2,0); |
... | ... | |
1317 | 1345 |
return effect; |
1318 | 1346 |
} |
1319 | 1347 |
|
1348 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1349 |
|
|
1350 |
VertexEffect[] createVertexEffectsMegaminxCorner() |
|
1351 |
{ |
|
1352 |
VertexEffect[] effect = new VertexEffect[9]; |
|
1353 |
|
|
1354 |
float Y = COS54/(2*SIN54); |
|
1355 |
float A = (float)(Math.acos(-SQ5/5)*180/Math.PI); // dihedral angle of a dedecahedron in degrees |
|
1356 |
|
|
1357 |
float sinA = (2*SIN54*SIN54-1)/COS54; |
|
1358 |
float cosA = (float)Math.sqrt(1-sinA*sinA); |
|
1359 |
float LEN = 0.5f/SIN54; |
|
1360 |
|
|
1361 |
Static3D axisA = new Static3D( SIN54, COS54, 0.0f); |
|
1362 |
Static3D axisB = new Static3D(-SIN54, COS54, 0.0f); |
|
1363 |
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f); |
|
1364 |
|
|
1365 |
Static3D centerU = new Static3D( 0.0f, Y, 0.0f); |
|
1366 |
Static3D centerD = new Static3D( 0.0f,-Y, 0.0f); |
|
1367 |
|
|
1368 |
Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN ); |
|
1369 |
Static3D move2= new Static3D(0.0f, Y , 0.0f ); |
|
1370 |
|
|
1371 |
Static1D angleD = new Static1D(A); |
|
1372 |
Static1D angleE = new Static1D(360-A); |
|
1373 |
Static1D angleF = new Static1D( (float)((180/Math.PI)*Math.asin(sinA) - 90) ); |
|
1374 |
|
|
1375 |
effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) ); |
|
1376 |
effect[1] = new VertexEffectRotate(angleE, axisA, centerU); |
|
1377 |
effect[2] = new VertexEffectRotate(angleD, axisB, centerU); |
|
1378 |
effect[3] = new VertexEffectMove(move1); |
|
1379 |
effect[4] = new VertexEffectRotate(angleE, axisA, centerD); |
|
1380 |
effect[5] = new VertexEffectRotate(angleD, axisB, centerD); |
|
1381 |
effect[6] = new VertexEffectRotate(angleF, axisX, centerD); |
|
1382 |
effect[7] = new VertexEffectMove(move2); |
|
1383 |
effect[8] = new VertexEffectScale(SIN54); |
|
1384 |
|
|
1385 |
effect[0].setMeshAssociation( 3,-1); // meshes 0,1 |
|
1386 |
effect[1].setMeshAssociation( 16,-1); // mesh 4 |
|
1387 |
effect[2].setMeshAssociation( 32,-1); // mesh 5 |
|
1388 |
effect[3].setMeshAssociation( 56,-1); // meshes 3,4,5 |
|
1389 |
effect[4].setMeshAssociation( 1,-1); // mesh 0 |
|
1390 |
effect[5].setMeshAssociation( 2,-1); // mesh 1 |
|
1391 |
|
|
1392 |
return effect; |
|
1393 |
} |
|
1394 |
|
|
1320 | 1395 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1321 | 1396 |
// OBJECTS |
1322 | 1397 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1667 | 1742 |
|
1668 | 1743 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1669 | 1744 |
|
1670 |
MeshBase createMinxCornerMesh()
|
|
1745 |
MeshBase createKilominxCornerMesh()
|
|
1671 | 1746 |
{ |
1672 |
MeshBase mesh = createFacesMinxCorner();
|
|
1673 |
VertexEffect[] effects = createVertexEffectsMinxCorner();
|
|
1747 |
MeshBase mesh = createFacesKilominxCorner();
|
|
1748 |
VertexEffect[] effects = createVertexEffectsKilominxCorner();
|
|
1674 | 1749 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
1675 | 1750 |
|
1676 |
float A = (2*SQ3/3)*MINX_C1;
|
|
1751 |
float A = (2*SQ3/3)* SIN54;
|
|
1677 | 1752 |
float B = 0.4f; |
1678 |
float X = MINX_C5*MINX_C1*MINX_C3;
|
|
1679 |
float Y = MINX_C1*MINX_C1 - 0.5f;
|
|
1680 |
float Z = MINX_C4*MINX_C1*MINX_C3;
|
|
1753 |
float X = SIN_HALFD* SIN54 * COS54;
|
|
1754 |
float Y = SIN54 * SIN54 - 0.5f;
|
|
1755 |
float Z = COS_HALFD* SIN54 * COS54;
|
|
1681 | 1756 |
|
1682 | 1757 |
Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B); |
1683 | 1758 |
|
... | ... | |
1691 | 1766 |
|
1692 | 1767 |
//mesh.mergeEffComponents(); |
1693 | 1768 |
|
1769 |
return mesh; |
|
1770 |
} |
|
1771 |
|
|
1772 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1773 |
|
|
1774 |
MeshBase createMegaminxCornerMesh() |
|
1775 |
{ |
|
1776 |
MeshBase mesh = createFacesMegaminxCorner(); |
|
1777 |
VertexEffect[] effects = createVertexEffectsMegaminxCorner(); |
|
1778 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1779 |
|
|
1780 |
float A = (2*SQ3/3)* SIN54; |
|
1781 |
float B = 0.4f; |
|
1782 |
float X = SIN_HALFD* SIN54 * COS54; |
|
1783 |
float Y = SIN54 * SIN54 - 0.5f; |
|
1784 |
float Z = COS_HALFD* SIN54 * COS54; |
|
1785 |
|
|
1786 |
Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B); |
|
1787 |
|
|
1788 |
Static3D[] vertices = new Static3D[4]; |
|
1789 |
vertices[0] = new Static3D( 0.0f, 0.0f, 0.0f); |
|
1790 |
vertices[1] = new Static3D( 0.0f,-0.5f, 0.0f); |
|
1791 |
vertices[2] = new Static3D(-X , Y ,-Z ); |
|
1792 |
vertices[3] = new Static3D(+X , Y ,-Z ); |
|
1793 |
|
|
1794 |
roundCorners(mesh,center,vertices,0.04f,0.10f); |
|
1795 |
|
|
1796 |
//mesh.mergeEffComponents(); |
|
1797 |
|
|
1694 | 1798 |
return mesh; |
1695 | 1799 |
} |
1696 | 1800 |
} |
Also available in: Unified diff
Beginnings of Megaminx & Gigaminx