Revision f242ba04
Added by Leszek Koltunski about 4 years ago
| src/main/java/org/distorted/objects/TwistyRex.java | ||
|---|---|---|
| 37 | 37 |
|
| 38 | 38 |
public class TwistyRex extends TwistyObject |
| 39 | 39 |
{
|
| 40 |
private static final int FACES_PER_CUBIT =6; |
|
| 41 |
|
|
| 42 |
public static final float REX_D = 0.2f; |
|
| 43 |
|
|
| 44 | 40 |
// the four rotation axis of a RubikRex. Must be normalized. |
| 45 | 41 |
static final Static3D[] ROT_AXIS = new Static3D[] |
| 46 | 42 |
{
|
| ... | ... | |
| 50 | 46 |
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3) |
| 51 | 47 |
}; |
| 52 | 48 |
|
| 53 |
private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
|
|
| 54 |
|
|
| 55 | 49 |
private static final int[] FACE_COLORS = new int[] |
| 56 | 50 |
{
|
| 57 | 51 |
COLOR_YELLOW, COLOR_WHITE, |
| ... | ... | |
| 59 | 53 |
COLOR_RED , COLOR_ORANGE |
| 60 | 54 |
}; |
| 61 | 55 |
|
| 62 |
// All legal rotation quats of a RubikRex |
|
| 63 |
private static final Static4D[] QUATS = new Static4D[] |
|
| 64 |
{
|
|
| 65 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ), |
|
| 66 |
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ), |
|
| 67 |
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ), |
|
| 68 |
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ), |
|
| 69 |
|
|
| 70 |
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ), |
|
| 71 |
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ), |
|
| 72 |
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f ), |
|
| 73 |
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ), |
|
| 74 |
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ), |
|
| 75 |
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ), |
|
| 76 |
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ), |
|
| 77 |
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ) |
|
| 78 |
}; |
|
| 79 |
|
|
| 80 |
private static final int[][] mFaceMap = |
|
| 81 |
{
|
|
| 82 |
{ 0, 18,18,18,18,18 },
|
|
| 83 |
{ 0, 18,18,18,18,18 },
|
|
| 84 |
{ 0, 18,18,18,18,18 },
|
|
| 85 |
{ 0, 18,18,18,18,18 },
|
|
| 86 |
{ 1, 18,18,18,18,18 },
|
|
| 87 |
{ 1, 18,18,18,18,18 },
|
|
| 88 |
{ 1, 18,18,18,18,18 },
|
|
| 89 |
{ 1, 18,18,18,18,18 },
|
|
| 90 |
{ 2, 18,18,18,18,18 },
|
|
| 91 |
{ 2, 18,18,18,18,18 },
|
|
| 92 |
{ 2, 18,18,18,18,18 },
|
|
| 93 |
{ 2, 18,18,18,18,18 },
|
|
| 94 |
{ 3, 18,18,18,18,18 },
|
|
| 95 |
{ 3, 18,18,18,18,18 },
|
|
| 96 |
{ 3, 18,18,18,18,18 },
|
|
| 97 |
{ 3, 18,18,18,18,18 },
|
|
| 98 |
{ 4, 18,18,18,18,18 },
|
|
| 99 |
{ 4, 18,18,18,18,18 },
|
|
| 100 |
{ 4, 18,18,18,18,18 },
|
|
| 101 |
{ 4, 18,18,18,18,18 },
|
|
| 102 |
{ 5, 18,18,18,18,18 },
|
|
| 103 |
{ 5, 18,18,18,18,18 },
|
|
| 104 |
{ 5, 18,18,18,18,18 },
|
|
| 105 |
{ 5, 18,18,18,18,18 },
|
|
| 106 |
|
|
| 107 |
{ 6, 18,18,18,18,18 },
|
|
| 108 |
{ 7, 18,18,18,18,18 },
|
|
| 109 |
{ 8, 18,18,18,18,18 },
|
|
| 110 |
{ 9, 18,18,18,18,18 },
|
|
| 111 |
{ 10, 18,18,18,18,18 },
|
|
| 112 |
{ 11, 18,18,18,18,18 },
|
|
| 113 |
|
|
| 114 |
{ 16,14, 18,18,18,18 },
|
|
| 115 |
{ 16,12, 18,18,18,18 },
|
|
| 116 |
{ 16,15, 18,18,18,18 },
|
|
| 117 |
{ 16,13, 18,18,18,18 },
|
|
| 118 |
{ 12,14, 18,18,18,18 },
|
|
| 119 |
{ 15,12, 18,18,18,18 },
|
|
| 120 |
{ 15,13, 18,18,18,18 },
|
|
| 121 |
{ 13,14, 18,18,18,18 },
|
|
| 122 |
{ 14,17, 18,18,18,18 },
|
|
| 123 |
{ 12,17, 18,18,18,18 },
|
|
| 124 |
{ 17,15, 18,18,18,18 },
|
|
| 125 |
{ 13,17, 18,18,18,18 },
|
|
| 126 |
}; |
|
| 127 |
|
|
| 128 |
private static final ObjectSticker[] mStickers; |
|
| 129 |
|
|
| 130 |
private static final float[][] STICKERS = new float[][] |
|
| 131 |
{
|
|
| 132 |
{ -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
|
|
| 133 |
{ -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
|
|
| 134 |
{ -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f }
|
|
| 135 |
}; |
|
| 136 |
private static final int NUM_STICKERS = STICKERS.length; |
|
| 137 |
|
|
| 138 |
static |
|
| 139 |
{
|
|
| 140 |
mStickers = new ObjectSticker[NUM_STICKERS]; |
|
| 141 |
|
|
| 142 |
final float F = (float)(Math.PI/20); |
|
| 143 |
final float R1= 0.02f; |
|
| 144 |
final float R2= 0.09f; |
|
| 145 |
final float R3= 0.06f; |
|
| 146 |
final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
|
|
| 147 |
final float[][] radii = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
|
|
| 148 |
final float[] strokes = { 0.06f, 0.07f, 0.05f };
|
|
| 149 |
|
|
| 150 |
for(int s=0; s<NUM_STICKERS; s++) |
|
| 151 |
{
|
|
| 152 |
mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]); |
|
| 153 |
} |
|
| 154 |
} |
|
| 56 |
public static final float REX_D = 0.2f; |
|
| 155 | 57 |
|
| 156 | 58 |
private int mCurrState; |
| 157 | 59 |
private int mIndexExcluded; |
| 158 | 60 |
private final ScrambleState[] mStates; |
| 159 | 61 |
private int[][] mScrambleTable; |
| 160 | 62 |
private int[] mNumOccurences; |
| 63 |
private int[] mBasicAngle; |
|
| 64 |
private Static4D[] mQuats; |
|
| 65 |
private int[][] mFaceMap; |
|
| 66 |
private ObjectSticker[] mStickers; |
|
| 161 | 67 |
|
| 162 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 163 | 69 |
|
| ... | ... | |
| 174 | 80 |
}; |
| 175 | 81 |
} |
| 176 | 82 |
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
|
|
| 85 |
private void initializeQuats() |
|
| 86 |
{
|
|
| 87 |
mQuats = new Static4D[] |
|
| 88 |
{
|
|
| 89 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ), |
|
| 90 |
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ), |
|
| 91 |
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ), |
|
| 92 |
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ), |
|
| 93 |
|
|
| 94 |
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ), |
|
| 95 |
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ), |
|
| 96 |
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f ), |
|
| 97 |
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ), |
|
| 98 |
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ), |
|
| 99 |
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ), |
|
| 100 |
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ), |
|
| 101 |
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ) |
|
| 102 |
}; |
|
| 103 |
} |
|
| 104 |
|
|
| 177 | 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 178 | 106 |
|
| 179 | 107 |
int[] getSolvedQuats(int cubit, int numLayers) |
| 180 | 108 |
{
|
| 109 |
if( mQuats==null ) initializeQuats(); |
|
| 181 | 110 |
int status = retCubitSolvedStatus(cubit,numLayers); |
| 182 |
return status<0 ? null : buildSolvedQuats(MovementRex.FACE_AXIS[status],QUATS);
|
|
| 111 |
return status<0 ? null : buildSolvedQuats(MovementRex.FACE_AXIS[status],mQuats);
|
|
| 183 | 112 |
} |
| 184 | 113 |
|
| 185 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 193 | 122 |
|
| 194 | 123 |
Static4D[] getQuats() |
| 195 | 124 |
{
|
| 196 |
return QUATS; |
|
| 125 |
if( mQuats==null ) initializeQuats(); |
|
| 126 |
return mQuats; |
|
| 197 | 127 |
} |
| 198 | 128 |
|
| 199 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 221 | 151 |
|
| 222 | 152 |
int getNumStickerTypes(int numLayers) |
| 223 | 153 |
{
|
| 224 |
return NUM_STICKERS;
|
|
| 154 |
return 3;
|
|
| 225 | 155 |
} |
| 226 | 156 |
|
| 227 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 237 | 167 |
|
| 238 | 168 |
int getNumCubitFaces() |
| 239 | 169 |
{
|
| 240 |
return FACES_PER_CUBIT;
|
|
| 170 |
return 6;
|
|
| 241 | 171 |
} |
| 242 | 172 |
|
| 243 | 173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 385 | 315 |
|
| 386 | 316 |
Static4D getQuat(int cubit, int numLayers) |
| 387 | 317 |
{
|
| 318 |
if( mQuats==null ) initializeQuats(); |
|
| 319 |
|
|
| 388 | 320 |
switch(cubit) |
| 389 | 321 |
{
|
| 390 | 322 |
case 0: return new Static4D(+SQ2/2, 0,+SQ2/2, 0); |
| 391 |
case 1: return QUATS[5];
|
|
| 323 |
case 1: return mQuats[5];
|
|
| 392 | 324 |
case 2: return new Static4D( 0,-SQ2/2, 0, SQ2/2); |
| 393 |
case 3: return QUATS[8];
|
|
| 394 |
case 4: return QUATS[6];
|
|
| 325 |
case 3: return mQuats[8];
|
|
| 326 |
case 4: return mQuats[6];
|
|
| 395 | 327 |
case 5: return new Static4D(-SQ2/2, 0,+SQ2/2, 0); |
| 396 |
case 6: return QUATS[11];
|
|
| 328 |
case 6: return mQuats[11];
|
|
| 397 | 329 |
case 7: return new Static4D( 0,+SQ2/2, 0, SQ2/2); |
| 398 | 330 |
case 8: return new Static4D(+SQ2/2, 0, 0, SQ2/2); |
| 399 |
case 9: return QUATS[10];
|
|
| 331 |
case 9: return mQuats[10];
|
|
| 400 | 332 |
case 10: return new Static4D( 0,+SQ2/2,+SQ2/2, 0); |
| 401 |
case 11: return QUATS[4];
|
|
| 402 |
case 12: return QUATS[9];
|
|
| 333 |
case 11: return mQuats[4];
|
|
| 334 |
case 12: return mQuats[9];
|
|
| 403 | 335 |
case 13: return new Static4D(-SQ2/2, 0, 0, SQ2/2); |
| 404 |
case 14: return QUATS[7];
|
|
| 336 |
case 14: return mQuats[7];
|
|
| 405 | 337 |
case 15: return new Static4D( 0,-SQ2/2,+SQ2/2, 0); |
| 406 | 338 |
case 16: return new Static4D( 0, 0,-SQ2/2, SQ2/2); |
| 407 |
case 17: return QUATS[0];
|
|
| 339 |
case 17: return mQuats[0];
|
|
| 408 | 340 |
case 18: return new Static4D( 0, 0,+SQ2/2, SQ2/2); |
| 409 |
case 19: return QUATS[3];
|
|
| 410 |
case 20: return QUATS[1];
|
|
| 341 |
case 19: return mQuats[3];
|
|
| 342 |
case 20: return mQuats[1];
|
|
| 411 | 343 |
case 21: return new Static4D(+SQ2/2,-SQ2/2, 0, 0); |
| 412 |
case 22: return QUATS[2];
|
|
| 344 |
case 22: return mQuats[2];
|
|
| 413 | 345 |
case 23: return new Static4D(+SQ2/2,+SQ2/2, 0, 0); |
| 414 | 346 |
|
| 415 | 347 |
case 24: return new Static4D( 0,-SQ2/2, 0, SQ2/2); |
| 416 | 348 |
case 25: return new Static4D( 0,+SQ2/2, 0, SQ2/2); |
| 417 | 349 |
case 26: return new Static4D(+SQ2/2, 0, 0, SQ2/2); |
| 418 | 350 |
case 27: return new Static4D(-SQ2/2, 0, 0, SQ2/2); |
| 419 |
case 28: return QUATS[0];
|
|
| 420 |
case 29: return QUATS[1];
|
|
| 351 |
case 28: return mQuats[0];
|
|
| 352 |
case 29: return mQuats[1];
|
|
| 421 | 353 |
|
| 422 |
case 30: return QUATS[0];
|
|
| 354 |
case 30: return mQuats[0];
|
|
| 423 | 355 |
case 31: return new Static4D( 0, 0,+SQ2/2, SQ2/2); |
| 424 |
case 32: return QUATS[3];
|
|
| 356 |
case 32: return mQuats[3];
|
|
| 425 | 357 |
case 33: return new Static4D( 0, 0,-SQ2/2, SQ2/2); |
| 426 | 358 |
case 34: return new Static4D( 0,-SQ2/2, 0, SQ2/2); |
| 427 |
case 35: return QUATS[7];
|
|
| 428 |
case 36: return QUATS[9];
|
|
| 359 |
case 35: return mQuats[7];
|
|
| 360 |
case 36: return mQuats[9];
|
|
| 429 | 361 |
case 37: return new Static4D( 0,+SQ2/2, 0, SQ2/2); |
| 430 | 362 |
case 38: return new Static4D(+SQ2/2, 0, 0, SQ2/2); |
| 431 |
case 39: return QUATS[8];
|
|
| 432 |
case 40: return QUATS[1];
|
|
| 433 |
case 41: return QUATS[6];
|
|
| 363 |
case 39: return mQuats[8];
|
|
| 364 |
case 40: return mQuats[1];
|
|
| 365 |
case 41: return mQuats[6];
|
|
| 434 | 366 |
} |
| 435 | 367 |
|
| 436 |
return QUATS[0];
|
|
| 368 |
return mQuats[0];
|
|
| 437 | 369 |
} |
| 438 | 370 |
|
| 439 | 371 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 454 | 386 |
|
| 455 | 387 |
int getFaceColor(int cubit, int cubitface, int numLayers) |
| 456 | 388 |
{
|
| 389 |
if( mFaceMap==null ) |
|
| 390 |
{
|
|
| 391 |
mFaceMap = new int[][] |
|
| 392 |
{
|
|
| 393 |
{ 0, 18,18,18,18,18 },
|
|
| 394 |
{ 0, 18,18,18,18,18 },
|
|
| 395 |
{ 0, 18,18,18,18,18 },
|
|
| 396 |
{ 0, 18,18,18,18,18 },
|
|
| 397 |
{ 1, 18,18,18,18,18 },
|
|
| 398 |
{ 1, 18,18,18,18,18 },
|
|
| 399 |
{ 1, 18,18,18,18,18 },
|
|
| 400 |
{ 1, 18,18,18,18,18 },
|
|
| 401 |
{ 2, 18,18,18,18,18 },
|
|
| 402 |
{ 2, 18,18,18,18,18 },
|
|
| 403 |
{ 2, 18,18,18,18,18 },
|
|
| 404 |
{ 2, 18,18,18,18,18 },
|
|
| 405 |
{ 3, 18,18,18,18,18 },
|
|
| 406 |
{ 3, 18,18,18,18,18 },
|
|
| 407 |
{ 3, 18,18,18,18,18 },
|
|
| 408 |
{ 3, 18,18,18,18,18 },
|
|
| 409 |
{ 4, 18,18,18,18,18 },
|
|
| 410 |
{ 4, 18,18,18,18,18 },
|
|
| 411 |
{ 4, 18,18,18,18,18 },
|
|
| 412 |
{ 4, 18,18,18,18,18 },
|
|
| 413 |
{ 5, 18,18,18,18,18 },
|
|
| 414 |
{ 5, 18,18,18,18,18 },
|
|
| 415 |
{ 5, 18,18,18,18,18 },
|
|
| 416 |
{ 5, 18,18,18,18,18 },
|
|
| 417 |
|
|
| 418 |
{ 6, 18,18,18,18,18 },
|
|
| 419 |
{ 7, 18,18,18,18,18 },
|
|
| 420 |
{ 8, 18,18,18,18,18 },
|
|
| 421 |
{ 9, 18,18,18,18,18 },
|
|
| 422 |
{ 10, 18,18,18,18,18 },
|
|
| 423 |
{ 11, 18,18,18,18,18 },
|
|
| 424 |
|
|
| 425 |
{ 16,14, 18,18,18,18 },
|
|
| 426 |
{ 16,12, 18,18,18,18 },
|
|
| 427 |
{ 16,15, 18,18,18,18 },
|
|
| 428 |
{ 16,13, 18,18,18,18 },
|
|
| 429 |
{ 12,14, 18,18,18,18 },
|
|
| 430 |
{ 15,12, 18,18,18,18 },
|
|
| 431 |
{ 15,13, 18,18,18,18 },
|
|
| 432 |
{ 13,14, 18,18,18,18 },
|
|
| 433 |
{ 14,17, 18,18,18,18 },
|
|
| 434 |
{ 12,17, 18,18,18,18 },
|
|
| 435 |
{ 17,15, 18,18,18,18 },
|
|
| 436 |
{ 13,17, 18,18,18,18 },
|
|
| 437 |
}; |
|
| 438 |
} |
|
| 439 |
|
|
| 457 | 440 |
return mFaceMap[cubit][cubitface]; |
| 458 | 441 |
} |
| 459 | 442 |
|
| ... | ... | |
| 468 | 451 |
|
| 469 | 452 |
ObjectSticker retSticker(int face) |
| 470 | 453 |
{
|
| 454 |
if( mStickers==null ) |
|
| 455 |
{
|
|
| 456 |
float[][] STICKERS = new float[][] |
|
| 457 |
{
|
|
| 458 |
{ -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
|
|
| 459 |
{ -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
|
|
| 460 |
{ -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f }
|
|
| 461 |
}; |
|
| 462 |
|
|
| 463 |
final float F = (float)(Math.PI/20); |
|
| 464 |
final float R1= 0.02f; |
|
| 465 |
final float R2= 0.09f; |
|
| 466 |
final float R3= 0.06f; |
|
| 467 |
final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
|
|
| 468 |
final float[][] radii = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
|
|
| 469 |
final float[] strokes = { 0.06f, 0.07f, 0.05f };
|
|
| 470 |
|
|
| 471 |
mStickers = new ObjectSticker[STICKERS.length]; |
|
| 472 |
|
|
| 473 |
for(int s=0; s<STICKERS.length; s++) |
|
| 474 |
{
|
|
| 475 |
mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]); |
|
| 476 |
} |
|
| 477 |
} |
|
| 478 |
|
|
| 471 | 479 |
return mStickers[face/NUM_FACES]; |
| 472 | 480 |
} |
| 473 | 481 |
|
| ... | ... | |
| 538 | 546 |
|
| 539 | 547 |
public int[] getBasicAngle() |
| 540 | 548 |
{
|
| 541 |
return BASIC_ANGLE; |
|
| 549 |
if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
|
|
| 550 |
return mBasicAngle; |
|
| 542 | 551 |
} |
| 543 | 552 |
|
| 544 | 553 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Remove statics from the Rex class.