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/objects/TwistyKilominx.java
37 37

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

  
43 45
///////////////////////////////////////////////////////////////////////////////////////////////////
44 46

  
......
323 325
      }
324 326
    }
325 327

  
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

  
330
  private MeshBase createCenterMesh(float width)
331
    {
332
    double X = width*COS18*SIN_HALFD;
333
    double Y = width*SIN18;
334
    double Z = width*COS18*COS_HALFD;
335
    double H = width*(SIN54/COS54);
336
    double H3= H/COS_HALFD;
337
    double X3= H*SIN_HALFD;
338
    double Z3= H*COS_HALFD;;
339
    double C = 1/(COS54*Math.sqrt(2-2*SIN18));
340

  
341
    double[][] vertices = new double[][]
342
        {
343
            { 0.0, 0.0  ,   0.0 },
344
            {   X,   Y  ,    -Z },
345
            { 0.0,C*2*Y ,-2*C*Z },
346
            {  -X,   Y  ,    -Z },
347
            { 0.0,-width,   0.0 },
348
            {  X3,-width,   -Z3 },
349
            { 0.0,-width,   -H3 },
350
            { -X3,-width,   -Z3 }
351
        };
352

  
353
    int[][] vertIndexes = new int[][]
354
        {
355
            {4,5,1,0},
356
            {7,4,0,3},
357
            {0,1,2,3},
358
            {7,6,2,3},
359
            {6,5,1,2},
360
            {4,5,6,7}
361
        };
362

  
363
    float[][] bands     = new float[][]
364
      {
365
         {0.04f,17,0.3f,0.2f,5,1,1},
366
         {0.00f, 0,0.0f,0.5f,2,0,0}
367
      };
368

  
369
    float A = (2*SQ3/3)*SIN54;
370
    float B = 0.4f;
371

  
372
    int[] bandIndexes   = new int[] { 0,0,0,1,1,1};
373
    float[][] corners   = new float[][] { {0.03f,0.10f} };
374
    int[] cornerIndexes = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
375
    float[][] centers   = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
376
    int[] centerIndexes = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
377

  
378
    FactoryCubit factory = FactoryCubit.getInstance();
379
    factory.createNewFaceTransform(vertices,vertIndexes);
380

  
381
    return factory.createRoundedSolid(vertices, vertIndexes,
382
                                      bands, bandIndexes,
383
                                      corners, cornerIndexes,
384
                                      centers, centerIndexes,
385
                                      getNumCubitFaces() );
386
    }
387

  
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

  
390
  private MeshBase createEdgeMesh(int numLayers, float width, float height, boolean left)
391
    {
392
    double X = height*SIN_HALFD;
393
    double Y = height*SIN18/COS18;
394
    double Z = height*COS_HALFD;
395

  
396
    double[][] vertices = new double[][]
397
        {
398
            { 0.0, 0.0   , 0.0 },
399
            {   X,   Y   ,  -Z },
400
            { 0.0, 2*Y   ,-2*Z },
401
            {  -X,   Y   ,  -Z },
402
            { 0.0, -width, 0.0 },
403
            {   X, -width,  -Z },
404
            { 0.0, -width,-2*Z },
405
            {  -X, -width,  -Z },
406
        };
407

  
408
    int[][] vertIndexes = new int[][]
409
        {
410
            {4,5,1,0},
411
            {7,4,0,3},
412
            {7,6,2,3},
413
            {6,5,1,2},
414
            {0,1,2,3},
415
            {4,5,6,7}
416
        };
417

  
418
    if( !left )
419
      {
420
      int tmp, len = vertices.length;
421
      for(int i=0; i<len; i++) vertices[i][1] = -vertices[i][1];
422

  
423
      len = vertIndexes.length;
424
      for(int i=0; i<len; i++)
425
        {
426
        tmp = vertIndexes[i][0];
427
        vertIndexes[i][0] = vertIndexes[i][3];
428
        vertIndexes[i][3] = tmp;
429

  
430
        tmp = vertIndexes[i][1];
431
        vertIndexes[i][1] = vertIndexes[i][2];
432
        vertIndexes[i][2] = tmp;
433
        }
434
      }
435

  
436
    int numBands0 = numLayers<=5 ? 5 : 3;
437
    int numBands1 = numLayers<=5 ? 3 : 2;
438

  
439
    float[][] bands     = new float[][]
440
      {
441
         {0.04f,34,0.2f,0.2f,numBands0,1,1},
442
         {0.00f, 0,0.0f,0.0f,numBands1,0,0}
443
      };
444
    int[] bandIndexes   = new int[] { 0,0,1,1,1,1};
445
    float[][] corners   = new float[][] { {0.04f,0.10f} };
446
    int[] cornerIndexes = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
447
    float[][] centers   = new float[][] { {0.0f, -width/2, (float)(-2*Z)} };
448
    int[] centerIndexes = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
449

  
450
    FactoryCubit factory = FactoryCubit.getInstance();
451
    factory.createNewFaceTransform(vertices,vertIndexes);
452

  
453
    return factory.createRoundedSolid(vertices, vertIndexes,
454
                                      bands, bandIndexes,
455
                                      corners, cornerIndexes,
456
                                      centers, centerIndexes,
457
                                      getNumCubitFaces() );
458
    }
459

  
326 460
///////////////////////////////////////////////////////////////////////////////////////////////////
327 461

  
328 462
  MeshBase createCubitMesh(int cubit, int numLayers)
......
349 483
      if( mCornerMeshes[indexCornerEdge]==null )
350 484
        {
351 485
        float width = (numLayers/3.0f)/(numLayers-1);
352
        mCornerMeshes[indexCornerEdge] = FactoryCubit.getInstance().createMinxCornerMesh(numLayers,width);
486
        mCornerMeshes[indexCornerEdge] = createCornerMesh(numLayers,width);
353 487
        }
354 488
      mesh = mCornerMeshes[indexCornerEdge].copy(true);
355 489
      }
......
363 497
        float height= tmp*COS18;
364 498
        float width = tmp + (type/2)*tmp*SIN18;
365 499

  
366
        mEdgeMeshes[indexCornerEdge][type] = FactoryCubit.getInstance().createKilominxEdgeMesh(numLayers,width,height, (type%2)==0 );
500
        mEdgeMeshes[indexCornerEdge][type] = createEdgeMesh(numLayers,width,height, (type%2)==0 );
367 501
        }
368 502

  
369 503
      mesh = mEdgeMeshes[indexCornerEdge][type].copy(true);
......
375 509
      if( mCenterMeshes[indexCenter]==null )
376 510
        {
377 511
        float width = (1+0.5f*(numLayers-3)*SIN18)*(numLayers/3.0f)/(numLayers-1);
378
        mCenterMeshes[indexCenter] = FactoryCubit.getInstance().createKilominxCenterMesh(width);
512
        mCenterMeshes[indexCenter] = createCenterMesh(width);
379 513
        }
380 514

  
381 515
      mesh = mCenterMeshes[indexCenter].copy(true);
......
487 621
    int variant = face/COLORS;
488 622
    int numLayers = getNumLayers();
489 623

  
490
    if( variant == (numLayers-1)/2 || numLayers==3 )
624
    if( variant == (numLayers-1)/2 || numLayers==3 ) // center
491 625
      {
492
      float S = 0.07f;
493
      float R = 0.09f;
494

  
495
      float A = 0.86f;
496
      float X1= (SQ5+1)/8;
497
      float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
498
      float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
626
      float R = 0.10f;
627
      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 };
499 630

  
500
      float[] vertices = { -X1, Y2, 0, -A*Y1, X1, Y2, 0, Y1 };
631
      float cx = vertices[2];
632
      float cy = vertices[3];
633
      vertices[2] *= A;
634
      vertices[3] *= A;
501 635

  
502 636
      FactorySticker factory = FactorySticker.getInstance();
503 637
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%NUM_FACES], R);
504

  
505
      float MID = TEXTURE_HEIGHT*0.5f;
506
      float WID = TEXTURE_HEIGHT*0.1f;
507
      float HEI = TEXTURE_HEIGHT*(0.47f+Y1);
508
      canvas.drawLine(left+MID-WID,top+HEI,left+MID+WID,top+HEI,paint);
638
      canvas.drawCircle(left+(0.5f+cx)*TEXTURE_HEIGHT, top+(0.5f-cy)*TEXTURE_HEIGHT, 0.05f*TEXTURE_HEIGHT, paint);
509 639
      }
510
    else if( variant==0 )
640
    else if( variant==0 ) // corner
511 641
      {
512
      float Y = COS54/(2*SIN54);
513
      float R = 0.09f;
514
      float S = 0.09f;
515
      float[] vertices = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y };
642
      float R = 0.10f;
643
      float S = 0.11f;
644
      float[] vertices = { -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f };
516 645

  
517 646
      FactorySticker factory = FactorySticker.getInstance();
518 647
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
519 648
      }
520
    else
649
    else  // edge
521 650
      {
522
      float R = 0.07f;
523
      float S = 0.07f;
524

  
525
      float tmp   = (numLayers/3.0f)/(numLayers-1);
526
      float height= tmp*COS18;
527
      float width = tmp + (variant-1)*tmp*SIN18;
528
      float D = height/COS18;
529
      float W = D*SIN18;
530
      float X1 = height/2;
531
      float Y1 = width/2;
532
      float[] vertices = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 };
651
      float R = 0.10f;
652
      float S = 0.10f;
653
      float[] vertices = { -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f };
533 654

  
534 655
      FactorySticker factory = FactorySticker.getInstance();
535 656
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);

Also available in: Unified diff