1 |
59b87d56
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.objects;
|
21 |
|
|
|
22 |
|
|
import android.content.res.Resources;
|
23 |
|
|
|
24 |
749ef882
|
Leszek Koltunski
|
import org.distorted.helpers.FactoryCubit;
|
25 |
9c06394a
|
Leszek Koltunski
|
import org.distorted.helpers.ObjectSticker;
|
26 |
59b87d56
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
27 |
|
|
import org.distorted.library.main.DistortedEffects;
|
28 |
|
|
import org.distorted.library.main.DistortedTexture;
|
29 |
|
|
import org.distorted.library.mesh.MeshBase;
|
30 |
|
|
import org.distorted.library.mesh.MeshSquare;
|
31 |
|
|
import org.distorted.library.type.Static3D;
|
32 |
|
|
import org.distorted.library.type.Static4D;
|
33 |
|
|
import org.distorted.main.R;
|
34 |
|
|
|
35 |
|
|
import java.util.Random;
|
36 |
|
|
|
37 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38 |
|
|
|
39 |
|
|
public class TwistyRex extends TwistyObject
|
40 |
|
|
{
|
41 |
da36b97e
|
Leszek Koltunski
|
private static final int FACES_PER_CUBIT =6;
|
42 |
59b87d56
|
Leszek Koltunski
|
|
43 |
be56193c
|
Leszek Koltunski
|
public static final float REX_D = 0.2f;
|
44 |
|
|
|
45 |
59b87d56
|
Leszek Koltunski
|
// the four rotation axis of a RubikRex. Must be normalized.
|
46 |
|
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
47 |
|
|
{
|
48 |
|
|
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
|
49 |
|
|
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
|
50 |
|
|
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
|
51 |
|
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
52 |
|
|
};
|
53 |
|
|
|
54 |
925ed78f
|
Leszek Koltunski
|
private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
|
55 |
|
|
|
56 |
59b87d56
|
Leszek Koltunski
|
private static final int[] FACE_COLORS = new int[]
|
57 |
|
|
{
|
58 |
|
|
COLOR_YELLOW, COLOR_WHITE,
|
59 |
|
|
COLOR_BLUE , COLOR_GREEN,
|
60 |
323b217c
|
Leszek Koltunski
|
COLOR_RED , COLOR_ORANGE
|
61 |
59b87d56
|
Leszek Koltunski
|
};
|
62 |
|
|
|
63 |
|
|
// All legal rotation quats of a RubikRex
|
64 |
|
|
private static final Static4D[] QUATS = new Static4D[]
|
65 |
|
|
{
|
66 |
|
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
67 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
68 |
|
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
69 |
|
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
70 |
|
|
|
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 |
|
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f )
|
79 |
|
|
};
|
80 |
|
|
|
81 |
|
|
private static final int[][] mFaceMap =
|
82 |
|
|
{
|
83 |
da36b97e
|
Leszek Koltunski
|
{ 0, 18,18,18,18,18 },
|
84 |
|
|
{ 0, 18,18,18,18,18 },
|
85 |
|
|
{ 0, 18,18,18,18,18 },
|
86 |
|
|
{ 0, 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 |
|
|
{ 1, 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 |
|
|
{ 2, 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 |
|
|
{ 3, 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 |
|
|
{ 4, 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 |
|
|
{ 5, 18,18,18,18,18 },
|
107 |
|
|
|
108 |
|
|
{ 6, 18,18,18,18,18 },
|
109 |
|
|
{ 7, 18,18,18,18,18 },
|
110 |
|
|
{ 8, 18,18,18,18,18 },
|
111 |
|
|
{ 9, 18,18,18,18,18 },
|
112 |
|
|
{ 10, 18,18,18,18,18 },
|
113 |
|
|
{ 11, 18,18,18,18,18 },
|
114 |
|
|
|
115 |
|
|
{ 16,14, 18,18,18,18 },
|
116 |
|
|
{ 16,12, 18,18,18,18 },
|
117 |
|
|
{ 16,15, 18,18,18,18 },
|
118 |
|
|
{ 16,13, 18,18,18,18 },
|
119 |
|
|
{ 12,14, 18,18,18,18 },
|
120 |
|
|
{ 15,12, 18,18,18,18 },
|
121 |
|
|
{ 15,13, 18,18,18,18 },
|
122 |
|
|
{ 13,14, 18,18,18,18 },
|
123 |
|
|
{ 14,17, 18,18,18,18 },
|
124 |
|
|
{ 12,17, 18,18,18,18 },
|
125 |
|
|
{ 17,15, 18,18,18,18 },
|
126 |
|
|
{ 13,17, 18,18,18,18 },
|
127 |
59b87d56
|
Leszek Koltunski
|
};
|
128 |
|
|
|
129 |
9c06394a
|
Leszek Koltunski
|
private static final ObjectSticker[] mStickers;
|
130 |
|
|
|
131 |
c75ab933
|
Leszek Koltunski
|
private static final float[][] STICKERS = new float[][]
|
132 |
|
|
{
|
133 |
|
|
{ -0.5f, 0.1428f, -0.1428f, 0.5f, 0.32f, -0.32f },
|
134 |
|
|
{ -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
|
135 |
|
|
{ -0.5f, 0.1f, 0.5f, 0.1f, 0.0f, -0.2f }
|
136 |
|
|
};
|
137 |
|
|
private static final int NUM_STICKERS = STICKERS.length;
|
138 |
|
|
|
139 |
9c06394a
|
Leszek Koltunski
|
static
|
140 |
|
|
{
|
141 |
|
|
mStickers = new ObjectSticker[NUM_STICKERS];
|
142 |
|
|
|
143 |
|
|
final float F = (float)(Math.PI/20);
|
144 |
|
|
final float R1= 0.02f;
|
145 |
c75ab933
|
Leszek Koltunski
|
final float R2= 0.09f;
|
146 |
9c06394a
|
Leszek Koltunski
|
final float R3= 0.06f;
|
147 |
c75ab933
|
Leszek Koltunski
|
final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
|
148 |
9c06394a
|
Leszek Koltunski
|
final float[][] radii = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
|
149 |
c75ab933
|
Leszek Koltunski
|
final float[] strokes = { 0.06f, 0.07f, 0.04f };
|
150 |
9c06394a
|
Leszek Koltunski
|
|
151 |
|
|
for(int s=0; s<NUM_STICKERS; s++)
|
152 |
|
|
{
|
153 |
c75ab933
|
Leszek Koltunski
|
mStickers[s] = new ObjectSticker(STICKERS[s],angles[s],radii[s],strokes[s]);
|
154 |
9c06394a
|
Leszek Koltunski
|
}
|
155 |
|
|
}
|
156 |
|
|
|
157 |
59b87d56
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158 |
|
|
|
159 |
|
|
TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
160 |
|
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
161 |
|
|
{
|
162 |
db875721
|
Leszek Koltunski
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.REX, res, scrWidth);
|
163 |
59b87d56
|
Leszek Koltunski
|
}
|
164 |
|
|
|
165 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166 |
|
|
|
167 |
|
|
float getScreenRatio()
|
168 |
|
|
{
|
169 |
80ec6abf
|
Leszek Koltunski
|
return 1.5f;
|
170 |
59b87d56
|
Leszek Koltunski
|
}
|
171 |
|
|
|
172 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173 |
|
|
|
174 |
|
|
Static4D[] getQuats()
|
175 |
|
|
{
|
176 |
|
|
return QUATS;
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180 |
|
|
|
181 |
|
|
int getNumFaces()
|
182 |
|
|
{
|
183 |
|
|
return FACE_COLORS.length;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187 |
|
|
|
188 |
|
|
boolean shouldResetTextureMaps()
|
189 |
|
|
{
|
190 |
|
|
return false;
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194 |
|
|
|
195 |
a64e07d0
|
Leszek Koltunski
|
int getNumStickerTypes(int numLayers)
|
196 |
59b87d56
|
Leszek Koltunski
|
{
|
197 |
9c06394a
|
Leszek Koltunski
|
return NUM_STICKERS;
|
198 |
59b87d56
|
Leszek Koltunski
|
}
|
199 |
|
|
|
200 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201 |
|
|
|
202 |
e6734aa9
|
Leszek Koltunski
|
float[][] getCuts(int numLayers)
|
203 |
59b87d56
|
Leszek Koltunski
|
{
|
204 |
c75ab933
|
Leszek Koltunski
|
float C = SQ3*0.15f; // bit less than 1/6 of the length of the main diagonal
|
205 |
|
|
float[] cut = new float[] {-C,+C};
|
206 |
e6734aa9
|
Leszek Koltunski
|
return new float[][] { cut,cut,cut,cut };
|
207 |
59b87d56
|
Leszek Koltunski
|
}
|
208 |
|
|
|
209 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
210 |
|
|
|
211 |
|
|
int getNumCubitFaces()
|
212 |
|
|
{
|
213 |
|
|
return FACES_PER_CUBIT;
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
217 |
|
|
|
218 |
e6cf7283
|
Leszek Koltunski
|
float[][] getCubitPositions(int numLayers)
|
219 |
59b87d56
|
Leszek Koltunski
|
{
|
220 |
c75ab933
|
Leszek Koltunski
|
final float DIST1= 0.50f;
|
221 |
da36b97e
|
Leszek Koltunski
|
final float DIST2= (1+2*REX_D)/6;
|
222 |
c75ab933
|
Leszek Koltunski
|
final float DIST3= 0.51f;
|
223 |
|
|
|
224 |
|
|
final float[][] CENTERS = new float[24+6+12][];
|
225 |
|
|
|
226 |
|
|
CENTERS[ 0] = new float[] { +DIST3, +DIST2, +DIST2};
|
227 |
|
|
CENTERS[ 1] = new float[] { +DIST3, +DIST2, -DIST2};
|
228 |
|
|
CENTERS[ 2] = new float[] { +DIST3, -DIST2, -DIST2};
|
229 |
|
|
CENTERS[ 3] = new float[] { +DIST3, -DIST2, +DIST2};
|
230 |
|
|
CENTERS[ 4] = new float[] { -DIST3, +DIST2, +DIST2};
|
231 |
|
|
CENTERS[ 5] = new float[] { -DIST3, +DIST2, -DIST2};
|
232 |
|
|
CENTERS[ 6] = new float[] { -DIST3, -DIST2, -DIST2};
|
233 |
|
|
CENTERS[ 7] = new float[] { -DIST3, -DIST2, +DIST2};
|
234 |
|
|
CENTERS[ 8] = new float[] { +DIST2, +DIST3, +DIST2};
|
235 |
|
|
CENTERS[ 9] = new float[] { +DIST2, +DIST3, -DIST2};
|
236 |
|
|
CENTERS[10] = new float[] { -DIST2, +DIST3, -DIST2};
|
237 |
|
|
CENTERS[11] = new float[] { -DIST2, +DIST3, +DIST2};
|
238 |
|
|
CENTERS[12] = new float[] { +DIST2, -DIST3, +DIST2};
|
239 |
|
|
CENTERS[13] = new float[] { +DIST2, -DIST3, -DIST2};
|
240 |
|
|
CENTERS[14] = new float[] { -DIST2, -DIST3, -DIST2};
|
241 |
|
|
CENTERS[15] = new float[] { -DIST2, -DIST3, +DIST2};
|
242 |
|
|
CENTERS[16] = new float[] { +DIST2, +DIST2, +DIST3};
|
243 |
|
|
CENTERS[17] = new float[] { +DIST2, -DIST2, +DIST3};
|
244 |
|
|
CENTERS[18] = new float[] { -DIST2, -DIST2, +DIST3};
|
245 |
|
|
CENTERS[19] = new float[] { -DIST2, +DIST2, +DIST3};
|
246 |
|
|
CENTERS[20] = new float[] { +DIST2, +DIST2, -DIST3};
|
247 |
|
|
CENTERS[21] = new float[] { +DIST2, -DIST2, -DIST3};
|
248 |
|
|
CENTERS[22] = new float[] { -DIST2, -DIST2, -DIST3};
|
249 |
|
|
CENTERS[23] = new float[] { -DIST2, +DIST2, -DIST3};
|
250 |
|
|
|
251 |
|
|
CENTERS[24] = new float[] { +DIST3, +0.00f, +0.00f};
|
252 |
|
|
CENTERS[25] = new float[] { -DIST3, +0.00f, +0.00f};
|
253 |
|
|
CENTERS[26] = new float[] { +0.00f, +DIST3, +0.00f};
|
254 |
|
|
CENTERS[27] = new float[] { +0.00f, -DIST3, +0.00f};
|
255 |
|
|
CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST3};
|
256 |
|
|
CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST3};
|
257 |
|
|
|
258 |
|
|
CENTERS[30] = new float[] { +0.00f, +DIST1, +DIST1};
|
259 |
|
|
CENTERS[31] = new float[] { +DIST1, +0.00f, +DIST1};
|
260 |
|
|
CENTERS[32] = new float[] { +0.00f, -DIST1, +DIST1};
|
261 |
|
|
CENTERS[33] = new float[] { -DIST1, +0.00f, +DIST1};
|
262 |
|
|
CENTERS[34] = new float[] { +DIST1, +DIST1, +0.00f};
|
263 |
|
|
CENTERS[35] = new float[] { +DIST1, -DIST1, +0.00f};
|
264 |
|
|
CENTERS[36] = new float[] { -DIST1, -DIST1, +0.00f};
|
265 |
|
|
CENTERS[37] = new float[] { -DIST1, +DIST1, +0.00f};
|
266 |
|
|
CENTERS[38] = new float[] { +0.00f, +DIST1, -DIST1};
|
267 |
|
|
CENTERS[39] = new float[] { +DIST1, +0.00f, -DIST1};
|
268 |
|
|
CENTERS[40] = new float[] { +0.00f, -DIST1, -DIST1};
|
269 |
|
|
CENTERS[41] = new float[] { -DIST1, +0.00f, -DIST1};
|
270 |
59b87d56
|
Leszek Koltunski
|
|
271 |
|
|
return CENTERS;
|
272 |
|
|
}
|
273 |
|
|
|
274 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
275 |
|
|
|
276 |
|
|
private Static4D getQuat(int cubit)
|
277 |
|
|
{
|
278 |
|
|
switch(cubit)
|
279 |
|
|
{
|
280 |
80ec6abf
|
Leszek Koltunski
|
case 0: return new Static4D(+SQ2/2, 0,+SQ2/2, 0);
|
281 |
|
|
case 1: return QUATS[5];
|
282 |
|
|
case 2: return new Static4D( 0,-SQ2/2, 0, SQ2/2);
|
283 |
|
|
case 3: return QUATS[8];
|
284 |
59b87d56
|
Leszek Koltunski
|
case 4: return QUATS[6];
|
285 |
80ec6abf
|
Leszek Koltunski
|
case 5: return new Static4D(-SQ2/2, 0,+SQ2/2, 0);
|
286 |
59b87d56
|
Leszek Koltunski
|
case 6: return QUATS[11];
|
287 |
80ec6abf
|
Leszek Koltunski
|
case 7: return new Static4D( 0,+SQ2/2, 0, SQ2/2);
|
288 |
|
|
case 8: return new Static4D(+SQ2/2, 0, 0, SQ2/2);
|
289 |
|
|
case 9: return QUATS[10];
|
290 |
59b87d56
|
Leszek Koltunski
|
case 10: return new Static4D( 0,+SQ2/2,+SQ2/2, 0);
|
291 |
|
|
case 11: return QUATS[4];
|
292 |
|
|
case 12: return QUATS[9];
|
293 |
|
|
case 13: return new Static4D(-SQ2/2, 0, 0, SQ2/2);
|
294 |
|
|
case 14: return QUATS[7];
|
295 |
|
|
case 15: return new Static4D( 0,-SQ2/2,+SQ2/2, 0);
|
296 |
|
|
case 16: return new Static4D( 0, 0,-SQ2/2, SQ2/2);
|
297 |
|
|
case 17: return QUATS[0];
|
298 |
|
|
case 18: return new Static4D( 0, 0,+SQ2/2, SQ2/2);
|
299 |
|
|
case 19: return QUATS[3];
|
300 |
80ec6abf
|
Leszek Koltunski
|
case 20: return QUATS[1];
|
301 |
|
|
case 21: return new Static4D(+SQ2/2,-SQ2/2, 0, 0);
|
302 |
|
|
case 22: return QUATS[2];
|
303 |
|
|
case 23: return new Static4D(+SQ2/2,+SQ2/2, 0, 0);
|
304 |
59b87d56
|
Leszek Koltunski
|
|
305 |
80ec6abf
|
Leszek Koltunski
|
case 24: return new Static4D( 0,-SQ2/2, 0, SQ2/2);
|
306 |
|
|
case 25: return new Static4D( 0,+SQ2/2, 0, SQ2/2);
|
307 |
59b87d56
|
Leszek Koltunski
|
case 26: return new Static4D(+SQ2/2, 0, 0, SQ2/2);
|
308 |
|
|
case 27: return new Static4D(-SQ2/2, 0, 0, SQ2/2);
|
309 |
|
|
case 28: return QUATS[0];
|
310 |
|
|
case 29: return QUATS[1];
|
311 |
|
|
|
312 |
|
|
case 30: return QUATS[0];
|
313 |
|
|
case 31: return new Static4D( 0, 0,+SQ2/2, SQ2/2);
|
314 |
|
|
case 32: return QUATS[3];
|
315 |
|
|
case 33: return new Static4D( 0, 0,-SQ2/2, SQ2/2);
|
316 |
80ec6abf
|
Leszek Koltunski
|
case 34: return new Static4D( 0,-SQ2/2, 0, SQ2/2);
|
317 |
59b87d56
|
Leszek Koltunski
|
case 35: return QUATS[7];
|
318 |
|
|
case 36: return QUATS[9];
|
319 |
80ec6abf
|
Leszek Koltunski
|
case 37: return new Static4D( 0,+SQ2/2, 0, SQ2/2);
|
320 |
59b87d56
|
Leszek Koltunski
|
case 38: return new Static4D(+SQ2/2, 0, 0, SQ2/2);
|
321 |
|
|
case 39: return QUATS[8];
|
322 |
|
|
case 40: return QUATS[1];
|
323 |
|
|
case 41: return QUATS[6];
|
324 |
|
|
}
|
325 |
|
|
|
326 |
|
|
return QUATS[0];
|
327 |
|
|
}
|
328 |
|
|
|
329 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
330 |
|
|
|
331 |
a64e07d0
|
Leszek Koltunski
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
332 |
59b87d56
|
Leszek Koltunski
|
{
|
333 |
a0b48da6
|
Leszek Koltunski
|
if( mMeshes==null )
|
334 |
|
|
{
|
335 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
336 |
|
|
factory.clear();
|
337 |
|
|
mMeshes = new MeshBase[3];
|
338 |
|
|
}
|
339 |
|
|
|
340 |
59b87d56
|
Leszek Koltunski
|
MeshBase mesh;
|
341 |
|
|
|
342 |
f5c134c3
|
Leszek Koltunski
|
if( cubit<24 )
|
343 |
59b87d56
|
Leszek Koltunski
|
{
|
344 |
a0b48da6
|
Leszek Koltunski
|
if( mMeshes[0]==null )
|
345 |
c75ab933
|
Leszek Koltunski
|
{
|
346 |
|
|
float G = (1-REX_D)*SQ2/2;
|
347 |
|
|
|
348 |
|
|
double[][] vertices =
|
349 |
|
|
{
|
350 |
|
|
{ -0.033333f, 0.23333f, 0.0f },
|
351 |
|
|
{ -0.233333f, 0.03333f, 0.0f },
|
352 |
|
|
{ +0.216666f,-0.23666f, 0.0f },
|
353 |
|
|
{ +0.236666f,-0.21666f, 0.0f }
|
354 |
|
|
};
|
355 |
|
|
|
356 |
|
|
int[][] vertIndexes =
|
357 |
|
|
{
|
358 |
|
|
{0,1,2,3},
|
359 |
|
|
{3,2,1,0}
|
360 |
|
|
};
|
361 |
|
|
|
362 |
|
|
float[][] centers= new float[][] { {0.0f,0.0f,-G/3} };
|
363 |
|
|
float[][] corners= new float[][] { {0.03f,0.10f} };
|
364 |
|
|
int[] indexes= {-1,-1,0,0};
|
365 |
|
|
|
366 |
|
|
int[] bandIndexes= new int[] { 0,1 };
|
367 |
|
|
|
368 |
|
|
float[][] bands =
|
369 |
|
|
{
|
370 |
|
|
{+0.016f,10,G/3,0.5f,5,1,1},
|
371 |
|
|
{+0.230f,45,G/3,0.0f,2,0,0}
|
372 |
|
|
};
|
373 |
|
|
|
374 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
375 |
|
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
376 |
a0b48da6
|
Leszek Koltunski
|
mMeshes[0] = factory.createRoundedSolid(vertices, vertIndexes,
|
377 |
|
|
bands, bandIndexes,
|
378 |
|
|
corners, indexes,
|
379 |
|
|
centers, indexes,
|
380 |
|
|
getNumCubitFaces(), null );
|
381 |
c75ab933
|
Leszek Koltunski
|
}
|
382 |
a0b48da6
|
Leszek Koltunski
|
mesh = mMeshes[0].copy(true);
|
383 |
59b87d56
|
Leszek Koltunski
|
}
|
384 |
f5c134c3
|
Leszek Koltunski
|
else if( cubit<30 )
|
385 |
59b87d56
|
Leszek Koltunski
|
{
|
386 |
a0b48da6
|
Leszek Koltunski
|
if( mMeshes[1]==null )
|
387 |
c75ab933
|
Leszek Koltunski
|
{
|
388 |
|
|
double[][] vertices =
|
389 |
|
|
{
|
390 |
|
|
{ -REX_D, 0.0f, 0.0f },
|
391 |
|
|
{ 0.0f, -REX_D, 0.0f },
|
392 |
|
|
{ +REX_D, 0.0f, 0.0f },
|
393 |
|
|
{ 0.0f, +REX_D, 0.0f }
|
394 |
|
|
};
|
395 |
|
|
|
396 |
|
|
int[][] vertIndexes=
|
397 |
|
|
{
|
398 |
|
|
{0,1,2,3},
|
399 |
|
|
{3,2,1,0}
|
400 |
|
|
};
|
401 |
|
|
|
402 |
|
|
float[][] bands =
|
403 |
|
|
{
|
404 |
|
|
{0.025f,10,REX_D/2,0.5f,5,0,0},
|
405 |
|
|
{0.000f,45,REX_D/2,0.0f,2,0,0}
|
406 |
|
|
};
|
407 |
|
|
|
408 |
|
|
int[] indexes= {-1,-1,-1,-1};
|
409 |
|
|
int[] bandIndexes= new int[] { 0,1 };
|
410 |
|
|
|
411 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
412 |
|
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
413 |
a0b48da6
|
Leszek Koltunski
|
mMeshes[1] = factory.createRoundedSolid(vertices, vertIndexes,
|
414 |
c75ab933
|
Leszek Koltunski
|
bands, bandIndexes,
|
415 |
|
|
null, indexes,
|
416 |
|
|
null, indexes,
|
417 |
|
|
getNumCubitFaces(), null );
|
418 |
|
|
}
|
419 |
a0b48da6
|
Leszek Koltunski
|
mesh = mMeshes[1].copy(true);
|
420 |
59b87d56
|
Leszek Koltunski
|
}
|
421 |
|
|
else
|
422 |
|
|
{
|
423 |
a0b48da6
|
Leszek Koltunski
|
if( mMeshes[2]==null )
|
424 |
c75ab933
|
Leszek Koltunski
|
{
|
425 |
|
|
float E = 0.5f - REX_D;
|
426 |
|
|
float F = 0.5f;
|
427 |
|
|
float G = (float)Math.sqrt(E*E+F*F);
|
428 |
|
|
|
429 |
|
|
double[][] vertices =
|
430 |
|
|
{
|
431 |
|
|
{ -F, 0, 0 },
|
432 |
|
|
{ 0,-E, 0 },
|
433 |
|
|
{ +F, 0, 0 },
|
434 |
|
|
{ 0, 0,-E },
|
435 |
|
|
};
|
436 |
|
|
|
437 |
|
|
int[][] vertIndexes =
|
438 |
|
|
{
|
439 |
|
|
{0,1,2},
|
440 |
|
|
{0,2,3},
|
441 |
|
|
{0,3,1},
|
442 |
|
|
{1,3,2}
|
443 |
|
|
};
|
444 |
|
|
|
445 |
|
|
float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} };
|
446 |
|
|
float[][] corners= new float[][] { {0.06f,0.10f} };
|
447 |
|
|
int[] indexes= {0,-1,0,-1};
|
448 |
|
|
|
449 |
|
|
int[] bandIndexes= new int[] { 0,0,1,1 };
|
450 |
|
|
|
451 |
|
|
float[][] bands =
|
452 |
|
|
{
|
453 |
|
|
{0.03f,27,F/3,0.8f,5,2,3},
|
454 |
|
|
{0.01f,45,G/3,0.2f,3,1,2}
|
455 |
|
|
};
|
456 |
|
|
|
457 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
458 |
|
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
459 |
a0b48da6
|
Leszek Koltunski
|
mMeshes[2] = factory.createRoundedSolid(vertices, vertIndexes,
|
460 |
|
|
bands, bandIndexes,
|
461 |
|
|
corners, indexes,
|
462 |
|
|
centers, indexes,
|
463 |
|
|
getNumCubitFaces(), null );
|
464 |
c75ab933
|
Leszek Koltunski
|
}
|
465 |
a0b48da6
|
Leszek Koltunski
|
mesh = mMeshes[2].copy(true);
|
466 |
59b87d56
|
Leszek Koltunski
|
}
|
467 |
|
|
|
468 |
|
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
|
469 |
|
|
mesh.apply(quat,0xffffffff,0);
|
470 |
|
|
|
471 |
|
|
return mesh;
|
472 |
|
|
}
|
473 |
|
|
|
474 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
475 |
|
|
|
476 |
|
|
int getFaceColor(int cubit, int cubitface, int numLayers)
|
477 |
|
|
{
|
478 |
|
|
return mFaceMap[cubit][cubitface];
|
479 |
|
|
}
|
480 |
|
|
|
481 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
482 |
|
|
|
483 |
9c06394a
|
Leszek Koltunski
|
int getColor(int face)
|
484 |
59b87d56
|
Leszek Koltunski
|
{
|
485 |
9c06394a
|
Leszek Koltunski
|
return FACE_COLORS[face];
|
486 |
|
|
}
|
487 |
29bc084f
|
Leszek Koltunski
|
|
488 |
9c06394a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
489 |
29bc084f
|
Leszek Koltunski
|
|
490 |
9c06394a
|
Leszek Koltunski
|
ObjectSticker retSticker(int face)
|
491 |
|
|
{
|
492 |
|
|
return mStickers[face/NUM_FACES];
|
493 |
59b87d56
|
Leszek Koltunski
|
}
|
494 |
|
|
|
495 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
496 |
|
|
|
497 |
|
|
float returnMultiplier()
|
498 |
|
|
{
|
499 |
|
|
return 2.0f;
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
503 |
|
|
// PUBLIC API
|
504 |
|
|
|
505 |
|
|
public Static3D[] getRotationAxis()
|
506 |
|
|
{
|
507 |
|
|
return ROT_AXIS;
|
508 |
|
|
}
|
509 |
|
|
|
510 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
511 |
|
|
|
512 |
925ed78f
|
Leszek Koltunski
|
public int[] getBasicAngle()
|
513 |
59b87d56
|
Leszek Koltunski
|
{
|
514 |
925ed78f
|
Leszek Koltunski
|
return BASIC_ANGLE;
|
515 |
59b87d56
|
Leszek Koltunski
|
}
|
516 |
|
|
|
517 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
518 |
|
|
|
519 |
9f171eba
|
Leszek Koltunski
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
|
520 |
59b87d56
|
Leszek Koltunski
|
{
|
521 |
9f171eba
|
Leszek Koltunski
|
if( curr==0 )
|
522 |
59b87d56
|
Leszek Koltunski
|
{
|
523 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][0] = rnd.nextInt(NUM_AXIS);
|
524 |
59b87d56
|
Leszek Koltunski
|
}
|
525 |
|
|
else
|
526 |
|
|
{
|
527 |
582617c1
|
Leszek Koltunski
|
int newVector = rnd.nextInt(NUM_AXIS -1);
|
528 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
|
529 |
59b87d56
|
Leszek Koltunski
|
}
|
530 |
|
|
|
531 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : 2;
|
532 |
59b87d56
|
Leszek Koltunski
|
|
533 |
5043d5d0
|
Leszek Koltunski
|
switch( rnd.nextInt(2) )
|
534 |
|
|
{
|
535 |
9f171eba
|
Leszek Koltunski
|
case 0: scramble[curr][2] = -1; break;
|
536 |
|
|
case 1: scramble[curr][2] = 1; break;
|
537 |
5043d5d0
|
Leszek Koltunski
|
}
|
538 |
59b87d56
|
Leszek Koltunski
|
}
|
539 |
|
|
|
540 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
541 |
|
|
// The Rex is solved if and only if:
|
542 |
|
|
//
|
543 |
5eedd516
|
Leszek Koltunski
|
// 1) all 12 of its edge cubits are rotated with the same quat
|
544 |
|
|
// 2) all its face & corner cubits are rotated with the same quat like the edge ones,
|
545 |
|
|
// and optionally they also might be upside down.
|
546 |
|
|
//
|
547 |
|
|
// i.e.
|
548 |
|
|
// corners ( 0, 1, 2, 3, 4, 5, 6, 7) and faces (24,25) - might be extra QUAT[1]
|
549 |
|
|
// corners ( 8, 9,10,11,12,13,14,15) and faces (26,27) - might be extra QUAT[2]
|
550 |
|
|
// corners (16,17,18,19,20,21,22,23) and faces (28,29) - might be extra QUAT[3]
|
551 |
59b87d56
|
Leszek Koltunski
|
|
552 |
|
|
public boolean isSolved()
|
553 |
|
|
{
|
554 |
cce59cd4
|
Leszek Koltunski
|
int q1,q = CUBITS[30].mQuatIndex;
|
555 |
59b87d56
|
Leszek Koltunski
|
|
556 |
cce59cd4
|
Leszek Koltunski
|
for(int i=31; i<42; i++)
|
557 |
59b87d56
|
Leszek Koltunski
|
{
|
558 |
|
|
if( CUBITS[i].mQuatIndex != q) return false;
|
559 |
|
|
}
|
560 |
|
|
|
561 |
5eedd516
|
Leszek Koltunski
|
q1 = mulQuat(q,1);
|
562 |
|
|
|
563 |
|
|
for(int i=0; i<8; i++)
|
564 |
|
|
{
|
565 |
|
|
if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
|
566 |
|
|
}
|
567 |
|
|
|
568 |
|
|
if( CUBITS[24].mQuatIndex != q && CUBITS[24].mQuatIndex != q1 ) return false;
|
569 |
|
|
if( CUBITS[25].mQuatIndex != q && CUBITS[25].mQuatIndex != q1 ) return false;
|
570 |
|
|
|
571 |
|
|
q1 = mulQuat(q,2);
|
572 |
|
|
|
573 |
|
|
for(int i=8; i<16; i++)
|
574 |
|
|
{
|
575 |
|
|
if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
|
576 |
|
|
}
|
577 |
|
|
|
578 |
|
|
if( CUBITS[26].mQuatIndex != q && CUBITS[26].mQuatIndex != q1 ) return false;
|
579 |
|
|
if( CUBITS[27].mQuatIndex != q && CUBITS[27].mQuatIndex != q1 ) return false;
|
580 |
|
|
|
581 |
|
|
q1 = mulQuat(q,3);
|
582 |
|
|
|
583 |
|
|
for(int i=16; i<24; i++)
|
584 |
|
|
{
|
585 |
|
|
if( CUBITS[i].mQuatIndex != q && CUBITS[i].mQuatIndex != q1 ) return false;
|
586 |
|
|
}
|
587 |
|
|
|
588 |
|
|
if( CUBITS[28].mQuatIndex != q && CUBITS[28].mQuatIndex != q1 ) return false;
|
589 |
|
|
if( CUBITS[29].mQuatIndex != q && CUBITS[29].mQuatIndex != q1 ) return false;
|
590 |
|
|
|
591 |
59b87d56
|
Leszek Koltunski
|
return true;
|
592 |
|
|
}
|
593 |
|
|
|
594 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
595 |
|
|
|
596 |
|
|
public int getObjectName(int numLayers)
|
597 |
|
|
{
|
598 |
|
|
return R.string.rex3;
|
599 |
|
|
}
|
600 |
|
|
|
601 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
602 |
|
|
|
603 |
|
|
public int getInventor(int numLayers)
|
604 |
|
|
{
|
605 |
|
|
return R.string.rex3_inventor;
|
606 |
|
|
}
|
607 |
|
|
|
608 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
609 |
|
|
|
610 |
|
|
public int getComplexity(int numLayers)
|
611 |
|
|
{
|
612 |
|
|
return 3;
|
613 |
|
|
}
|
614 |
|
|
}
|