Project

General

Profile

« Previous | Next » 

Revision 7dc57f89

Added by Leszek Koltunski over 3 years ago

Convert the Skewb.

View differences:

src/main/java/org/distorted/helpers/FactoryCubit.java
238 238
      }
239 239
    }
240 240

  
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

  
243
  MeshBase createFacesSkewbCorner()
244
    {
245
    MeshBase[] meshes = new MeshBase[6];
246

  
247
    float E = 0.5f;
248
    float F = SQ2/2;
249
    float G = SQ6/16;
250
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
251
    float[] bands0 = computeBands(0.028f,35,E/3,0.7f,7);
252

  
253
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
254
    meshes[0].setEffectAssociation(0,1,0);
255
    meshes[1] = meshes[0].copy(true);
256
    meshes[1].setEffectAssociation(0,2,0);
257
    meshes[2] = meshes[0].copy(true);
258
    meshes[2].setEffectAssociation(0,4,0);
259

  
260
    float[] vertices1 = { -F/2,-2*G, F/2,-2*G, 3*F/8,-G, 1*F/8,G, 0,2*G };
261
    float[] bands1 = computeBands(0,0,1,0,3);
262

  
263
    meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
264
    meshes[3].setEffectAssociation(0,8,0);
265
    meshes[4] = meshes[3].copy(true);
266
    meshes[4].setEffectAssociation(0,16,0);
267
    meshes[5] = meshes[3].copy(true);
268
    meshes[5].setEffectAssociation(0,32,0);
269

  
270
    return new MeshJoined(meshes);
271
    }
272

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

  
275
  MeshBase createFacesSkewbFace()
276
    {
277
    MeshBase[] meshes = new MeshBase[5];
278

  
279
    float E = SQ2/4;
280
    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
281
    float[] bands0 = computeBands(0.051f,35,E/2,0.9f,7);
282

  
283
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
284
    meshes[0].setEffectAssociation(0,1,0);
285

  
286
    float[] vertices1 = { -E,-SQ3*E, -E*0.7f,-SQ3*E, +E*0.7f,-SQ3*E, +E,-SQ3*E, 0,0 };
287
    float[] bands1 = computeBands(0,0,1,0,3);
288

  
289
    meshes[1] = new MeshPolygon(vertices1,bands1,0,0);
290
    meshes[1].setEffectAssociation(0,2,0);
291
    meshes[2] = meshes[1].copy(true);
292
    meshes[2].setEffectAssociation(0,4,0);
293
    meshes[3] = meshes[1].copy(true);
294
    meshes[3].setEffectAssociation(0,8,0);
295
    meshes[4] = meshes[1].copy(true);
296
    meshes[4].setEffectAssociation(0,16,0);
297

  
298
    return new MeshJoined(meshes);
299
    }
300

  
301 241
///////////////////////////////////////////////////////////////////////////////////////////////////
302 242

  
303 243
  MeshBase createFacesHelicopterCorner()
......
813 753

  
814 754
///////////////////////////////////////////////////////////////////////////////////////////////////
815 755
// EFFECTS
816
///////////////////////////////////////////////////////////////////////////////////////////////////
817

  
818
///////////////////////////////////////////////////////////////////////////////////////////////////
819

  
820
  VertexEffect[] createVertexEffectsSkewbCorner()
821
    {
822
    float E = 0.5f;
823

  
824
    Static3D axisX  = new Static3D(1,0,0);
825
    Static3D axisY  = new Static3D(0,1,0);
826
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
827
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
828
    Static1D angle1 = new Static1D(+90);
829
    Static1D angle2 = new Static1D(-90);
830
    Static1D angle3 = new Static1D(-15);
831
    Static1D angle4 = new Static1D((float)((180.0f/Math.PI)*Math.acos(SQ3/3)));
832
    Static1D angle5 = new Static1D(120);
833
    Static1D angle6 = new Static1D(240);
834
    Static3D center1= new Static3D(0,0,0);
835
    Static3D center2= new Static3D(-0.5f,-0.5f,-0.5f);
836
    Static3D move1  = new Static3D(-E/4,-E/4,0);
837
    Static3D move2  = new Static3D(-0.5f+SQ2/4,-0.5f+SQ6/8,-0.5f);
838

  
839
    VertexEffect[] effect = new VertexEffect[10];
840

  
841
    effect[0] = new VertexEffectMove(move1);
842
    effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
843
    effect[2] = new VertexEffectRotate(angle1,axisX,center1);
844
    effect[3] = new VertexEffectRotate(angle2,axisY,center1);
845
    effect[4] = new VertexEffectMove(move2);
846
    effect[5] = new VertexEffectRotate(angle1,axisX,center2);
847
    effect[6] = new VertexEffectRotate(angle3,axisY,center2);
848
    effect[7] = new VertexEffectRotate(angle4,axis0,center2);
849
    effect[8] = new VertexEffectRotate(angle5,axis1,center2);
850
    effect[9] = new VertexEffectRotate(angle6,axis1,center2);
851

  
852
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
853
    effect[1].setMeshAssociation( 6,-1);  // meshes 1,2
854
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
855
    effect[3].setMeshAssociation( 4,-1);  // mesh 2
856
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
857
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
858
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
859
    effect[7].setMeshAssociation(56,-1);  // meshes 3,4,5
860
    effect[8].setMeshAssociation(16,-1);  // mesh 4
861
    effect[9].setMeshAssociation(32,-1);  // mesh 5
862

  
863
    return effect;
864
    }
865

  
866
///////////////////////////////////////////////////////////////////////////////////////////////////
867

  
868
  VertexEffect[] createVertexEffectsSkewbFace()
869
    {
870
    Static3D center = new Static3D(0,0,0);
871
    Static3D axisX  = new Static3D(1,0,0);
872
    Static3D axisZ  = new Static3D(0,0,1);
873
    float angle = -(float)((180.0f/Math.PI)*Math.acos(SQ3/3));
874

  
875
    VertexEffect[] effect = new VertexEffect[6];
876

  
877
    effect[0] = new VertexEffectRotate( new Static1D(angle), axisX, center);
878
    effect[1] = new VertexEffectRotate( new Static1D(  135), axisZ, center);
879
    effect[2] = new VertexEffectRotate( new Static1D(   45), axisZ, center);
880
    effect[3] = new VertexEffectRotate( new Static1D(  -45), axisZ, center);
881
    effect[4] = new VertexEffectRotate( new Static1D( -135), axisZ, center);
882
    effect[5] = new VertexEffectMove( new Static3D(0,0,-0.5f) );
883

  
884
    effect[0].setMeshAssociation(30,-1);  // meshes 1,2,3,4
885
    effect[1].setMeshAssociation( 2,-1);  // mesh 1
886
    effect[2].setMeshAssociation( 5,-1);  // meshes 0,2
887
    effect[3].setMeshAssociation( 8,-1);  // mesh 3
888
    effect[4].setMeshAssociation(16,-1);  // mesh 4
889
    effect[5].setMeshAssociation(30,-1);  // meshes 1,2,3,4
890

  
891
    return effect;
892
    }
893

  
894 756
///////////////////////////////////////////////////////////////////////////////////////////////////
895 757

  
896 758
  VertexEffect[] createVertexEffectsHelicopterCorner()
......
1468 1330
///////////////////////////////////////////////////////////////////////////////////////////////////
1469 1331

  
1470 1332

  
1471
///////////////////////////////////////////////////////////////////////////////////////////////////
1472
// SKEWB
1473

  
1474
  public MeshBase createSkewbCornerMesh()
1475
    {
1476
    MeshBase mesh = createFacesSkewbCorner();
1477
    VertexEffect[] effects = createVertexEffectsSkewbCorner();
1478
    for( VertexEffect effect : effects ) mesh.apply(effect);
1479

  
1480
    float E = 0.5f;
1481
    Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
1482

  
1483
    Static3D[] verticesType1 = new Static3D[1];
1484
    verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
1485
    roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
1486

  
1487
    Static3D[] verticesType2 = new Static3D[3];
1488
    verticesType2[0] = new Static3D(-E, 0, 0);
1489
    verticesType2[1] = new Static3D( 0,-E, 0);
1490
    verticesType2[2] = new Static3D( 0, 0,-E);
1491
    roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
1492

  
1493
    mesh.mergeEffComponents();
1494

  
1495
    return mesh;
1496
    }
1497

  
1498
///////////////////////////////////////////////////////////////////////////////////////////////////
1499

  
1500
  public MeshBase createSkewbFaceMesh()
1501
    {
1502
    MeshBase mesh = createFacesSkewbFace();
1503
    VertexEffect[] effects = createVertexEffectsSkewbFace();
1504
    for( VertexEffect effect : effects ) mesh.apply(effect);
1505

  
1506
    Static3D roundingCenter = new Static3D(0,0,-0.2f);
1507
    float E = SQ2/4;
1508
    Static3D[] vertices = new Static3D[4];
1509
    vertices[0] = new Static3D(-E*SQ2,      0, 0);
1510
    vertices[1] = new Static3D(+E*SQ2,      0, 0);
1511
    vertices[2] = new Static3D(     0, -E*SQ2, 0);
1512
    vertices[3] = new Static3D(     0, +E*SQ2, 0);
1513
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.10f);
1514

  
1515
    mesh.mergeEffComponents();
1516
    mesh.addEmptyTexComponent();
1517

  
1518
    return mesh;
1519
    }
1520

  
1521 1333
///////////////////////////////////////////////////////////////////////////////////////////////////
1522 1334
// Helicopter
1523 1335

  
......
2367 2179
      staticVert[0] = new Static3D( (float)vertices[v][0], (float)vertices[v][1], (float)vertices[v][2]);
2368 2180

  
2369 2181
      int cent = centerIndexes[v];
2370
      center.set( centers[cent][0], centers[cent][1], centers[cent][2]);
2371 2182

  
2372
      int corn = cornerIndexes[v];
2373
      float strength = corners[corn][0];
2374
      float radius   = corners[corn][1];
2183
      if( cent>=0 )
2184
        {
2185
        center.set( centers[cent][0], centers[cent][1], centers[cent][2]);
2186

  
2187
        int corn = cornerIndexes[v];
2188
        float strength = corners[corn][0];
2189
        float radius   = corners[corn][1];
2375 2190

  
2376
      roundCorners(mesh, center, staticVert, strength, radius);
2191
        roundCorners(mesh, center, staticVert, strength, radius);
2192
        }
2377 2193
      }
2378 2194
    }
2379 2195

  
src/main/java/org/distorted/objects/TwistySkewb.java
116 116

  
117 117
  private static final double[][] VERTICES_CORNER = new double[][]
118 118
          {
119
             // TODO
119
              {-0.5f, 0.0f, 0.0f},
120
              { 0.0f,-0.5f, 0.0f},
121
              { 0.0f, 0.0f,-0.5f},
122
              {-0.5f,-0.5f,-0.5f},
123
              { 0.0f, 0.0f, 0.0f}
120 124
          };
121 125

  
122 126
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
123 127
          {
124
             // TODO
128
              {0,1,4},
129
              {2,0,4},
130
              {1,2,4},
131
              {3,1,0},
132
              {3,2,1},
133
              {3,0,2}
125 134
          };
126 135

  
127 136
  private static final double[][] VERTICES_EDGE = new double[][]
......
142 151

  
143 152
  private static final double[][] VERTICES_FACE = new double[][]
144 153
          {
145
             // TODO
154
             {-0.5f, 0.0f, 0.0f },
155
             { 0.0f,-0.5f, 0.0f },
156
             { 0.5f, 0.0f, 0.0f },
157
             { 0.0f, 0.5f, 0.0f },
158
             { 0.0f, 0.0f,-0.5f }
146 159
          };
147 160

  
148 161
  private static final int[][] VERT_INDEXES_FACE = new int[][]
149 162
          {
150
             // TODO
163
             {0,1,2,3},
164
             {4,1,0},
165
             {4,2,1},
166
             {4,3,2},
167
             {4,0,3}
168
          };
169

  
170

  
171
  private static final float[][] STICKERS = new float[][]
172
          {
173
             { -0.5f,   0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
174
             {  0.0f, -1.0f/3, 0.50f, 1.0f/6, -0.5f, 1.0f/6 },
175
             { -0.5f,    0.0f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
151 176
          };
152 177

  
153 178
  private static MeshBase[] mMeshes;
......
478 503
      {
479 504
      if( mMeshes[0]==null )
480 505
        {
481
        mMeshes[0] = FactoryCubit.getInstance().createSkewbCornerMesh();
506
        float[][] bands= new float[][]
507
          {
508
             {0.028f,35,0.16f,0.7f,7,3,3},
509
             {0.000f, 0,1.00f,0.0f,3,1,5}
510
          };
511
        int[] bandIndexes   = new int[] { 0,0,0,1,1,1 };
512
        float[][] corners   = new float[][] { {0.08f,0.15f}, {0.08f,0.20f} };
513
        int[] cornerIndexes = new int[] { 1,1,1,0,0 };
514
        float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.25f} };
515
        int[] centerIndexes = new int[] { 0,0,0,-1,0 };
516

  
517
        FactoryCubit factory = FactoryCubit.getInstance();
518
        factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
519
        mMeshes[0] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
520
                                                bands, bandIndexes,
521
                                                corners, cornerIndexes,
522
                                                centers, centerIndexes,
523
                                                getNumCubitFaces() );
524
        //mMeshes[0] = FactoryCubit.getInstance().createSkewbCornerMesh();
482 525
        }
483 526
      mesh = mMeshes[0].copy(true);
484 527
      }
......
511 554
      {
512 555
      if( mMeshes[2]==null )
513 556
        {
514
        mMeshes[2] = FactoryCubit.getInstance().createSkewbFaceMesh();
557
        float[][] bands= new float[][]
558
          {
559
             {0.051f,35,SQ2/8,0.9f, 7,3,3},
560
             {0.000f, 0,    1,0.0f, 3,0,0}
561
          };
562
        int[] bandIndexes   = new int[] { 0,1,1,1,1 };
563
        float[][] corners   = new float[][] { {0.06f,0.10f} };
564
        int[] cornerIndexes = new int[] { 0,0,0,0,0 };
565
        float[][] centers   = new float[][] { {0,0,-0.2f} };
566
        int[] centerIndexes = new int[] { 0,0,0,0,-1 };
567

  
568
        FactoryCubit factory = FactoryCubit.getInstance();
569
        factory.createNewFaceTransform(VERTICES_FACE,VERT_INDEXES_FACE);
570
        mMeshes[2] = factory.createRoundedSolid(VERTICES_FACE, VERT_INDEXES_FACE,
571
                                                bands, bandIndexes,
572
                                                corners, cornerIndexes,
573
                                                centers, centerIndexes,
574
                                                getNumCubitFaces() );
515 575
        }
516 576
      mesh = mMeshes[2].copy(true);
517 577
      }
......
550 610
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
551 611
    {
552 612
    int COLORS = FACE_COLORS.length;
553
    float R,S;
554
    float[] vertices;
613
    float R=0.0f,S=0.0f;
614
    int cubitType = face/COLORS;
555 615

  
556
    if( face<COLORS )
557
      {
558
      float E = 0.5f;
559
      R = 0.023f;
560
      S = 0.035f;
561
      vertices = new float[] { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
562
      }
563
    else if( face<2*COLORS )
564
      {
565
      float E = 0.5f;
566
      R = 0.025f;
567
      S = 0.05f;
568
      vertices = new float[] { -E,E/3, 0,-2*E/3, +E,E/3 };
569
      }
570
    else
616
    switch(cubitType)
571 617
      {
572
      float E = SQ2/4;
573
      R = 0.055f;
574
      S = 0.035f;
575
      vertices = new float[] { -E,-E, +E,-E, +E,+E, -E,+E };
618
      case 0: R = 0.025f; S = 0.045f; break;
619
      case 1: R = 0.025f; S = 0.035f; break;
620
      case 2: R = 0.055f; S = 0.035f; break;
576 621
      }
577 622

  
578 623
    FactorySticker factory = FactorySticker.getInstance();
579
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
624
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[cubitType], S, FACE_COLORS[face%COLORS], R);
580 625
    }
581 626

  
582 627
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff