1 |
e844c116
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 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 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.objects;
|
21 |
e844c116
|
Leszek Koltunski
|
|
22 |
ccf9fec5
|
Leszek Koltunski
|
import android.content.res.Resources;
|
23 |
e844c116
|
Leszek Koltunski
|
|
24 |
749ef882
|
Leszek Koltunski
|
import org.distorted.helpers.FactoryCubit;
|
25 |
045d8cbd
|
Leszek Koltunski
|
import org.distorted.helpers.ObjectShape;
|
26 |
9c06394a
|
Leszek Koltunski
|
import org.distorted.helpers.ObjectSticker;
|
27 |
045d8cbd
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
28 |
e844c116
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
29 |
|
|
import org.distorted.library.main.DistortedTexture;
|
30 |
|
|
import org.distorted.library.mesh.MeshBase;
|
31 |
efa8aa48
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshSquare;
|
32 |
e844c116
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
33 |
|
|
import org.distorted.library.type.Static4D;
|
34 |
6fd4a72c
|
Leszek Koltunski
|
import org.distorted.main.R;
|
35 |
e844c116
|
Leszek Koltunski
|
|
36 |
7c969a6d
|
Leszek Koltunski
|
import java.util.Random;
|
37 |
|
|
|
38 |
e844c116
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
9c2f0c91
|
Leszek Koltunski
|
public class TwistyPyraminx extends TwistyObject
|
41 |
e844c116
|
Leszek Koltunski
|
{
|
42 |
f074c272
|
Leszek Koltunski
|
static final float SCREEN_RATIO = 0.88f;
|
43 |
|
|
|
44 |
ad38d800
|
Leszek Koltunski
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
45 |
e844c116
|
Leszek Koltunski
|
{
|
46 |
ac940e24
|
Leszek Koltunski
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
47 |
|
|
new Static3D( 0,-SQ3/3,+SQ6/3),
|
48 |
|
|
new Static3D(+SQ6/3,+SQ3/3, 0),
|
49 |
|
|
new Static3D(-SQ6/3,+SQ3/3, 0),
|
50 |
ad38d800
|
Leszek Koltunski
|
};
|
51 |
|
|
|
52 |
925ed78f
|
Leszek Koltunski
|
private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
|
53 |
|
|
|
54 |
e844c116
|
Leszek Koltunski
|
private static final int[] FACE_COLORS = new int[]
|
55 |
|
|
{
|
56 |
ece1b58d
|
Leszek Koltunski
|
COLOR_GREEN , COLOR_YELLOW,
|
57 |
|
|
COLOR_BLUE , COLOR_RED
|
58 |
e844c116
|
Leszek Koltunski
|
};
|
59 |
|
|
|
60 |
9f4c44fe
|
Leszek Koltunski
|
// computed with res/raw/compute_quats.c
|
61 |
10585385
|
Leszek Koltunski
|
private static final Static4D[] QUATS = new Static4D[]
|
62 |
e844c116
|
Leszek Koltunski
|
{
|
63 |
10585385
|
Leszek Koltunski
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f),
|
64 |
ac940e24
|
Leszek Koltunski
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f),
|
65 |
|
|
new Static4D( SQ2/2, 0.5f, 0.0f, 0.5f),
|
66 |
|
|
new Static4D(-SQ2/2, 0.5f, 0.0f, 0.5f),
|
67 |
|
|
new Static4D( 0.0f, -0.5f, -SQ2/2, 0.5f),
|
68 |
|
|
new Static4D( 0.0f, -0.5f, SQ2/2, 0.5f),
|
69 |
|
|
new Static4D( SQ2/2, 0.5f, 0.0f, -0.5f),
|
70 |
|
|
new Static4D(-SQ2/2, 0.5f, 0.0f, -0.5f),
|
71 |
|
|
new Static4D( 0.0f, -0.5f, -SQ2/2, -0.5f),
|
72 |
|
|
new Static4D( 0.0f, -0.5f, SQ2/2, -0.5f),
|
73 |
|
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f),
|
74 |
|
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f)
|
75 |
e844c116
|
Leszek Koltunski
|
};
|
76 |
|
|
|
77 |
31cd7256
|
Leszek Koltunski
|
private static final double[][] VERTICES_TETRA = new double[][]
|
78 |
b1f2ccf5
|
Leszek Koltunski
|
{
|
79 |
|
|
{-0.5, SQ2/4, 0.0},
|
80 |
|
|
{ 0.5, SQ2/4, 0.0},
|
81 |
|
|
{ 0.0,-SQ2/4, 0.5},
|
82 |
|
|
{ 0.0,-SQ2/4,-0.5}
|
83 |
|
|
};
|
84 |
|
|
|
85 |
31cd7256
|
Leszek Koltunski
|
private static final int[][] VERT_INDEXES_TETRA = new int[][]
|
86 |
b1f2ccf5
|
Leszek Koltunski
|
{
|
87 |
|
|
{2,1,0}, // counterclockwise!
|
88 |
31cd7256
|
Leszek Koltunski
|
{3,0,1},
|
89 |
b1f2ccf5
|
Leszek Koltunski
|
{3,2,0},
|
90 |
31cd7256
|
Leszek Koltunski
|
{2,3,1}
|
91 |
b1f2ccf5
|
Leszek Koltunski
|
};
|
92 |
|
|
|
93 |
31cd7256
|
Leszek Koltunski
|
private static final double[][] VERTICES_OCTA = new double[][]
|
94 |
b1f2ccf5
|
Leszek Koltunski
|
{
|
95 |
|
|
{ 0.5, 0.0, 0.5},
|
96 |
|
|
{ 0.5, 0.0,-0.5},
|
97 |
|
|
{-0.5, 0.0,-0.5},
|
98 |
|
|
{-0.5, 0.0, 0.5},
|
99 |
|
|
{ 0.0, SQ2/2, 0.0},
|
100 |
|
|
{ 0.0,-SQ2/2, 0.0}
|
101 |
|
|
};
|
102 |
|
|
|
103 |
31cd7256
|
Leszek Koltunski
|
private static final int[][] VERT_INDEXES_OCTA = new int[][]
|
104 |
b1f2ccf5
|
Leszek Koltunski
|
{
|
105 |
|
|
{3,0,4}, // counterclockwise!
|
106 |
|
|
{0,1,4},
|
107 |
|
|
{1,2,4},
|
108 |
|
|
{2,3,4},
|
109 |
|
|
{5,0,3},
|
110 |
|
|
{5,1,0},
|
111 |
|
|
{5,2,1},
|
112 |
|
|
{5,3,2}
|
113 |
|
|
};
|
114 |
|
|
|
115 |
31cd7256
|
Leszek Koltunski
|
private static final float[][] STICKERS = new float[][]
|
116 |
|
|
{
|
117 |
|
|
{ -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f }
|
118 |
|
|
};
|
119 |
|
|
|
120 |
0203be88
|
Leszek Koltunski
|
private static float[] mRowChances;
|
121 |
49f67f9b
|
Leszek Koltunski
|
|
122 |
9c06394a
|
Leszek Koltunski
|
private static final ObjectSticker[] mStickers;
|
123 |
|
|
|
124 |
|
|
static
|
125 |
|
|
{
|
126 |
|
|
mStickers = new ObjectSticker[STICKERS.length];
|
127 |
|
|
final float stroke = 0.08f;
|
128 |
|
|
final float radius = 0.06f;
|
129 |
|
|
final float[] radii= {radius,radius,radius};
|
130 |
|
|
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
|
131 |
|
|
}
|
132 |
|
|
|
133 |
e844c116
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134 |
|
|
|
135 |
ac940e24
|
Leszek Koltunski
|
TwistyPyraminx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
136 |
|
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
137 |
e844c116
|
Leszek Koltunski
|
{
|
138 |
db875721
|
Leszek Koltunski
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.PYRA, res, scrWidth);
|
139 |
e844c116
|
Leszek Koltunski
|
}
|
140 |
|
|
|
141 |
0203be88
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142 |
|
|
|
143 |
|
|
private float[] getRowChances(int numLayers)
|
144 |
|
|
{
|
145 |
|
|
int total = numLayers*(numLayers+1)/2;
|
146 |
|
|
float running=0.0f;
|
147 |
|
|
float[] chances = new float[numLayers];
|
148 |
|
|
|
149 |
|
|
for(int i=0; i<numLayers; i++)
|
150 |
|
|
{
|
151 |
|
|
running += (numLayers-i);
|
152 |
|
|
chances[i] = running / total;
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
return chances;
|
156 |
|
|
}
|
157 |
|
|
|
158 |
e844c116
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
159 |
|
|
|
160 |
e6cf7283
|
Leszek Koltunski
|
private void addTetrahedralLattice(int size, int index, float[][] pos)
|
161 |
49f67f9b
|
Leszek Koltunski
|
{
|
162 |
ac940e24
|
Leszek Koltunski
|
final float DX = 1.0f;
|
163 |
|
|
final float DY = SQ2/2;
|
164 |
|
|
final float DZ = 1.0f;
|
165 |
49f67f9b
|
Leszek Koltunski
|
|
166 |
ac940e24
|
Leszek Koltunski
|
float startX = 0.0f;
|
167 |
|
|
float startY =-DY*(size-1)/2;
|
168 |
|
|
float startZ = DZ*(size-1)/2;
|
169 |
769409d2
|
Leszek Koltunski
|
|
170 |
ac940e24
|
Leszek Koltunski
|
for(int layer=0; layer<size; layer++)
|
171 |
49f67f9b
|
Leszek Koltunski
|
{
|
172 |
ac940e24
|
Leszek Koltunski
|
float currX = startX;
|
173 |
|
|
float currY = startY;
|
174 |
|
|
|
175 |
|
|
for(int x=0; x<layer+1; x++)
|
176 |
|
|
{
|
177 |
|
|
float currZ = startZ;
|
178 |
|
|
|
179 |
|
|
for(int z=0; z<size-layer; z++)
|
180 |
|
|
{
|
181 |
e6cf7283
|
Leszek Koltunski
|
pos[index] = new float[] {currX,currY,currZ};
|
182 |
ac940e24
|
Leszek Koltunski
|
index++;
|
183 |
|
|
currZ -= DZ;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
currX += DX;
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
startX-=DX/2;
|
190 |
|
|
startY+=DY;
|
191 |
|
|
startZ-=DZ/2;
|
192 |
49f67f9b
|
Leszek Koltunski
|
}
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196 |
ac940e24
|
Leszek Koltunski
|
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons
|
197 |
49f67f9b
|
Leszek Koltunski
|
|
198 |
e6cf7283
|
Leszek Koltunski
|
float[][] getCubitPositions(int size)
|
199 |
e844c116
|
Leszek Koltunski
|
{
|
200 |
ac940e24
|
Leszek Koltunski
|
int numOcta = (size-1)*size*(size+1)/6;
|
201 |
|
|
int numTetra= size*(size+1)*(size+2)/6;
|
202 |
e6cf7283
|
Leszek Koltunski
|
float[][] ret = new float[numOcta+numTetra][];
|
203 |
49f67f9b
|
Leszek Koltunski
|
|
204 |
ac940e24
|
Leszek Koltunski
|
addTetrahedralLattice(size-1, 0,ret);
|
205 |
|
|
addTetrahedralLattice(size ,numOcta,ret);
|
206 |
49f67f9b
|
Leszek Koltunski
|
|
207 |
ac940e24
|
Leszek Koltunski
|
return ret;
|
208 |
e844c116
|
Leszek Koltunski
|
}
|
209 |
|
|
|
210 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
211 |
|
|
|
212 |
10585385
|
Leszek Koltunski
|
Static4D[] getQuats()
|
213 |
e844c116
|
Leszek Koltunski
|
{
|
214 |
10585385
|
Leszek Koltunski
|
return QUATS;
|
215 |
e844c116
|
Leszek Koltunski
|
}
|
216 |
|
|
|
217 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
218 |
|
|
|
219 |
|
|
int getNumFaces()
|
220 |
|
|
{
|
221 |
|
|
return FACE_COLORS.length;
|
222 |
|
|
}
|
223 |
|
|
|
224 |
eab9d8f8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225 |
|
|
|
226 |
a64e07d0
|
Leszek Koltunski
|
int getNumStickerTypes(int numLayers)
|
227 |
eab9d8f8
|
Leszek Koltunski
|
{
|
228 |
31cd7256
|
Leszek Koltunski
|
return STICKERS.length;
|
229 |
eab9d8f8
|
Leszek Koltunski
|
}
|
230 |
|
|
|
231 |
7403cdfa
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232 |
|
|
|
233 |
e6734aa9
|
Leszek Koltunski
|
float[][] getCuts(int size)
|
234 |
7403cdfa
|
Leszek Koltunski
|
{
|
235 |
e6734aa9
|
Leszek Koltunski
|
float[][] cuts = new float[4][size-1];
|
236 |
a97e02b7
|
Leszek Koltunski
|
|
237 |
|
|
for(int i=0; i<size-1; i++)
|
238 |
|
|
{
|
239 |
e6734aa9
|
Leszek Koltunski
|
float cut = (1.0f-0.25f*size+i)*(SQ6/3);
|
240 |
|
|
cuts[0][i] = cut;
|
241 |
|
|
cuts[1][i] = cut;
|
242 |
|
|
cuts[2][i] = cut;
|
243 |
|
|
cuts[3][i] = cut;
|
244 |
a97e02b7
|
Leszek Koltunski
|
}
|
245 |
|
|
|
246 |
|
|
return cuts;
|
247 |
7403cdfa
|
Leszek Koltunski
|
}
|
248 |
|
|
|
249 |
8f53e513
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
250 |
|
|
|
251 |
|
|
int getNumCubitFaces()
|
252 |
|
|
{
|
253 |
ac940e24
|
Leszek Koltunski
|
return 8;
|
254 |
8f53e513
|
Leszek Koltunski
|
}
|
255 |
|
|
|
256 |
f0fa83ae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257 |
|
|
|
258 |
|
|
float getScreenRatio()
|
259 |
|
|
{
|
260 |
f074c272
|
Leszek Koltunski
|
return SCREEN_RATIO;
|
261 |
f0fa83ae
|
Leszek Koltunski
|
}
|
262 |
|
|
|
263 |
eaee1ddc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264 |
|
|
|
265 |
|
|
boolean shouldResetTextureMaps()
|
266 |
|
|
{
|
267 |
|
|
return false;
|
268 |
|
|
}
|
269 |
|
|
|
270 |
31cd7256
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
271 |
|
|
|
272 |
|
|
private int getNumOctahedrons(int numLayers)
|
273 |
|
|
{
|
274 |
|
|
return (numLayers-1)*numLayers*(numLayers+1)/6;
|
275 |
|
|
}
|
276 |
|
|
|
277 |
f6d06256
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
278 |
|
|
|
279 |
ac940e24
|
Leszek Koltunski
|
private int faceColor(int cubit, int axis)
|
280 |
f6d06256
|
Leszek Koltunski
|
{
|
281 |
f0450fcc
|
Leszek Koltunski
|
return CUBITS[cubit].mRotationRow[axis] == 1 ? axis : NUM_FACES;
|
282 |
f6d06256
|
Leszek Koltunski
|
}
|
283 |
|
|
|
284 |
f0fa83ae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
285 |
|
|
|
286 |
ac940e24
|
Leszek Koltunski
|
int getFaceColor(int cubit, int cubitface, int size)
|
287 |
e844c116
|
Leszek Koltunski
|
{
|
288 |
ac940e24
|
Leszek Koltunski
|
if( cubit< (size-1)*size*(size+1)/6 )
|
289 |
40ab026e
|
Leszek Koltunski
|
{
|
290 |
ac940e24
|
Leszek Koltunski
|
switch( cubitface )
|
291 |
|
|
{
|
292 |
|
|
case 0: return faceColor(cubit,0);
|
293 |
|
|
case 2: return faceColor(cubit,1);
|
294 |
|
|
case 5: return faceColor(cubit,3);
|
295 |
|
|
case 7: return faceColor(cubit,2);
|
296 |
|
|
default:return NUM_FACES;
|
297 |
|
|
}
|
298 |
40ab026e
|
Leszek Koltunski
|
}
|
299 |
ac940e24
|
Leszek Koltunski
|
else
|
300 |
89a11f7b
|
Leszek Koltunski
|
{
|
301 |
ac940e24
|
Leszek Koltunski
|
return cubitface<NUM_FACES ? faceColor(cubit,cubitface) : NUM_FACES;
|
302 |
89a11f7b
|
Leszek Koltunski
|
}
|
303 |
e844c116
|
Leszek Koltunski
|
}
|
304 |
|
|
|
305 |
045d8cbd
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
306 |
|
|
|
307 |
|
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
308 |
|
|
{
|
309 |
|
|
int variant = getCubitVariant(cubit,numLayers);
|
310 |
|
|
|
311 |
|
|
if( variant==0 )
|
312 |
|
|
{
|
313 |
|
|
int N = numLayers==3? 6 : 5;
|
314 |
|
|
int E = numLayers==3? 2 : 1;
|
315 |
|
|
float[][] bands = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
|
316 |
|
|
int[] bandIndices = new int[] { 0,0,0,0,0,0,0,0 };
|
317 |
|
|
float[][] corners = new float[][] { {0.04f,0.20f} };
|
318 |
|
|
int[] cornerIndices = new int[] { 0,0,0,0,0,0 };
|
319 |
|
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
320 |
|
|
int[] centerIndices = new int[] { 0,0,0,0,0,0 };
|
321 |
|
|
return new ObjectShape(VERTICES_OCTA,VERT_INDEXES_OCTA,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
322 |
|
|
}
|
323 |
|
|
else
|
324 |
|
|
{
|
325 |
|
|
int N = numLayers==3? 6 : 5;
|
326 |
|
|
int E = numLayers==3? 2 : 1;
|
327 |
|
|
float[][] bands = new float[][] { {0.05f,35,0.5f,0.8f,N,E,E} };
|
328 |
|
|
int[] bandIndices = new int[] { 0,0,0,0 };
|
329 |
|
|
float[][] corners = new float[][] { {0.06f,0.15f} };
|
330 |
|
|
int[] cornerIndices = new int[] { 0,0,0,0 };
|
331 |
|
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
332 |
|
|
int[] centerIndices = new int[] { 0,0,0,0 };
|
333 |
|
|
return new ObjectShape(VERTICES_TETRA,VERT_INDEXES_TETRA,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
334 |
|
|
}
|
335 |
|
|
}
|
336 |
|
|
|
337 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
338 |
|
|
|
339 |
|
|
private Static4D getQuat(int cubit, int numLayers)
|
340 |
|
|
{
|
341 |
|
|
return QUATS[0];
|
342 |
|
|
}
|
343 |
|
|
|
344 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
345 |
|
|
|
346 |
|
|
private int getNumCubitVariants(int numLayers)
|
347 |
|
|
{
|
348 |
|
|
return 2;
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
352 |
|
|
|
353 |
|
|
int getCubitVariant(int cubit, int numLayers)
|
354 |
|
|
{
|
355 |
|
|
return cubit<getNumOctahedrons(numLayers) ? 0:1;
|
356 |
|
|
}
|
357 |
|
|
|
358 |
40ab026e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
359 |
|
|
|
360 |
a64e07d0
|
Leszek Koltunski
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
361 |
40ab026e
|
Leszek Koltunski
|
{
|
362 |
045d8cbd
|
Leszek Koltunski
|
int variant = getCubitVariant(cubit,numLayers);
|
363 |
|
|
|
364 |
31cd7256
|
Leszek Koltunski
|
if( mMeshes==null )
|
365 |
40ab026e
|
Leszek Koltunski
|
{
|
366 |
31cd7256
|
Leszek Koltunski
|
FactoryCubit factory = FactoryCubit.getInstance();
|
367 |
|
|
factory.clear();
|
368 |
045d8cbd
|
Leszek Koltunski
|
mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
|
369 |
31cd7256
|
Leszek Koltunski
|
}
|
370 |
|
|
|
371 |
045d8cbd
|
Leszek Koltunski
|
if( mMeshes[variant]==null )
|
372 |
31cd7256
|
Leszek Koltunski
|
{
|
373 |
045d8cbd
|
Leszek Koltunski
|
ObjectShape shape = getObjectShape(cubit,numLayers);
|
374 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
375 |
|
|
factory.createNewFaceTransform(shape);
|
376 |
|
|
mMeshes[variant] = factory.createRoundedSolid(shape);
|
377 |
40ab026e
|
Leszek Koltunski
|
}
|
378 |
31cd7256
|
Leszek Koltunski
|
|
379 |
045d8cbd
|
Leszek Koltunski
|
MeshBase mesh = mMeshes[variant].copy(true);
|
380 |
|
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
|
381 |
|
|
mesh.apply(quat,0xffffffff,0);
|
382 |
|
|
|
383 |
31cd7256
|
Leszek Koltunski
|
return mesh;
|
384 |
40ab026e
|
Leszek Koltunski
|
}
|
385 |
|
|
|
386 |
7289fd6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
387 |
|
|
|
388 |
9c06394a
|
Leszek Koltunski
|
int getColor(int face)
|
389 |
7289fd6c
|
Leszek Koltunski
|
{
|
390 |
9c06394a
|
Leszek Koltunski
|
return FACE_COLORS[face];
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
394 |
76c2bd07
|
Leszek Koltunski
|
|
395 |
9c06394a
|
Leszek Koltunski
|
ObjectSticker retSticker(int face)
|
396 |
|
|
{
|
397 |
|
|
return mStickers[face/NUM_FACES];
|
398 |
7289fd6c
|
Leszek Koltunski
|
}
|
399 |
|
|
|
400 |
fb377dae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
401 |
7403cdfa
|
Leszek Koltunski
|
// SQ6/3 = height of the tetrahedron
|
402 |
fb377dae
|
Leszek Koltunski
|
|
403 |
|
|
float returnMultiplier()
|
404 |
|
|
{
|
405 |
d99f3a48
|
Leszek Koltunski
|
return getNumLayers()/(SQ6/3);
|
406 |
fb377dae
|
Leszek Koltunski
|
}
|
407 |
|
|
|
408 |
e844c116
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
409 |
|
|
// PUBLIC API
|
410 |
|
|
|
411 |
12ad3fca
|
Leszek Koltunski
|
public Static3D[] getRotationAxis()
|
412 |
|
|
{
|
413 |
ad38d800
|
Leszek Koltunski
|
return ROT_AXIS;
|
414 |
12ad3fca
|
Leszek Koltunski
|
}
|
415 |
|
|
|
416 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
417 |
|
|
|
418 |
925ed78f
|
Leszek Koltunski
|
public int[] getBasicAngle()
|
419 |
e844c116
|
Leszek Koltunski
|
{
|
420 |
925ed78f
|
Leszek Koltunski
|
return BASIC_ANGLE;
|
421 |
e844c116
|
Leszek Koltunski
|
}
|
422 |
39e74052
|
Leszek Koltunski
|
|
423 |
7c969a6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
424 |
|
|
|
425 |
9f171eba
|
Leszek Koltunski
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
|
426 |
7c969a6d
|
Leszek Koltunski
|
{
|
427 |
0203be88
|
Leszek Koltunski
|
int numLayers = getNumLayers();
|
428 |
|
|
|
429 |
|
|
if( mRowChances==null ) mRowChances = getRowChances(numLayers);
|
430 |
|
|
|
431 |
9f171eba
|
Leszek Koltunski
|
if( curr==0 )
|
432 |
5cf34c5f
|
Leszek Koltunski
|
{
|
433 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][0] = rnd.nextInt(NUM_AXIS);
|
434 |
7c969a6d
|
Leszek Koltunski
|
}
|
435 |
|
|
else
|
436 |
|
|
{
|
437 |
3ca97293
|
Leszek Koltunski
|
int newVector = rnd.nextInt(NUM_AXIS-1);
|
438 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
|
439 |
3ca97293
|
Leszek Koltunski
|
|
440 |
|
|
// Correct the situation when we first rotate the largest layer, then a tip (which doesn't
|
441 |
|
|
// intersect anything besides the largest layer!) and then we try to rotate again along
|
442 |
|
|
// the same axis like 2 rotations before - which carries the risk we rotate the largest
|
443 |
|
|
// layer back to its spot again and the three moves end up being only a single tip rotation.
|
444 |
|
|
if( curr>=2 && scramble[curr-1][1]==(numLayers-1) && scramble[curr][0]==scramble[curr-2][0] )
|
445 |
|
|
{
|
446 |
|
|
for(int ax=0; ax<NUM_AXIS; ax++)
|
447 |
|
|
{
|
448 |
|
|
if( scramble[curr-1][0]!=ax && scramble[curr-2][0]!=ax )
|
449 |
|
|
{
|
450 |
|
|
scramble[curr][0]=ax;
|
451 |
|
|
break;
|
452 |
|
|
}
|
453 |
|
|
}
|
454 |
|
|
}
|
455 |
5cf34c5f
|
Leszek Koltunski
|
}
|
456 |
e46e17fb
|
Leszek Koltunski
|
|
457 |
7c969a6d
|
Leszek Koltunski
|
float rowFloat = rnd.nextFloat();
|
458 |
e46e17fb
|
Leszek Koltunski
|
|
459 |
0203be88
|
Leszek Koltunski
|
for(int row=0; row<numLayers; row++)
|
460 |
7c969a6d
|
Leszek Koltunski
|
{
|
461 |
bbc6471c
|
Leszek Koltunski
|
if( rowFloat<=mRowChances[row] )
|
462 |
|
|
{
|
463 |
9f171eba
|
Leszek Koltunski
|
scramble[curr][1] = row;
|
464 |
bbc6471c
|
Leszek Koltunski
|
break;
|
465 |
|
|
}
|
466 |
7c969a6d
|
Leszek Koltunski
|
}
|
467 |
|
|
|
468 |
5043d5d0
|
Leszek Koltunski
|
switch( rnd.nextInt(2) )
|
469 |
|
|
{
|
470 |
9f171eba
|
Leszek Koltunski
|
case 0: scramble[curr][2] = -1; break;
|
471 |
|
|
case 1: scramble[curr][2] = 1; break;
|
472 |
5043d5d0
|
Leszek Koltunski
|
}
|
473 |
e46e17fb
|
Leszek Koltunski
|
}
|
474 |
f0336037
|
Leszek Koltunski
|
|
475 |
6b6504fe
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
476 |
|
|
|
477 |
|
|
public boolean isSolved()
|
478 |
|
|
{
|
479 |
|
|
int index = CUBITS[0].mQuatIndex;
|
480 |
|
|
|
481 |
|
|
for(int i=1; i<NUM_CUBITS; i++)
|
482 |
|
|
{
|
483 |
722b2512
|
Leszek Koltunski
|
if( thereIsVisibleDifference(CUBITS[i], index) ) return false;
|
484 |
6b6504fe
|
Leszek Koltunski
|
}
|
485 |
|
|
|
486 |
|
|
return true;
|
487 |
|
|
}
|
488 |
|
|
|
489 |
6fd4a72c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
490 |
|
|
|
491 |
|
|
public int getObjectName(int numLayers)
|
492 |
|
|
{
|
493 |
|
|
switch(numLayers)
|
494 |
|
|
{
|
495 |
|
|
case 3: return R.string.pyra3;
|
496 |
|
|
case 4: return R.string.pyra4;
|
497 |
|
|
case 5: return R.string.pyra5;
|
498 |
|
|
}
|
499 |
|
|
return R.string.pyra3;
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
503 |
|
|
|
504 |
|
|
public int getInventor(int numLayers)
|
505 |
|
|
{
|
506 |
|
|
switch(numLayers)
|
507 |
|
|
{
|
508 |
|
|
case 3: return R.string.pyra3_inventor;
|
509 |
|
|
case 4: return R.string.pyra4_inventor;
|
510 |
|
|
case 5: return R.string.pyra5_inventor;
|
511 |
|
|
}
|
512 |
|
|
return R.string.pyra3_inventor;
|
513 |
|
|
}
|
514 |
|
|
|
515 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
516 |
|
|
|
517 |
|
|
public int getComplexity(int numLayers)
|
518 |
|
|
{
|
519 |
|
|
switch(numLayers)
|
520 |
|
|
{
|
521 |
|
|
case 3: return 4;
|
522 |
|
|
case 4: return 6;
|
523 |
|
|
case 5: return 8;
|
524 |
|
|
}
|
525 |
|
|
return 4;
|
526 |
|
|
}
|
527 |
e844c116
|
Leszek Koltunski
|
}
|