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/TwistyObject.java
47 47
import org.distorted.library.type.Static3D;
48 48
import org.distorted.library.type.Static4D;
49 49
import org.distorted.main.BuildConfig;
50
import org.distorted.main.RubikSurfaceView;
50 51

  
51 52
import java.io.DataInputStream;
52 53
import java.io.IOException;
......
306 307

  
307 308
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
308 309
    {
309
    int cubitRow = (int)(CUBITS[cubit].mRotationRow[axis]+0.5f);
310
    return ((1<<cubitRow)&rowBitmap)!=0;
310
    return ((1<<CUBITS[cubit].mRotationRow[axis]) & rowBitmap) != 0;
311 311
    }
312 312

  
313 313
///////////////////////////////////////////////////////////////////////////////////////////////////
......
396 396
    pos.set( mOrigPos[minErrorIndex] );
397 397
    }
398 398

  
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400
// return if the Cubit, when rotated with its own mQuatScramble, would have looked any different
401
// then if it were rotated by quaternion 'quat'.
402
// No it is not so simple as the quats need to be the same - imagine a 4x4x4 cube where the two
403
// middle squares get interchanged. No visible difference!
404
//
405
// So: this is true iff the cubit
406
// a) is a corner or edge and the quaternions are the same
407
// b) is inside one of the faces and after rotations by both quats it ends up on the same face.
408

  
409
  boolean thereIsNoVisibleDifference(Cubit cubit, int quatIndex)
410
    {
411
    if ( cubit.mQuatIndex == quatIndex ) return true;
412

  
413
    int belongsToHowManyFaces = 0;
414
    int lastLayer = getNumLayers()-1;
415
    int row;
416

  
417
    for(int i=0; i<NUM_AXIS; i++)
418
      {
419
      row = cubit.mRotationRow[i];
420
      if( row==0 || row==lastLayer ) belongsToHowManyFaces++;
421
      }
422

  
423
    switch(belongsToHowManyFaces)
424
      {
425
      case 0 : return true ;  // 'inside' cubit that does not lie on any face
426
      case 1 :                // cubit that lies inside one of the faces
427
               Static3D orig = cubit.getOrigPosition();
428
               Static4D quat1 = QUATS[quatIndex];
429
               Static4D quat2 = QUATS[cubit.mQuatIndex];
430

  
431
               Static4D cubitCenter = new Static4D( orig.get0(), orig.get1(), orig.get2(), 0);
432
               Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 );
433
               Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 );
434

  
435
               float row1, row2;
436
               float x1 = rotated1.get0();
437
               float y1 = rotated1.get1();
438
               float z1 = rotated1.get2();
439
               float x2 = rotated2.get0();
440
               float y2 = rotated2.get1();
441
               float z2 = rotated2.get2();
442

  
443
               for(int i=0; i<NUM_AXIS; i++)
444
                 {
445
                 row1 = computeRow(x1,y1,z1,i);
446
                 row2 = computeRow(x2,y2,z2,i);
447

  
448
                 if( (row1==0 && row2==0) || (row1==lastLayer && row2==lastLayer) ) return true;
449
                 }
450
               return false;
451

  
452
      default: return false;  // edge or corner
453
      }
454
    }
455

  
399 456
///////////////////////////////////////////////////////////////////////////////////////////////////
400 457
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size)
401 458

  

Also available in: Unified diff