Revision f6d06256
Added by Leszek Koltunski over 3 years ago
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(); |
Also available in: Unified diff
Move the knowledge about colors of individual cubit faces down to each Object subclass.