1 |
bbc6da6c
|
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 |
|
|
import android.graphics.Canvas;
|
24 |
|
|
import android.graphics.Paint;
|
25 |
|
|
|
26 |
749ef882
|
Leszek Koltunski
|
import org.distorted.helpers.FactoryCubit;
|
27 |
|
|
import org.distorted.helpers.FactorySticker;
|
28 |
bbc6da6c
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
29 |
|
|
import org.distorted.library.main.DistortedEffects;
|
30 |
|
|
import org.distorted.library.main.DistortedTexture;
|
31 |
|
|
import org.distorted.library.mesh.MeshBase;
|
32 |
|
|
import org.distorted.library.mesh.MeshSquare;
|
33 |
|
|
import org.distorted.library.type.Static3D;
|
34 |
|
|
import org.distorted.library.type.Static4D;
|
35 |
|
|
import org.distorted.main.R;
|
36 |
ead91342
|
Leszek Koltunski
|
import org.distorted.main.RubikSurfaceView;
|
37 |
|
|
|
38 |
bbc6da6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
a64e07d0
|
Leszek Koltunski
|
public class TwistyKilominx extends TwistyMinx
|
41 |
bbc6da6c
|
Leszek Koltunski
|
{
|
42 |
7764a67a
|
Leszek Koltunski
|
private static MeshBase[] mCenterMeshes, mCornerMeshes;
|
43 |
|
|
private static MeshBase[][] mEdgeMeshes;
|
44 |
|
|
|
45 |
22b32e57
|
Leszek Koltunski
|
private static final int[] mCenterFaceMap = new int[]
|
46 |
|
|
{
|
47 |
|
|
0,0,0,0,1,
|
48 |
|
|
1,0,1,1,0,
|
49 |
|
|
2,0,1,1,0,
|
50 |
|
|
2,2,1,0,2,
|
51 |
|
|
2,1,0,0,1,
|
52 |
|
|
1,2,0,1,0,
|
53 |
|
|
0,1,0,1,1,
|
54 |
|
|
0,1,0,2,0,
|
55 |
|
|
2,1,2,2,2,
|
56 |
|
|
1,0,2,1,2,
|
57 |
|
|
2,1,0,1,2,
|
58 |
|
|
2,2,2,2,2
|
59 |
|
|
};
|
60 |
|
|
|
61 |
bb11be2a
|
Leszek Koltunski
|
private static final float CENTER_CORR = 0.87f;
|
62 |
|
|
|
63 |
|
|
private static final float[][] STICKERS = new float[][]
|
64 |
|
|
{
|
65 |
|
|
{ -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f },
|
66 |
|
|
{ -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
|
67 |
|
|
{ -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f }
|
68 |
|
|
};
|
69 |
|
|
|
70 |
7764a67a
|
Leszek Koltunski
|
private static final int mNumCornerEdgeVariants;
|
71 |
|
|
|
72 |
|
|
static
|
73 |
|
|
{
|
74 |
|
|
int[] sizes = ObjectList.KILO.getSizes();
|
75 |
|
|
int variants = sizes.length;
|
76 |
|
|
mNumCornerEdgeVariants = sizes[0]==3 ? variants-1 : variants;
|
77 |
bb11be2a
|
Leszek Koltunski
|
|
78 |
|
|
STICKERS[0][2] *= CENTER_CORR;
|
79 |
|
|
STICKERS[0][3] *= CENTER_CORR;
|
80 |
7764a67a
|
Leszek Koltunski
|
}
|
81 |
bbc6da6c
|
Leszek Koltunski
|
|
82 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83 |
|
|
|
84 |
a64e07d0
|
Leszek Koltunski
|
TwistyKilominx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
85 |
|
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
86 |
bbc6da6c
|
Leszek Koltunski
|
{
|
87 |
a64e07d0
|
Leszek Koltunski
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
|
88 |
bbc6da6c
|
Leszek Koltunski
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
f6e46300
|
Leszek Koltunski
|
private int numCubitsPerCorner(int numLayers)
|
93 |
bbc6da6c
|
Leszek Koltunski
|
{
|
94 |
ead91342
|
Leszek Koltunski
|
return 3*((numLayers-3)/2)*((numLayers-5)/2) + (numLayers<5 ? 0:1);
|
95 |
bbc6da6c
|
Leszek Koltunski
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
f6e46300
|
Leszek Koltunski
|
private int numCubitsPerEdge(int numLayers)
|
100 |
bbc6da6c
|
Leszek Koltunski
|
{
|
101 |
ead91342
|
Leszek Koltunski
|
return numLayers<5 ? 0 : 2*(numLayers-4);
|
102 |
bbc6da6c
|
Leszek Koltunski
|
}
|
103 |
|
|
|
104 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105 |
|
|
|
106 |
f6e46300
|
Leszek Koltunski
|
int getNumStickerTypes(int numLayers)
|
107 |
bbc6da6c
|
Leszek Koltunski
|
{
|
108 |
ead91342
|
Leszek Koltunski
|
return numLayers<5 ? 1 : numLayers/2 + 1;
|
109 |
bbc6da6c
|
Leszek Koltunski
|
}
|
110 |
|
|
|
111 |
ab210d63
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112 |
|
|
|
113 |
|
|
float getScreenRatio()
|
114 |
|
|
{
|
115 |
|
|
return 1.00f;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
bbc6da6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119 |
f6e46300
|
Leszek Koltunski
|
|
120 |
e6734aa9
|
Leszek Koltunski
|
float[][] getCuts(int numLayers)
|
121 |
f6e46300
|
Leszek Koltunski
|
{
|
122 |
e6734aa9
|
Leszek Koltunski
|
float[][] cuts = new float[6][numLayers-1];
|
123 |
ead91342
|
Leszek Koltunski
|
float D = numLayers*MovementMinx.DIST3D;
|
124 |
bb11be2a
|
Leszek Koltunski
|
float E = 2*SIN54;
|
125 |
ead91342
|
Leszek Koltunski
|
float X = 2*D*E/(1+2*E); // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
|
126 |
|
|
// its height is then D*2*DIST3D, it has one 'lower' part of height X, one
|
127 |
|
|
// 'middle' part of height Y and one upper part of height X again.
|
128 |
|
|
// It's edge length = numLayers/3.0f.
|
129 |
|
|
int num = (numLayers-1)/2;
|
130 |
|
|
float G = X*0.5f/num; // height of one Layer
|
131 |
|
|
|
132 |
|
|
for(int i=0; i<num; i++)
|
133 |
|
|
{
|
134 |
e6734aa9
|
Leszek Koltunski
|
float cut = -D + (i+0.5f)*G;
|
135 |
|
|
int j = 2*num-1-i;
|
136 |
|
|
cuts[0][i] = +cut;
|
137 |
|
|
cuts[0][j] = -cut;
|
138 |
|
|
cuts[1][i] = +cut;
|
139 |
|
|
cuts[1][j] = -cut;
|
140 |
|
|
cuts[2][i] = +cut;
|
141 |
|
|
cuts[2][j] = -cut;
|
142 |
|
|
cuts[3][i] = +cut;
|
143 |
|
|
cuts[3][j] = -cut;
|
144 |
|
|
cuts[4][i] = +cut;
|
145 |
|
|
cuts[4][j] = -cut;
|
146 |
|
|
cuts[5][i] = +cut;
|
147 |
|
|
cuts[5][j] = -cut;
|
148 |
ead91342
|
Leszek Koltunski
|
}
|
149 |
|
|
|
150 |
|
|
return cuts;
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
154 |
|
|
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
|
155 |
|
|
// Appropriate one: QUATS[QUAT_INDICES[corner]].
|
156 |
|
|
|
157 |
|
|
private void computeBasicCornerVectors(int corner)
|
158 |
|
|
{
|
159 |
|
|
Static4D quat = QUATS[QUAT_CORNER_INDICES[corner]];
|
160 |
|
|
|
161 |
|
|
mCurrCornerV[0] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[0],quat);
|
162 |
|
|
mCurrCornerV[1] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[1],quat);
|
163 |
|
|
mCurrCornerV[2] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[2],quat);
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167 |
|
|
|
168 |
|
|
private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
|
169 |
|
|
{
|
170 |
|
|
float D = numLayers/3.0f;
|
171 |
|
|
float[] corn = CORNERS[corner];
|
172 |
|
|
|
173 |
|
|
if( part==0 )
|
174 |
|
|
{
|
175 |
|
|
return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
|
176 |
|
|
}
|
177 |
|
|
else
|
178 |
|
|
{
|
179 |
|
|
float E = D/(0.5f*(numLayers-1)); // ?? maybe 0.5*
|
180 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
181 |
|
|
int block = (part-1) % N;
|
182 |
|
|
int index = (part-1) / N;
|
183 |
|
|
Static4D pri = mCurrCornerV[index];
|
184 |
|
|
Static4D sec = mCurrCornerV[(index+2)%3];
|
185 |
|
|
|
186 |
|
|
int layers= (numLayers-5)/2;
|
187 |
|
|
int multP = (block % layers) + 1;
|
188 |
|
|
int multS = (block / layers);
|
189 |
|
|
|
190 |
|
|
return new float[] {
|
191 |
|
|
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
|
192 |
|
|
corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
|
193 |
|
|
corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
|
194 |
|
|
};
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199 |
|
|
|
200 |
|
|
private float[] computeCenter(int numLayers, int center, int part)
|
201 |
|
|
{
|
202 |
|
|
int corner = mCenterMap[center][part];
|
203 |
|
|
float[] cent = mCenterCoords[center];
|
204 |
|
|
float[] corn = CORNERS[corner];
|
205 |
|
|
float D = numLayers/3.0f;
|
206 |
|
|
float F = 1.0f - (2.0f*numLayers-6.0f)/(numLayers-1)*COS54*COS54;
|
207 |
|
|
|
208 |
|
|
return new float[]
|
209 |
|
|
{
|
210 |
|
|
D * ( cent[0] + (corn[0]-cent[0])*F),
|
211 |
|
|
D * ( cent[1] + (corn[1]-cent[1])*F),
|
212 |
|
|
D * ( cent[2] + (corn[2]-cent[2])*F)
|
213 |
|
|
};
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
217 |
|
|
|
218 |
|
|
private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
219 |
|
|
{
|
220 |
|
|
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
|
221 |
7764a67a
|
Leszek Koltunski
|
return part - 2*(part/4);
|
222 |
ead91342
|
Leszek Koltunski
|
}
|
223 |
|
|
|
224 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225 |
|
|
|
226 |
|
|
private float[] computeEdge(int numLayers, int edge, int part)
|
227 |
|
|
{
|
228 |
|
|
float D = numLayers/3.0f;
|
229 |
|
|
float[] c1 = CORNERS[ mEdgeMap[edge][0] ];
|
230 |
|
|
float[] c2 = CORNERS[ mEdgeMap[edge][1] ];
|
231 |
|
|
|
232 |
16f34a98
|
Leszek Koltunski
|
int leftRight = 2*(part%2) -1;
|
233 |
ead91342
|
Leszek Koltunski
|
part /= 2;
|
234 |
|
|
|
235 |
|
|
if( part==0 )
|
236 |
|
|
{
|
237 |
16f34a98
|
Leszek Koltunski
|
float T = 0.5f + leftRight/(numLayers-1.0f);
|
238 |
|
|
float x = D * (T*c1[0]+(1.0f-T)*c2[0]);
|
239 |
|
|
float y = D * (T*c1[1]+(1.0f-T)*c2[1]);
|
240 |
|
|
float z = D * (T*c1[2]+(1.0f-T)*c2[2]);
|
241 |
|
|
|
242 |
ead91342
|
Leszek Koltunski
|
return new float[] { x, y, z };
|
243 |
|
|
}
|
244 |
|
|
else
|
245 |
|
|
{
|
246 |
|
|
int mult = (part+1)/2;
|
247 |
|
|
int dir = (part+1)%2;
|
248 |
|
|
float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
|
249 |
16f34a98
|
Leszek Koltunski
|
float x = 0.5f * D * (c1[0]+c2[0]);
|
250 |
|
|
float y = 0.5f * D * (c1[1]+c2[1]);
|
251 |
|
|
float z = 0.5f * D * (c1[2]+c2[2]);
|
252 |
ead91342
|
Leszek Koltunski
|
|
253 |
|
|
float vX = D*center[0] - x;
|
254 |
|
|
float vY = D*center[1] - y;
|
255 |
|
|
float vZ = D*center[2] - z;
|
256 |
|
|
|
257 |
a4962b9c
|
Leszek Koltunski
|
float T = 0.5f + leftRight*(mult*SIN18 + 1.0f)/(numLayers-1);
|
258 |
|
|
|
259 |
16f34a98
|
Leszek Koltunski
|
x = D * (T*c1[0]+(1.0f-T)*c2[0]);
|
260 |
|
|
y = D * (T*c1[1]+(1.0f-T)*c2[1]);
|
261 |
|
|
z = D * (T*c1[2]+(1.0f-T)*c2[2]);
|
262 |
|
|
|
263 |
|
|
float H = mult*D*COS18/(numLayers-1);
|
264 |
|
|
H /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
265 |
ead91342
|
Leszek Koltunski
|
|
266 |
16f34a98
|
Leszek Koltunski
|
return new float[] { x + H*vX, y + H*vY, z + H*vZ };
|
267 |
ead91342
|
Leszek Koltunski
|
}
|
268 |
f6e46300
|
Leszek Koltunski
|
}
|
269 |
|
|
|
270 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
271 |
|
|
|
272 |
|
|
float[][] getCubitPositions(int numLayers)
|
273 |
|
|
{
|
274 |
ead91342
|
Leszek Koltunski
|
if( numLayers<5 ) return CORNERS;
|
275 |
|
|
|
276 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
277 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
278 |
|
|
int numCubitsPerCenter = 5;
|
279 |
|
|
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS*numCubitsPerCenter;
|
280 |
|
|
int index=0;
|
281 |
|
|
|
282 |
|
|
final float[][] CENTERS = new float[numCubits][];
|
283 |
|
|
|
284 |
|
|
for(int corner=0; corner<NUM_CORNERS; corner++)
|
285 |
|
|
{
|
286 |
|
|
computeBasicCornerVectors(corner);
|
287 |
|
|
|
288 |
|
|
for(int part=0; part<numCubitsPerCorner; part++, index++)
|
289 |
|
|
{
|
290 |
|
|
CENTERS[index] = computeCorner(numCubitsPerCorner,numLayers,corner,part);
|
291 |
|
|
}
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
for(int edge=0; edge<NUM_EDGES; edge++)
|
295 |
|
|
{
|
296 |
|
|
for(int part=0; part<numCubitsPerEdge; part++, index++)
|
297 |
|
|
{
|
298 |
|
|
CENTERS[index] = computeEdge(numLayers, edge, part );
|
299 |
|
|
}
|
300 |
|
|
}
|
301 |
|
|
|
302 |
b5347187
|
Leszek Koltunski
|
for(int center=0; center<NUM_CENTERS; center++)
|
303 |
ead91342
|
Leszek Koltunski
|
{
|
304 |
|
|
for(int part=0; part<numCubitsPerCenter; part++, index++)
|
305 |
|
|
{
|
306 |
|
|
CENTERS[index] = computeCenter(numLayers,center, part);
|
307 |
|
|
}
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
return CENTERS;
|
311 |
f6e46300
|
Leszek Koltunski
|
}
|
312 |
|
|
|
313 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
314 |
bbc6da6c
|
Leszek Koltunski
|
|
315 |
7764a67a
|
Leszek Koltunski
|
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
316 |
bbc6da6c
|
Leszek Koltunski
|
{
|
317 |
7764a67a
|
Leszek Koltunski
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
318 |
|
|
{
|
319 |
|
|
int corner = cubit/numCubitsPerCorner;
|
320 |
|
|
return QUAT_CORNER_INDICES[corner];
|
321 |
|
|
}
|
322 |
|
|
|
323 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
324 |
|
|
{
|
325 |
|
|
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
|
326 |
|
|
return QUAT_EDGE_INDICES[edge];
|
327 |
|
|
}
|
328 |
|
|
|
329 |
|
|
if( numCubitsPerCorner==0 )
|
330 |
|
|
{
|
331 |
|
|
return QUAT_CORNER_INDICES[cubit];
|
332 |
|
|
}
|
333 |
|
|
else
|
334 |
|
|
{
|
335 |
|
|
cubit -= (NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge);
|
336 |
|
|
int numCubitsPerCenter = 5;
|
337 |
|
|
int face = cubit/numCubitsPerCenter;
|
338 |
|
|
int index= cubit%numCubitsPerCenter;
|
339 |
|
|
int corner=mCenterMap[face][index];
|
340 |
|
|
|
341 |
|
|
return QUAT_CORNER_INDICES[corner];
|
342 |
|
|
}
|
343 |
bbc6da6c
|
Leszek Koltunski
|
}
|
344 |
|
|
|
345 |
5e06e92f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
346 |
|
|
|
347 |
|
|
private MeshBase createCenterMesh(float width)
|
348 |
|
|
{
|
349 |
|
|
double X = width*COS18*SIN_HALFD;
|
350 |
|
|
double Y = width*SIN18;
|
351 |
|
|
double Z = width*COS18*COS_HALFD;
|
352 |
|
|
double H = width*(SIN54/COS54);
|
353 |
|
|
double H3= H/COS_HALFD;
|
354 |
|
|
double X3= H*SIN_HALFD;
|
355 |
|
|
double Z3= H*COS_HALFD;;
|
356 |
|
|
double C = 1/(COS54*Math.sqrt(2-2*SIN18));
|
357 |
|
|
|
358 |
|
|
double[][] vertices = new double[][]
|
359 |
|
|
{
|
360 |
|
|
{ 0.0, 0.0 , 0.0 },
|
361 |
|
|
{ X, Y , -Z },
|
362 |
|
|
{ 0.0,C*2*Y ,-2*C*Z },
|
363 |
|
|
{ -X, Y , -Z },
|
364 |
|
|
{ 0.0,-width, 0.0 },
|
365 |
|
|
{ X3,-width, -Z3 },
|
366 |
|
|
{ 0.0,-width, -H3 },
|
367 |
|
|
{ -X3,-width, -Z3 }
|
368 |
|
|
};
|
369 |
|
|
|
370 |
|
|
int[][] vertIndexes = new int[][]
|
371 |
|
|
{
|
372 |
|
|
{4,5,1,0},
|
373 |
|
|
{7,4,0,3},
|
374 |
|
|
{0,1,2,3},
|
375 |
|
|
{7,6,2,3},
|
376 |
|
|
{6,5,1,2},
|
377 |
|
|
{4,5,6,7}
|
378 |
|
|
};
|
379 |
|
|
|
380 |
|
|
float[][] bands = new float[][]
|
381 |
|
|
{
|
382 |
|
|
{0.04f,17,0.3f,0.2f,5,1,1},
|
383 |
|
|
{0.00f, 0,0.0f,0.5f,2,0,0}
|
384 |
|
|
};
|
385 |
|
|
|
386 |
|
|
float A = (2*SQ3/3)*SIN54;
|
387 |
|
|
float B = 0.4f;
|
388 |
|
|
|
389 |
|
|
int[] bandIndexes = new int[] { 0,0,0,1,1,1};
|
390 |
|
|
float[][] corners = new float[][] { {0.03f,0.10f} };
|
391 |
|
|
int[] cornerIndexes = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
|
392 |
|
|
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
|
393 |
|
|
int[] centerIndexes = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
|
394 |
|
|
|
395 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
396 |
|
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
397 |
|
|
|
398 |
|
|
return factory.createRoundedSolid(vertices, vertIndexes,
|
399 |
|
|
bands, bandIndexes,
|
400 |
|
|
corners, cornerIndexes,
|
401 |
|
|
centers, centerIndexes,
|
402 |
|
|
getNumCubitFaces() );
|
403 |
|
|
}
|
404 |
|
|
|
405 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
406 |
|
|
|
407 |
|
|
private MeshBase createEdgeMesh(int numLayers, float width, float height, boolean left)
|
408 |
|
|
{
|
409 |
|
|
double X = height*SIN_HALFD;
|
410 |
|
|
double Y = height*SIN18/COS18;
|
411 |
|
|
double Z = height*COS_HALFD;
|
412 |
|
|
|
413 |
|
|
double[][] vertices = new double[][]
|
414 |
|
|
{
|
415 |
|
|
{ 0.0, 0.0 , 0.0 },
|
416 |
|
|
{ X, Y , -Z },
|
417 |
|
|
{ 0.0, 2*Y ,-2*Z },
|
418 |
|
|
{ -X, Y , -Z },
|
419 |
|
|
{ 0.0, -width, 0.0 },
|
420 |
|
|
{ X, -width, -Z },
|
421 |
|
|
{ 0.0, -width,-2*Z },
|
422 |
|
|
{ -X, -width, -Z },
|
423 |
|
|
};
|
424 |
|
|
|
425 |
|
|
int[][] vertIndexes = new int[][]
|
426 |
|
|
{
|
427 |
|
|
{4,5,1,0},
|
428 |
|
|
{7,4,0,3},
|
429 |
|
|
{7,6,2,3},
|
430 |
|
|
{6,5,1,2},
|
431 |
|
|
{0,1,2,3},
|
432 |
|
|
{4,5,6,7}
|
433 |
|
|
};
|
434 |
|
|
|
435 |
|
|
if( !left )
|
436 |
|
|
{
|
437 |
|
|
int tmp, len = vertices.length;
|
438 |
|
|
for(int i=0; i<len; i++) vertices[i][1] = -vertices[i][1];
|
439 |
|
|
|
440 |
|
|
len = vertIndexes.length;
|
441 |
|
|
for(int i=0; i<len; i++)
|
442 |
|
|
{
|
443 |
|
|
tmp = vertIndexes[i][0];
|
444 |
|
|
vertIndexes[i][0] = vertIndexes[i][3];
|
445 |
|
|
vertIndexes[i][3] = tmp;
|
446 |
|
|
|
447 |
|
|
tmp = vertIndexes[i][1];
|
448 |
|
|
vertIndexes[i][1] = vertIndexes[i][2];
|
449 |
|
|
vertIndexes[i][2] = tmp;
|
450 |
|
|
}
|
451 |
|
|
}
|
452 |
|
|
|
453 |
|
|
int numBands0 = numLayers<=5 ? 5 : 3;
|
454 |
|
|
int numBands1 = numLayers<=5 ? 3 : 2;
|
455 |
|
|
|
456 |
|
|
float[][] bands = new float[][]
|
457 |
|
|
{
|
458 |
|
|
{0.04f,34,0.2f,0.2f,numBands0,1,1},
|
459 |
|
|
{0.00f, 0,0.0f,0.0f,numBands1,0,0}
|
460 |
|
|
};
|
461 |
|
|
int[] bandIndexes = new int[] { 0,0,1,1,1,1};
|
462 |
|
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
463 |
|
|
int[] cornerIndexes = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
|
464 |
|
|
float[][] centers = new float[][] { {0.0f, -width/2, (float)(-2*Z)} };
|
465 |
|
|
int[] centerIndexes = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
|
466 |
|
|
|
467 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
468 |
|
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
469 |
|
|
|
470 |
|
|
return factory.createRoundedSolid(vertices, vertIndexes,
|
471 |
|
|
bands, bandIndexes,
|
472 |
|
|
corners, cornerIndexes,
|
473 |
|
|
centers, centerIndexes,
|
474 |
|
|
getNumCubitFaces() );
|
475 |
|
|
}
|
476 |
|
|
|
477 |
bbc6da6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
478 |
|
|
|
479 |
a64e07d0
|
Leszek Koltunski
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
480 |
bbc6da6c
|
Leszek Koltunski
|
{
|
481 |
7764a67a
|
Leszek Koltunski
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
482 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
483 |
|
|
int[] sizes = ObjectList.KILO.getSizes();
|
484 |
|
|
int variants = sizes.length;
|
485 |
|
|
int highestSize = sizes[variants-1];
|
486 |
|
|
int lowestSize = sizes[0];
|
487 |
|
|
int indexCornerEdge = (numLayers-lowestSize)/2 - (lowestSize==3 ? 1:0);
|
488 |
|
|
MeshBase mesh;
|
489 |
|
|
|
490 |
|
|
if( mNumCornerEdgeVariants>0 )
|
491 |
|
|
{
|
492 |
|
|
if( mCornerMeshes==null ) mCornerMeshes = new MeshBase[mNumCornerEdgeVariants];
|
493 |
b5347187
|
Leszek Koltunski
|
if( mEdgeMeshes ==null ) mEdgeMeshes = new MeshBase[mNumCornerEdgeVariants][highestSize-3];
|
494 |
7764a67a
|
Leszek Koltunski
|
}
|
495 |
|
|
|
496 |
|
|
if( mCenterMeshes==null ) mCenterMeshes = new MeshBase[variants];
|
497 |
|
|
|
498 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
499 |
|
|
{
|
500 |
|
|
if( mCornerMeshes[indexCornerEdge]==null )
|
501 |
|
|
{
|
502 |
16f34a98
|
Leszek Koltunski
|
float width = (numLayers/3.0f)/(numLayers-1);
|
503 |
5e06e92f
|
Leszek Koltunski
|
mCornerMeshes[indexCornerEdge] = createCornerMesh(numLayers,width);
|
504 |
7764a67a
|
Leszek Koltunski
|
}
|
505 |
|
|
mesh = mCornerMeshes[indexCornerEdge].copy(true);
|
506 |
|
|
}
|
507 |
|
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
508 |
|
|
{
|
509 |
|
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge); // left-top, right-top, left-second, right-second, left-third...
|
510 |
|
|
|
511 |
|
|
if( mEdgeMeshes[indexCornerEdge][type]==null )
|
512 |
|
|
{
|
513 |
|
|
float tmp = (numLayers/3.0f)/(numLayers-1);
|
514 |
|
|
float height= tmp*COS18;
|
515 |
a4962b9c
|
Leszek Koltunski
|
float width = tmp + (type/2)*tmp*SIN18;
|
516 |
7764a67a
|
Leszek Koltunski
|
|
517 |
5e06e92f
|
Leszek Koltunski
|
mEdgeMeshes[indexCornerEdge][type] = createEdgeMesh(numLayers,width,height, (type%2)==0 );
|
518 |
7764a67a
|
Leszek Koltunski
|
}
|
519 |
|
|
|
520 |
|
|
mesh = mEdgeMeshes[indexCornerEdge][type].copy(true);
|
521 |
|
|
}
|
522 |
|
|
else
|
523 |
|
|
{
|
524 |
|
|
int indexCenter = (numLayers-3)/2;
|
525 |
|
|
|
526 |
|
|
if( mCenterMeshes[indexCenter]==null )
|
527 |
|
|
{
|
528 |
|
|
float width = (1+0.5f*(numLayers-3)*SIN18)*(numLayers/3.0f)/(numLayers-1);
|
529 |
5e06e92f
|
Leszek Koltunski
|
mCenterMeshes[indexCenter] = createCenterMesh(width);
|
530 |
7764a67a
|
Leszek Koltunski
|
}
|
531 |
|
|
|
532 |
|
|
mesh = mCenterMeshes[indexCenter].copy(true);
|
533 |
|
|
}
|
534 |
bbc6da6c
|
Leszek Koltunski
|
|
535 |
7764a67a
|
Leszek Koltunski
|
Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
|
536 |
|
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( q, new Static3D(0,0,0) );
|
537 |
bbc6da6c
|
Leszek Koltunski
|
mesh.apply(quat,0xffffffff,0);
|
538 |
|
|
|
539 |
|
|
return mesh;
|
540 |
|
|
}
|
541 |
|
|
|
542 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
543 |
|
|
|
544 |
a4962b9c
|
Leszek Koltunski
|
int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
|
545 |
bbc6da6c
|
Leszek Koltunski
|
{
|
546 |
a4962b9c
|
Leszek Koltunski
|
if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
|
547 |
|
|
|
548 |
|
|
int part = cubit % numCubitsPerCorner;
|
549 |
|
|
int corner= cubit / numCubitsPerCorner;
|
550 |
|
|
|
551 |
|
|
if( part==0 )
|
552 |
b5347187
|
Leszek Koltunski
|
{
|
553 |
a4962b9c
|
Leszek Koltunski
|
return mCornerFaceMap[corner][cubitface];
|
554 |
b5347187
|
Leszek Koltunski
|
}
|
555 |
a4962b9c
|
Leszek Koltunski
|
else
|
556 |
|
|
{
|
557 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
558 |
|
|
int block = (part-1) % N;
|
559 |
|
|
int index = (part-1) / N;
|
560 |
b5347187
|
Leszek Koltunski
|
|
561 |
a4962b9c
|
Leszek Koltunski
|
if( block< (numLayers-3)/2 )
|
562 |
|
|
{
|
563 |
|
|
switch(index)
|
564 |
|
|
{
|
565 |
|
|
case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
566 |
|
|
case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
567 |
|
|
case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
568 |
|
|
}
|
569 |
|
|
}
|
570 |
|
|
else
|
571 |
|
|
{
|
572 |
|
|
switch(index)
|
573 |
|
|
{
|
574 |
|
|
case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
575 |
|
|
case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
576 |
|
|
case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
577 |
|
|
}
|
578 |
|
|
}
|
579 |
|
|
}
|
580 |
|
|
|
581 |
|
|
return NUM_TEXTURES;
|
582 |
|
|
}
|
583 |
|
|
|
584 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
585 |
|
|
|
586 |
|
|
int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
|
587 |
|
|
{
|
588 |
|
|
if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
|
589 |
7a606778
|
Leszek Koltunski
|
|
590 |
a4962b9c
|
Leszek Koltunski
|
int part = edge % numCubitsPerEdge;
|
591 |
|
|
int variant = edge / numCubitsPerEdge;
|
592 |
7a606778
|
Leszek Koltunski
|
|
593 |
a4962b9c
|
Leszek Koltunski
|
part /=2;
|
594 |
|
|
|
595 |
|
|
return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACES : NUM_TEXTURES;
|
596 |
|
|
}
|
597 |
|
|
|
598 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
599 |
|
|
|
600 |
|
|
int getCenterColor(int center, int cubitface, int numLayers)
|
601 |
|
|
{
|
602 |
|
|
if( numLayers==3 )
|
603 |
7a606778
|
Leszek Koltunski
|
{
|
604 |
a4962b9c
|
Leszek Koltunski
|
return cubitface>=0 && cubitface<3 ? mCornerFaceMap[center][cubitface] : NUM_TEXTURES;
|
605 |
7a606778
|
Leszek Koltunski
|
}
|
606 |
|
|
|
607 |
22b32e57
|
Leszek Koltunski
|
return cubitface==mCenterFaceMap[center] ? center/5 + NUM_FACES*(numLayers-1)/2 : NUM_TEXTURES;
|
608 |
a4962b9c
|
Leszek Koltunski
|
}
|
609 |
|
|
|
610 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
611 |
|
|
|
612 |
|
|
int getFaceColor(int cubit, int cubitface, int numLayers)
|
613 |
|
|
{
|
614 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
615 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
616 |
|
|
|
617 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
618 |
|
|
{
|
619 |
|
|
return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
|
620 |
|
|
}
|
621 |
|
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
622 |
|
|
{
|
623 |
|
|
int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
|
624 |
|
|
return getEdgeColor(edge,cubitface,numCubitsPerEdge);
|
625 |
|
|
}
|
626 |
|
|
else
|
627 |
|
|
{
|
628 |
|
|
int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
|
629 |
|
|
return getCenterColor( center, cubitface, numLayers);
|
630 |
|
|
}
|
631 |
bbc6da6c
|
Leszek Koltunski
|
}
|
632 |
|
|
|
633 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
634 |
|
|
|
635 |
|
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
|
636 |
|
|
{
|
637 |
ca824448
|
Leszek Koltunski
|
int COLORS = FACE_COLORS.length;
|
638 |
|
|
int variant = face/COLORS;
|
639 |
|
|
int numLayers = getNumLayers();
|
640 |
bbc6da6c
|
Leszek Koltunski
|
|
641 |
5e06e92f
|
Leszek Koltunski
|
if( variant == (numLayers-1)/2 || numLayers==3 ) // center
|
642 |
ca824448
|
Leszek Koltunski
|
{
|
643 |
5e06e92f
|
Leszek Koltunski
|
float R = 0.10f;
|
644 |
|
|
float S = 0.09f;
|
645 |
bb11be2a
|
Leszek Koltunski
|
float cx = STICKERS[0][2]/CENTER_CORR;
|
646 |
|
|
float cy = STICKERS[0][3]/CENTER_CORR;
|
647 |
4e627d8b
|
Leszek Koltunski
|
|
648 |
ca824448
|
Leszek Koltunski
|
FactorySticker factory = FactorySticker.getInstance();
|
649 |
bb11be2a
|
Leszek Koltunski
|
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face%NUM_FACES], R);
|
650 |
5e06e92f
|
Leszek Koltunski
|
canvas.drawCircle(left+(0.5f+cx)*TEXTURE_HEIGHT, top+(0.5f-cy)*TEXTURE_HEIGHT, 0.05f*TEXTURE_HEIGHT, paint);
|
651 |
ca824448
|
Leszek Koltunski
|
}
|
652 |
5e06e92f
|
Leszek Koltunski
|
else if( variant==0 ) // corner
|
653 |
ca824448
|
Leszek Koltunski
|
{
|
654 |
5e06e92f
|
Leszek Koltunski
|
float R = 0.10f;
|
655 |
|
|
float S = 0.11f;
|
656 |
ca824448
|
Leszek Koltunski
|
FactorySticker factory = FactorySticker.getInstance();
|
657 |
bb11be2a
|
Leszek Koltunski
|
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[1], S, FACE_COLORS[face%COLORS], R);
|
658 |
ca824448
|
Leszek Koltunski
|
}
|
659 |
5e06e92f
|
Leszek Koltunski
|
else // edge
|
660 |
ca824448
|
Leszek Koltunski
|
{
|
661 |
5e06e92f
|
Leszek Koltunski
|
float R = 0.10f;
|
662 |
|
|
float S = 0.10f;
|
663 |
ca824448
|
Leszek Koltunski
|
FactorySticker factory = FactorySticker.getInstance();
|
664 |
bb11be2a
|
Leszek Koltunski
|
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[2], S, FACE_COLORS[face%COLORS], R);
|
665 |
ca824448
|
Leszek Koltunski
|
}
|
666 |
bbc6da6c
|
Leszek Koltunski
|
}
|
667 |
|
|
|
668 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
669 |
|
|
// PUBLIC API
|
670 |
|
|
|
671 |
|
|
public boolean isSolved()
|
672 |
|
|
{
|
673 |
f6e46300
|
Leszek Koltunski
|
int index = CUBITS[0].mQuatIndex;
|
674 |
bbc6da6c
|
Leszek Koltunski
|
|
675 |
f6e46300
|
Leszek Koltunski
|
for(int i=1; i<NUM_CUBITS; i++)
|
676 |
bbc6da6c
|
Leszek Koltunski
|
{
|
677 |
f6e46300
|
Leszek Koltunski
|
if( thereIsVisibleDifference(CUBITS[i], index) ) return false;
|
678 |
bbc6da6c
|
Leszek Koltunski
|
}
|
679 |
|
|
|
680 |
|
|
return true;
|
681 |
|
|
}
|
682 |
|
|
|
683 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
684 |
|
|
|
685 |
|
|
public int getObjectName(int numLayers)
|
686 |
|
|
{
|
687 |
f6e46300
|
Leszek Koltunski
|
if( numLayers==3 ) return R.string.minx2;
|
688 |
|
|
if( numLayers==5 ) return R.string.minx4;
|
689 |
|
|
|
690 |
|
|
return 0;
|
691 |
bbc6da6c
|
Leszek Koltunski
|
}
|
692 |
|
|
|
693 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
694 |
|
|
|
695 |
|
|
public int getInventor(int numLayers)
|
696 |
|
|
{
|
697 |
f6e46300
|
Leszek Koltunski
|
if( numLayers==3 ) return R.string.minx2_inventor;
|
698 |
|
|
if( numLayers==5 ) return R.string.minx4_inventor;
|
699 |
|
|
|
700 |
|
|
return 0;
|
701 |
bbc6da6c
|
Leszek Koltunski
|
}
|
702 |
|
|
|
703 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
704 |
|
|
|
705 |
|
|
public int getComplexity(int numLayers)
|
706 |
|
|
{
|
707 |
|
|
return 3;
|
708 |
|
|
}
|
709 |
|
|
}
|