Project

General

Profile

« Previous | Next » 

Revision 8e4a3670

Added by Leszek Koltunski over 3 years ago

Convert Megaminx to the new scheme.

View differences:

src/main/java/org/distorted/objects/TwistyMegaminx.java
22 22
import android.content.res.Resources;
23 23

  
24 24
import org.distorted.helpers.FactoryCubit;
25
import org.distorted.helpers.ObjectShape;
25 26
import org.distorted.helpers.ObjectSticker;
26 27
import org.distorted.helpers.QuatHelper;
27 28
import org.distorted.library.effect.MatrixEffectQuaternion;
......
298 299

  
299 300
///////////////////////////////////////////////////////////////////////////////////////////////////
300 301

  
301
  MeshBase createEdgeMesh(int numLayers, float width, float height)
302
  ObjectShape getObjectShape(int cubit, int numLayers)
302 303
    {
303
    double W = width/2;
304
    double X = height*SIN_HALFD;
305
    double Y = height*SIN18/COS18;
306
    double Z = height*COS_HALFD;
304
    int variant = getCubitVariant(cubit,numLayers);
305
    int numVariants = getNumCubitVariants(numLayers);
307 306

  
308
    double[][] vertices = new double[][]
307
    if( variant==0 )
308
      {
309
      float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
310
      float A = (2*SQ3/3)*SIN54;
311
      float B = 0.4f;
312
      double X = width*COS18*SIN_HALFD;
313
      double Y = width*SIN18;
314
      double Z = width*COS18*COS_HALFD;
315
      int N = numLayers==3 ? 1:0;
316

  
317
      double[][] vertices = new double[][]
318
        {
319
            { 0.0, 0.0      , 0.0 },
320
            {   X,   Y      ,  -Z },
321
            { 0.0, 2*Y      ,-2*Z },
322
            {  -X,   Y      ,  -Z },
323
            { 0.0, 0.0-width, 0.0 },
324
            {   X,   Y-width,  -Z },
325
            { 0.0, 2*Y-width,-2*Z },
326
            {  -X,   Y-width,  -Z },
327
        };
328

  
329
      int[][] vertIndexes = new int[][]
330
        {
331
            {4,5,1,0},
332
            {7,4,0,3},
333
            {0,1,2,3},
334
            {4,5,6,7},
335
            {6,5,1,2},
336
            {7,6,2,3}
337
        };
338

  
339
      float[][] bands    = new float[][]
340
        {
341
         {0.04f,34,0.3f,0.2f, 3, N, 0},
342
         {0.00f, 0,0.0f,0.0f, 2, N, 0}
343
        };
344

  
345
      int[] bandIndices   = new int[] { 0,0,0,1,1,1};
346
      float[][] corners   = new float[][] { {0.04f,0.10f} };
347
      int[] cornerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
348
      float[][] centers   = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
349
      int[] centerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
350

  
351
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
352
      }
353
    if( variant<numVariants-1 )
354
      {
355
      int numCubitsPerCorner = numCubitsPerCorner(numLayers);
356
      int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
357
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
358
      float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
359
      float width = (numLayers/3.0f)*2*MEGA_D + 2*type*height*SIN18/COS18;
360

  
361
      double W = width/2;
362
      double X = height*SIN_HALFD;
363
      double Y = height*SIN18/COS18;
364
      double Z = height*COS_HALFD;
365

  
366
      double[][] vertices = new double[][]
309 367
        {
310 368
            { 0.0,   W   , 0.0 },
311 369
            {   X, W+Y   ,  -Z },
......
317 375
            {  -X,-W-Y   ,  -Z },
318 376
        };
319 377

  
320
    int[][] vertIndexes = new int[][]
378
      int[][] vertIndexes = new int[][]
321 379
        {
322 380
            {4,5,1,0},
323 381
            {7,4,0,3},
......
327 385
            {4,5,6,7}
328 386
        };
329 387

  
330
    int N = numLayers<=5 ? 5 : 3;
388
      int N = numLayers<=5 ? 5 : 3;
331 389

  
332
    float[][] bands     = new float[][]
333
      {
390
      float[][] bands     = new float[][]
391
        {
334 392
         {0.04f,34,0.2f,0.2f,N,0,0},
335 393
         {0.00f, 0,0.3f,0.2f,2,0,0}
336
      };
337
    int[] bandIndexes   = new int[] { 0,0,1,1,1,1};
338
    float[][] corners   = new float[][] { {0.04f,0.10f} };
339
    int[] cornerIndexes = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
340
    float[][] centers   = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} };
341
    int[] centerIndexes = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
342

  
343
    FactoryCubit factory = FactoryCubit.getInstance();
344
    factory.createNewFaceTransform(vertices,vertIndexes);
345

  
346
    return factory.createRoundedSolid(vertices, vertIndexes,
347
                                      bands, bandIndexes,
348
                                      corners, cornerIndexes,
349
                                      centers, centerIndexes,
350
                                      getNumCubitFaces(), null );
351
    }
352

  
353
///////////////////////////////////////////////////////////////////////////////////////////////////
394
        };
395
      int[] bandIndices   = new int[] { 0,0,1,1,1,1};
396
      float[][] corners   = new float[][] { {0.04f,0.10f} };
397
      int[] cornerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
398
      float[][] centers   = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} };
399
      int[] centerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
354 400

  
355
  MeshBase createCenterMesh(int numLayers, float width)
356
    {
357
    final double V = 0.83;   // ??
358
    final double ANGLE = V*Math.PI;
359
    final double cosA  = Math.cos(ANGLE);
360
    final double sinA  = Math.sin(ANGLE);
361

  
362
    float R  = 0.5f*width/COS54;
363
    float X1 = R*COS54;
364
    float Y1 = R*SIN54;
365
    float X2 = R*COS18;
366
    float Y2 = R*SIN18;
367

  
368
    double[][] vertices = new double[][]
401
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
402
      }
403
    else
369 404
      {
405
      float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18);
406
      final double V = 0.83;   // ??
407
      final double ANGLE = V*Math.PI;
408
      final double cosA  = Math.cos(ANGLE);
409
      final double sinA  = Math.sin(ANGLE);
410

  
411
      float R  = 0.5f*width/COS54;
412
      float X1 = R*COS54;
413
      float Y1 = R*SIN54;
414
      float X2 = R*COS18;
415
      float Y2 = R*SIN18;
416

  
417
      double[][] vertices = new double[][]
418
        {
370 419
          {-X1,+Y1*sinA, Y1*cosA},
371 420
          {-X2,-Y2*sinA,-Y2*cosA},
372 421
          {0.0f,-R*sinA, -R*cosA},
373 422
          {+X2,-Y2*sinA,-Y2*cosA},
374 423
          {+X1,+Y1*sinA, Y1*cosA}
375
      };
424
        };
376 425

  
377
    int[][] vertIndexes = new int[][]
378
      {
426
      int[][] vertIndexes = new int[][]
427
        {
379 428
          {0,1,2,3,4},
380 429
          {0,1,2,3,4}
381
      };
430
        };
382 431

  
383
    int N = numLayers==3 ? 4 : 3;
432
      int N = numLayers==3 ? 4 : 3;
384 433

  
385
    float[][] bands = new float[][]
386
      {
434
      float[][] bands = new float[][]
435
        {
387 436
         {0.04f,45, R/3,0.2f,N,0,0},
388 437
         {0.00f, 0, R/3,0.2f,2,0,0}
389
      };
390
    int[] bandIndexes   = new int[] { 0,1 };
391
    float[][] corners   = new float[][] { {0.04f,0.10f} };
392
    int[] cornerIndexes = new int[] { -1,-1,-1,-1, -1 };
393
    float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
394
    int[] centerIndexes = new int[] { -1,-1,-1,-1, -1 };
395

  
396
    FactoryCubit factory = FactoryCubit.getInstance();
397
    factory.createNewFaceTransform(vertices,vertIndexes);
398

  
399
    return factory.createRoundedSolid(vertices, vertIndexes,
400
                                      bands, bandIndexes,
401
                                      corners, cornerIndexes,
402
                                      centers, centerIndexes,
403
                                      getNumCubitFaces(), null );
438
        };
439

  
440
      int[] bandIndices   = new int[] { 0,1 };
441
      float[][] corners   = new float[][] { {0.04f,0.10f} };
442
      int[] cornerIndices = new int[] { -1,-1,-1,-1, -1 };
443
      float[][] centers   = new float[][] { {0.0f, 0.0f, 0.0f} };
444
      int[] centerIndices = new int[] { -1,-1,-1,-1, -1 };
445

  
446
      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
447
      }
404 448
    }
405 449

  
450

  
406 451
///////////////////////////////////////////////////////////////////////////////////////////////////
407 452

  
408
  MeshBase createCubitMesh(int cubit, int numLayers)
453
  private Static4D getQuat(int cubit, int numLayers)
409 454
    {
410 455
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
411 456
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
457

  
458
    return QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
459
    }
460

  
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

  
463
  private int getNumCubitVariants(int numLayers)
464
    {
412 465
    int[] sizes = ObjectList.MEGA.getSizes();
413 466
    int variants = sizes.length;
414
    int numShapes = 2+(sizes[variants-1]-1)/2;
415
    MeshBase mesh;
416 467

  
417
    if( mMeshes==null ) mMeshes = new MeshBase[numShapes];
468
    return 2+(sizes[variants-1]-1)/2;
469
    }
418 470

  
419
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
420
      {
421
      if( mMeshes[0]==null )
422
        {
423
        float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
424
        mMeshes[0] = createCornerMesh(numLayers, width);
425
        }
426
      mesh = mMeshes[0].copy(true);
427
      }
428
    else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

  
473
  int getCubitVariant(int cubit, int numLayers)
474
    {
475
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
476

  
477
    if( cubit<NUM_CORNERS*numCubitsPerCorner ) return 0;
478

  
479
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
480

  
481
    if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
429 482
      {
430 483
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
484
      return type+1;
485
      }
431 486

  
432
      if( mMeshes[1+type]==null )
433
        {
434
        float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
435
        float width = (numLayers/3.0f)*2*MEGA_D + 2*type*height*SIN18/COS18;
487
    int[] sizes = ObjectList.MEGA.getSizes();
488
    int variants = sizes.length;
489
    int numShapes = 2+(sizes[variants-1]-1)/2;
436 490

  
437
        mMeshes[1+type] = createEdgeMesh(numLayers,width,height);
438
        }
439
      mesh = mMeshes[1+type].copy(true);
440
      }
441
    else
491
    return numShapes-1;
492
    }
493

  
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

  
496
  MeshBase createCubitMesh(int cubit, int numLayers)
497
    {
498
    int variant = getCubitVariant(cubit,numLayers);
499

  
500
    if( mMeshes==null )
442 501
      {
443
      if( mMeshes[numShapes-1]==null )
444
        {
445
        float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18);
446
        mMeshes[numShapes-1] = createCenterMesh(numLayers,width);
447
        }
502
      FactoryCubit factory = FactoryCubit.getInstance();
503
      factory.clear();
504
      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
505
      }
448 506

  
449
      mesh = mMeshes[numShapes-1].copy(true);
507
    if( mMeshes[variant]==null )
508
      {
509
      ObjectShape shape = getObjectShape(cubit,numLayers);
510
      FactoryCubit factory = FactoryCubit.getInstance();
511
      factory.createNewFaceTransform(shape);
512
      mMeshes[variant] = factory.createRoundedSolid(shape);
450 513
      }
451 514

  
452
    Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
453
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( q, new Static3D(0,0,0) );
515
    MeshBase mesh = mMeshes[variant].copy(true);
516
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
454 517
    mesh.apply(quat,0xffffffff,0);
455 518

  
456 519
    return mesh;
src/main/java/org/distorted/objects/TwistyMinx.java
373 373
    return 2.0f;
374 374
    }
375 375

  
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

  
378
  MeshBase createCornerMesh(int numLayers, float width)
379
    {
380
    float A = (2*SQ3/3)*SIN54;
381
    float B = 0.4f;
382
    int   N = numLayers==3 ? 5 : 3;
383
    int   E1= numLayers==3 ? 1 : 0;
384
    int   E2= numLayers==3 ? 3 : 0;
385

  
386
    double X = width*COS18*SIN_HALFD;
387
    double Y = width*SIN18;
388
    double Z = width*COS18*COS_HALFD;
389

  
390
    double[][] vertices = new double[][]
391
        {
392
            { 0.0, 0.0      , 0.0 },
393
            {   X,   Y      ,  -Z },
394
            { 0.0, 2*Y      ,-2*Z },
395
            {  -X,   Y      ,  -Z },
396
            { 0.0, 0.0-width, 0.0 },
397
            {   X,   Y-width,  -Z },
398
            { 0.0, 2*Y-width,-2*Z },
399
            {  -X,   Y-width,  -Z },
400
        };
401

  
402
    int[][] vertIndexes = new int[][]
403
        {
404
            {4,5,1,0},
405
            {7,4,0,3},
406
            {0,1,2,3},
407
            {4,5,6,7},
408
            {6,5,1,2},
409
            {7,6,2,3}
410
        };
411

  
412
    float[][] bands     = new float[][]
413
      {
414
         {0.04f,34,0.3f,0.2f, N, 1, E1},
415
         {0.00f, 0,0.0f,0.0f, 2, 1, E2}
416
      };
417
    int[] bandIndexes   = new int[] { 0,0,0,1,1,1};
418
    float[][] corners   = new float[][] { {0.04f,0.10f} };
419
    int[] cornerIndexes = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
420
    float[][] centers   = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
421
    int[] centerIndexes = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
422

  
423
    FactoryCubit factory = FactoryCubit.getInstance();
424
    factory.createNewFaceTransform(vertices,vertIndexes);
425

  
426
    return factory.createRoundedSolid(vertices, vertIndexes,
427
                                      bands, bandIndexes,
428
                                      corners, cornerIndexes,
429
                                      centers, centerIndexes,
430
                                      getNumCubitFaces(), null );
431
    }
432

  
433 376
///////////////////////////////////////////////////////////////////////////////////////////////////
434 377

  
435 378
  private void initializeScrambleTable(int[] first, int numLayers)

Also available in: Unified diff