Project

General

Profile

« Previous | Next » 

Revision 6d020cb6

Added by Leszek Koltunski almost 4 years ago

Progress with Megaminx.

View differences:

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 SIN54    = (SQ5+1)/4;                         // sin(54 deg)
52
  static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);    // cos(54 deg)
50
  static final float SIN18    = (SQ5-1)/4;
51
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
52
  static final float SIN54    = (SQ5+1)/4;
53
  static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
53 54
  static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
54 55
  static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
55 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
  private static final Static1D RADIUS = new Static1D(1);
57 61

  
58 62
  private static FactoryCubit mThis;
......
795 799
    return new MeshJoined(meshes);
796 800
    }
797 801

  
802
///////////////////////////////////////////////////////////////////////////////////////////////////
803

  
804
  MeshBase createFacesMegaminxEdge(float width, float height)
805
    {
806
    MeshBase[] meshes = new MeshPolygon[6];
807

  
808
    float D = height/COS18;
809
    float W = D*SIN18;
810

  
811
    float Y1 = 0.5f*width;
812
    float Y2 = 0.5f*width + W;
813
    float Y3 = 0.5f*width + 2*W;
814
    float X2 = D*SIN54;
815
    float X1 = 0.5f*height;
816
    float Y4 = D*COS54;
817

  
818
    float[] vertices0 = { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 };
819
    float[] vertices1 = { -X1, Y3, -X1, -Y3, X1, -Y2, X1, Y2 };
820
    float[] vertices2 = { -X2, 0.0f, 0.0f, -Y4, X2, 0.0f, 0.0f, Y4 };
821

  
822
    float[] bands0 = computeBands(0.04f,34,  X1,0.2f,5);
823
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2);
824

  
825
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
826
    meshes[0].setEffectAssociation(0, 1,0);
827
    meshes[1] = meshes[0].copy(true);
828
    meshes[1].setEffectAssociation(0, 2,0);
829
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 4);
830
    meshes[2].setEffectAssociation(0, 4,0);
831
    meshes[3] = meshes[2].copy(true);
832
    meshes[3].setEffectAssociation(0, 8,0);
833
    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 4);
834
    meshes[4].setEffectAssociation(0,16,0);
835
    meshes[5] = meshes[4].copy(true);
836
    meshes[5].setEffectAssociation(0,32,0);
837

  
838
    return new MeshJoined(meshes);
839
    }
840

  
798 841
///////////////////////////////////////////////////////////////////////////////////////////////////
799 842
// EFFECTS
800 843
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1302 1345
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
1303 1346
    float Y2= H/(2*COS_HALFD);
1304 1347
    float A = (float)(Math.acos(-SQ5/5)*180/Math.PI);  // dihedral angle of a dedecahedron in degrees
1305
    float sin18 = MINX_C0;
1306
    float cos18 = (float)(Math.sqrt(1-MINX_C0*MINX_C0));
1348
    float sin18 = SIN18;
1349
    float cos18 = (float)(Math.sqrt(1- SIN18 * SIN18));
1307 1350
    float LEN   = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f);
1308 1351

  
1309 1352
    Static3D axisZ = new Static3D(0.0f  , 0.0f , 1.0f);
......
1352 1395
    VertexEffect[] effect = new VertexEffect[9];
1353 1396

  
1354 1397
    float Y = COS54/(2*SIN54);
1355
    float A = (float)(Math.acos(-SQ5/5)*180/Math.PI);  // dihedral angle of a dedecahedron in degrees
1356 1398

  
1357 1399
    float sinA = (2*SIN54*SIN54-1)/COS54;
1358 1400
    float cosA = (float)Math.sqrt(1-sinA*sinA);
......
1368 1410
    Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN );
1369 1411
    Static3D move2= new Static3D(0.0f, Y , 0.0f );
1370 1412

  
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) );
1413
    Static1D angleD = new Static1D(DIHEDRAL1);
1414
    Static1D angleE = new Static1D(360-DIHEDRAL1);
1415
    Static1D angleF = new Static1D(DIHEDRAL2);
1374 1416

  
1375 1417
    effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) );
1376 1418
    effect[1] = new VertexEffectRotate(angleE, axisA, centerU);
......
1392 1434
    return effect;
1393 1435
    }
1394 1436

  
1437
///////////////////////////////////////////////////////////////////////////////////////////////////
1438

  
1439
  VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
1440
    {
1441
    VertexEffect[] effect = new VertexEffect[11];
1442

  
1443
    float X = 0.5f*height;
1444
    float Y = height*(COS54/COS18) + width*0.5f;
1445
    float Z = 2*height*COS_HALFD;
1446

  
1447
    float alpha = 90-DIHEDRAL1/2;
1448
    float beta  = DIHEDRAL2;
1449

  
1450
    Static1D angle1 = new Static1D(alpha);
1451
    Static1D angle2 = new Static1D(180-alpha);
1452
    Static1D angle3 = new Static1D(beta);
1453

  
1454
    Static3D move1 = new Static3D(X,0,0);
1455
    Static3D move2 = new Static3D(X,0,-Z);
1456
    Static3D move3 = new Static3D(0,+Y,0);
1457
    Static3D move4 = new Static3D(0,-Y,0);
1458
    Static3D scale = new Static3D(+1,+1,-1);
1459

  
1460
    Static3D axisXplus = new Static3D(+1, 0, 0);
1461
    Static3D axisXminus= new Static3D(-1, 0, 0);
1462
    Static3D axisYplus = new Static3D( 0,+1, 0);
1463
    Static3D axisYminus= new Static3D( 0,-1, 0);
1464

  
1465
    Static3D center1= new Static3D( 0, 0, 0);
1466
    Static3D center2= new Static3D( 0, 0,-Z);
1467
    Static3D center3= new Static3D( 0,+width*0.5f, 0);
1468
    Static3D center4= new Static3D( 0,-width*0.5f, 0);
1469

  
1470
    effect[ 0] = new VertexEffectMove(move1);
1471
    effect[ 1] = new VertexEffectMove(move2);
1472
    effect[ 2] = new VertexEffectMove(move3);
1473
    effect[ 3] = new VertexEffectMove(move4);
1474
    effect[ 4] = new VertexEffectScale(scale);
1475
    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
1476
    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
1477
    effect[ 7] = new VertexEffectRotate(angle1, axisYminus, center2);
1478
    effect[ 8] = new VertexEffectRotate(angle2, axisYminus, center2);
1479
    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center3);
1480
    effect[10] = new VertexEffectRotate(angle3, axisXminus, center4);
1481

  
1482
    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
1483
    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
1484
    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
1485
    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
1486
    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
1487
    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
1488
    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
1489
    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
1490
    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
1491
    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
1492
    effect[10].setMeshAssociation(32,-1);  // mesh 5
1493

  
1494
    return effect;
1495
    }
1496

  
1395 1497
///////////////////////////////////////////////////////////////////////////////////////////////////
1396 1498
// OBJECTS
1397 1499
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1795 1897

  
1796 1898
    //mesh.mergeEffComponents();
1797 1899

  
1900
    return mesh;
1901
    }
1902

  
1903
///////////////////////////////////////////////////////////////////////////////////////////////////
1904

  
1905
  MeshBase createMegaminxEdgeMesh(float width, float height)
1906
    {
1907
    MeshBase mesh = createFacesMegaminxEdge(width,height);
1908
    VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height);
1909
    for( VertexEffect effect : effects ) mesh.apply(effect);
1910

  
1911
    //mesh.mergeEffComponents();
1912

  
1798 1913
    return mesh;
1799 1914
    }
1800 1915
  }
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
328 328
    private void createMesh()
329 329
      {
330 330
      FactoryCubit factory = FactoryCubit.getInstance();
331
      mMesh = factory.createMegaminxCornerMesh();
331
      mMesh = factory.createMegaminxEdgeMesh(0.2f,0.5f);
332 332

  
333 333
      //mMesh = createStaticMesh();
334 334

  

Also available in: Unified diff