Project

General

Profile

« Previous | Next » 

Revision 16f34a98

Added by Leszek Koltunski about 3 years ago

Progress with any size Kilominx.

View differences:

src/main/java/org/distorted/objects/FactoryCubit.java
708 708

  
709 709
///////////////////////////////////////////////////////////////////////////////////////////////////
710 710

  
711
  MeshBase createFacesMegaminxCorner(int numLayers)
711
  MeshBase createFacesMinxCorner(int numLayers)
712 712
    {
713 713
    MeshBase[] meshes = new MeshPolygon[6];
714 714

  
......
740 740
    return new MeshJoined(meshes);
741 741
    }
742 742

  
743
///////////////////////////////////////////////////////////////////////////////////////////////////
744

  
745
  MeshBase createFacesKilominxEdge(int numLayers, float width, float height)
746
    {
747
     MeshBase[] meshes = new MeshPolygon[6];
748

  
749
    float D = height/COS18;
750
    float W = D*SIN18;
751
    float X1 = height/2;
752
    float Y1 = width/2;
753
    float Y2 = (width+W)/2;
754
    float X3 = D*SIN54;
755
    float Y3 = D*COS54;
756
    float X4 = height*SIN_HALFD;
757
    float Y4 = height*COS_HALFD;
758

  
759
    float[] vertices0 = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 };
760
    float[] vertices1 = { -X1,-Y2, X1, -Y2, X1, Y2+W,-X1, Y2 };
761
    float[] vertices2 = { -X3, 0.0f, 0.0f, -Y3, X3, 0.0f, 0.0f, Y3 };
762
    float[] vertices3 = { -X4, 0.0f, 0.0f, -Y4, X4, 0.0f, 0.0f, Y4 };
763

  
764
    int numBands0 = numLayers<=5 ? 5 : 3;
765
    int numBands1 = numLayers<=5 ? 3 : 2;
766
    float h       = numLayers<=5 ? 0.03f : 0.03f;
767

  
768
    float[] bands0 = computeBands(h    ,34,0.2f,0.2f,numBands0);
769
    float[] bands1 = computeBands(0.01f,34,0.3f,0.2f,numBands1);
770

  
771
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
772
    meshes[0].setEffectAssociation(0, 1,0);
773
    meshes[1] = meshes[0].copy(true);
774
    meshes[1].setEffectAssociation(0, 2,0);
775
    meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
776
    meshes[2].setEffectAssociation(0, 4,0);
777
    meshes[3] = meshes[2].copy(true);
778
    meshes[3].setEffectAssociation(0, 8,0);
779
    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 2);
780
    meshes[4].setEffectAssociation(0,16,0);
781
    meshes[5] = new MeshPolygon(vertices3, bands1, 1, 2);
782
    meshes[5].setEffectAssociation(0,32,0);
783

  
784
    return new MeshJoined(meshes);
785
    }
786

  
743 787
///////////////////////////////////////////////////////////////////////////////////////////////////
744 788

  
745 789
  MeshBase createFacesMegaminxEdge(int numLayers, float width, float height)
......
1409 1453

  
1410 1454
///////////////////////////////////////////////////////////////////////////////////////////////////
1411 1455

  
1412
  VertexEffect[] createVertexEffectsMegaminxCorner(int numLayers)
1456
  VertexEffect[] createVertexEffectsMinxCorner(float width)
1413 1457
    {
1414 1458
    VertexEffect[] effect = new VertexEffect[9];
1415 1459

  
......
1418 1462
    float sinA = (2*SIN54*SIN54-1)/COS54;
1419 1463
    float cosA = (float)Math.sqrt(1-sinA*sinA);
1420 1464
    float LEN  = 0.5f/SIN54;
1421
    float scale= (numLayers/3.0f)*(0.5f-MEGA_D)/(LEN*0.5f*(numLayers-1));
1465
    float scale= width/LEN;
1422 1466

  
1423 1467
    Static3D axisA = new Static3D( SIN54, COS54, 0.0f);
1424 1468
    Static3D axisB = new Static3D(-SIN54, COS54, 0.0f);
......
1454 1498
    return effect;
1455 1499
    }
1456 1500

  
1501
///////////////////////////////////////////////////////////////////////////////////////////////////
1502

  
1503
  VertexEffect[] createVertexEffectsKilominxEdge(float width, float height, boolean left)
1504
    {
1505
    VertexEffect[] effect = new VertexEffect[11 + (left ? 0:1)];
1506

  
1507
    float D = height/COS18;
1508
    float W = D*SIN18;
1509
    float X1 = height/2;
1510
    float Y1 = width/2;
1511
    float Y2 = (width+W)/2;
1512
    float Y3 = D*COS54;
1513
    float Y4 = height*COS_HALFD;
1514
    float Z = 2*height*COS_HALFD;
1515
    float alpha = 90-DIHEDRAL1/2;
1516

  
1517
    Static1D angle1 = new Static1D(alpha);
1518
    Static1D angle2 = new Static1D(180-alpha);
1519
    Static1D angle3 = new Static1D(DIHEDRAL2);
1520
    Static1D angle4 = new Static1D(90);
1521

  
1522
    Static3D move1 = new Static3D(+X1,-Y1,0);
1523
    Static3D move2 = new Static3D(-X1,-Y2+W,-Z);
1524
    Static3D move3 = new Static3D(0,+Y3,0);
1525
    Static3D move4 = new Static3D(0,-Y4-width,0);
1526
    Static3D scale = new Static3D(+1,+1,-1);
1527

  
1528
    Static3D axisXplus = new Static3D(+1, 0, 0);
1529
    Static3D axisYplus = new Static3D( 0,+1, 0);
1530

  
1531
    Static3D center1= new Static3D( 0, 0, 0);
1532
    Static3D center2= new Static3D( 0, 0,-Z);
1533
    Static3D center3= new Static3D( 0,-width, 0);
1534

  
1535
    effect[ 0] = new VertexEffectMove(move1);
1536
    effect[ 1] = new VertexEffectMove(move2);
1537
    effect[ 2] = new VertexEffectMove(move3);
1538
    effect[ 3] = new VertexEffectMove(move4);
1539
    effect[ 4] = new VertexEffectScale(scale);
1540
    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
1541
    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
1542
    effect[ 7] = new VertexEffectRotate(angle1, axisYplus , center2);
1543
    effect[ 8] = new VertexEffectRotate(angle2, axisYplus , center2);
1544
    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center1);
1545
    effect[10] = new VertexEffectRotate(angle4, axisXplus , center3);
1546

  
1547
    if( !left )
1548
      {
1549
      Static3D scale1 = new Static3D(+1,-1,+1);
1550
      effect[11] = new VertexEffectScale(scale1);
1551
      }
1552

  
1553
    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
1554
    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
1555
    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
1556
    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
1557
    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
1558
    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
1559
    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
1560
    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
1561
    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
1562
    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
1563
    effect[10].setMeshAssociation(32,-1);  // mesh 5
1564

  
1565
    return effect;
1566
    }
1567

  
1457 1568
///////////////////////////////////////////////////////////////////////////////////////////////////
1458 1569

  
1459 1570
  VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
......
1964 2075
///////////////////////////////////////////////////////////////////////////////////////////////////
1965 2076
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
1966 2077
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
1967
// TODO
1968 2078

  
1969
  MeshBase createKilominxEdgeMesh(int numLayers, float width, float height)
2079
  MeshBase createKilominxEdgeMesh(int numLayers, float width, float height, boolean left)
1970 2080
    {
1971
    MeshBase mesh = createFacesMegaminxEdge(numLayers,width,height);
1972
    VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height);
2081
    MeshBase mesh = createFacesKilominxEdge(numLayers,width,height);
2082
    VertexEffect[] effects = createVertexEffectsKilominxEdge(width,height,left);
1973 2083
    for( VertexEffect effect : effects ) mesh.apply(effect);
1974 2084

  
2085
// round...
2086

  
1975 2087
    mesh.mergeEffComponents();
1976 2088

  
1977 2089
    return mesh;
......
1979 2091

  
1980 2092
///////////////////////////////////////////////////////////////////////////////////////////////////
1981 2093

  
1982
  MeshBase createMinxCornerMesh(ObjectList object, int numLayers)
2094
  MeshBase createMinxCornerMesh(int numLayers, float width)
1983 2095
    {
1984
    MeshBase mesh = createFacesMegaminxCorner(numLayers);
1985
    VertexEffect[] effects = createVertexEffectsMegaminxCorner(numLayers);
2096
    MeshBase mesh = createFacesMinxCorner(numLayers);
2097
    VertexEffect[] effects = createVertexEffectsMinxCorner(width);
1986 2098
    for( VertexEffect effect : effects ) mesh.apply(effect);
1987 2099

  
1988 2100
    float A = (2*SQ3/3)* SIN54;
1989 2101
    float B = 0.4f;
2102
/*
1990 2103
    float X = SIN_HALFD* SIN54 * COS54;
1991 2104
    float Y = SIN54 * SIN54 - 0.5f;
1992 2105
    float Z = COS_HALFD* SIN54 * COS54;
1993
    float S = 2*SIN54*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
1994

  
2106
    float S = 2*width;
2107
*/
1995 2108
    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
1996

  
1997
    Static3D[] vertices = new Static3D[4];
2109
    Static3D[] vertices = new Static3D[1];
1998 2110
    vertices[0] = new Static3D( 0.0f, 0.0f  , 0.0f);
2111
/*
1999 2112
    vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f);
2000 2113
    vertices[2] = new Static3D(-X*S , Y*S   ,-Z*S );
2001 2114
    vertices[3] = new Static3D(+X*S , Y*S   ,-Z*S );
2002

  
2115
*/
2003 2116
    roundCorners(mesh,center,vertices,0.04f,0.10f);
2004 2117

  
2005 2118
    mesh.mergeEffComponents();

Also available in: Unified diff