1 |
29b82486
|
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.objectlib.objects;
|
21 |
|
|
|
22 |
|
|
import static org.distorted.objectlib.main.Movement12.COS54;
|
23 |
|
|
import static org.distorted.objectlib.main.Movement12.SIN54;
|
24 |
|
|
|
25 |
|
|
import android.content.res.Resources;
|
26 |
|
|
|
27 |
|
|
import org.distorted.library.main.DistortedEffects;
|
28 |
|
|
import org.distorted.library.main.DistortedTexture;
|
29 |
|
|
import org.distorted.library.mesh.MeshSquare;
|
30 |
ecf3d6e3
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
31 |
29b82486
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
32 |
a706f8e0
|
Leszek Koltunski
|
import org.distorted.library.main.QuatHelper;
|
33 |
29b82486
|
Leszek Koltunski
|
|
34 |
|
|
import org.distorted.objectlib.R;
|
35 |
8005e762
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectType;
|
36 |
198c5bf0
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.ObjectShape;
|
37 |
|
|
import org.distorted.objectlib.helpers.ObjectSticker;
|
38 |
29b82486
|
Leszek Koltunski
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
|
|
public class TwistyMegaminx extends TwistyMinx
|
42 |
|
|
{
|
43 |
|
|
static final float MEGA_D = 0.04f;
|
44 |
|
|
private int[] mQuatCenterIndices;
|
45 |
|
|
|
46 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47 |
|
|
|
48 |
ecf3d6e3
|
Leszek Koltunski
|
public TwistyMegaminx(int size, Static4D quat, Static3D move, DistortedTexture texture,
|
49 |
|
|
MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
|
50 |
29b82486
|
Leszek Koltunski
|
{
|
51 |
ecf3d6e3
|
Leszek Koltunski
|
super(size, size, quat, move, texture, mesh, effects, res, scrWidth);
|
52 |
29b82486
|
Leszek Koltunski
|
}
|
53 |
|
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
|
|
private void initializeCenterIndices()
|
57 |
|
|
{
|
58 |
|
|
mQuatCenterIndices = new int[] { 16, 18, 22, 1, 20, 13, 14, 15, 0, 12, 2, 3 };
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
|
|
private int numCubitsPerCorner(int numLayers)
|
64 |
|
|
{
|
65 |
|
|
return 3*((numLayers-1)/2)*((numLayers-3)/2) + 1;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
|
|
private int numCubitsPerEdge(int numLayers)
|
71 |
|
|
{
|
72 |
|
|
return numLayers-2;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
4e1dc313
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
|
|
|
77 |
|
|
protected int getResource(int numLayers)
|
78 |
|
|
{
|
79 |
|
|
switch(numLayers)
|
80 |
|
|
{
|
81 |
|
|
case 3: return R.raw.mega3;
|
82 |
|
|
case 5: return R.raw.mega5;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
return 0;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
|
|
|
90 |
|
|
protected int getNumStickerTypes(int numLayers)
|
91 |
|
|
{
|
92 |
|
|
return (numLayers+3)/2;
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96 |
|
|
|
97 |
|
|
protected float[][] getCuts(int numLayers)
|
98 |
|
|
{
|
99 |
|
|
return genericGetCuts(numLayers,0.5f-MEGA_D);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103 |
|
|
|
104 |
|
|
private float[] computeCenter(int center, int numLayers)
|
105 |
|
|
{
|
106 |
|
|
if( mCenterCoords==null ) initializeCenterCoords();
|
107 |
|
|
float[] coords = mCenterCoords[center];
|
108 |
|
|
float A = 0.33f*numLayers;
|
109 |
|
|
|
110 |
|
|
return new float[] { A*coords[0], A*coords[1], A*coords[2] };
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114 |
|
|
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
|
115 |
|
|
// Appropriate one: QUATS[QUAT_INDICES[corner]].
|
116 |
|
|
|
117 |
|
|
private void computeBasicCornerVectors(int corner)
|
118 |
|
|
{
|
119 |
|
|
if( mQuatCornerIndices==null ) initializeQuatIndices();
|
120 |
|
|
if( mQuats==null ) initializeQuats();
|
121 |
|
|
if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
|
122 |
|
|
|
123 |
|
|
Static4D quat = mQuats[mQuatCornerIndices[corner]];
|
124 |
|
|
|
125 |
|
|
mCurrCornerV[0] = QuatHelper.rotateVectorByQuat(mBasicCornerV[0],quat);
|
126 |
|
|
mCurrCornerV[1] = QuatHelper.rotateVectorByQuat(mBasicCornerV[1],quat);
|
127 |
|
|
mCurrCornerV[2] = QuatHelper.rotateVectorByQuat(mBasicCornerV[2],quat);
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
|
|
|
132 |
|
|
private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
|
133 |
|
|
{
|
134 |
|
|
if( mCorners==null ) initializeCorners();
|
135 |
|
|
if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
|
136 |
|
|
|
137 |
|
|
float D = numLayers/3.0f;
|
138 |
|
|
float[] corn = mCorners[corner];
|
139 |
|
|
|
140 |
|
|
if( part==0 )
|
141 |
|
|
{
|
142 |
|
|
return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
|
143 |
|
|
}
|
144 |
|
|
else
|
145 |
|
|
{
|
146 |
|
|
float E = 2.0f*D*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
|
147 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
148 |
|
|
int block = (part-1) % N;
|
149 |
|
|
int index = (part-1) / N;
|
150 |
|
|
Static4D pri = mCurrCornerV[index];
|
151 |
|
|
Static4D sec = mCurrCornerV[(index+2)%3];
|
152 |
|
|
|
153 |
|
|
int layers= (numLayers-3)/2;
|
154 |
|
|
int multP = (block % layers) + 1;
|
155 |
|
|
int multS = (block / layers);
|
156 |
|
|
|
157 |
|
|
return new float[] {
|
158 |
|
|
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
|
159 |
|
|
corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
|
160 |
|
|
corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
|
161 |
|
|
};
|
162 |
|
|
}
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166 |
|
|
|
167 |
|
|
private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
168 |
|
|
{
|
169 |
|
|
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
|
170 |
|
|
return (part+1)/2;
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174 |
|
|
|
175 |
|
|
private float[] computeEdge(int numLayers, int edge, int part)
|
176 |
|
|
{
|
177 |
|
|
if( mCenterCoords==null ) initializeCenterCoords();
|
178 |
|
|
if( mCorners==null ) initializeCorners();
|
179 |
|
|
if( mEdgeMap==null ) initializeEdgeMap();
|
180 |
|
|
|
181 |
|
|
float D = numLayers/3.0f;
|
182 |
|
|
float[] c1 = mCorners[ mEdgeMap[edge][0] ];
|
183 |
|
|
float[] c2 = mCorners[ mEdgeMap[edge][1] ];
|
184 |
|
|
float x = D * (c1[0]+c2[0]) / 2;
|
185 |
|
|
float y = D * (c1[1]+c2[1]) / 2;
|
186 |
|
|
float z = D * (c1[2]+c2[2]) / 2;
|
187 |
|
|
|
188 |
|
|
if( part==0 )
|
189 |
|
|
{
|
190 |
|
|
return new float[] { x, y, z };
|
191 |
|
|
}
|
192 |
|
|
else
|
193 |
|
|
{
|
194 |
|
|
int mult = (part+1)/2;
|
195 |
|
|
int dir = (part+1)%2;
|
196 |
|
|
float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
|
197 |
|
|
|
198 |
|
|
float vX = D*center[0] - x;
|
199 |
|
|
float vY = D*center[1] - y;
|
200 |
|
|
float vZ = D*center[2] - z;
|
201 |
|
|
|
202 |
|
|
float A = 3*mult*D*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
|
203 |
|
|
A /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
204 |
|
|
|
205 |
|
|
return new float[] { x+A*vX, y+A*vY, z+A*vZ };
|
206 |
|
|
}
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
210 |
|
|
|
211 |
|
|
protected float[][] getCubitPositions(int numLayers)
|
212 |
|
|
{
|
213 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
214 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
215 |
|
|
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS;
|
216 |
|
|
int index=0;
|
217 |
|
|
|
218 |
|
|
final float[][] CENTERS = new float[numCubits][];
|
219 |
|
|
|
220 |
|
|
for(int corner=0; corner<NUM_CORNERS; corner++)
|
221 |
|
|
{
|
222 |
|
|
computeBasicCornerVectors(corner);
|
223 |
|
|
|
224 |
|
|
for(int part=0; part<numCubitsPerCorner; part++, index++)
|
225 |
|
|
{
|
226 |
|
|
CENTERS[index] = computeCorner(numCubitsPerCorner,numLayers,corner,part);
|
227 |
|
|
}
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
for(int edge=0; edge<NUM_EDGES; edge++)
|
231 |
|
|
{
|
232 |
|
|
for(int part=0; part<numCubitsPerEdge; part++, index++)
|
233 |
|
|
{
|
234 |
|
|
CENTERS[index] = computeEdge(numLayers, edge, part );
|
235 |
|
|
}
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
for(int center=0; center<NUM_CENTERS; center++, index++)
|
239 |
|
|
{
|
240 |
|
|
CENTERS[index] = computeCenter(center, numLayers);
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
return CENTERS;
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
247 |
|
|
|
248 |
|
|
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
249 |
|
|
{
|
250 |
|
|
if( mQuatCornerIndices==null || mQuatEdgeIndices==null ) initializeQuatIndices();
|
251 |
|
|
if( mQuatCenterIndices==null ) initializeCenterIndices();
|
252 |
|
|
|
253 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
254 |
|
|
{
|
255 |
|
|
int corner = cubit/numCubitsPerCorner;
|
256 |
|
|
return mQuatCornerIndices[corner];
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
260 |
|
|
{
|
261 |
|
|
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
|
262 |
|
|
return mQuatEdgeIndices[edge];
|
263 |
|
|
}
|
264 |
|
|
|
265 |
|
|
int center = cubit - NUM_CORNERS*numCubitsPerCorner - NUM_EDGES*numCubitsPerEdge;
|
266 |
|
|
return mQuatCenterIndices[center];
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
270 |
|
|
|
271 |
|
|
protected ObjectShape getObjectShape(int cubit, int numLayers)
|
272 |
|
|
{
|
273 |
|
|
int variant = getCubitVariant(cubit,numLayers);
|
274 |
|
|
int numVariants = getNumCubitVariants(numLayers);
|
275 |
|
|
|
276 |
|
|
if( variant==0 )
|
277 |
|
|
{
|
278 |
|
|
float width = numLayers*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
|
279 |
|
|
float A = (2*SQ3/3)*SIN54;
|
280 |
|
|
float B = 0.4f;
|
281 |
|
|
double X = width*COS18*SIN_HALFD;
|
282 |
|
|
double Y = width*SIN18;
|
283 |
|
|
double Z = width*COS18*COS_HALFD;
|
284 |
|
|
int N = numLayers==3 ? 1:0;
|
285 |
|
|
|
286 |
|
|
double[][] vertices = new double[][]
|
287 |
|
|
{
|
288 |
|
|
{ 0.0, 0.0 , 0.0 },
|
289 |
|
|
{ X, Y , -Z },
|
290 |
|
|
{ 0.0, 2*Y ,-2*Z },
|
291 |
|
|
{ -X, Y , -Z },
|
292 |
|
|
{ 0.0, 0.0-width, 0.0 },
|
293 |
|
|
{ X, Y-width, -Z },
|
294 |
|
|
{ 0.0, 2*Y-width,-2*Z },
|
295 |
|
|
{ -X, Y-width, -Z },
|
296 |
|
|
};
|
297 |
|
|
|
298 |
|
|
int[][] vertIndexes = new int[][]
|
299 |
|
|
{
|
300 |
|
|
{4,5,1,0},
|
301 |
|
|
{7,4,0,3},
|
302 |
|
|
{0,1,2,3},
|
303 |
|
|
{4,5,6,7},
|
304 |
|
|
{6,5,1,2},
|
305 |
|
|
{7,6,2,3}
|
306 |
|
|
};
|
307 |
|
|
|
308 |
|
|
float[][] bands = new float[][]
|
309 |
|
|
{
|
310 |
|
|
{0.04f,34,0.3f,0.2f, 3, N, 0},
|
311 |
|
|
{0.00f, 0,0.0f,0.0f, 2, N, 0}
|
312 |
|
|
};
|
313 |
|
|
|
314 |
|
|
int[] bandIndices = new int[] { 0,0,0,1,1,1};
|
315 |
|
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
316 |
|
|
int[] cornerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
|
317 |
|
|
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
|
318 |
|
|
int[] centerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
|
319 |
|
|
|
320 |
|
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
321 |
|
|
}
|
322 |
|
|
if( variant<numVariants-1 )
|
323 |
|
|
{
|
324 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
325 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
326 |
|
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
327 |
|
|
float height= numLayers*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
|
328 |
|
|
float width = numLayers*2*MEGA_D + 2*type*height*SIN18/COS18;
|
329 |
|
|
|
330 |
|
|
double W = width/2;
|
331 |
|
|
double X = height*SIN_HALFD;
|
332 |
|
|
double Y = height*SIN18/COS18;
|
333 |
|
|
double Z = height*COS_HALFD;
|
334 |
|
|
|
335 |
|
|
double[][] vertices = new double[][]
|
336 |
|
|
{
|
337 |
|
|
{ 0.0, W , 0.0 },
|
338 |
|
|
{ X, W+Y , -Z },
|
339 |
|
|
{ 0.0, W+2*Y ,-2*Z },
|
340 |
|
|
{ -X, W+Y , -Z },
|
341 |
|
|
{ 0.0, -W , 0.0 },
|
342 |
|
|
{ X,-W-Y , -Z },
|
343 |
|
|
{ 0.0,-W-2*Y ,-2*Z },
|
344 |
|
|
{ -X,-W-Y , -Z },
|
345 |
|
|
};
|
346 |
|
|
|
347 |
|
|
int[][] vertIndexes = new int[][]
|
348 |
|
|
{
|
349 |
|
|
{4,5,1,0},
|
350 |
|
|
{7,4,0,3},
|
351 |
|
|
{7,6,2,3},
|
352 |
|
|
{6,5,1,2},
|
353 |
|
|
{0,1,2,3},
|
354 |
|
|
{4,5,6,7}
|
355 |
|
|
};
|
356 |
|
|
|
357 |
|
|
int N = numLayers<=5 ? 5 : 3;
|
358 |
|
|
|
359 |
|
|
float[][] bands = new float[][]
|
360 |
|
|
{
|
361 |
|
|
{0.04f,34,0.2f,0.2f,N,0,0},
|
362 |
|
|
{0.00f, 0,0.3f,0.2f,2,0,0}
|
363 |
|
|
};
|
364 |
|
|
int[] bandIndices = new int[] { 0,0,1,1,1,1};
|
365 |
|
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
366 |
|
|
int[] cornerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
|
367 |
|
|
float[][] centers = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} };
|
368 |
|
|
int[] centerIndices = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
|
369 |
|
|
|
370 |
|
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
371 |
|
|
}
|
372 |
|
|
else
|
373 |
|
|
{
|
374 |
|
|
float width = 2*numLayers*(MEGA_D+(0.5f-MEGA_D)*SIN18);
|
375 |
|
|
final double V = 0.83; // ??
|
376 |
|
|
final double ANGLE = V*Math.PI;
|
377 |
|
|
final double cosA = Math.cos(ANGLE);
|
378 |
|
|
final double sinA = Math.sin(ANGLE);
|
379 |
|
|
|
380 |
|
|
float R = 0.5f*width/COS54;
|
381 |
|
|
float X1 = R*COS54;
|
382 |
|
|
float Y1 = R*SIN54;
|
383 |
|
|
float X2 = R*COS18;
|
384 |
|
|
float Y2 = R*SIN18;
|
385 |
|
|
|
386 |
|
|
double[][] vertices = new double[][]
|
387 |
|
|
{
|
388 |
|
|
{-X1,+Y1*sinA, Y1*cosA},
|
389 |
|
|
{-X2,-Y2*sinA,-Y2*cosA},
|
390 |
|
|
{0.0f,-R*sinA, -R*cosA},
|
391 |
|
|
{+X2,-Y2*sinA,-Y2*cosA},
|
392 |
|
|
{+X1,+Y1*sinA, Y1*cosA}
|
393 |
|
|
};
|
394 |
|
|
|
395 |
|
|
int[][] vertIndexes = new int[][]
|
396 |
|
|
{
|
397 |
|
|
{0,1,2,3,4},
|
398 |
|
|
{0,1,2,3,4}
|
399 |
|
|
};
|
400 |
|
|
|
401 |
|
|
int N = numLayers==3 ? 4 : 3;
|
402 |
|
|
|
403 |
|
|
float[][] bands = new float[][]
|
404 |
|
|
{
|
405 |
|
|
{0.04f,45, R/3,0.2f,N,0,0},
|
406 |
|
|
{0.00f, 0, R/3,0.2f,2,0,0}
|
407 |
|
|
};
|
408 |
|
|
|
409 |
|
|
int[] bandIndices = new int[] { 0,1 };
|
410 |
|
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
411 |
|
|
int[] cornerIndices = new int[] { -1,-1,-1,-1, -1 };
|
412 |
|
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
413 |
|
|
int[] centerIndices = new int[] { -1,-1,-1,-1, -1 };
|
414 |
|
|
|
415 |
|
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
416 |
|
|
}
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
420 |
|
|
|
421 |
|
|
protected Static4D getQuat(int cubit, int numLayers)
|
422 |
|
|
{
|
423 |
|
|
if( mQuats==null ) initializeQuats();
|
424 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
425 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
426 |
|
|
|
427 |
|
|
return mQuats[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
431 |
|
|
|
432 |
|
|
protected int getNumCubitVariants(int numLayers)
|
433 |
|
|
{
|
434 |
61aa85e4
|
Leszek Koltunski
|
switch(numLayers)
|
435 |
|
|
{
|
436 |
|
|
case 3: return 3;
|
437 |
|
|
case 5: return 4;
|
438 |
|
|
}
|
439 |
29b82486
|
Leszek Koltunski
|
|
440 |
61aa85e4
|
Leszek Koltunski
|
return 3;
|
441 |
29b82486
|
Leszek Koltunski
|
}
|
442 |
|
|
|
443 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
444 |
|
|
|
445 |
|
|
protected int getCubitVariant(int cubit, int numLayers)
|
446 |
|
|
{
|
447 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
448 |
|
|
|
449 |
|
|
if( cubit<NUM_CORNERS*numCubitsPerCorner ) return 0;
|
450 |
|
|
|
451 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
452 |
|
|
|
453 |
|
|
if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
454 |
|
|
{
|
455 |
|
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
456 |
|
|
return type+1;
|
457 |
|
|
}
|
458 |
|
|
|
459 |
61aa85e4
|
Leszek Koltunski
|
return getNumCubitVariants(numLayers)-1;
|
460 |
29b82486
|
Leszek Koltunski
|
}
|
461 |
|
|
|
462 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
463 |
|
|
|
464 |
|
|
int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
|
465 |
|
|
{
|
466 |
|
|
if( mCornerFaceMap==null ) initializeCornerFaceMap();
|
467 |
|
|
if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
|
468 |
|
|
|
469 |
|
|
int part = cubit % numCubitsPerCorner;
|
470 |
|
|
int corner= cubit / numCubitsPerCorner;
|
471 |
|
|
|
472 |
|
|
if( part==0 )
|
473 |
|
|
{
|
474 |
|
|
return mCornerFaceMap[corner][cubitface];
|
475 |
|
|
}
|
476 |
|
|
else
|
477 |
|
|
{
|
478 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
479 |
|
|
int block = (part-1) % N;
|
480 |
|
|
int index = (part-1) / N;
|
481 |
|
|
|
482 |
|
|
if( block< (numLayers-3)/2 )
|
483 |
|
|
{
|
484 |
|
|
switch(index)
|
485 |
|
|
{
|
486 |
|
|
case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
487 |
|
|
case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
488 |
|
|
case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
489 |
|
|
}
|
490 |
|
|
}
|
491 |
|
|
else
|
492 |
|
|
{
|
493 |
|
|
switch(index)
|
494 |
|
|
{
|
495 |
|
|
case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
496 |
|
|
case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
497 |
|
|
case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
498 |
|
|
}
|
499 |
|
|
}
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
return NUM_TEXTURES;
|
503 |
|
|
}
|
504 |
|
|
|
505 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
506 |
|
|
|
507 |
|
|
int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
|
508 |
|
|
{
|
509 |
|
|
if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
|
510 |
|
|
|
511 |
|
|
int part = edge % numCubitsPerEdge;
|
512 |
|
|
int variant = edge / numCubitsPerEdge;
|
513 |
|
|
if( mEdgeMap==null ) initializeEdgeMap();
|
514 |
|
|
|
515 |
|
|
return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACE_COLORS : NUM_TEXTURES;
|
516 |
|
|
}
|
517 |
|
|
|
518 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
519 |
|
|
|
520 |
|
|
int getCenterColor(int center, int cubitface, int numLayers)
|
521 |
|
|
{
|
522 |
|
|
return cubitface>0 ? NUM_TEXTURES : center + NUM_FACE_COLORS*(numLayers+1)/2;
|
523 |
|
|
}
|
524 |
|
|
|
525 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
526 |
|
|
|
527 |
|
|
protected int getFaceColor(int cubit, int cubitface, int numLayers)
|
528 |
|
|
{
|
529 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
530 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
531 |
|
|
|
532 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
533 |
|
|
{
|
534 |
|
|
return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
|
535 |
|
|
}
|
536 |
|
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
537 |
|
|
{
|
538 |
|
|
int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
|
539 |
|
|
return getEdgeColor(edge,cubitface,numCubitsPerEdge);
|
540 |
|
|
}
|
541 |
|
|
else
|
542 |
|
|
{
|
543 |
|
|
int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
|
544 |
|
|
return getCenterColor( center, cubitface, numLayers);
|
545 |
|
|
}
|
546 |
|
|
}
|
547 |
|
|
|
548 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
549 |
|
|
|
550 |
|
|
protected ObjectSticker retSticker(int face)
|
551 |
|
|
{
|
552 |
|
|
if( mStickers==null )
|
553 |
|
|
{
|
554 |
|
|
float[][] STICKERS = new float[][]
|
555 |
|
|
{
|
556 |
|
|
{ -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
|
557 |
|
|
{ -0.5f, -0.0914315f, 0.5f, -0.4163512f, 0.5f, 0.4163512f, -0.5f, 0.0914315f },
|
558 |
|
|
{ -0.49233657f, -0.18006028f, 0.49233657f, -0.5f, 0.49233657f, 0.5f, -0.49233657f, 0.18006028f },
|
559 |
|
|
{ -0.3002273f, -0.30490047f, 0.3002273f, -0.5f, 0.3002273f, 0.5f, -0.3002273f, 0.30490047f },
|
560 |
|
|
{ -0.29389262f, 0.4045085f, -0.47552824f, -0.1545085f, 0.0f, -0.5f, 0.47552824f, -0.1545085f, 0.29389262f, 0.4045085f }
|
561 |
|
|
};
|
562 |
|
|
|
563 |
|
|
mStickers = new ObjectSticker[STICKERS.length];
|
564 |
|
|
|
565 |
|
|
final float R0 = 0.08f;
|
566 |
|
|
final float R1 = 0.12f;
|
567 |
|
|
final float R2 = 0.12f;
|
568 |
|
|
final float R3 = 0.08f;
|
569 |
|
|
final float R4 = 0.10f;
|
570 |
|
|
final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3},{R4,R4,R4,R4,R4} };
|
571 |
|
|
final float[] strokes = { 0.10f,0.12f,0.12f,0.08f,0.07f };
|
572 |
|
|
|
573 |
|
|
for(int s=0; s<STICKERS.length; s++)
|
574 |
|
|
{
|
575 |
|
|
mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
|
576 |
|
|
}
|
577 |
|
|
}
|
578 |
|
|
|
579 |
|
|
return mStickers[getStickerIndex(face)];
|
580 |
|
|
}
|
581 |
|
|
|
582 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
583 |
|
|
|
584 |
|
|
private int getStickerIndex(int face)
|
585 |
|
|
{
|
586 |
|
|
int variant = face/NUM_FACE_COLORS;
|
587 |
|
|
|
588 |
|
|
if( variant==0 ) return 0;
|
589 |
|
|
|
590 |
|
|
int numLayers = getNumLayers();
|
591 |
|
|
|
592 |
|
|
if( variant < (numLayers+1)/2 )
|
593 |
|
|
{
|
594 |
|
|
if( numLayers==3 ) return 1;
|
595 |
|
|
else
|
596 |
|
|
{
|
597 |
|
|
if( variant==1 ) return 2;
|
598 |
|
|
else return 3;
|
599 |
|
|
}
|
600 |
|
|
}
|
601 |
|
|
|
602 |
|
|
return 4;
|
603 |
|
|
}
|
604 |
|
|
|
605 |
61aa85e4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
606 |
|
|
|
607 |
c8bc83d9
|
Leszek Koltunski
|
public ObjectType intGetObjectType(int numLayers)
|
608 |
61aa85e4
|
Leszek Koltunski
|
{
|
609 |
|
|
switch(numLayers)
|
610 |
|
|
{
|
611 |
8005e762
|
Leszek Koltunski
|
case 3: return ObjectType.MEGA_3;
|
612 |
|
|
case 5: return ObjectType.MEGA_5;
|
613 |
61aa85e4
|
Leszek Koltunski
|
}
|
614 |
|
|
|
615 |
8005e762
|
Leszek Koltunski
|
return ObjectType.MEGA_3;
|
616 |
61aa85e4
|
Leszek Koltunski
|
}
|
617 |
|
|
|
618 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
619 |
|
|
|
620 |
|
|
public int getObjectName(int numLayers)
|
621 |
|
|
{
|
622 |
|
|
if( numLayers==3 ) return R.string.minx3;
|
623 |
|
|
if( numLayers==5 ) return R.string.minx5;
|
624 |
|
|
|
625 |
|
|
return 0;
|
626 |
|
|
}
|
627 |
|
|
|
628 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
629 |
|
|
|
630 |
|
|
public int getInventor(int numLayers)
|
631 |
|
|
{
|
632 |
|
|
if( numLayers==3 ) return R.string.minx3_inventor;
|
633 |
|
|
if( numLayers==5 ) return R.string.minx5_inventor;
|
634 |
|
|
|
635 |
|
|
return 0;
|
636 |
|
|
}
|
637 |
|
|
|
638 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
639 |
|
|
|
640 |
|
|
public int getComplexity(int numLayers)
|
641 |
|
|
{
|
642 |
|
|
if( numLayers==3 ) return 4;
|
643 |
|
|
|
644 |
|
|
return 5;
|
645 |
|
|
}
|
646 |
|
|
}
|