Revision db608887
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objects/FactoryCubit.java | ||
---|---|---|
47 | 47 |
private static final float SQ5 = (float)Math.sqrt(5); |
48 | 48 |
private static final float SQ6 = (float)Math.sqrt(6); |
49 | 49 |
|
50 |
static final float SIN54 = (SQ5+1)/4; // sin(54 deg)
|
|
51 |
static final float COS54 = (float)(Math.sqrt(10-2*SQ5)/4); // cos(54 deg)
|
|
52 |
|
|
53 |
static final float MINX_C0 = (SQ5-1)/4;
|
|
50 |
static final float SIN54 = (SQ5+1)/4;
|
|
51 |
static final float COS54 = (float)(Math.sqrt(10-2*SQ5)/4);
|
|
52 |
static final float SIN18 = (SQ5-1)/4; |
|
53 |
static final float COS18 = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
|
|
54 | 54 |
static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle) |
55 | 55 |
static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle) |
56 |
|
|
57 |
static final float DIHEDRAL1= (float)(Math.acos(-SQ5/5)*180/Math.PI); |
|
58 |
static final float DIHEDRAL2= (float)((180/Math.PI)*Math.asin((2*SIN54*SIN54-1)/COS54) - 90); |
|
59 |
|
|
56 | 60 |
static final float MINX_SC = 0.5f; |
57 | 61 |
|
58 | 62 |
private static final int IVY_N = 8; |
... | ... | |
749 | 753 |
return new MeshJoined(meshes); |
750 | 754 |
} |
751 | 755 |
|
756 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
757 |
|
|
758 |
MeshBase createFacesMegaminxEdge(float width, float height) |
|
759 |
{ |
|
760 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
761 |
|
|
762 |
float D = height/COS18; |
|
763 |
float W = D*SIN18; |
|
764 |
|
|
765 |
float Y1 = 0.5f*width; |
|
766 |
float Y2 = 0.5f*width + W; |
|
767 |
float Y3 = 0.5f*width + 2*W; |
|
768 |
float X2 = D*SIN54; |
|
769 |
float X1 = 0.5f*height; |
|
770 |
float Y4 = D*COS54; |
|
771 |
|
|
772 |
float[] vertices0 = { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 }; |
|
773 |
float[] vertices1 = { -X1, Y3, -X1, -Y3, X1, -Y2, X1, Y2 }; |
|
774 |
float[] vertices2 = { -X2, 0.0f, 0.0f, -Y4, X2, 0.0f, 0.0f, Y4 }; |
|
775 |
|
|
776 |
float[] bands0 = computeBands(0.04f,34, X1,0.2f,5); |
|
777 |
float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2); |
|
778 |
|
|
779 |
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1); |
|
780 |
meshes[0].setEffectAssociation(0, 1,0); |
|
781 |
meshes[1] = meshes[0].copy(true); |
|
782 |
meshes[1].setEffectAssociation(0, 2,0); |
|
783 |
meshes[2] = new MeshPolygon(vertices1, bands1, 1, 4); |
|
784 |
meshes[2].setEffectAssociation(0, 4,0); |
|
785 |
meshes[3] = meshes[2].copy(true); |
|
786 |
meshes[3].setEffectAssociation(0, 8,0); |
|
787 |
meshes[4] = new MeshPolygon(vertices2, bands1, 1, 4); |
|
788 |
meshes[4].setEffectAssociation(0,16,0); |
|
789 |
meshes[5] = meshes[4].copy(true); |
|
790 |
meshes[5].setEffectAssociation(0,32,0); |
|
791 |
|
|
792 |
return new MeshJoined(meshes); |
|
793 |
} |
|
794 |
|
|
752 | 795 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
753 | 796 |
// EFFECTS |
754 | 797 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1256 | 1299 |
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4); |
1257 | 1300 |
float Y2= H/(2*COS_HALFD); |
1258 | 1301 |
float A = (float)(Math.acos(-SQ5/5)*180/Math.PI); // dihedral angle of a dedecahedron in degrees |
1259 |
float sin18 = MINX_C0;
|
|
1260 |
float cos18 = (float)(Math.sqrt(1-MINX_C0*MINX_C0));
|
|
1302 |
float sin18 = SIN18;
|
|
1303 |
float cos18 = (float)(Math.sqrt(1- SIN18 * SIN18));
|
|
1261 | 1304 |
float LEN = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f); |
1262 | 1305 |
|
1263 | 1306 |
Static3D axisZ = new Static3D(0.0f , 0.0f , 1.0f); |
... | ... | |
1308 | 1351 |
VertexEffect[] effect = new VertexEffect[9]; |
1309 | 1352 |
|
1310 | 1353 |
float Y = COS54/(2*SIN54); |
1311 |
float A = (float)(Math.acos(-SQ5/5)*180/Math.PI); // dihedral angle of a dedecahedron in degrees |
|
1312 | 1354 |
|
1313 | 1355 |
float sinA = (2*SIN54*SIN54-1)/COS54; |
1314 | 1356 |
float cosA = (float)Math.sqrt(1-sinA*sinA); |
... | ... | |
1325 | 1367 |
Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN ); |
1326 | 1368 |
Static3D move2= new Static3D(0.0f, Y , 0.0f ); |
1327 | 1369 |
|
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) );
|
|
1370 |
Static1D angleD = new Static1D(DIHEDRAL1);
|
|
1371 |
Static1D angleE = new Static1D(360-DIHEDRAL1);
|
|
1372 |
Static1D angleF = new Static1D(DIHEDRAL2);
|
|
1331 | 1373 |
|
1332 | 1374 |
effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) ); |
1333 | 1375 |
effect[1] = new VertexEffectRotate(angleE, axisA, centerU); |
... | ... | |
1349 | 1391 |
return effect; |
1350 | 1392 |
} |
1351 | 1393 |
|
1394 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1395 |
|
|
1396 |
VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height) |
|
1397 |
{ |
|
1398 |
VertexEffect[] effect = new VertexEffect[11]; |
|
1399 |
|
|
1400 |
float X = 0.5f*height; |
|
1401 |
float Y = height*(COS54/COS18) + width*0.5f; |
|
1402 |
float Z = 2*height*COS_HALFD; |
|
1403 |
|
|
1404 |
float alpha = 90-DIHEDRAL1/2; |
|
1405 |
float beta = DIHEDRAL2; |
|
1406 |
|
|
1407 |
Static1D angle1 = new Static1D(alpha); |
|
1408 |
Static1D angle2 = new Static1D(180-alpha); |
|
1409 |
Static1D angle3 = new Static1D(beta); |
|
1410 |
|
|
1411 |
Static3D move1 = new Static3D(X,0,0); |
|
1412 |
Static3D move2 = new Static3D(X,0,-Z); |
|
1413 |
Static3D move3 = new Static3D(0,+Y,0); |
|
1414 |
Static3D move4 = new Static3D(0,-Y,0); |
|
1415 |
Static3D scale = new Static3D(+1,+1,-1); |
|
1416 |
|
|
1417 |
Static3D axisXplus = new Static3D(+1, 0, 0); |
|
1418 |
Static3D axisXminus= new Static3D(-1, 0, 0); |
|
1419 |
Static3D axisYplus = new Static3D( 0,+1, 0); |
|
1420 |
Static3D axisYminus= new Static3D( 0,-1, 0); |
|
1421 |
|
|
1422 |
Static3D center1= new Static3D( 0, 0, 0); |
|
1423 |
Static3D center2= new Static3D( 0, 0,-Z); |
|
1424 |
Static3D center3= new Static3D( 0,+width*0.5f, 0); |
|
1425 |
Static3D center4= new Static3D( 0,-width*0.5f, 0); |
|
1426 |
|
|
1427 |
effect[ 0] = new VertexEffectMove(move1); |
|
1428 |
effect[ 1] = new VertexEffectMove(move2); |
|
1429 |
effect[ 2] = new VertexEffectMove(move3); |
|
1430 |
effect[ 3] = new VertexEffectMove(move4); |
|
1431 |
effect[ 4] = new VertexEffectScale(scale); |
|
1432 |
effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1); |
|
1433 |
effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1); |
|
1434 |
effect[ 7] = new VertexEffectRotate(angle1, axisYminus, center2); |
|
1435 |
effect[ 8] = new VertexEffectRotate(angle2, axisYminus, center2); |
|
1436 |
effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center3); |
|
1437 |
effect[10] = new VertexEffectRotate(angle3, axisXminus, center4); |
|
1438 |
|
|
1439 |
effect[ 0].setMeshAssociation( 3,-1); // meshes 0,1 |
|
1440 |
effect[ 1].setMeshAssociation(12,-1); // meshes 2,3 |
|
1441 |
effect[ 2].setMeshAssociation(16,-1); // mesh 4 |
|
1442 |
effect[ 3].setMeshAssociation(32,-1); // mesh 5 |
|
1443 |
effect[ 4].setMeshAssociation( 2,-1); // mesh 1 |
|
1444 |
effect[ 5].setMeshAssociation( 1,-1); // mesh 0 |
|
1445 |
effect[ 6].setMeshAssociation( 2,-1); // mesh 1 |
|
1446 |
effect[ 7].setMeshAssociation( 4,-1); // mesh 2 |
|
1447 |
effect[ 8].setMeshAssociation( 8,-1); // mesh 3 |
|
1448 |
effect[ 9].setMeshAssociation(16,-1); // mesh 4 |
|
1449 |
effect[10].setMeshAssociation(32,-1); // mesh 5 |
|
1450 |
|
|
1451 |
return effect; |
|
1452 |
} |
|
1453 |
|
|
1352 | 1454 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1353 | 1455 |
// OBJECTS |
1354 | 1456 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1765 | 1867 |
// numLayers==3 --> index=0; numLayers=5 --> index=1 ... |
1766 | 1868 |
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc |
1767 | 1869 |
|
1768 |
MeshBase createMegaminxEdgeMesh(int index, int type)
|
|
1870 |
MeshBase createMegaminxEdgeMesh(float width, float height)
|
|
1769 | 1871 |
{ |
1872 |
MeshBase mesh = createFacesMegaminxEdge(width,height); |
|
1873 |
VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height); |
|
1874 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1875 |
|
|
1876 |
mesh.mergeEffComponents(); |
|
1770 | 1877 |
|
1771 |
return createTetraMesh();
|
|
1878 |
return mesh;
|
|
1772 | 1879 |
} |
1773 | 1880 |
} |
Also available in: Unified diff
Progress with Megaminx.