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/TwistyCube.java
216 216

  
217 217
  int getFaceColor(int cubit, int cubitface, int size)
218 218
    {
219
    float diff = CUBITS[cubit].mRotationRow[cubitface/2] - (cubitface%2==0 ? size-1:0);
220
    return diff*diff < 0.0001f ? cubitface : NUM_FACES;
219
    return CUBITS[cubit].mRotationRow[cubitface/2] == (cubitface%2==0 ? size-1:0) ? cubitface : NUM_FACES;
221 220
    }
222 221

  
223 222
///////////////////////////////////////////////////////////////////////////////////////////////////
......
301 300
    return true;
302 301
    }
303 302

  
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305
// return if the Cubit, when rotated with its own mQuatScramble, would have looked any different
306
// then if it were rotated by quaternion 'quat'.
307
// No it is not so simple as the quats need to be the same - imagine a 4x4x4 cube where the two
308
// middle squares get interchanged. No visible difference!
309
//
310
// So: this is true iff the cubit
311
// a) is a corner or edge and the quaternions are the same
312
// b) is inside one of the faces and after rotations by both quats it ends up on the same face.
313

  
314
  private boolean thereIsNoVisibleDifference(Cubit cubit, int quatIndex)
315
    {
316
    if ( cubit.mQuatIndex == quatIndex ) return true;
317

  
318
    int belongsToHowManyFaces = 0;
319
    int lastLayer = getNumLayers()-1;
320
    float row;
321
    final float MAX_ERROR = 0.01f;
322

  
323
    for(int i=0; i<NUM_AXIS; i++)
324
      {
325
      row = cubit.mRotationRow[i];
326
      if( (row          <MAX_ERROR && row          >-MAX_ERROR) ||
327
          (row-lastLayer<MAX_ERROR && row-lastLayer>-MAX_ERROR)  ) belongsToHowManyFaces++;
328
      }
329

  
330
    switch(belongsToHowManyFaces)
331
      {
332
      case 0 : return true ;  // 'inside' cubit that does not lie on any face
333
      case 1 :                // cubit that lies inside one of the faces
334
               Static3D orig = cubit.getOrigPosition();
335
               Static4D quat1 = QUATS[quatIndex];
336
               Static4D quat2 = QUATS[cubit.mQuatIndex];
337

  
338
               Static4D cubitCenter = new Static4D( orig.get0(), orig.get1(), orig.get2(), 0);
339
               Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 );
340
               Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 );
341

  
342
               float row1, row2;
343
               float x1 = rotated1.get0();
344
               float y1 = rotated1.get1();
345
               float z1 = rotated1.get2();
346
               float x2 = rotated2.get0();
347
               float y2 = rotated2.get1();
348
               float z2 = rotated2.get2();
349

  
350
               for(int i=0; i<NUM_AXIS; i++)
351
                 {
352
                 row1 = computeRow(x1,y1,z1,i);
353
                 row2 = computeRow(x2,y2,z2,i);
354

  
355
                 if( (row1==0 && row2==0) || (row1==lastLayer && row2==lastLayer) ) return true;
356
                 }
357
               return false;
358

  
359
      default: return false;  // edge or corner
360
      }
361
    }
362

  
363 303
///////////////////////////////////////////////////////////////////////////////////////////////////
364 304
// order: Up --> Right --> Front --> Down --> Left --> Back
365 305
// (because the first implemented Solver - the two-phase Cube3 one - expects such order)

Also available in: Unified diff