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