Revision eaee1ddc
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/objects/RubikDino.java | ||
---|---|---|
37 | 37 |
import org.distorted.library.type.Static1D; |
38 | 38 |
import org.distorted.library.type.Static3D; |
39 | 39 |
import org.distorted.library.type.Static4D; |
40 |
import org.distorted.main.RubikSurfaceView; |
|
41 | 40 |
|
42 | 41 |
import java.util.Random; |
43 | 42 |
|
... | ... | |
45 | 44 |
|
46 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | 46 |
|
48 |
public class RubikDino extends RubikObject |
|
47 |
public abstract class RubikDino extends RubikObject
|
|
49 | 48 |
{ |
50 | 49 |
private static final float SQ2 = (float)Math.sqrt(2); |
51 | 50 |
private static final float SQ3 = (float)Math.sqrt(3); |
... | ... | |
75 | 74 |
}; |
76 | 75 |
|
77 | 76 |
// All legal rotation quats of a RubikDino |
78 |
private static final Static4D[] QUATS = new Static4D[]
|
|
77 |
static final Static4D[] QUATS = new Static4D[] |
|
79 | 78 |
{ |
80 | 79 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ), |
81 | 80 |
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ), |
... | ... | |
108 | 107 |
new Static3D(-1.5f, 0.0f,-1.5f ) |
109 | 108 |
}; |
110 | 109 |
|
111 |
private static final int[] mFaceMap = {4,2, 0,4, 4,3, 1,4, |
|
112 |
2,0, 3,0, 3,1, 2,1, |
|
113 |
5,2, 0,5, 5,3, 1,5 }; |
|
114 |
|
|
115 | 110 |
private static MeshBase mMesh; |
116 | 111 |
|
117 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
118 | 113 |
|
119 |
RubikDino(int size, Static4D quat, DistortedTexture texture, |
|
120 |
MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
|
114 |
RubikDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
|
115 |
DistortedEffects effects, int[][] moves, RubikObjectList obj, Resources res, int scrWidth)
|
|
121 | 116 |
{ |
122 |
super(size, 60, quat, texture, mesh, effects, moves, RubikObjectList.DINO, res, scrWidth);
|
|
117 |
super(size, 60, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
|
123 | 118 |
} |
124 | 119 |
|
125 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
312 | 307 |
return mesh; |
313 | 308 |
} |
314 | 309 |
|
315 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
316 |
|
|
317 |
int getFaceColor(int cubit, int cubitface, int size) |
|
318 |
{ |
|
319 |
switch(cubitface) |
|
320 |
{ |
|
321 |
case 0 : return mFaceMap[2*cubit]; |
|
322 |
case 1 : return mFaceMap[2*cubit+1]; |
|
323 |
default: return NUM_FACES; |
|
324 |
} |
|
325 |
} |
|
326 |
|
|
327 | 310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
328 | 311 |
|
329 | 312 |
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side) |
... | ... | |
468 | 451 |
} |
469 | 452 |
} |
470 | 453 |
|
471 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
472 |
// remember about the double cover or unit quaternions! |
|
473 |
|
|
474 |
private int mulQuat(int q1, int q2) |
|
475 |
{ |
|
476 |
Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]); |
|
477 |
|
|
478 |
float rX = result.get0(); |
|
479 |
float rY = result.get1(); |
|
480 |
float rZ = result.get2(); |
|
481 |
float rW = result.get3(); |
|
482 |
|
|
483 |
final float MAX_ERROR = 0.1f; |
|
484 |
float dX,dY,dZ,dW; |
|
485 |
|
|
486 |
for(int i=0; i<QUATS.length; i++) |
|
487 |
{ |
|
488 |
dX = QUATS[i].get0() - rX; |
|
489 |
dY = QUATS[i].get1() - rY; |
|
490 |
dZ = QUATS[i].get2() - rZ; |
|
491 |
dW = QUATS[i].get3() - rW; |
|
492 |
|
|
493 |
if( dX<MAX_ERROR && dX>-MAX_ERROR && |
|
494 |
dY<MAX_ERROR && dY>-MAX_ERROR && |
|
495 |
dZ<MAX_ERROR && dZ>-MAX_ERROR && |
|
496 |
dW<MAX_ERROR && dW>-MAX_ERROR ) return i; |
|
497 |
|
|
498 |
dX = QUATS[i].get0() + rX; |
|
499 |
dY = QUATS[i].get1() + rY; |
|
500 |
dZ = QUATS[i].get2() + rZ; |
|
501 |
dW = QUATS[i].get3() + rW; |
|
502 |
|
|
503 |
if( dX<MAX_ERROR && dX>-MAX_ERROR && |
|
504 |
dY<MAX_ERROR && dY>-MAX_ERROR && |
|
505 |
dZ<MAX_ERROR && dZ>-MAX_ERROR && |
|
506 |
dW<MAX_ERROR && dW>-MAX_ERROR ) return i; |
|
507 |
} |
|
508 |
|
|
509 |
return -1; |
|
510 |
} |
|
511 |
|
|
512 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
513 |
// Dino is solved if and only if: |
|
514 |
// |
|
515 |
// All four 'X' cubits (i.e. those whose longest edge goes along the X axis) are rotated |
|
516 |
// by the same quaternion qX, similarly all four 'Y' cubits by the same qY and all four 'Z' |
|
517 |
// by the same qZ, and then either: |
|
518 |
// |
|
519 |
// a) qX = qY = qZ |
|
520 |
// b) qY = qX*Q2 and qZ = qX*Q8 (i.e. swap of WHITE and YELLOW faces) |
|
521 |
// c) qX = qY*Q2 and qZ = qY*Q10 (i.e. swap of BLUE and GREEN faces) |
|
522 |
// d) qX = qZ*Q8 and qY = qZ*Q10 (i.e. swap of RED and BROWN faces) |
|
523 |
// |
|
524 |
// BUT: cases b), c) and d) are really the same - it's all just a mirror image of the original. |
|
525 |
// |
|
526 |
// X cubits: 0, 2, 8, 10 |
|
527 |
// Y cubits: 1, 3, 9, 11 |
|
528 |
// Z cubits: 4, 5, 6, 7 |
|
529 |
|
|
530 |
public boolean isSolved() |
|
531 |
{ |
|
532 |
int qX = CUBITS[0].mQuatIndex; |
|
533 |
int qY = CUBITS[1].mQuatIndex; |
|
534 |
int qZ = CUBITS[4].mQuatIndex; |
|
535 |
|
|
536 |
if( CUBITS[2].mQuatIndex != qX || CUBITS[8].mQuatIndex != qX || CUBITS[10].mQuatIndex != qX || |
|
537 |
CUBITS[3].mQuatIndex != qY || CUBITS[9].mQuatIndex != qY || CUBITS[11].mQuatIndex != qY || |
|
538 |
CUBITS[5].mQuatIndex != qZ || CUBITS[6].mQuatIndex != qZ || CUBITS[ 7].mQuatIndex != qZ ) |
|
539 |
{ |
|
540 |
return false; |
|
541 |
} |
|
542 |
|
|
543 |
return ( qX==qY && qX==qZ ) || ( qY==mulQuat(qX,2) && qZ==mulQuat(qX,8) ); |
|
544 |
} |
|
545 |
|
|
546 | 454 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
547 | 455 |
// only needed for solvers - there are no Dino solvers ATM) |
548 | 456 |
|
Also available in: Unified diff
Add the 4-color Dino.
Still one thing needs to be done about it: randomization of Moves (now sometimes in Level 1 the randomized move leads to an already solved position)