Project

General

Profile

« Previous | Next » 

Revision bb11be2a

Added by Leszek Koltunski over 3 years ago

New cubit engine: finish converting Kilominx & 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 SQ5 = (float)Math.sqrt(5);
45

  
46 44
  private static final Static1D RADIUS = new Static1D(1);
47 45
  private static FactoryCubit mThis;
48 46

  
......
55 53
  // REX
56 54
  public static final float REX_D = 0.2f;
57 55

  
58
  // KILO / MEGAMINX
59
  public static final float SIN54    = (SQ5+1)/4;
60
  public static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
61
  public static final float SIN18    = (SQ5-1)/4;
62
  public static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
63
  public static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
64
  public static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
65
  public static final float DIHEDRAL1= (float)(Math.acos(-SQ5/5)*180/Math.PI);
66
  public static final float DIHEDRAL2= (float)((180/Math.PI)*Math.asin((2*SIN54*SIN54-1)/COS54) - 90);
67

  
68 56
  private static final double[] mBuffer = new double[3];
69 57
  private static final double[] mQuat1  = new double[4];
70 58
  private static final double[] mQuat2  = new double[4];
......
388 376
    return new MeshJoined(meshes);
389 377
    }
390 378

  
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

  
393
  MeshBase createFacesMegaminxEdge(int numLayers, float width, float height)
394
    {
395
    MeshBase[] meshes = new MeshPolygon[6];
396

  
397
    float D = height/COS18;
398
    float W = D*SIN18;
399

  
400
    float Y1 = 0.5f*width;
401
    float Y2 = 0.5f*width + W;
402
    float Y3 = 0.5f*width + 2*W;
403
    float X2 = D*SIN54;
404
    float X1 = 0.5f*height;
405
    float Y4 = D*COS54;
406

  
407
    float[] vertices0 = { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 };
408
    float[] vertices1 = { -X1, Y3, -X1, -Y3, X1, -Y2, X1, Y2 };
409
    float[] vertices2 = { -X2, 0.0f, 0.0f, -Y4, X2, 0.0f, 0.0f, Y4 };
410

  
411
    int numBands0 = numLayers==3 ? 5 : 3;
412
    int numBands1 = numLayers==3 ? 2 : 2;
413
    float h       = numLayers==3 ? 0.03f : 0.03f;
414

  
415
    float[] bands0 = computeBands(h    ,34,0.2f,0.2f,numBands0);
416
    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,numBands1);
417

  
418
    meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0);
419
    meshes[0].setEffectAssociation(0, 1,0);
420
    meshes[1] = meshes[0].copy(true);
421
    meshes[1].setEffectAssociation(0, 2,0);
422
    meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
423
    meshes[2].setEffectAssociation(0, 4,0);
424
    meshes[3] = meshes[2].copy(true);
425
    meshes[3].setEffectAssociation(0, 8,0);
426
    meshes[4] = new MeshPolygon(vertices2, bands1, 0, 0);
427
    meshes[4].setEffectAssociation(0,16,0);
428
    meshes[5] = meshes[4].copy(true);
429
    meshes[5].setEffectAssociation(0,32,0);
430

  
431
    return new MeshJoined(meshes);
432
    }
433

  
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

  
436
  MeshBase createFacesMegaminxCenter(int numLayers)
437
    {
438
    MeshBase[] meshes = new MeshPolygon[2];
439

  
440
    float R  = 0.5f;
441
    float X1 = R*COS54;
442
    float Y1 = R*SIN54;
443
    float X2 = R*COS18;
444
    float Y2 = R*SIN18;
445

  
446
    float[] vertices0 = { -X1,+Y1, -X2,-Y2, 0.0f,-R, +X2,-Y2, +X1,+Y1 };
447

  
448
    int numBands0 = numLayers==3 ? 4 : 3;
449
    int numBands1 = numLayers==3 ? 2 : 2;
450
    float h       = numLayers==3 ? 0.04f : 0.04f;
451

  
452
    float[] bands0 = computeBands( h    ,45, R/3,0.2f, numBands0);
453
    float[] bands1 = computeBands( 0.00f,34, R/3,0.2f, numBands1);
454

  
455
    meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0);
456
    meshes[0].setEffectAssociation(0,1,0);
457
    meshes[1] = new MeshPolygon(vertices0, bands1, 0, 0);
458
    meshes[1].setEffectAssociation(0,2,0);
459

  
460
    return new MeshJoined(meshes);
461
    }
462

  
463 379
///////////////////////////////////////////////////////////////////////////////////////////////////
464 380

  
465 381
  private float[] createVertices(int A, int B)
......
602 518
    return effect;
603 519
    }
604 520

  
605
///////////////////////////////////////////////////////////////////////////////////////////////////
606

  
607
  VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
608
    {
609
    VertexEffect[] effect = new VertexEffect[11];
610

  
611
    float X = 0.5f*height;
612
    float Y = height*(COS54/COS18) + width*0.5f;
613
    float Z = 2*height*COS_HALFD;
614

  
615
    float alpha = 90-DIHEDRAL1/2;
616
    float beta  = DIHEDRAL2;
617

  
618
    Static1D angle1 = new Static1D(alpha);
619
    Static1D angle2 = new Static1D(180-alpha);
620
    Static1D angle3 = new Static1D(beta);
621

  
622
    Static3D move1 = new Static3D(X,0,0);
623
    Static3D move2 = new Static3D(X,0,-Z);
624
    Static3D move3 = new Static3D(0,+Y,0);
625
    Static3D move4 = new Static3D(0,-Y,0);
626
    Static3D scale = new Static3D(+1,+1,-1);
627

  
628
    Static3D axisXplus = new Static3D(+1, 0, 0);
629
    Static3D axisXminus= new Static3D(-1, 0, 0);
630
    Static3D axisYplus = new Static3D( 0,+1, 0);
631
    Static3D axisYminus= new Static3D( 0,-1, 0);
632

  
633
    Static3D center1= new Static3D( 0, 0, 0);
634
    Static3D center2= new Static3D( 0, 0,-Z);
635
    Static3D center3= new Static3D( 0,+width*0.5f, 0);
636
    Static3D center4= new Static3D( 0,-width*0.5f, 0);
637

  
638
    effect[ 0] = new VertexEffectMove(move1);
639
    effect[ 1] = new VertexEffectMove(move2);
640
    effect[ 2] = new VertexEffectMove(move3);
641
    effect[ 3] = new VertexEffectMove(move4);
642
    effect[ 4] = new VertexEffectScale(scale);
643
    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
644
    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
645
    effect[ 7] = new VertexEffectRotate(angle1, axisYminus, center2);
646
    effect[ 8] = new VertexEffectRotate(angle2, axisYminus, center2);
647
    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center3);
648
    effect[10] = new VertexEffectRotate(angle3, axisXminus, center4);
649

  
650
    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
651
    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
652
    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
653
    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
654
    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
655
    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
656
    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
657
    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
658
    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
659
    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
660
    effect[10].setMeshAssociation(32,-1);  // mesh 5
661

  
662
    return effect;
663
    }
664

  
665
///////////////////////////////////////////////////////////////////////////////////////////////////
666

  
667
  VertexEffect[] createVertexEffectsMegaminxCenter(float width)
668
    {
669
    VertexEffect[] effect = new VertexEffect[2];
670

  
671
    Static1D angle = new Static1D(DIHEDRAL2);
672
    Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
673
    Static3D center= new Static3D( 0, 0, 0);
674

  
675
    effect[0] = new VertexEffectScale(width/COS54);
676
    effect[1] = new VertexEffectRotate(angle, axisX, center);
677

  
678
    return effect;
679
    }
680

  
681 521
///////////////////////////////////////////////////////////////////////////////////////////////////
682 522

  
683 523
  VertexEffect[] createCuboidEffects(int[] dimensions)
......
830 670
    return mesh;
831 671
    }
832 672

  
833
///////////////////////////////////////////////////////////////////////////////////////////////////
834
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
835
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
836

  
837
  public MeshBase createMegaminxEdgeMesh(int numLayers, float width, float height)
838
    {
839
    MeshBase mesh = createFacesMegaminxEdge(numLayers,width,height);
840
    VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height);
841
    for( VertexEffect effect : effects ) mesh.apply(effect);
842

  
843
    mesh.mergeEffComponents();
844

  
845
    return mesh;
846
    }
847

  
848
///////////////////////////////////////////////////////////////////////////////////////////////////
849

  
850
  public MeshBase createMegaminxCenterMesh(int numLayers, float width)
851
    {
852
    MeshBase mesh = createFacesMegaminxCenter(numLayers);
853
    VertexEffect[] effects = createVertexEffectsMegaminxCenter(width);
854
    for( VertexEffect effect : effects ) mesh.apply(effect);
855

  
856
    mesh.mergeEffComponents();
857
    mesh.addEmptyTexComponent();
858
    mesh.addEmptyTexComponent();
859
    mesh.addEmptyTexComponent();
860
    mesh.addEmptyTexComponent();
861

  
862
    return mesh;
863
    }
864

  
865 673
///////////////////////////////////////////////////////////////////////////////////////////////////
866 674

  
867 675
  public MeshBase createCuboidMesh(int[] dimensions)
......
1535 1343

  
1536 1344
      mNewFaceTransf.add(newT);
1537 1345
      }
1538

  
1539
    printStickerCoords();
1540 1346
    }
1541 1347

  
1542 1348
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/MovementMinx.java
20 20
package org.distorted.objects;
21 21

  
22 22
import org.distorted.library.type.Static3D;
23
import static org.distorted.objects.TwistyKilominx.C1;
24
import static org.distorted.objects.TwistyKilominx.C2;
25
import static org.distorted.objects.TwistyKilominx.LEN;
26
import static org.distorted.helpers.FactoryCubit.SIN54;
27
import static org.distorted.helpers.FactoryCubit.COS54;
23
import static org.distorted.objects.TwistyMinx.C2;
24
import static org.distorted.objects.TwistyMinx.LEN;
25
import static org.distorted.objects.TwistyMinx.SIN54;
26
import static org.distorted.objects.TwistyMinx.COS54;
28 27
import static org.distorted.objects.TwistyObject.SQ5;
29 28

  
30 29
///////////////////////////////////////////////////////////////////////////////////////////////////
......
36 35

  
37 36
  static final Static3D[] FACE_AXIS = new Static3D[]
38 37
         {
39
           new Static3D( C2/LEN, C1/LEN, 0      ),
40
           new Static3D( C2/LEN,-C1/LEN, 0      ),
41
           new Static3D(-C2/LEN, C1/LEN, 0      ),
42
           new Static3D(-C2/LEN,-C1/LEN, 0      ),
43
           new Static3D( 0     , C2/LEN, C1/LEN ),
44
           new Static3D( 0     , C2/LEN,-C1/LEN ),
45
           new Static3D( 0     ,-C2/LEN, C1/LEN ),
46
           new Static3D( 0     ,-C2/LEN,-C1/LEN ),
47
           new Static3D( C1/LEN, 0     , C2/LEN ),
48
           new Static3D( C1/LEN, 0     ,-C2/LEN ),
49
           new Static3D(-C1/LEN, 0     , C2/LEN ),
50
           new Static3D(-C1/LEN, 0     ,-C2/LEN )
38
           new Static3D(    C2/LEN, SIN54/LEN,    0      ),
39
           new Static3D(    C2/LEN,-SIN54/LEN,    0      ),
40
           new Static3D(   -C2/LEN, SIN54/LEN,    0      ),
41
           new Static3D(   -C2/LEN,-SIN54/LEN,    0      ),
42
           new Static3D( 0        ,    C2/LEN, SIN54/LEN ),
43
           new Static3D( 0        ,    C2/LEN,-SIN54/LEN ),
44
           new Static3D( 0        ,   -C2/LEN, SIN54/LEN ),
45
           new Static3D( 0        ,   -C2/LEN,-SIN54/LEN ),
46
           new Static3D( SIN54/LEN,    0     ,    C2/LEN ),
47
           new Static3D( SIN54/LEN,    0     ,   -C2/LEN ),
48
           new Static3D(-SIN54/LEN,    0     ,    C2/LEN ),
49
           new Static3D(-SIN54/LEN,    0     ,   -C2/LEN )
51 50
         };
52 51

  
53 52
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyKilominx.java
35 35
import org.distorted.main.R;
36 36
import org.distorted.main.RubikSurfaceView;
37 37

  
38
import static org.distorted.helpers.FactoryCubit.COS18;
39
import static org.distorted.helpers.FactoryCubit.COS54;
40
import static org.distorted.helpers.FactoryCubit.COS_HALFD;
41
import static org.distorted.helpers.FactoryCubit.SIN18;
42
import static org.distorted.helpers.FactoryCubit.SIN54;
43
import static org.distorted.helpers.FactoryCubit.SIN_HALFD;
44

  
45 38
///////////////////////////////////////////////////////////////////////////////////////////////////
46 39

  
47 40
public class TwistyKilominx extends TwistyMinx
......
65 58
        2,2,2,2,2
66 59
      };
67 60

  
61
  private static final float CENTER_CORR = 0.87f;
62

  
63
  private static final float[][] STICKERS = new float[][]
64
      {
65
        { -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f },
66
        { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
67
        { -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f }
68
      };
69

  
68 70
  private static final int mNumCornerEdgeVariants;
69 71

  
70 72
  static
......
72 74
    int[] sizes = ObjectList.KILO.getSizes();
73 75
    int variants = sizes.length;
74 76
    mNumCornerEdgeVariants = sizes[0]==3 ? variants-1 : variants;
77

  
78
    STICKERS[0][2] *= CENTER_CORR;
79
    STICKERS[0][3] *= CENTER_CORR;
75 80
    }
76 81

  
77 82
///////////////////////////////////////////////////////////////////////////////////////////////////
......
116 121
    {
117 122
    float[] cuts = new float[numLayers-1];
118 123
    float D = numLayers*MovementMinx.DIST3D;
119
    float E = 2*C1;           // 2*cos(36 deg)
124
    float E = 2*SIN54;
120 125
    float X = 2*D*E/(1+2*E);  // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
121 126
                              // its height is then D*2*DIST3D, it has one 'lower' part of height X, one
122 127
                              // 'middle' part of height Y and one upper part of height X again.
......
625 630
      {
626 631
      float R = 0.10f;
627 632
      float S = 0.09f;
628
      float A = 0.87f;
629
      float[] vertices = { -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f };
630

  
631
      float cx = vertices[2];
632
      float cy = vertices[3];
633
      vertices[2] *= A;
634
      vertices[3] *= A;
633
      float cx = STICKERS[0][2]/CENTER_CORR;
634
      float cy = STICKERS[0][3]/CENTER_CORR;
635 635

  
636 636
      FactorySticker factory = FactorySticker.getInstance();
637
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%NUM_FACES], R);
637
      factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face%NUM_FACES], R);
638 638
      canvas.drawCircle(left+(0.5f+cx)*TEXTURE_HEIGHT, top+(0.5f-cy)*TEXTURE_HEIGHT, 0.05f*TEXTURE_HEIGHT, paint);
639 639
      }
640 640
    else if( variant==0 ) // corner
641 641
      {
642 642
      float R = 0.10f;
643 643
      float S = 0.11f;
644
      float[] vertices = { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f };
645

  
646 644
      FactorySticker factory = FactorySticker.getInstance();
647
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
645
      factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[1], S, FACE_COLORS[face%COLORS], R);
648 646
      }
649 647
    else  // edge
650 648
      {
651 649
      float R = 0.10f;
652 650
      float S = 0.10f;
653
      float[] vertices = { -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f };
654

  
655 651
      FactorySticker factory = FactorySticker.getInstance();
656
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
652
      factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[2], S, FACE_COLORS[face%COLORS], R);
657 653
      }
658 654
    }
659 655

  
src/main/java/org/distorted/objects/TwistyMegaminx.java
35 35
import org.distorted.main.R;
36 36
import org.distorted.main.RubikSurfaceView;
37 37

  
38
import static org.distorted.helpers.FactoryCubit.COS18;
39
import static org.distorted.helpers.FactoryCubit.COS54;
40
import static org.distorted.helpers.FactoryCubit.SIN18;
41
import static org.distorted.helpers.FactoryCubit.SIN54;
42

  
43 38
///////////////////////////////////////////////////////////////////////////////////////////////////
44 39

  
45 40
public class TwistyMegaminx extends TwistyMinx
......
54 49
  private static MeshBase[] mCenterMeshes, mCornerMeshes;
55 50
  private static MeshBase[][] mEdgeMeshes;
56 51

  
52
  private static final float[][] STICKERS = new float[][]
53
      {
54
        { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
55
        { -0.5f, -0.0914315f, 0.5f, -0.4163512f, 0.5f, 0.4163512f, -0.5f, 0.0914315f },
56
        { -0.49233657f, -0.18006028f, 0.49233657f, -0.5f, 0.49233657f, 0.5f, -0.49233657f, 0.18006028f },
57
        { -0.3002273f, -0.30490047f, 0.3002273f, -0.5f, 0.3002273f, 0.5f, -0.3002273f, 0.30490047f },
58
        { -0.29389262f, 0.4045085f, -0.47552824f, -0.1545085f, 0.0f, -0.5f, 0.47552824f, -0.1545085f, 0.29389262f, 0.4045085f }
59
      };
60

  
57 61
///////////////////////////////////////////////////////////////////////////////////////////////////
58 62

  
59 63
  TwistyMegaminx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
......
96 100
    {
97 101
    float[] cuts = new float[numLayers-1];
98 102
    float D = numLayers*MovementMinx.DIST3D;
99
    float E = 2*C1;           // 2*cos(36 deg)
103
    float E = 2*SIN54;
100 104
    float X = 2*D*E/(1+2*E);  // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
101 105
                              // its height is then D*2*DIST3D, it has one 'lower' part of height X, one
102 106
                              // 'middle' part of height Y and one upper part of height X again.
......
266 270
    return QUAT_CENTER_INDICES[center];
267 271
    }
268 272

  
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

  
275
  MeshBase createEdgeMesh(int numLayers, float width, float height)
276
    {
277
    double W = width/2;
278
    double X = height*SIN_HALFD;
279
    double Y = height*SIN18/COS18;
280
    double Z = height*COS_HALFD;
281

  
282
    double[][] vertices = new double[][]
283
        {
284
            { 0.0,   W   , 0.0 },
285
            {   X, W+Y   ,  -Z },
286
            { 0.0, W+2*Y ,-2*Z },
287
            {  -X, W+Y   ,  -Z },
288
            { 0.0,  -W   , 0.0 },
289
            {   X,-W-Y   ,  -Z },
290
            { 0.0,-W-2*Y ,-2*Z },
291
            {  -X,-W-Y   ,  -Z },
292
        };
293

  
294
    int[][] vertIndexes = new int[][]
295
        {
296
            {4,5,1,0},
297
            {7,4,0,3},
298
            {7,6,2,3},
299
            {6,5,1,2},
300
            {0,1,2,3},
301
            {4,5,6,7}
302
        };
303

  
304
    int N = numLayers<=5 ? 5 : 3;
305

  
306
    float[][] bands     = new float[][]
307
      {
308
         {0.04f,34,0.2f,0.2f,N,0,0},
309
         {0.00f, 0,0.3f,0.2f,2,0,0}
310
      };
311
    int[] bandIndexes   = new int[] { 0,0,1,1,1,1};
312
    float[][] corners   = new float[][] { {0.04f,0.10f} };
313
    int[] cornerIndexes = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
314
    float[][] centers   = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} };
315
    int[] centerIndexes = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
316

  
317
    FactoryCubit factory = FactoryCubit.getInstance();
318
    factory.createNewFaceTransform(vertices,vertIndexes);
319

  
320
    return factory.createRoundedSolid(vertices, vertIndexes,
321
                                      bands, bandIndexes,
322
                                      corners, cornerIndexes,
323
                                      centers, centerIndexes,
324
                                      getNumCubitFaces() );
325
    }
326

  
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

  
329
  MeshBase createCenterMesh(int numLayers, float width)
330
    {
331
    final double V = 0.83;   // ??
332
    final double ANGLE = V*Math.PI;
333
    final double cosA  = Math.cos(ANGLE);
334
    final double sinA  = Math.sin(ANGLE);
335

  
336
    float R  = 0.5f*width/COS54;
337
    float X1 = R*COS54;
338
    float Y1 = R*SIN54;
339
    float X2 = R*COS18;
340
    float Y2 = R*SIN18;
341

  
342
    double[][] vertices = new double[][]
343
      {
344
          {-X1,+Y1*sinA, Y1*cosA},
345
          {-X2,-Y2*sinA,-Y2*cosA},
346
          {0.0f,-R*sinA, -R*cosA},
347
          {+X2,-Y2*sinA,-Y2*cosA},
348
          {+X1,+Y1*sinA, Y1*cosA}
349
      };
350

  
351
    int[][] vertIndexes = new int[][]
352
      {
353
          {0,1,2,3,4},
354
          {0,1,2,3,4}
355
      };
356

  
357
    int N = numLayers==3 ? 4 : 3;
358

  
359
    float[][] bands = new float[][]
360
      {
361
         {0.04f,45, R/3,0.2f,N,0,0},
362
         {0.00f, 0, R/3,0.2f,2,0,0}
363
      };
364
    int[] bandIndexes   = new int[] { 0,1 };
365
    float[][] corners   = new float[][] { {0.04f,0.10f} };
366
    int[] cornerIndexes = new int[] { -1,-1,-1,-1, -1 };
367
    float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
368
    int[] centerIndexes = new int[] { -1,-1,-1,-1, -1 };
369

  
370
    FactoryCubit factory = FactoryCubit.getInstance();
371
    factory.createNewFaceTransform(vertices,vertIndexes);
372

  
373
    return factory.createRoundedSolid(vertices, vertIndexes,
374
                                      bands, bandIndexes,
375
                                      corners, cornerIndexes,
376
                                      centers, centerIndexes,
377
                                      getNumCubitFaces() );
378
    }
379

  
269 380
///////////////////////////////////////////////////////////////////////////////////////////////////
270 381

  
271 382
  MeshBase createCubitMesh(int cubit, int numLayers)
......
299 410
        float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
300 411
        float width = (numLayers/3.0f)*2*MEGA_D + 2*type*height*SIN18/COS18;
301 412

  
302
        mEdgeMeshes[index][type] = FactoryCubit.getInstance().createMegaminxEdgeMesh(numLayers,width,height);
413
        mEdgeMeshes[index][type] = createEdgeMesh(numLayers,width,height);
303 414
        }
304 415

  
305 416
      mesh = mEdgeMeshes[index][type].copy(true);
......
309 420
      if( mCenterMeshes[index]==null )
310 421
        {
311 422
        float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18);
312
        mCenterMeshes[index] = FactoryCubit.getInstance().createMegaminxCenterMesh(numLayers,width);
423
        mCenterMeshes[index] = createCenterMesh(numLayers,width);
313 424
        }
314 425

  
315 426
      mesh = mCenterMeshes[index].copy(true);
......
412 523
    {
413 524
    int COLORS = FACE_COLORS.length;
414 525
    float R,S;
415
    float[] vertices;
526
    int index,variant = face/COLORS;
416 527

  
417
    int variant = face/COLORS;
418

  
419
    if( variant==0 )
420
      {
421
      R = 0.080f;
422
      S = 0.10f;
423
      vertices = new float[] { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f };
424
      }
528
    if( variant==0 ) { R = 0.08f; S = 0.10f; index = 0; }
425 529
    else
426 530
      {
427 531
      int numLayers = getNumLayers();
428
      float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
429
      float W = height*SIN18/COS18;
430
      float width = (numLayers/3.0f)*2*MEGA_D + 2*(variant-1)*W;
431 532

  
432 533
      if( variant < (numLayers+1)/2 )
433 534
        {
434
        float X1 = 0.5f*height;
435
        float Y1 = 0.5f*width;
436
        float Y2 = 0.5f*width + W;
437

  
438
        R = 0.045f;
439
        S = 0.055f;
440
        vertices = new float[] { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 };
441
        }
442
      else
443
        {
444
        float Z  = 0.5f;
445
        float X1 = Z*COS54;
446
        float Y1 = Z*SIN54;
447
        float X2 = Z*COS18;
448
        float Y2 = Z*SIN18;
449

  
450
        R = 0.09f;
451
        S = 0.08f;
452
        vertices = new float[] { -X1,+Y1, -X2,-Y2, 0.0f,-Z, +X2,-Y2, +X1,+Y1 };
535
        if( numLayers==3 ) { R = 0.12f; S = 0.12f; index = 1; }
536
        else
537
          {
538
          if( variant==1 ) { R = 0.12f; S = 0.12f; index = 2; }
539
          else             { R = 0.08f; S = 0.08f; index = 3; }
540
          }
453 541
        }
542
      else { R = 0.10f; S = 0.07f; index = 4; }
454 543
      }
455 544

  
456 545
    FactorySticker factory = FactorySticker.getInstance();
457
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
546
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[index], S, FACE_COLORS[face%COLORS], R);
458 547
    }
459 548

  
460 549
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyMinx.java
31 31

  
32 32
import java.util.Random;
33 33

  
34
import static org.distorted.helpers.FactoryCubit.COS18;
35
import static org.distorted.helpers.FactoryCubit.COS_HALFD;
36
import static org.distorted.helpers.FactoryCubit.SIN18;
37
import static org.distorted.helpers.FactoryCubit.SIN54;
38
import static org.distorted.helpers.FactoryCubit.SIN_HALFD;
39

  
40 34
///////////////////////////////////////////////////////////////////////////////////////////////////
41 35

  
42 36
abstract class TwistyMinx extends TwistyObject
......
47 41
  static final int NUM_CENTERS = 12;
48 42
  static final int NUM_EDGES   = 30;
49 43

  
50
  static final float C0 = (SQ5-1)/4;                       // cos(72 deg)
51
  static final float C1 = (SQ5+1)/4;                       // cos(36 deg)
52
  static final float C2 = (SQ5+3)/4;
53
  static final float LEN= (float)(Math.sqrt(1.25f+0.5f*SQ5));
44
  static final float C2       = (SQ5+3)/4;
45
  static final float LEN      = (float)(Math.sqrt(1.25f+0.5f*SQ5));
46
  static final float SIN54    = (SQ5+1)/4;
47
  static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
48
  static final float SIN18    = (SQ5-1)/4;
49
  static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
50
  static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
51
  static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
54 52

  
55 53
  // the six rotation axis of a Minx. Must be normalized.
56 54
  static final Static3D[] ROT_AXIS = new Static3D[]
57 55
         {
58
           new Static3D( C2/LEN, C1/LEN, 0      ),
59
           new Static3D(-C2/LEN, C1/LEN, 0      ),
60
           new Static3D( 0     , C2/LEN, C1/LEN ),
61
           new Static3D( 0     ,-C2/LEN, C1/LEN ),
62
           new Static3D( C1/LEN, 0     , C2/LEN ),
63
           new Static3D( C1/LEN, 0     ,-C2/LEN )
56
           new Static3D(    C2/LEN, SIN54/LEN,    0      ),
57
           new Static3D(   -C2/LEN, SIN54/LEN,    0      ),
58
           new Static3D( 0        ,    C2/LEN, SIN54/LEN ),
59
           new Static3D( 0        ,   -C2/LEN, SIN54/LEN ),
60
           new Static3D( SIN54/LEN,    0     ,    C2/LEN ),
61
           new Static3D( SIN54/LEN,    0     ,   -C2/LEN )
64 62
         };
65 63

  
66 64
  private static final int MINX_LGREEN = 0xff53aa00;
......
100 98
           new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
101 99
           new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
102 100

  
103
           new Static4D(  0.5f,    C1,    C0,  0.0f ), // 12
104
           new Static4D(  0.5f,    C1,   -C0,  0.0f ),
105
           new Static4D(  0.5f,   -C1,    C0,  0.0f ),
106
           new Static4D(  0.5f,   -C1,   -C0,  0.0f ),
107
           new Static4D(    C0,  0.5f,    C1,  0.0f ),
108
           new Static4D(    C0,  0.5f,   -C1,  0.0f ),
109
           new Static4D(   -C0,  0.5f,    C1,  0.0f ),
110
           new Static4D(   -C0,  0.5f,   -C1,  0.0f ),
111
           new Static4D(    C1,    C0,  0.5f,  0.0f ),
112
           new Static4D(    C1,   -C0,  0.5f,  0.0f ),
113
           new Static4D(   -C1,    C0,  0.5f,  0.0f ),
114
           new Static4D(   -C1,   -C0,  0.5f,  0.0f ),
115

  
116
           new Static4D(  0.0f,    C0,    C1,  0.5f ), //24
117
           new Static4D(  0.0f,    C0,   -C1,  0.5f ),
118
           new Static4D(  0.0f,   -C0,    C1,  0.5f ),
119
           new Static4D(  0.0f,   -C0,   -C1,  0.5f ),
120
           new Static4D(    C0,    C1,  0.0f,  0.5f ),
121
           new Static4D(    C0,   -C1,  0.0f,  0.5f ),
122
           new Static4D(   -C0,    C1,  0.0f,  0.5f ),
123
           new Static4D(   -C0,   -C1,  0.0f,  0.5f ),
124
           new Static4D(    C1,  0.0f,    C0,  0.5f ),
125
           new Static4D(    C1,  0.0f,   -C0,  0.5f ),
126
           new Static4D(   -C1,  0.0f,    C0,  0.5f ),
127
           new Static4D(   -C1,  0.0f,   -C0,  0.5f ),
128

  
129
           new Static4D(  0.0f,    C1,  0.5f,    C0 ), //36
130
           new Static4D(  0.0f,    C1, -0.5f,    C0 ),
131
           new Static4D(  0.0f,   -C1,  0.5f,    C0 ),
132
           new Static4D(  0.0f,   -C1, -0.5f,    C0 ),
133
           new Static4D(  0.5f,  0.0f,    C1,    C0 ),
134
           new Static4D(  0.5f,  0.0f,   -C1,    C0 ),
135
           new Static4D( -0.5f,  0.0f,    C1,    C0 ),
136
           new Static4D( -0.5f,  0.0f,   -C1,    C0 ),
137
           new Static4D(    C1,  0.5f,  0.0f,    C0 ),
138
           new Static4D(    C1, -0.5f,  0.0f,    C0 ),
139
           new Static4D(   -C1,  0.5f,  0.0f,    C0 ),
140
           new Static4D(   -C1, -0.5f,  0.0f,    C0 ),
141

  
142
           new Static4D(  0.0f,  0.5f,    C0,    C1 ), //48
143
           new Static4D(  0.0f,  0.5f,   -C0,    C1 ),
144
           new Static4D(  0.0f, -0.5f,    C0,    C1 ),
145
           new Static4D(  0.0f, -0.5f,   -C0,    C1 ),
146
           new Static4D(  0.5f,    C0,  0.0f,    C1 ),
147
           new Static4D(  0.5f,   -C0,  0.0f,    C1 ),
148
           new Static4D( -0.5f,    C0,  0.0f,    C1 ),
149
           new Static4D( -0.5f,   -C0,  0.0f,    C1 ),
150
           new Static4D(    C0,  0.0f,  0.5f,    C1 ),
151
           new Static4D(    C0,  0.0f, -0.5f,    C1 ),
152
           new Static4D(   -C0,  0.0f,  0.5f,    C1 ),
153
           new Static4D(   -C0,  0.0f, -0.5f,    C1 ),
101
           new Static4D(  0.5f, SIN54, SIN18,  0.0f ), // 12
102
           new Static4D(  0.5f, SIN54,-SIN18,  0.0f ),
103
           new Static4D(  0.5f,-SIN54, SIN18,  0.0f ),
104
           new Static4D(  0.5f,-SIN54,-SIN18,  0.0f ),
105
           new Static4D( SIN18,  0.5f, SIN54,  0.0f ),
106
           new Static4D( SIN18,  0.5f,-SIN54,  0.0f ),
107
           new Static4D(-SIN18,  0.5f, SIN54,  0.0f ),
108
           new Static4D(-SIN18,  0.5f,-SIN54,  0.0f ),
109
           new Static4D( SIN54, SIN18,  0.5f,  0.0f ),
110
           new Static4D( SIN54,-SIN18,  0.5f,  0.0f ),
111
           new Static4D(-SIN54, SIN18,  0.5f,  0.0f ),
112
           new Static4D(-SIN54,-SIN18,  0.5f,  0.0f ),
113

  
114
           new Static4D(  0.0f, SIN18, SIN54,  0.5f ), //24
115
           new Static4D(  0.0f, SIN18,-SIN54,  0.5f ),
116
           new Static4D(  0.0f,-SIN18, SIN54,  0.5f ),
117
           new Static4D(  0.0f,-SIN18,-SIN54,  0.5f ),
118
           new Static4D( SIN18, SIN54,  0.0f,  0.5f ),
119
           new Static4D( SIN18,-SIN54,  0.0f,  0.5f ),
120
           new Static4D(-SIN18, SIN54,  0.0f,  0.5f ),
121
           new Static4D(-SIN18,-SIN54,  0.0f,  0.5f ),
122
           new Static4D( SIN54,  0.0f, SIN18,  0.5f ),
123
           new Static4D( SIN54,  0.0f,-SIN18,  0.5f ),
124
           new Static4D(-SIN54,  0.0f, SIN18,  0.5f ),
125
           new Static4D(-SIN54,  0.0f,-SIN18,  0.5f ),
126

  
127
           new Static4D(  0.0f, SIN54,  0.5f, SIN18 ), //36
128
           new Static4D(  0.0f, SIN54, -0.5f, SIN18 ),
129
           new Static4D(  0.0f,-SIN54,  0.5f, SIN18 ),
130
           new Static4D(  0.0f,-SIN54, -0.5f, SIN18 ),
131
           new Static4D(  0.5f,  0.0f, SIN54, SIN18 ),
132
           new Static4D(  0.5f,  0.0f,-SIN54, SIN18 ),
133
           new Static4D( -0.5f,  0.0f, SIN54, SIN18 ),
134
           new Static4D( -0.5f,  0.0f,-SIN54, SIN18 ),
135
           new Static4D( SIN54,  0.5f,  0.0f, SIN18 ),
136
           new Static4D( SIN54, -0.5f,  0.0f, SIN18 ),
137
           new Static4D(-SIN54,  0.5f,  0.0f, SIN18 ),
138
           new Static4D(-SIN54, -0.5f,  0.0f, SIN18 ),
139

  
140
           new Static4D(  0.0f,  0.5f, SIN18, SIN54 ), //48
141
           new Static4D(  0.0f,  0.5f,-SIN18, SIN54 ),
142
           new Static4D(  0.0f, -0.5f, SIN18, SIN54 ),
143
           new Static4D(  0.0f, -0.5f,-SIN18, SIN54 ),
144
           new Static4D(  0.5f, SIN18,  0.0f, SIN54 ),
145
           new Static4D(  0.5f,-SIN18,  0.0f, SIN54 ),
146
           new Static4D( -0.5f, SIN18,  0.0f, SIN54 ),
147
           new Static4D( -0.5f,-SIN18,  0.0f, SIN54 ),
148
           new Static4D( SIN18,  0.0f,  0.5f, SIN54 ),
149
           new Static4D( SIN18,  0.0f, -0.5f, SIN54 ),
150
           new Static4D(-SIN18,  0.0f,  0.5f, SIN54 ),
151
           new Static4D(-SIN18,  0.0f, -0.5f, SIN54 ),
154 152
         };
155 153

  
156 154
  // Coordinates of all 20 corners of a Minx
157 155
  static final float[][] CORNERS = new float[][]
158 156
         {
159
             { 0.0f, 0.5f,   C2},
160
             { 0.0f, 0.5f,  -C2},
161
             { 0.0f,-0.5f,   C2},
162
             { 0.0f,-0.5f,  -C2},
163
             {   C2, 0.0f, 0.5f},
164
             {   C2, 0.0f,-0.5f},
165
             {  -C2, 0.0f, 0.5f},
166
             {  -C2, 0.0f,-0.5f},
167
             { 0.5f,   C2, 0.0f},
168
             { 0.5f,  -C2, 0.0f},
169
             {-0.5f,   C2, 0.0f},
170
             {-0.5f,  -C2, 0.0f},
171
             {   C1,   C1,   C1},
172
             {   C1,   C1,  -C1},
173
             {   C1,  -C1,   C1},
174
             {   C1,  -C1,  -C1},
175
             {  -C1,   C1,   C1},
176
             {  -C1,   C1,  -C1},
177
             {  -C1,  -C1,   C1},
178
             {  -C1,  -C1,  -C1},
157
             {  0.0f,  0.5f,    C2},
158
             {  0.0f,  0.5f,   -C2},
159
             {  0.0f, -0.5f,    C2},
160
             {  0.0f, -0.5f,   -C2},
161
             {    C2,  0.0f,  0.5f},
162
             {    C2,  0.0f, -0.5f},
163
             {   -C2,  0.0f,  0.5f},
164
             {   -C2,  0.0f, -0.5f},
165
             {  0.5f,    C2,  0.0f},
166
             {  0.5f,   -C2,  0.0f},
167
             { -0.5f,    C2,  0.0f},
168
             { -0.5f,   -C2,  0.0f},
169
             { SIN54, SIN54, SIN54},
170
             { SIN54, SIN54,-SIN54},
171
             { SIN54,-SIN54, SIN54},
172
             { SIN54,-SIN54,-SIN54},
173
             {-SIN54, SIN54, SIN54},
174
             {-SIN54, SIN54,-SIN54},
175
             {-SIN54,-SIN54, SIN54},
176
             {-SIN54,-SIN54,-SIN54},
179 177
         };
180 178

  
181 179
  static final int[][] mCornerFaceMap =

Also available in: Unified diff