Project

General

Profile

« Previous | Next » 

Revision 54e47d9b

Added by Leszek Koltunski about 3 years ago

Progress with any size Kilominx.

View differences:

src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
46 46
  private static final float IVY_M = 0.35f;
47 47
  private static final float REX_D = 0.2f;
48 48
  private static final int   REX_N = 5;
49
  private static final float MEGA_D = 0.04f;
49 50

  
50 51
  static final float SIN18    = (SQ5-1)/4;
51 52
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
......
773 774

  
774 775
///////////////////////////////////////////////////////////////////////////////////////////////////
775 776

  
776
  MeshBase createFacesMegaminxCorner()
777
  MeshBase createFacesMinxCorner(int numLayers)
777 778
    {
778 779
    MeshBase[] meshes = new MeshPolygon[6];
779 780

  
780 781
    float Y = COS54/(2*SIN54);
781 782

  
782 783
    float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y };
783
    float[] bands0 = computeBands(0.04f,34,0.3f,0.2f,5);
784
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2);
784

  
785
    int numBands0 = numLayers==3 ? 5 : 3;
786
    int numBands1 = numLayers==3 ? 2 : 2;
787
    float h       = numLayers==3 ? 0.04f : 0.03f;
788
    int   e       = numLayers==3 ? 4 : 1;
789

  
790
    float[] bands0 = computeBands(h    ,34,0.3f,0.2f, numBands0);
791
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f, numBands1);
785 792

  
786 793
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
787 794
    meshes[0].setEffectAssociation(0, 1,0);
......
789 796
    meshes[1].setEffectAssociation(0, 2,0);
790 797
    meshes[2] = meshes[0].copy(true);
791 798
    meshes[2].setEffectAssociation(0, 4,0);
792
    meshes[3] = new MeshPolygon(vertices0, bands1, 1, 4);
799
    meshes[3] = new MeshPolygon(vertices0, bands1, 1, e);
793 800
    meshes[3].setEffectAssociation(0, 8,0);
794 801
    meshes[4] = meshes[3].copy(true);
795 802
    meshes[4].setEffectAssociation(0,16,0);
......
799 806
    return new MeshJoined(meshes);
800 807
    }
801 808

  
809
///////////////////////////////////////////////////////////////////////////////////////////////////
810

  
811
  MeshBase createFacesKilominxEdge(int numLayers, float width, float height)
812
    {
813
    MeshBase[] meshes = new MeshPolygon[6];
814

  
815
    float D = height/COS18;
816
    float W = D*SIN18;
817
    float X1 = height/2;
818
    float Y1 = width/2;
819
    float Y2 = (width+W)/2;
820
    float X3 = D*SIN54;
821
    float Y3 = D*COS54;
822
    float X4 = height*SIN_HALFD;
823
    float Y4 = height*COS_HALFD;
824

  
825
    float[] vertices0 = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 };
826
    float[] vertices1 = { -X1,-Y2, X1, -Y2, X1, Y2+W,-X1, Y2 };
827
    float[] vertices2 = { -X3, 0.0f, 0.0f, -Y3, X3, 0.0f, 0.0f, Y3 };
828
    float[] vertices3 = { -X4, 0.0f, 0.0f, -Y4, X4, 0.0f, 0.0f, Y4 };
829

  
830
    int numBands0 = numLayers<=5 ? 5 : 3;
831
    int numBands1 = numLayers<=5 ? 3 : 2;
832
    float h       = numLayers<=5 ? 0.03f : 0.03f;
833

  
834
    float[] bands0 = computeBands(h    ,34,0.2f,0.2f,numBands0);
835
    float[] bands1 = computeBands(0.01f,34,0.3f,0.2f,numBands1);
836

  
837
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
838
    meshes[0].setEffectAssociation(0, 1,0);
839
    meshes[1] = meshes[0].copy(true);
840
    meshes[1].setEffectAssociation(0, 2,0);
841
    meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
842
    meshes[2].setEffectAssociation(0, 4,0);
843
    meshes[3] = meshes[2].copy(true);
844
    meshes[3].setEffectAssociation(0, 8,0);
845
    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 2);
846
    meshes[4].setEffectAssociation(0,16,0);
847
    meshes[5] = new MeshPolygon(vertices3, bands1, 1, 2);
848
    meshes[5].setEffectAssociation(0,32,0);
849

  
850
    return new MeshJoined(meshes);
851
    }
852

  
802 853
///////////////////////////////////////////////////////////////////////////////////////////////////
803 854

  
804 855
  MeshBase createFacesMegaminxEdge(float width, float height)
......
1435 1486

  
1436 1487
///////////////////////////////////////////////////////////////////////////////////////////////////
1437 1488

  
1438
  VertexEffect[] createVertexEffectsMegaminxCorner()
1489
  VertexEffect[] createVertexEffectsMinxCorner(float width)
1439 1490
    {
1440 1491
    VertexEffect[] effect = new VertexEffect[9];
1441 1492

  
......
1444 1495
    float sinA = (2*SIN54*SIN54-1)/COS54;
1445 1496
    float cosA = (float)Math.sqrt(1-sinA*sinA);
1446 1497
    float LEN  = 0.5f/SIN54;
1498
    float scale= width/LEN;
1447 1499

  
1448 1500
    Static3D axisA = new Static3D( SIN54, COS54, 0.0f);
1449 1501
    Static3D axisB = new Static3D(-SIN54, COS54, 0.0f);
......
1467 1519
    effect[5] = new VertexEffectRotate(angleD, axisB, centerD);
1468 1520
    effect[6] = new VertexEffectRotate(angleF, axisX, centerD);
1469 1521
    effect[7] = new VertexEffectMove(move2);
1470
    effect[8] = new VertexEffectScale(SIN54);
1522
    effect[8] = new VertexEffectScale(scale);
1471 1523

  
1472 1524
    effect[0].setMeshAssociation(  3,-1);  // meshes 0,1
1473 1525
    effect[1].setMeshAssociation( 16,-1);  // mesh 4
......
1479 1531
    return effect;
1480 1532
    }
1481 1533

  
1534
///////////////////////////////////////////////////////////////////////////////////////////////////
1535

  
1536
  VertexEffect[] createVertexEffectsKilominxEdge(float width, float height, boolean left)
1537
    {
1538
    VertexEffect[] effect = new VertexEffect[11 + (left ? 0:1)];
1539

  
1540
    float D = height/COS18;
1541
    float W = D*SIN18;
1542
    float X1 = height/2;
1543
    float Y1 = width/2;
1544
    float Y2 = (width+W)/2;
1545
    float Y3 = D*COS54;
1546
    float Y4 = height*COS_HALFD;
1547
    float Z = 2*height*COS_HALFD;
1548
    float alpha = 90-DIHEDRAL1/2;
1549
    float beta  = DIHEDRAL2;
1550

  
1551
    Static1D angle1 = new Static1D(alpha);
1552
    Static1D angle2 = new Static1D(180-alpha);
1553
    Static1D angle3 = new Static1D(beta);
1554
    Static1D angle4 = new Static1D(90);
1555

  
1556
    Static3D move1 = new Static3D(+X1,-Y1,0);
1557
    Static3D move2 = new Static3D(-X1,-Y2+W,-Z);
1558
    Static3D move3 = new Static3D(0,+Y3,0);
1559
    Static3D move4 = new Static3D(0,-Y4-width,0);
1560
    Static3D scale = new Static3D(+1,+1,-1);
1561

  
1562
    Static3D axisXplus = new Static3D(+1, 0, 0);
1563
    Static3D axisYplus = new Static3D( 0,+1, 0);
1564

  
1565
    Static3D center1= new Static3D( 0, 0, 0);
1566
    Static3D center2= new Static3D( 0, 0,-Z);
1567
    Static3D center3= new Static3D( 0,-width, 0);
1568

  
1569
    effect[ 0] = new VertexEffectMove(move1);
1570
    effect[ 1] = new VertexEffectMove(move2);
1571
    effect[ 2] = new VertexEffectMove(move3);
1572
    effect[ 3] = new VertexEffectMove(move4);
1573
    effect[ 4] = new VertexEffectScale(scale);
1574
    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
1575
    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
1576
    effect[ 7] = new VertexEffectRotate(angle1, axisYplus , center2);
1577
    effect[ 8] = new VertexEffectRotate(angle2, axisYplus , center2);
1578
    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center1);
1579
    effect[10] = new VertexEffectRotate(angle4, axisXplus , center3);
1580

  
1581
    if( !left )
1582
      {
1583
      Static3D scale1 = new Static3D(+1,-1,+1);
1584
      effect[11] = new VertexEffectScale(scale1);
1585
      }
1586

  
1587
    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
1588
    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
1589
    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
1590
    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
1591
    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
1592
    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
1593
    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
1594
    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
1595
    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
1596
    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
1597
    effect[10].setMeshAssociation(32,-1);  // mesh 5
1598

  
1599
    return effect;
1600
    }
1601

  
1482 1602
///////////////////////////////////////////////////////////////////////////////////////////////////
1483 1603

  
1484 1604
  VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
......
1967 2087

  
1968 2088
///////////////////////////////////////////////////////////////////////////////////////////////////
1969 2089

  
1970
  MeshBase createMegaminxCornerMesh()
2090
  MeshBase createKilominxEdgeMesh(int numLayers, float width, float height, boolean left)
1971 2091
    {
1972
    MeshBase mesh = createFacesMegaminxCorner();
1973
    VertexEffect[] effects = createVertexEffectsMegaminxCorner();
2092
    MeshBase mesh = createFacesKilominxEdge(numLayers,width,height);
2093
    VertexEffect[] effects = createVertexEffectsKilominxEdge(width,height,left);
1974 2094
    for( VertexEffect effect : effects ) mesh.apply(effect);
1975 2095

  
1976 2096
    float A = (2*SQ3/3)* SIN54;
......
1978 2098
    float X = SIN_HALFD* SIN54 * COS54;
1979 2099
    float Y = SIN54 * SIN54 - 0.5f;
1980 2100
    float Z = COS_HALFD* SIN54 * COS54;
2101
    float S = 2*width;
1981 2102

  
1982 2103
    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
1983

  
1984 2104
    Static3D[] vertices = new Static3D[4];
1985
    vertices[0] = new Static3D( 0.0f, 0.0f, 0.0f);
1986
    vertices[1] = new Static3D( 0.0f,-0.5f, 0.0f);
1987
    vertices[2] = new Static3D(-X   , Y   ,-Z   );
1988
    vertices[3] = new Static3D(+X   , Y   ,-Z   );
2105
    vertices[0] = new Static3D( 0.0f, 0.0f  , 0.0f);
2106
    vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f);
2107
    vertices[2] = new Static3D(-X*S , Y*S   ,-Z*S );
2108
    vertices[3] = new Static3D(+X*S , Y*S   ,-Z*S );
1989 2109

  
1990 2110
    roundCorners(mesh,center,vertices,0.04f,0.10f);
1991 2111

  
......
1994 2114
    return mesh;
1995 2115
    }
1996 2116

  
2117
///////////////////////////////////////////////////////////////////////////////////////////////////
2118

  
2119
  MeshBase createMinxCornerMesh()
2120
    {
2121
    int numLayers = 9;
2122
    float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
2123

  
2124
    MeshBase mesh = createFacesMinxCorner(numLayers);
2125
    VertexEffect[] effects = createVertexEffectsMinxCorner(width);
2126
    for( VertexEffect effect : effects ) mesh.apply(effect);
2127

  
2128
    float A = (2*SQ3/3)* SIN54;
2129
    float B = 0.4f;
2130
    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
2131
    Static3D[] vertices = new Static3D[1];
2132
    vertices[0] = new Static3D( 0.0f, 0.0f  , 0.0f);
2133
    roundCorners(mesh,center,vertices,0.04f,0.10f);
2134

  
2135
    //mesh.mergeEffComponents();
2136

  
2137
    return mesh;
2138
    }
2139

  
1997 2140
///////////////////////////////////////////////////////////////////////////////////////////////////
1998 2141

  
1999 2142
  MeshBase createMegaminxEdgeMesh(float width, float height)

Also available in: Unified diff