Project

General

Profile

« Previous | Next » 

Revision 5e06e92f

Added by Leszek Koltunski about 3 years ago

New cubit engine: convert Kiliminx & some Megaminx.

View differences:

src/main/java/org/distorted/helpers/FactoryCubit.java
41 41
public class FactoryCubit
42 42
  {
43 43
  private static final float SQ2 = (float)Math.sqrt(2);
44
  private static final float SQ3 = (float)Math.sqrt(3);
45 44
  private static final float SQ5 = (float)Math.sqrt(5);
46 45

  
47 46
  private static final Static1D RADIUS = new Static1D(1);
......
65 64
  public static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
66 65
  public static final float DIHEDRAL1= (float)(Math.acos(-SQ5/5)*180/Math.PI);
67 66
  public static final float DIHEDRAL2= (float)((180/Math.PI)*Math.asin((2*SIN54*SIN54-1)/COS54) - 90);
68
  public static final float MINX_SC  = 0.5f;
69

  
70 67

  
71 68
  private static final double[] mBuffer = new double[3];
72 69
  private static final double[] mQuat1  = new double[4];
......
391 388
    return new MeshJoined(meshes);
392 389
    }
393 390

  
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395

  
396
  MeshBase createFacesKilominxCenter()
397
    {
398
    MeshBase[] meshes = new MeshPolygon[6];
399

  
400
    float X1= 0.5f*SIN54;
401
    float Y1= 0.5f*SIN_HALFD;
402
    float Y2= Y1 - 0.5f*COS54;
403
    float H = 0.5f* SIN54 /COS54  ;
404
    float X2= MINX_SC*H* SIN_HALFD;
405
    float Y3= MINX_SC*H/(2*COS_HALFD);
406
    float Y4= MINX_SC*H*(1/(2*COS_HALFD) - COS_HALFD);
407

  
408
    float[] vertices0 = { -X1, Y2, 0, -Y1, X1, Y2, 0, Y1 };
409
    float[] bands0 = computeBands(0.04f,17,0.3f,0.2f,5);
410
    float[] vertices1 = { -X2, Y4, 0, -Y3, X2, Y4, 0, Y3 };
411
    float[] bands1 = computeBands(0.00f, 0,0.25f,0.5f,2);
412

  
413
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
414
    meshes[0].setEffectAssociation(0, 1,0);
415
    meshes[1] = meshes[0].copy(true);
416
    meshes[1].setEffectAssociation(0, 2,0);
417
    meshes[2] = meshes[0].copy(true);
418
    meshes[2].setEffectAssociation(0, 4,0);
419
    meshes[3] = new MeshPolygon(vertices1, bands1, 0, 0);
420
    meshes[3].setEffectAssociation(0, 8,0);
421
    meshes[4] = meshes[3].copy(true);
422
    meshes[4].setEffectAssociation(0,16,0);
423
    meshes[5] = meshes[3].copy(true);
424
    meshes[5].setEffectAssociation(0,32,0);
425

  
426
    return new MeshJoined(meshes);
427
    }
428

  
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

  
431
  MeshBase createFacesMinxCorner(int numLayers)
432
    {
433
    MeshBase[] meshes = new MeshPolygon[6];
434

  
435
    float Y = COS54/(2*SIN54);
436

  
437
    float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y };
438

  
439
    int numBands0 = numLayers==3 ? 5 : 3;
440
    int numBands1 = numLayers==3 ? 2 : 2;
441
    float h       = numLayers==3 ? 0.04f : 0.03f;
442
    int   e       = numLayers==3 ? 4 : 1;
443

  
444
    float[] bands0 = computeBands(h    ,34,0.3f,0.2f, numBands0);
445
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f, numBands1);
446

  
447
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
448
    meshes[0].setEffectAssociation(0, 1,0);
449
    meshes[1] = meshes[0].copy(true);
450
    meshes[1].setEffectAssociation(0, 2,0);
451
    meshes[2] = meshes[0].copy(true);
452
    meshes[2].setEffectAssociation(0, 4,0);
453
    meshes[3] = new MeshPolygon(vertices0, bands1, 1, e);
454
    meshes[3].setEffectAssociation(0, 8,0);
455
    meshes[4] = meshes[3].copy(true);
456
    meshes[4].setEffectAssociation(0,16,0);
457
    meshes[5] = meshes[3].copy(true);
458
    meshes[5].setEffectAssociation(0,32,0);
459

  
460
    return new MeshJoined(meshes);
461
    }
462

  
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

  
465
  MeshBase createFacesKilominxEdge(int numLayers, float width, float height)
466
    {
467
     MeshBase[] meshes = new MeshPolygon[6];
468

  
469
    float D = height/COS18;
470
    float W = D*SIN18;
471
    float X1 = height/2;
472
    float Y1 = width/2;
473
    float Y2 = (width+W)/2;
474
    float X3 = D*SIN54;
475
    float Y3 = D*COS54;
476
    float X4 = height*SIN_HALFD;
477
    float Y4 = height*COS_HALFD;
478

  
479
    float[] vertices0 = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 };
480
    float[] vertices1 = { -X1,-Y2, X1, -Y2, X1, Y2+W,-X1, Y2 };
481
    float[] vertices2 = { -X3, 0.0f, 0.0f, -Y3, X3, 0.0f, 0.0f, Y3 };
482
    float[] vertices3 = { -X4, 0.0f, 0.0f, -Y4, X4, 0.0f, 0.0f, Y4 };
483

  
484
    int numBands0 = numLayers<=5 ? 5 : 3;
485
    int numBands1 = numLayers<=5 ? 3 : 2;
486
    float h       = numLayers<=5 ? 0.03f : 0.03f;
487

  
488
    float[] bands0 = computeBands(h    ,34,0.2f,0.2f,numBands0);
489
    float[] bands1 = computeBands(0.01f,34,0.3f,0.2f,numBands1);
490

  
491
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
492
    meshes[0].setEffectAssociation(0, 1,0);
493
    meshes[1] = meshes[0].copy(true);
494
    meshes[1].setEffectAssociation(0, 2,0);
495
    meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
496
    meshes[2].setEffectAssociation(0, 4,0);
497
    meshes[3] = meshes[2].copy(true);
498
    meshes[3].setEffectAssociation(0, 8,0);
499
    meshes[4] = new MeshPolygon(vertices2, bands1, 0, 0);
500
    meshes[4].setEffectAssociation(0,16,0);
501
    meshes[5] = new MeshPolygon(vertices3, bands1, 0, 0);
502
    meshes[5].setEffectAssociation(0,32,0);
503

  
504
    return new MeshJoined(meshes);
505
    }
506

  
507 391
///////////////////////////////////////////////////////////////////////////////////////////////////
508 392

  
509 393
  MeshBase createFacesMegaminxEdge(int numLayers, float width, float height)
......
718 602
    return effect;
719 603
    }
720 604

  
721
///////////////////////////////////////////////////////////////////////////////////////////////////
722

  
723
  VertexEffect[] createVertexEffectsKilominxCenter(float width)
724
    {
725
    VertexEffect[] effect = new VertexEffect[11];
726

  
727
    float H = 0.5f*(SIN54/COS54);
728
    float Y1= 0.5f*SIN_HALFD;
729
    float Y2= H/(2*COS_HALFD);
730
    float cos18 = (float)(Math.sqrt(1- SIN18 * SIN18));
731
    float LEN   = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f);
732

  
733
    Static3D axisZ = new Static3D(0.0f  , 0.0f , 1.0f);
734
    Static3D axisY = new Static3D(0.0f  , 1.0f , 0.0f);
735
    Static3D axisA = new Static3D(-SIN18, cos18, 0.0f);
736
    Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H* SIN_HALFD /(COS_HALFD*LEN));
737

  
738
    Static3D move1 = new Static3D(0,-Y1,0);
739
    Static3D move2 = new Static3D(0,-Y2,0);
740
    Static3D move3 = new Static3D(0.5f*cos18,0.5f*SIN18,0);
741
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
742

  
743
    Static1D angle1 = new Static1D(54);
744
    Static1D angle2 = new Static1D(DIHEDRAL1/2+18);
745
    Static1D angle3 = new Static1D(90);
746
    Static1D angle4 = new Static1D(120);
747
    Static1D angle5 = new Static1D(240);
748
    Static1D angle6 = new Static1D(90-DIHEDRAL1/2);
749

  
750
    effect[0] = new VertexEffectMove(move1);
751
    effect[1] = new VertexEffectScale(1/MINX_SC);
752
    effect[2] = new VertexEffectMove(move2);
753
    effect[3] = new VertexEffectRotate(angle1, axisZ, center);
754
    effect[4] = new VertexEffectRotate(angle2, axisZ, center);
755
    effect[5] = new VertexEffectRotate(angle3, axisA, center);
756
    effect[6] = new VertexEffectMove(move3);
757
    effect[7] = new VertexEffectRotate(angle4, axisC, center);
758
    effect[8] = new VertexEffectRotate(angle5, axisC, center);
759
    effect[9] = new VertexEffectRotate(angle6, axisY, center);
760
    effect[10]= new VertexEffectScale(width/0.5f);
761

  
762
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
763
    effect[1].setMeshAssociation(56,-1);  // meshes 3,4,5
764
    effect[2].setMeshAssociation(56,-1);  // meshes 3,4,5
765
    effect[3].setMeshAssociation( 7,-1);  // meshes 0,1,2
766
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
767
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
768
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
769
    effect[7].setMeshAssociation(18,-1);  // meshes 1,4
770
    effect[8].setMeshAssociation(36,-1);  // meshes 2,5
771

  
772
    return effect;
773
    }
774

  
775
///////////////////////////////////////////////////////////////////////////////////////////////////
776

  
777
  VertexEffect[] createVertexEffectsMinxCorner(float width)
778
    {
779
    VertexEffect[] effect = new VertexEffect[9];
780

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

  
783
    float sinA = (2*SIN54*SIN54-1)/COS54;
784
    float cosA = (float)Math.sqrt(1-sinA*sinA);
785
    float LEN  = 0.5f/SIN54;
786
    float scale= width/LEN;
787

  
788
    Static3D axisA = new Static3D( SIN54, COS54, 0.0f);
789
    Static3D axisB = new Static3D(-SIN54, COS54, 0.0f);
790
    Static3D axisX = new Static3D(  1.0f,  0.0f, 0.0f);
791

  
792
    Static3D centerU = new Static3D( 0.0f, Y, 0.0f);
793
    Static3D centerD = new Static3D( 0.0f,-Y, 0.0f);
794

  
795
    Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN );
796
    Static3D move2= new Static3D(0.0f, Y , 0.0f );
797

  
798
    Static1D angleD = new Static1D(DIHEDRAL1);
799
    Static1D angleE = new Static1D(360-DIHEDRAL1);
800
    Static1D angleF = new Static1D(DIHEDRAL2);
801

  
802
    effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) );
803
    effect[1] = new VertexEffectRotate(angleE, axisA, centerU);
804
    effect[2] = new VertexEffectRotate(angleD, axisB, centerU);
805
    effect[3] = new VertexEffectMove(move1);
806
    effect[4] = new VertexEffectRotate(angleE, axisA, centerD);
807
    effect[5] = new VertexEffectRotate(angleD, axisB, centerD);
808
    effect[6] = new VertexEffectRotate(angleF, axisX, centerD);
809
    effect[7] = new VertexEffectMove(move2);
810
    effect[8] = new VertexEffectScale(scale);
811

  
812
    effect[0].setMeshAssociation(  3,-1);  // meshes 0,1
813
    effect[1].setMeshAssociation( 16,-1);  // mesh 4
814
    effect[2].setMeshAssociation( 32,-1);  // mesh 5
815
    effect[3].setMeshAssociation( 56,-1);  // meshes 3,4,5
816
    effect[4].setMeshAssociation(  1,-1);  // mesh 0
817
    effect[5].setMeshAssociation(  2,-1);  // mesh 1
818

  
819
    return effect;
820
    }
821

  
822
///////////////////////////////////////////////////////////////////////////////////////////////////
823

  
824
  VertexEffect[] createVertexEffectsKilominxEdge(float width, float height, boolean left)
825
    {
826
    VertexEffect[] effect = new VertexEffect[11 + (left ? 0:1)];
827

  
828
    float D = height/COS18;
829
    float W = D*SIN18;
830
    float X1 = height/2;
831
    float Y1 = width/2;
832
    float Y2 = (width+W)/2;
833
    float Y3 = D*COS54;
834
    float Y4 = height*COS_HALFD;
835
    float Z = 2*height*COS_HALFD;
836
    float alpha = 90-DIHEDRAL1/2;
837

  
838
    Static1D angle1 = new Static1D(alpha);
839
    Static1D angle2 = new Static1D(180-alpha);
840
    Static1D angle3 = new Static1D(DIHEDRAL2);
841
    Static1D angle4 = new Static1D(90);
842

  
843
    Static3D move1 = new Static3D(+X1,-Y1,0);
844
    Static3D move2 = new Static3D(-X1,-Y2+W,-Z);
845
    Static3D move3 = new Static3D(0,+Y3,0);
846
    Static3D move4 = new Static3D(0,-Y4-width,0);
847
    Static3D scale = new Static3D(+1,+1,-1);
848

  
849
    Static3D axisXplus = new Static3D(+1, 0, 0);
850
    Static3D axisYplus = new Static3D( 0,+1, 0);
851

  
852
    Static3D center1= new Static3D( 0, 0, 0);
853
    Static3D center2= new Static3D( 0, 0,-Z);
854
    Static3D center3= new Static3D( 0,-width, 0);
855

  
856
    effect[ 0] = new VertexEffectMove(move1);
857
    effect[ 1] = new VertexEffectMove(move2);
858
    effect[ 2] = new VertexEffectMove(move3);
859
    effect[ 3] = new VertexEffectMove(move4);
860
    effect[ 4] = new VertexEffectScale(scale);
861
    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
862
    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
863
    effect[ 7] = new VertexEffectRotate(angle1, axisYplus , center2);
864
    effect[ 8] = new VertexEffectRotate(angle2, axisYplus , center2);
865
    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center1);
866
    effect[10] = new VertexEffectRotate(angle4, axisXplus , center3);
867

  
868
    if( !left )
869
      {
870
      Static3D scale1 = new Static3D(+1,-1,+1);
871
      effect[11] = new VertexEffectScale(scale1);
872
      }
873

  
874
    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
875
    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
876
    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
877
    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
878
    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
879
    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
880
    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
881
    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
882
    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
883
    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
884
    effect[10].setMeshAssociation(32,-1);  // mesh 5
885

  
886
    return effect;
887
    }
888

  
889 605
///////////////////////////////////////////////////////////////////////////////////////////////////
890 606

  
891 607
  VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
......
1114 830
    return mesh;
1115 831
    }
1116 832

  
1117
///////////////////////////////////////////////////////////////////////////////////////////////////
1118

  
1119
  public MeshBase createKilominxCenterMesh(float width)
1120
    {
1121
    MeshBase mesh = createFacesKilominxCenter();
1122
    VertexEffect[] effects = createVertexEffectsKilominxCenter(width);
1123
    for( VertexEffect effect : effects ) mesh.apply(effect);
1124

  
1125
    float A = (2*SQ3/3)* SIN54;
1126
    float B = 0.4f;
1127
    float X = SIN_HALFD * SIN54 *COS54  ;
1128
    float Y = SIN54 * SIN54 - 0.5f;
1129
    float Z = COS_HALFD* SIN54 *COS54  ;
1130

  
1131
    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
1132

  
1133
    Static3D[] vertices = new Static3D[4];
1134
    vertices[0] = new Static3D( 0.0f, 0.0f, 0.0f);
1135
    vertices[1] = new Static3D( 0.0f,-0.5f, 0.0f);
1136
    vertices[2] = new Static3D(-X   , Y   ,-Z   );
1137
    vertices[3] = new Static3D(+X   , Y   ,-Z   );
1138

  
1139
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1140

  
1141
    mesh.mergeEffComponents();
1142

  
1143
    return mesh;
1144
    }
1145

  
1146
///////////////////////////////////////////////////////////////////////////////////////////////////
1147
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
1148
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
1149

  
1150
  public MeshBase createKilominxEdgeMesh(int numLayers, float width, float height, boolean left)
1151
    {
1152
    MeshBase mesh = createFacesKilominxEdge(numLayers,width,height);
1153
    VertexEffect[] effects = createVertexEffectsKilominxEdge(width,height,left);
1154
    for( VertexEffect effect : effects ) mesh.apply(effect);
1155

  
1156
// round...
1157

  
1158
    mesh.mergeEffComponents();
1159

  
1160
    return mesh;
1161
    }
1162

  
1163
///////////////////////////////////////////////////////////////////////////////////////////////////
1164

  
1165
  public MeshBase createMinxCornerMesh(int numLayers, float width)
1166
    {
1167
    MeshBase mesh = createFacesMinxCorner(numLayers);
1168
    VertexEffect[] effects = createVertexEffectsMinxCorner(width);
1169
    for( VertexEffect effect : effects ) mesh.apply(effect);
1170

  
1171
    float A = (2*SQ3/3)* SIN54;
1172
    float B = 0.4f;
1173
/*
1174
    float X = SIN_HALFD* SIN54 * COS54;
1175
    float Y = SIN54 * SIN54 - 0.5f;
1176
    float Z = COS_HALFD* SIN54 * COS54;
1177
    float S = 2*width;
1178
*/
1179
    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
1180
    Static3D[] vertices = new Static3D[1];
1181
    vertices[0] = new Static3D( 0.0f, 0.0f  , 0.0f);
1182
/*
1183
    vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f);
1184
    vertices[2] = new Static3D(-X*S , Y*S   ,-Z*S );
1185
    vertices[3] = new Static3D(+X*S , Y*S   ,-Z*S );
1186
*/
1187
    roundCorners(mesh,center,vertices,0.04f,0.10f);
1188

  
1189
    mesh.mergeEffComponents();
1190

  
1191
    return mesh;
1192
    }
1193

  
1194 833
///////////////////////////////////////////////////////////////////////////////////////////////////
1195 834
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
1196 835
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
......
1278 917
    return mesh;
1279 918
    }
1280 919

  
1281

  
1282

  
1283

  
1284 920
///////////////////////////////////////////////////////////////////////////////////////////////////
1285 921

  
1286 922
  private boolean areColinear(double[][] vertices, int index1, int index2, int index3)
......
1899 1535

  
1900 1536
      mNewFaceTransf.add(newT);
1901 1537
      }
1538

  
1539
    printStickerCoords();
1902 1540
    }
1903 1541

  
1904 1542
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff