Project

General

Profile

« Previous | Next » 

Revision f6d06256

Added by Leszek Koltunski over 3 years ago

Move the knowledge about colors of individual cubit faces down to each Object subclass.

View differences:

src/main/java/org/distorted/objects/RubikCube.java
166 166
    return 0.5f;
167 167
    }
168 168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
  int getFaceColor(int cubit, int cubitface, int size)
172
    {
173
    boolean belongs = isOnFace(cubit, cubitface/2, cubitface%2==0 ? size-1:0 );
174
    return belongs ? cubitface : NUM_FACES;
175
    }
176

  
169 177
///////////////////////////////////////////////////////////////////////////////////////////////////
170 178

  
171 179
  MeshBase createCubitMesh(int cubit)
src/main/java/org/distorted/objects/RubikDino.java
100 100
           new Static3D(-0.5f, 0.0f,-0.5f )
101 101
         };
102 102

  
103
  private static final int[] mFaceMap = {2,4, 4,0, 3,4, 4,1,
104
                                         0,2, 0,3, 1,3, 1,2,
105
                                         2,5, 5,0, 3,5, 5,1 };
106

  
103 107
  private static MeshBase mMesh;
104 108

  
105 109
///////////////////////////////////////////////////////////////////////////////////////////////////
......
273 277
    return mesh;
274 278
    }
275 279

  
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

  
282
  int getFaceColor(int cubit, int cubitface, int size)
283
    {
284
    switch(cubitface)
285
      {
286
      case 0 : return mFaceMap[2*cubit];
287
      case 1 : return mFaceMap[2*cubit+1];
288
      default: return NUM_FACES;
289
      }
290
    }
291

  
276 292
///////////////////////////////////////////////////////////////////////////////////////////////////
277 293

  
278 294
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
src/main/java/org/distorted/objects/RubikObject.java
274 274
    return ((1<<cubitRow)&rowBitmap)!=0;
275 275
    }
276 276

  
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278
// we cannot use belongsToRotation for deciding if to texture a face. Counterexample: the 'rotated'
279
// tetrahedrons of Pyraminx nearby the edge: they belong to rotation but their face which is rotated
280
// away from the face of the Pyraminx shouldn't be textured.
281

  
282
  private boolean isOnFace( int cubit, int axis, int row)
283
    {
284
    final float MAX_ERROR = 0.0001f;
285
    float diff = mCubits[cubit].mRotationRow[axis] - row;
286
    return diff*diff < MAX_ERROR;
287
    }
288

  
289 277
///////////////////////////////////////////////////////////////////////////////////////////////////
290 278
// note the minus in front of the sin() - we rotate counterclockwise
291 279
// when looking towards the direction where the axis increases in values.
......
330 318
      }
331 319
    }
332 320

  
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
// we cannot use belongsToRotation for deciding if to texture a face. Counterexample: the 'rotated'
323
// tetrahedrons of Pyraminx nearby the edge: they belong to rotation but their face which is rotated
324
// away from the face of the Pyraminx shouldn't be textured.
325

  
326
  boolean isOnFace( int cubit, int axis, int row)
327
    {
328
    final float MAX_ERROR = 0.0001f;
329
    float diff = mCubits[cubit].mRotationRow[axis] - row;
330
    return diff*diff < MAX_ERROR;
331
    }
332

  
333 333
///////////////////////////////////////////////////////////////////////////////////////////////////
334 334

  
335 335
  int getCubitFaceColorIndex(int cubit, int face)
......
491 491

  
492 492
  public void resetAllTextureMaps()
493 493
    {
494
    boolean belongs;
495 494
    final float ratio = 1.0f/(NUM_FACES+1);
496

  
497
    if( 3*ROTATION_AXIS.length == 2*NUM_FACES ) // Dino
498
      {
499
      final Static4D[] maps = new Static4D[NUM_CUBITS*NUM_CUBIT_FACES];
500

  
501
      final int[] map = {2,4, 4,0, 3,4, 4,1,
502
                         0,2, 0,3, 1,3, 1,2,
503
                         2,5, 5,0, 3,5, 5,1 };
504

  
505
      for(int i=0; i<NUM_CUBITS; i++)
506
        {
507
        maps[NUM_CUBIT_FACES*i    ] = new Static4D( map[2*i  ]*ratio, 0.0f, ratio, 1.0f);
508
        maps[NUM_CUBIT_FACES*i + 1] = new Static4D( map[2*i+1]*ratio, 0.0f, ratio, 1.0f);
509
        maps[NUM_CUBIT_FACES*i + 2] = new Static4D( NUM_FACES *ratio, 0.0f, ratio, 1.0f);
510
        maps[NUM_CUBIT_FACES*i + 3] = new Static4D( NUM_FACES *ratio, 0.0f, ratio, 1.0f);
511
        }
512

  
513
      mMesh.setTextureMap(maps,0);
514
      return;
515
      }
516

  
495
    int color;
517 496

  
518 497
    for(int cubit=0; cubit<NUM_CUBITS; cubit++)
519 498
      {
520 499
      final Static4D[] maps = new Static4D[NUM_CUBIT_FACES];
521 500

  
522
      if( 2*ROTATION_AXIS.length == NUM_FACES )  // i.e. there are faces on both ends of the axis (cube)
523
        {
524
        for(int i=0; i<NUM_CUBIT_FACES; i++)
525
          {
526
          belongs = isOnFace(cubit, i/2, i%2==0 ? mSize-1:0 );
527
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
528
          }
529
        }
530
      else if( ROTATION_AXIS.length == NUM_FACES )  // just a single face on the right end of an axis (pyraminx)
501
      for(int cubitface=0; cubitface<NUM_CUBIT_FACES; cubitface++)
531 502
        {
532
        for(int i=0; i<NUM_CUBIT_FACES; i++)
533
          {
534
          belongs = isOnFace(cubit, i, 0 );
535
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
536
          }
503
        color = getFaceColor(cubit,cubitface,mSize);
504
        maps[cubitface] = new Static4D( color*ratio, 0.0f, ratio, 1.0f);
537 505
        }
538 506

  
539 507
      mMesh.setTextureMap(maps,NUM_CUBIT_FACES*cubit);
......
726 694
  abstract int getNumCubitFaces();
727 695
  abstract MeshBase createCubitMesh(int cubit);
728 696
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
697
  abstract int getFaceColor(int cubit, int cubitface, int size);
729 698
  public abstract Static3D[] getRotationAxis();
730 699
  public abstract int getBasicAngle();
731 700
  public abstract float returnMultiplier();
src/main/java/org/distorted/objects/RubikPyraminx.java
223 223
    return 0.82f;
224 224
    }
225 225

  
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

  
228
  int getFaceColor(int cubit, int cubitface, int size)
229
    {
230
    boolean belongs = isOnFace(cubit, cubitface, 0 );
231
    return belongs ? cubitface : NUM_FACES;
232
    }
233

  
226 234
///////////////////////////////////////////////////////////////////////////////////////////////////
227 235

  
228 236
  private MeshBase createStaticMesh(int cubit)

Also available in: Unified diff