Revision 10585385
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/objects/RubikCube.java | ||
---|---|---|
39 | 39 |
|
40 | 40 |
class RubikCube extends RubikObject |
41 | 41 |
{ |
42 |
static final float SQ2 = (float)Math.sqrt(2); |
|
43 |
|
|
42 | 44 |
// the three rotation axis of a RubikCube. Must be normalized. |
43 | 45 |
static final Static3D[] AXIS = new Static3D[] |
44 | 46 |
{ |
... | ... | |
54 | 56 |
0xffff0000, 0xffb5651d // AXIS[2]right (front-RED ) AXIS[2]left (back -BROWN) |
55 | 57 |
}; |
56 | 58 |
|
57 |
// All legal rotation quats of a RubikCube of any size must have all four of their components |
|
58 |
// equal to either 0, +-1, +-0.5 or +-sqrt(2)/2. |
|
59 |
// All legal rotation quats of a RubikCube of any size. |
|
59 | 60 |
// Here's how to compute this: |
60 | 61 |
// 1) compute how many rotations there are (RubikCube of any size = 24) |
61 | 62 |
// 2) take the AXIS, angles of rotation (90 in RubikCube's case) compute the basic quaternions |
62 | 63 |
// (i.e. rotations of 1 basic angle along each of the axis) and from there start semi-randomly |
63 | 64 |
// multiplying them and eventually you'll find all (24) legal rotations. |
64 |
// 3) linear scan through those shows that the only floats in those 24 quats are those 7 given |
|
65 |
// below. |
|
66 |
// |
|
67 | 65 |
// Example program in C, res/raw/compute_quats.c , is included. |
68 |
private static final float[] LEGALQUATS = new float[]
|
|
66 |
private static final Static4D[] QUATS = new Static4D[]
|
|
69 | 67 |
{ |
70 |
0.0f , |
|
71 |
0.5f , |
|
72 |
-0.5f , |
|
73 |
1.0f , |
|
74 |
-1.0f , |
|
75 |
0.5f*((float)Math.sqrt(2)) , |
|
76 |
-0.5f*((float)Math.sqrt(2)) |
|
68 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f), |
|
69 |
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f), |
|
70 |
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f), |
|
71 |
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f), |
|
72 |
|
|
73 |
new Static4D( SQ2/2, SQ2/2, 0.0f , 0.0f), |
|
74 |
new Static4D( SQ2/2, -SQ2/2, 0.0f , 0.0f), |
|
75 |
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f), |
|
76 |
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f), |
|
77 |
new Static4D( SQ2/2, 0.0f, 0.0f, SQ2/2), |
|
78 |
new Static4D( SQ2/2, 0.0f, 0.0f, -SQ2/2), |
|
79 |
new Static4D( 0.0f, SQ2/2, SQ2/2, 0.0f), |
|
80 |
new Static4D( 0.0f, SQ2/2, -SQ2/2, 0.0f), |
|
81 |
new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2), |
|
82 |
new Static4D( 0.0f, SQ2/2, 0.0f, -SQ2/2), |
|
83 |
new Static4D( 0.0f, 0.0f, SQ2/2, SQ2/2), |
|
84 |
new Static4D( 0.0f, 0.0f, SQ2/2, -SQ2/2), |
|
85 |
|
|
86 |
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f), |
|
87 |
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f), |
|
88 |
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f), |
|
89 |
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f), |
|
90 |
new Static4D( -0.5f, -0.5f, -0.5f, 0.5f), |
|
91 |
new Static4D( -0.5f, 0.5f, -0.5f, -0.5f), |
|
92 |
new Static4D( -0.5f, 0.5f, 0.5f, -0.5f), |
|
93 |
new Static4D( -0.5f, 0.5f, 0.5f, 0.5f) |
|
77 | 94 |
}; |
78 | 95 |
|
79 | 96 |
private static MeshBase mMesh = null; |
... | ... | |
121 | 138 |
|
122 | 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
123 | 140 |
|
124 |
float[] getLegalQuats()
|
|
141 |
Static4D[] getQuats()
|
|
125 | 142 |
{ |
126 |
return LEGALQUATS;
|
|
143 |
return QUATS; |
|
127 | 144 |
} |
128 | 145 |
|
129 | 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
More progreess porting RubikCube.