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 |
749ef882
|
Leszek Koltunski
|
import static org.distorted.helpers.FactoryCubit.COS18;
|
39 |
|
|
import static org.distorted.helpers.FactoryCubit.COS54;
|
40 |
|
|
import static org.distorted.helpers.FactoryCubit.SIN18;
|
41 |
|
|
import static org.distorted.helpers.FactoryCubit.SIN54;
|
42 |
bbc6da6c
|
Leszek Koltunski
|
|
43 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44 |
|
|
|
45 |
a64e07d0
|
Leszek Koltunski
|
public class TwistyKilominx extends TwistyMinx
|
46 |
bbc6da6c
|
Leszek Koltunski
|
{
|
47 |
7764a67a
|
Leszek Koltunski
|
private static MeshBase[] mCenterMeshes, mCornerMeshes;
|
48 |
|
|
private static MeshBase[][] mEdgeMeshes;
|
49 |
|
|
|
50 |
22b32e57
|
Leszek Koltunski
|
private static final int[] mCenterFaceMap = new int[]
|
51 |
|
|
{
|
52 |
|
|
0,0,0,0,1,
|
53 |
|
|
1,0,1,1,0,
|
54 |
|
|
2,0,1,1,0,
|
55 |
|
|
2,2,1,0,2,
|
56 |
|
|
2,1,0,0,1,
|
57 |
|
|
1,2,0,1,0,
|
58 |
|
|
0,1,0,1,1,
|
59 |
|
|
0,1,0,2,0,
|
60 |
|
|
2,1,2,2,2,
|
61 |
|
|
1,0,2,1,2,
|
62 |
|
|
2,1,0,1,2,
|
63 |
|
|
2,2,2,2,2
|
64 |
|
|
};
|
65 |
|
|
|
66 |
7764a67a
|
Leszek Koltunski
|
private static final int mNumCornerEdgeVariants;
|
67 |
|
|
|
68 |
|
|
static
|
69 |
|
|
{
|
70 |
|
|
int[] sizes = ObjectList.KILO.getSizes();
|
71 |
|
|
int variants = sizes.length;
|
72 |
|
|
mNumCornerEdgeVariants = sizes[0]==3 ? variants-1 : variants;
|
73 |
|
|
}
|
74 |
bbc6da6c
|
Leszek Koltunski
|
|
75 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
|
|
|
77 |
a64e07d0
|
Leszek Koltunski
|
TwistyKilominx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
78 |
|
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
79 |
bbc6da6c
|
Leszek Koltunski
|
{
|
80 |
a64e07d0
|
Leszek Koltunski
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
|
81 |
bbc6da6c
|
Leszek Koltunski
|
}
|
82 |
|
|
|
83 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
f6e46300
|
Leszek Koltunski
|
private int numCubitsPerCorner(int numLayers)
|
86 |
bbc6da6c
|
Leszek Koltunski
|
{
|
87 |
ead91342
|
Leszek Koltunski
|
return 3*((numLayers-3)/2)*((numLayers-5)/2) + (numLayers<5 ? 0:1);
|
88 |
bbc6da6c
|
Leszek Koltunski
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
f6e46300
|
Leszek Koltunski
|
private int numCubitsPerEdge(int numLayers)
|
93 |
bbc6da6c
|
Leszek Koltunski
|
{
|
94 |
ead91342
|
Leszek Koltunski
|
return numLayers<5 ? 0 : 2*(numLayers-4);
|
95 |
bbc6da6c
|
Leszek Koltunski
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
f6e46300
|
Leszek Koltunski
|
int getNumStickerTypes(int numLayers)
|
100 |
bbc6da6c
|
Leszek Koltunski
|
{
|
101 |
ead91342
|
Leszek Koltunski
|
return numLayers<5 ? 1 : numLayers/2 + 1;
|
102 |
bbc6da6c
|
Leszek Koltunski
|
}
|
103 |
|
|
|
104 |
ab210d63
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105 |
|
|
|
106 |
|
|
float getScreenRatio()
|
107 |
|
|
{
|
108 |
|
|
return 1.00f;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
bbc6da6c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112 |
f6e46300
|
Leszek Koltunski
|
|
113 |
|
|
float[] getCuts(int numLayers)
|
114 |
|
|
{
|
115 |
ead91342
|
Leszek Koltunski
|
float[] cuts = new float[numLayers-1];
|
116 |
|
|
float D = numLayers*MovementMinx.DIST3D;
|
117 |
|
|
float E = 2*C1; // 2*cos(36 deg)
|
118 |
|
|
float X = 2*D*E/(1+2*E); // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
|
119 |
|
|
// its height is then D*2*DIST3D, it has one 'lower' part of height X, one
|
120 |
|
|
// 'middle' part of height Y and one upper part of height X again.
|
121 |
|
|
// It's edge length = numLayers/3.0f.
|
122 |
|
|
int num = (numLayers-1)/2;
|
123 |
|
|
float G = X*0.5f/num; // height of one Layer
|
124 |
|
|
|
125 |
|
|
for(int i=0; i<num; i++)
|
126 |
|
|
{
|
127 |
|
|
cuts[ i] = -D + (i+0.5f)*G;
|
128 |
|
|
cuts[2*num-1-i] = -cuts[i];
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
return cuts;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135 |
|
|
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
|
136 |
|
|
// Appropriate one: QUATS[QUAT_INDICES[corner]].
|
137 |
|
|
|
138 |
|
|
private void computeBasicCornerVectors(int corner)
|
139 |
|
|
{
|
140 |
|
|
Static4D quat = QUATS[QUAT_CORNER_INDICES[corner]];
|
141 |
|
|
|
142 |
|
|
mCurrCornerV[0] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[0],quat);
|
143 |
|
|
mCurrCornerV[1] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[1],quat);
|
144 |
|
|
mCurrCornerV[2] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[2],quat);
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148 |
|
|
|
149 |
|
|
private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
|
150 |
|
|
{
|
151 |
|
|
float D = numLayers/3.0f;
|
152 |
|
|
float[] corn = CORNERS[corner];
|
153 |
|
|
|
154 |
|
|
if( part==0 )
|
155 |
|
|
{
|
156 |
|
|
return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
|
157 |
|
|
}
|
158 |
|
|
else
|
159 |
|
|
{
|
160 |
|
|
float E = D/(0.5f*(numLayers-1)); // ?? maybe 0.5*
|
161 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
162 |
|
|
int block = (part-1) % N;
|
163 |
|
|
int index = (part-1) / N;
|
164 |
|
|
Static4D pri = mCurrCornerV[index];
|
165 |
|
|
Static4D sec = mCurrCornerV[(index+2)%3];
|
166 |
|
|
|
167 |
|
|
int layers= (numLayers-5)/2;
|
168 |
|
|
int multP = (block % layers) + 1;
|
169 |
|
|
int multS = (block / layers);
|
170 |
|
|
|
171 |
|
|
return new float[] {
|
172 |
|
|
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
|
173 |
|
|
corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
|
174 |
|
|
corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
|
175 |
|
|
};
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180 |
|
|
|
181 |
|
|
private float[] computeCenter(int numLayers, int center, int part)
|
182 |
|
|
{
|
183 |
|
|
int corner = mCenterMap[center][part];
|
184 |
|
|
float[] cent = mCenterCoords[center];
|
185 |
|
|
float[] corn = CORNERS[corner];
|
186 |
|
|
float D = numLayers/3.0f;
|
187 |
|
|
float F = 1.0f - (2.0f*numLayers-6.0f)/(numLayers-1)*COS54*COS54;
|
188 |
|
|
|
189 |
|
|
return new float[]
|
190 |
|
|
{
|
191 |
|
|
D * ( cent[0] + (corn[0]-cent[0])*F),
|
192 |
|
|
D * ( cent[1] + (corn[1]-cent[1])*F),
|
193 |
|
|
D * ( cent[2] + (corn[2]-cent[2])*F)
|
194 |
|
|
};
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198 |
|
|
|
199 |
|
|
private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
200 |
|
|
{
|
201 |
|
|
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
|
202 |
7764a67a
|
Leszek Koltunski
|
return part - 2*(part/4);
|
203 |
ead91342
|
Leszek Koltunski
|
}
|
204 |
|
|
|
205 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
206 |
|
|
|
207 |
|
|
private float[] computeEdge(int numLayers, int edge, int part)
|
208 |
|
|
{
|
209 |
|
|
float D = numLayers/3.0f;
|
210 |
|
|
float[] c1 = CORNERS[ mEdgeMap[edge][0] ];
|
211 |
|
|
float[] c2 = CORNERS[ mEdgeMap[edge][1] ];
|
212 |
|
|
|
213 |
16f34a98
|
Leszek Koltunski
|
int leftRight = 2*(part%2) -1;
|
214 |
ead91342
|
Leszek Koltunski
|
part /= 2;
|
215 |
|
|
|
216 |
|
|
if( part==0 )
|
217 |
|
|
{
|
218 |
16f34a98
|
Leszek Koltunski
|
float T = 0.5f + leftRight/(numLayers-1.0f);
|
219 |
|
|
float x = D * (T*c1[0]+(1.0f-T)*c2[0]);
|
220 |
|
|
float y = D * (T*c1[1]+(1.0f-T)*c2[1]);
|
221 |
|
|
float z = D * (T*c1[2]+(1.0f-T)*c2[2]);
|
222 |
|
|
|
223 |
ead91342
|
Leszek Koltunski
|
return new float[] { x, y, z };
|
224 |
|
|
}
|
225 |
|
|
else
|
226 |
|
|
{
|
227 |
|
|
int mult = (part+1)/2;
|
228 |
|
|
int dir = (part+1)%2;
|
229 |
|
|
float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
|
230 |
16f34a98
|
Leszek Koltunski
|
float x = 0.5f * D * (c1[0]+c2[0]);
|
231 |
|
|
float y = 0.5f * D * (c1[1]+c2[1]);
|
232 |
|
|
float z = 0.5f * D * (c1[2]+c2[2]);
|
233 |
ead91342
|
Leszek Koltunski
|
|
234 |
|
|
float vX = D*center[0] - x;
|
235 |
|
|
float vY = D*center[1] - y;
|
236 |
|
|
float vZ = D*center[2] - z;
|
237 |
|
|
|
238 |
a4962b9c
|
Leszek Koltunski
|
float T = 0.5f + leftRight*(mult*SIN18 + 1.0f)/(numLayers-1);
|
239 |
|
|
|
240 |
16f34a98
|
Leszek Koltunski
|
x = D * (T*c1[0]+(1.0f-T)*c2[0]);
|
241 |
|
|
y = D * (T*c1[1]+(1.0f-T)*c2[1]);
|
242 |
|
|
z = D * (T*c1[2]+(1.0f-T)*c2[2]);
|
243 |
|
|
|
244 |
|
|
float H = mult*D*COS18/(numLayers-1);
|
245 |
|
|
H /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
246 |
ead91342
|
Leszek Koltunski
|
|
247 |
16f34a98
|
Leszek Koltunski
|
return new float[] { x + H*vX, y + H*vY, z + H*vZ };
|
248 |
ead91342
|
Leszek Koltunski
|
}
|
249 |
f6e46300
|
Leszek Koltunski
|
}
|
250 |
|
|
|
251 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
252 |
|
|
|
253 |
|
|
float[][] getCubitPositions(int numLayers)
|
254 |
|
|
{
|
255 |
ead91342
|
Leszek Koltunski
|
if( numLayers<5 ) return CORNERS;
|
256 |
|
|
|
257 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
258 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
259 |
|
|
int numCubitsPerCenter = 5;
|
260 |
|
|
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS*numCubitsPerCenter;
|
261 |
|
|
int index=0;
|
262 |
|
|
|
263 |
|
|
final float[][] CENTERS = new float[numCubits][];
|
264 |
|
|
|
265 |
|
|
for(int corner=0; corner<NUM_CORNERS; corner++)
|
266 |
|
|
{
|
267 |
|
|
computeBasicCornerVectors(corner);
|
268 |
|
|
|
269 |
|
|
for(int part=0; part<numCubitsPerCorner; part++, index++)
|
270 |
|
|
{
|
271 |
|
|
CENTERS[index] = computeCorner(numCubitsPerCorner,numLayers,corner,part);
|
272 |
|
|
}
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
for(int edge=0; edge<NUM_EDGES; edge++)
|
276 |
|
|
{
|
277 |
|
|
for(int part=0; part<numCubitsPerEdge; part++, index++)
|
278 |
|
|
{
|
279 |
|
|
CENTERS[index] = computeEdge(numLayers, edge, part );
|
280 |
|
|
}
|
281 |
|
|
}
|
282 |
|
|
|
283 |
b5347187
|
Leszek Koltunski
|
for(int center=0; center<NUM_CENTERS; center++)
|
284 |
ead91342
|
Leszek Koltunski
|
{
|
285 |
|
|
for(int part=0; part<numCubitsPerCenter; part++, index++)
|
286 |
|
|
{
|
287 |
|
|
CENTERS[index] = computeCenter(numLayers,center, part);
|
288 |
|
|
}
|
289 |
|
|
}
|
290 |
|
|
|
291 |
|
|
return CENTERS;
|
292 |
f6e46300
|
Leszek Koltunski
|
}
|
293 |
|
|
|
294 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
295 |
bbc6da6c
|
Leszek Koltunski
|
|
296 |
7764a67a
|
Leszek Koltunski
|
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
297 |
bbc6da6c
|
Leszek Koltunski
|
{
|
298 |
7764a67a
|
Leszek Koltunski
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
299 |
|
|
{
|
300 |
|
|
int corner = cubit/numCubitsPerCorner;
|
301 |
|
|
return QUAT_CORNER_INDICES[corner];
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
305 |
|
|
{
|
306 |
|
|
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
|
307 |
|
|
return QUAT_EDGE_INDICES[edge];
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
if( numCubitsPerCorner==0 )
|
311 |
|
|
{
|
312 |
|
|
return QUAT_CORNER_INDICES[cubit];
|
313 |
|
|
}
|
314 |
|
|
else
|
315 |
|
|
{
|
316 |
|
|
cubit -= (NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge);
|
317 |
|
|
int numCubitsPerCenter = 5;
|
318 |
|
|
int face = cubit/numCubitsPerCenter;
|
319 |
|
|
int index= cubit%numCubitsPerCenter;
|
320 |
|
|
int corner=mCenterMap[face][index];
|
321 |
|
|
|
322 |
|
|
return QUAT_CORNER_INDICES[corner];
|
323 |
|
|
}
|
324 |
bbc6da6c
|
Leszek Koltunski
|
}
|
325 |
|
|
|
326 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
327 |
|
|
|
328 |
a64e07d0
|
Leszek Koltunski
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
329 |
bbc6da6c
|
Leszek Koltunski
|
{
|
330 |
7764a67a
|
Leszek Koltunski
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
331 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
332 |
|
|
int[] sizes = ObjectList.KILO.getSizes();
|
333 |
|
|
int variants = sizes.length;
|
334 |
|
|
int highestSize = sizes[variants-1];
|
335 |
|
|
int lowestSize = sizes[0];
|
336 |
|
|
int indexCornerEdge = (numLayers-lowestSize)/2 - (lowestSize==3 ? 1:0);
|
337 |
|
|
MeshBase mesh;
|
338 |
|
|
|
339 |
|
|
if( mNumCornerEdgeVariants>0 )
|
340 |
|
|
{
|
341 |
|
|
if( mCornerMeshes==null ) mCornerMeshes = new MeshBase[mNumCornerEdgeVariants];
|
342 |
b5347187
|
Leszek Koltunski
|
if( mEdgeMeshes ==null ) mEdgeMeshes = new MeshBase[mNumCornerEdgeVariants][highestSize-3];
|
343 |
7764a67a
|
Leszek Koltunski
|
}
|
344 |
|
|
|
345 |
|
|
if( mCenterMeshes==null ) mCenterMeshes = new MeshBase[variants];
|
346 |
|
|
|
347 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
348 |
|
|
{
|
349 |
|
|
if( mCornerMeshes[indexCornerEdge]==null )
|
350 |
|
|
{
|
351 |
16f34a98
|
Leszek Koltunski
|
float width = (numLayers/3.0f)/(numLayers-1);
|
352 |
|
|
mCornerMeshes[indexCornerEdge] = FactoryCubit.getInstance().createMinxCornerMesh(numLayers,width);
|
353 |
7764a67a
|
Leszek Koltunski
|
}
|
354 |
|
|
mesh = mCornerMeshes[indexCornerEdge].copy(true);
|
355 |
|
|
}
|
356 |
|
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
357 |
|
|
{
|
358 |
|
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge); // left-top, right-top, left-second, right-second, left-third...
|
359 |
|
|
|
360 |
|
|
if( mEdgeMeshes[indexCornerEdge][type]==null )
|
361 |
|
|
{
|
362 |
|
|
float tmp = (numLayers/3.0f)/(numLayers-1);
|
363 |
|
|
float height= tmp*COS18;
|
364 |
a4962b9c
|
Leszek Koltunski
|
float width = tmp + (type/2)*tmp*SIN18;
|
365 |
7764a67a
|
Leszek Koltunski
|
|
366 |
16f34a98
|
Leszek Koltunski
|
mEdgeMeshes[indexCornerEdge][type] = FactoryCubit.getInstance().createKilominxEdgeMesh(numLayers,width,height, (type%2)==0 );
|
367 |
7764a67a
|
Leszek Koltunski
|
}
|
368 |
|
|
|
369 |
|
|
mesh = mEdgeMeshes[indexCornerEdge][type].copy(true);
|
370 |
|
|
}
|
371 |
|
|
else
|
372 |
|
|
{
|
373 |
|
|
int indexCenter = (numLayers-3)/2;
|
374 |
|
|
|
375 |
|
|
if( mCenterMeshes[indexCenter]==null )
|
376 |
|
|
{
|
377 |
|
|
float width = (1+0.5f*(numLayers-3)*SIN18)*(numLayers/3.0f)/(numLayers-1);
|
378 |
|
|
mCenterMeshes[indexCenter] = FactoryCubit.getInstance().createKilominxCenterMesh(width);
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
mesh = mCenterMeshes[indexCenter].copy(true);
|
382 |
|
|
}
|
383 |
bbc6da6c
|
Leszek Koltunski
|
|
384 |
7764a67a
|
Leszek Koltunski
|
Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
|
385 |
|
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( q, new Static3D(0,0,0) );
|
386 |
bbc6da6c
|
Leszek Koltunski
|
mesh.apply(quat,0xffffffff,0);
|
387 |
|
|
|
388 |
|
|
return mesh;
|
389 |
|
|
}
|
390 |
|
|
|
391 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
392 |
|
|
|
393 |
a4962b9c
|
Leszek Koltunski
|
int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
|
394 |
bbc6da6c
|
Leszek Koltunski
|
{
|
395 |
a4962b9c
|
Leszek Koltunski
|
if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
|
396 |
|
|
|
397 |
|
|
int part = cubit % numCubitsPerCorner;
|
398 |
|
|
int corner= cubit / numCubitsPerCorner;
|
399 |
|
|
|
400 |
|
|
if( part==0 )
|
401 |
b5347187
|
Leszek Koltunski
|
{
|
402 |
a4962b9c
|
Leszek Koltunski
|
return mCornerFaceMap[corner][cubitface];
|
403 |
b5347187
|
Leszek Koltunski
|
}
|
404 |
a4962b9c
|
Leszek Koltunski
|
else
|
405 |
|
|
{
|
406 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
407 |
|
|
int block = (part-1) % N;
|
408 |
|
|
int index = (part-1) / N;
|
409 |
b5347187
|
Leszek Koltunski
|
|
410 |
a4962b9c
|
Leszek Koltunski
|
if( block< (numLayers-3)/2 )
|
411 |
|
|
{
|
412 |
|
|
switch(index)
|
413 |
|
|
{
|
414 |
|
|
case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
415 |
|
|
case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
416 |
|
|
case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
417 |
|
|
}
|
418 |
|
|
}
|
419 |
|
|
else
|
420 |
|
|
{
|
421 |
|
|
switch(index)
|
422 |
|
|
{
|
423 |
|
|
case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
424 |
|
|
case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
425 |
|
|
case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
426 |
|
|
}
|
427 |
|
|
}
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
return NUM_TEXTURES;
|
431 |
|
|
}
|
432 |
|
|
|
433 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434 |
|
|
|
435 |
|
|
int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
|
436 |
|
|
{
|
437 |
|
|
if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
|
438 |
7a606778
|
Leszek Koltunski
|
|
439 |
a4962b9c
|
Leszek Koltunski
|
int part = edge % numCubitsPerEdge;
|
440 |
|
|
int variant = edge / numCubitsPerEdge;
|
441 |
7a606778
|
Leszek Koltunski
|
|
442 |
a4962b9c
|
Leszek Koltunski
|
part /=2;
|
443 |
|
|
|
444 |
|
|
return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACES : NUM_TEXTURES;
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
448 |
|
|
|
449 |
|
|
int getCenterColor(int center, int cubitface, int numLayers)
|
450 |
|
|
{
|
451 |
|
|
if( numLayers==3 )
|
452 |
7a606778
|
Leszek Koltunski
|
{
|
453 |
a4962b9c
|
Leszek Koltunski
|
return cubitface>=0 && cubitface<3 ? mCornerFaceMap[center][cubitface] : NUM_TEXTURES;
|
454 |
7a606778
|
Leszek Koltunski
|
}
|
455 |
|
|
|
456 |
22b32e57
|
Leszek Koltunski
|
return cubitface==mCenterFaceMap[center] ? center/5 + NUM_FACES*(numLayers-1)/2 : NUM_TEXTURES;
|
457 |
a4962b9c
|
Leszek Koltunski
|
}
|
458 |
|
|
|
459 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
460 |
|
|
|
461 |
|
|
int getFaceColor(int cubit, int cubitface, int numLayers)
|
462 |
|
|
{
|
463 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
464 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
465 |
|
|
|
466 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
467 |
|
|
{
|
468 |
|
|
return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
|
469 |
|
|
}
|
470 |
|
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
471 |
|
|
{
|
472 |
|
|
int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
|
473 |
|
|
return getEdgeColor(edge,cubitface,numCubitsPerEdge);
|
474 |
|
|
}
|
475 |
|
|
else
|
476 |
|
|
{
|
477 |
|
|
int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
|
478 |
|
|
return getCenterColor( center, cubitface, numLayers);
|
479 |
|
|
}
|
480 |
bbc6da6c
|
Leszek Koltunski
|
}
|
481 |
|
|
|
482 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
483 |
|
|
|
484 |
|
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
|
485 |
|
|
{
|
486 |
ca824448
|
Leszek Koltunski
|
int COLORS = FACE_COLORS.length;
|
487 |
|
|
int variant = face/COLORS;
|
488 |
|
|
int numLayers = getNumLayers();
|
489 |
bbc6da6c
|
Leszek Koltunski
|
|
490 |
ca824448
|
Leszek Koltunski
|
if( variant == (numLayers-1)/2 || numLayers==3 )
|
491 |
|
|
{
|
492 |
|
|
float S = 0.07f;
|
493 |
|
|
float R = 0.09f;
|
494 |
|
|
|
495 |
|
|
float A = 0.86f;
|
496 |
|
|
float X1= (SQ5+1)/8;
|
497 |
|
|
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
|
498 |
|
|
float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
|
499 |
|
|
|
500 |
|
|
float[] vertices = { -X1, Y2, 0, -A*Y1, X1, Y2, 0, Y1 };
|
501 |
4e627d8b
|
Leszek Koltunski
|
|
502 |
ca824448
|
Leszek Koltunski
|
FactorySticker factory = FactorySticker.getInstance();
|
503 |
|
|
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%NUM_FACES], R);
|
504 |
bbc6da6c
|
Leszek Koltunski
|
|
505 |
ca824448
|
Leszek Koltunski
|
float MID = TEXTURE_HEIGHT*0.5f;
|
506 |
|
|
float WID = TEXTURE_HEIGHT*0.1f;
|
507 |
|
|
float HEI = TEXTURE_HEIGHT*(0.47f+Y1);
|
508 |
|
|
canvas.drawLine(left+MID-WID,top+HEI,left+MID+WID,top+HEI,paint);
|
509 |
|
|
}
|
510 |
|
|
else if( variant==0 )
|
511 |
|
|
{
|
512 |
|
|
float Y = COS54/(2*SIN54);
|
513 |
|
|
float R = 0.09f;
|
514 |
|
|
float S = 0.09f;
|
515 |
|
|
float[] vertices = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y };
|
516 |
4b4c217e
|
Leszek Koltunski
|
|
517 |
ca824448
|
Leszek Koltunski
|
FactorySticker factory = FactorySticker.getInstance();
|
518 |
|
|
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
|
519 |
|
|
}
|
520 |
|
|
else
|
521 |
|
|
{
|
522 |
|
|
float R = 0.07f;
|
523 |
|
|
float S = 0.07f;
|
524 |
|
|
|
525 |
|
|
float tmp = (numLayers/3.0f)/(numLayers-1);
|
526 |
|
|
float height= tmp*COS18;
|
527 |
|
|
float width = tmp + (variant-1)*tmp*SIN18;
|
528 |
|
|
float D = height/COS18;
|
529 |
|
|
float W = D*SIN18;
|
530 |
|
|
float X1 = height/2;
|
531 |
|
|
float Y1 = width/2;
|
532 |
|
|
float[] vertices = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 };
|
533 |
|
|
|
534 |
|
|
FactorySticker factory = FactorySticker.getInstance();
|
535 |
|
|
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
|
536 |
|
|
}
|
537 |
bbc6da6c
|
Leszek Koltunski
|
}
|
538 |
|
|
|
539 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
540 |
|
|
// PUBLIC API
|
541 |
|
|
|
542 |
|
|
public boolean isSolved()
|
543 |
|
|
{
|
544 |
f6e46300
|
Leszek Koltunski
|
int index = CUBITS[0].mQuatIndex;
|
545 |
bbc6da6c
|
Leszek Koltunski
|
|
546 |
f6e46300
|
Leszek Koltunski
|
for(int i=1; i<NUM_CUBITS; i++)
|
547 |
bbc6da6c
|
Leszek Koltunski
|
{
|
548 |
f6e46300
|
Leszek Koltunski
|
if( thereIsVisibleDifference(CUBITS[i], index) ) return false;
|
549 |
bbc6da6c
|
Leszek Koltunski
|
}
|
550 |
|
|
|
551 |
|
|
return true;
|
552 |
|
|
}
|
553 |
|
|
|
554 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
555 |
|
|
|
556 |
|
|
public int getObjectName(int numLayers)
|
557 |
|
|
{
|
558 |
f6e46300
|
Leszek Koltunski
|
if( numLayers==3 ) return R.string.minx2;
|
559 |
|
|
if( numLayers==5 ) return R.string.minx4;
|
560 |
|
|
|
561 |
|
|
return 0;
|
562 |
bbc6da6c
|
Leszek Koltunski
|
}
|
563 |
|
|
|
564 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
565 |
|
|
|
566 |
|
|
public int getInventor(int numLayers)
|
567 |
|
|
{
|
568 |
f6e46300
|
Leszek Koltunski
|
if( numLayers==3 ) return R.string.minx2_inventor;
|
569 |
|
|
if( numLayers==5 ) return R.string.minx4_inventor;
|
570 |
|
|
|
571 |
|
|
return 0;
|
572 |
bbc6da6c
|
Leszek Koltunski
|
}
|
573 |
|
|
|
574 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
575 |
|
|
|
576 |
|
|
public int getComplexity(int numLayers)
|
577 |
|
|
{
|
578 |
|
|
return 3;
|
579 |
|
|
}
|
580 |
|
|
}
|