Project

General

Profile

« Previous | Next » 

Revision 53ca4624

Added by Leszek Koltunski over 1 year ago

Preparation for Camouflage Cubes.

View differences:

src/main/java/org/distorted/objectlib/objects/TwistyBandagedCuboid.java
163 163
  private int[][] mSolvedQuatsAbstract;
164 164
  private float[][] mPosition;
165 165
  private ObjectSignature mSignature;
166
  private ObjectShape[] mTmpShapes;
167
  private int mNumVariants;
166 168

  
167 169
///////////////////////////////////////////////////////////////////////////////////////////////////
168 170

  
......
382 384

  
383 385
///////////////////////////////////////////////////////////////////////////////////////////////////
384 386

  
385
  public ObjectShape getObjectShape(int variant)
387
  private void produceTmpShape(int variant)
388
    {
389
    float[][] positions = getPositions();
390
    int cubit,numCubits = positions.length;
391

  
392
    for(cubit=0; cubit<numCubits; cubit++)
393
      {
394
      if( mCubitVariantMap[cubit]==variant ) break;
395
      }
396

  
397
    if( cubit>=numCubits )
398
      {
399
      android.util.Log.e("D", "unknown variant: "+variant);
400
      }
401
    else
402
      {
403
      FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
404
      mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]);
405
      }
406
    }
407

  
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409

  
410
  private float[][] getVertices(int variant)
386 411
    {
387 412
    int type,numTypes = mDims.length;
388 413
    for(type=0; type<numTypes; type++) if( mTypeVariantMap[type]==variant ) break;
......
393 418
      int Y = mDims[type][1];
394 419
      int Z = mDims[type][2];
395 420

  
396
      float[][] vertices =
421
      return new float[][]
397 422
        {
398 423
          { 0.5f*X, 0.5f*Y, 0.5f*Z},
399 424
          { 0.5f*X, 0.5f*Y,-0.5f*Z},
......
404 429
          {-0.5f*X,-0.5f*Y, 0.5f*Z},
405 430
          {-0.5f*X,-0.5f*Y,-0.5f*Z}
406 431
        };
432
      }
433

  
434
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
435
    if( mTmpShapes[variant]==null ) produceTmpShape(variant);
436
    return mTmpShapes[variant].getVertices();
437
    }
438

  
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

  
441
  public ObjectShape getObjectShape(int variant)
442
    {
443
    int type,numTypes = mDims.length;
444
    for(type=0; type<numTypes; type++) if( mTypeVariantMap[type]==variant ) break;
407 445

  
446
    if( type<numTypes )
447
      {
408 448
      int[][] indices =
409 449
        {
410 450
          {2,3,1,0},
......
415 455
          {3,7,5,1},
416 456
        };
417 457

  
418
      return new ObjectShape(vertices, indices);
419
      }
420

  
421
    float[][] positions = getPositions();
422
    int cubit,numCubits = positions.length;
423

  
424
    for(cubit=0; cubit<numCubits; cubit++)
425
      {
426
      if( mCubitVariantMap[cubit]==variant ) break;
427
      }
428

  
429
    if( cubit>=numCubits )
430
      {
431
      android.util.Log.e("D", "unknown variant: "+variant);
432
      return null;
458
      return new ObjectShape( getVertices(variant), indices);
433 459
      }
434 460

  
435
    FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
436
    return factory.createIrregularShape(variant,positions[cubit]);
461
    if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
462
    if( mTmpShapes[variant]==null )produceTmpShape(variant);
463
    return mTmpShapes[variant];
437 464
    }
438 465

  
439 466
///////////////////////////////////////////////////////////////////////////////////////////////////
......
484 511
    int[] numLayers = getNumLayers();
485 512
    int size = (numLayers[0]+numLayers[1]+numLayers[2])/3;
486 513
    boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
514

  
487 515
    int type,numTypes = mDims.length;
488 516
    for(type=0; type<numTypes; type++) if( mTypeVariantMap[type]==variant ) break;
489 517

  
490 518
    if( type<numTypes )
491 519
      {
492
      int X = mDims[type][0];
493
      int Y = mDims[type][1];
494
      int Z = mDims[type][2];
495

  
496
      float[][] centers =
497
        {
498
          { 0.5f*X, 0.5f*Y, 0.5f*Z},
499
          { 0.5f*X, 0.5f*Y,-0.5f*Z},
500
          { 0.5f*X,-0.5f*Y, 0.5f*Z},
501
          { 0.5f*X,-0.5f*Y,-0.5f*Z},
502
          {-0.5f*X, 0.5f*Y, 0.5f*Z},
503
          {-0.5f*X, 0.5f*Y,-0.5f*Z},
504
          {-0.5f*X,-0.5f*Y, 0.5f*Z},
505
          {-0.5f*X,-0.5f*Y,-0.5f*Z}
506
        };
507

  
520
      float[][] vertices = getVertices(variant);
508 521
      float strength = -0.04f;
509 522

  
510 523
      float[][] variables =
511 524
        {
512
          { 0, strength*centers[0][0], strength*centers[0][1], strength*centers[0][2], 1  },
513
          { 0, strength*centers[1][0], strength*centers[1][1], strength*centers[1][2], 1  },
514
          { 0, strength*centers[2][0], strength*centers[2][1], strength*centers[2][2], 1  },
515
          { 0, strength*centers[3][0], strength*centers[3][1], strength*centers[3][2], 1  },
516
          { 0, strength*centers[4][0], strength*centers[4][1], strength*centers[4][2], 1  },
517
          { 0, strength*centers[5][0], strength*centers[5][1], strength*centers[5][2], 1  },
518
          { 0, strength*centers[6][0], strength*centers[6][1], strength*centers[6][2], 1  },
519
          { 0, strength*centers[7][0], strength*centers[7][1], strength*centers[7][2], 1  },
525
          { 0, strength*vertices[0][0], strength*vertices[0][1], strength*vertices[0][2], 1  },
526
          { 0, strength*vertices[1][0], strength*vertices[1][1], strength*vertices[1][2], 1  },
527
          { 0, strength*vertices[2][0], strength*vertices[2][1], strength*vertices[2][2], 1  },
528
          { 0, strength*vertices[3][0], strength*vertices[3][1], strength*vertices[3][2], 1  },
529
          { 0, strength*vertices[4][0], strength*vertices[4][1], strength*vertices[4][2], 1  },
530
          { 0, strength*vertices[5][0], strength*vertices[5][1], strength*vertices[5][2], 1  },
531
          { 0, strength*vertices[6][0], strength*vertices[6][1], strength*vertices[6][2], 1  },
532
          { 0, strength*vertices[7][0], strength*vertices[7][1], strength*vertices[7][2], 1  },
520 533
        };
521 534

  
522 535
      String name = EffectName.DEFORM.name();
......
526 539
      float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg};
527 540
      boolean[] uses = {round,round,round,round,round,round,round,round};
528 541

  
529
      return new ObjectVertexEffects(names,variables,centers,regions,uses);
542
      return new ObjectVertexEffects(names,variables,vertices,regions,uses);
530 543
      }
531 544

  
532 545
    FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
......
564 577

  
565 578
  public int getNumCubitVariants(int[] numLayers)
566 579
    {
567
    int numVariants = 0;
568
    float[][] positions = getPositions();
569
    boolean C111=false;
570
    boolean C211=false;
571
    boolean C311=false;
572
    boolean C221=false;
573
    boolean C222=false;
574

  
575
    int numCubits = positions.length;
576
    mCubitVariantMap = new int[numCubits];
580
    if( mNumVariants==0 )
581
      {
582
      float[][] positions = getPositions();
583
      boolean C111=false;
584
      boolean C211=false;
585
      boolean C311=false;
586
      boolean C221=false;
587
      boolean C222=false;
577 588

  
578
    int numTypes = mDims.length;
579
    mTypeVariantMap = new int[numTypes];
580
    for(int i=0; i<numTypes; i++) mTypeVariantMap[i] = -1;
589
      int numCubits = positions.length;
590
      mCubitVariantMap = new int[numCubits];
581 591

  
582
    for (int cubit=0; cubit<numCubits; cubit++)
583
      {
584
      int type = getType(positions[cubit]);
592
      int numTypes = mDims.length;
593
      mTypeVariantMap = new int[numTypes];
594
      for(int i=0; i<numTypes; i++) mTypeVariantMap[i] = -1;
585 595

  
586
      switch (type)
596
      for (int cubit=0; cubit<numCubits; cubit++)
587 597
        {
588
        case CUBIT_111: if (!C111) { C111 = true; mTypeVariantMap[CUBIT_111]=numVariants++; }
589
                        mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_111];
590
                        break;
591
        case CUBIT_211: if (!C211) { C211 = true; mTypeVariantMap[CUBIT_211]=numVariants++; }
592
                        mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_211];
593
                        break;
594
        case CUBIT_311: if (!C311) { C311 = true; mTypeVariantMap[CUBIT_311]=numVariants++; }
595
                        mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_311];
596
                        break;
597
        case CUBIT_221: if (!C221) { C221 = true; mTypeVariantMap[CUBIT_221]=numVariants++; }
598
                        mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_221];
599
                        break;
600
        case CUBIT_222: if (!C222) { C222 = true; mTypeVariantMap[CUBIT_222]=numVariants++; }
601
                        mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_222];
602
                        break;
603
        default       : mCubitVariantMap[cubit] = numVariants++;
598
        int type = getType(positions[cubit]);
599

  
600
        switch (type)
601
          {
602
          case CUBIT_111: if (!C111) { C111 = true; mTypeVariantMap[CUBIT_111]=mNumVariants++; }
603
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_111];
604
                          break;
605
          case CUBIT_211: if (!C211) { C211 = true; mTypeVariantMap[CUBIT_211]=mNumVariants++; }
606
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_211];
607
                          break;
608
          case CUBIT_311: if (!C311) { C311 = true; mTypeVariantMap[CUBIT_311]=mNumVariants++; }
609
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_311];
610
                          break;
611
          case CUBIT_221: if (!C221) { C221 = true; mTypeVariantMap[CUBIT_221]=mNumVariants++; }
612
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_221];
613
                          break;
614
          case CUBIT_222: if (!C222) { C222 = true; mTypeVariantMap[CUBIT_222]=mNumVariants++; }
615
                          mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_222];
616
                          break;
617
          default       : mCubitVariantMap[cubit] = mNumVariants++;
618
          }
604 619
        }
605
      }
606 620

  
607
    FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
608
    factory.prepare(numVariants,numLayers[0],numLayers[1],numLayers[2]);
621
      FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
622
      factory.prepare(mNumVariants,numLayers[0],numLayers[1],numLayers[2]);
623
      }
609 624

  
610
    return numVariants;
625
    return mNumVariants;
611 626
    }
612 627

  
613 628
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff