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