Project

General

Profile

« Previous | Next » 

Revision 221a4090

Added by Leszek Koltunski about 3 years ago

Simplification with objects.

View differences:

src/main/java/org/distorted/objects/TwistyMegaminx.java
582 582
    return true;
583 583
    }
584 584

  
585
///////////////////////////////////////////////////////////////////////////////////////////////////
586
// return if the Cubit, when rotated with its own mQuatScramble, would have looked any different
587
// then if it were rotated by quaternion 'quat'.
588
// No it is not so simple as the quats need to be the same - imagine a 4x4x4 cube where the two
589
// middle squares get interchanged. No visible difference!
590
//
591
// So: this is true iff the cubit
592
// a) is a corner or edge and the quaternions are the same
593
// b) is inside one of the faces and after rotations by both quats it ends up on the same face.
594

  
595
  private boolean thereIsNoVisibleDifference(Cubit cubit, int quatIndex)
596
    {
597
    if ( cubit.mQuatIndex == quatIndex ) return true;
598

  
599
    int belongsToHowManyFaces = 0;
600
    int lastLayer = getNumLayers()-1;
601
    float row;
602
    final float MAX_ERROR = 0.01f;
603

  
604
    for(int i=0; i<NUM_AXIS; i++)
605
      {
606
      row = cubit.mRotationRow[i];
607
      if( (row          <MAX_ERROR && row          >-MAX_ERROR) ||
608
          (row-lastLayer<MAX_ERROR && row-lastLayer>-MAX_ERROR)  ) belongsToHowManyFaces++;
609
      }
610

  
611
    switch(belongsToHowManyFaces)
612
      {
613
      case 0 : return true ;  // 'inside' cubit that does not lie on any face
614
      case 1 :                // cubit that lies inside one of the faces
615
               Static3D orig = cubit.getOrigPosition();
616
               Static4D quat1 = QUATS[quatIndex];
617
               Static4D quat2 = QUATS[cubit.mQuatIndex];
618

  
619
               Static4D cubitCenter = new Static4D( orig.get0(), orig.get1(), orig.get2(), 0);
620
               Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 );
621
               Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 );
622

  
623
               float row1, row2;
624
               float x1 = rotated1.get0();
625
               float y1 = rotated1.get1();
626
               float z1 = rotated1.get2();
627
               float x2 = rotated2.get0();
628
               float y2 = rotated2.get1();
629
               float z2 = rotated2.get2();
630

  
631
               for(int i=0; i<NUM_AXIS; i++)
632
                 {
633
                 row1 = computeRow(x1,y1,z1,i);
634
                 row2 = computeRow(x2,y2,z2,i);
635

  
636
                 if( (row1==0 && row2==0) || (row1==lastLayer && row2==lastLayer) ) return true;
637
                 }
638
               return false;
639

  
640
      default: return false;  // edge or corner
641
      }
642
    }
643

  
644 585
///////////////////////////////////////////////////////////////////////////////////////////////////
645 586

  
646 587
  public int getObjectName(int numLayers)

Also available in: Unified diff