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 TwistyKilominx extends TwistyMinx
|
42 |
|
|
{
|
43 |
|
|
private int[] mCenterFaceMap;
|
44 |
|
|
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
|
47 |
ecf3d6e3
|
Leszek Koltunski
|
public TwistyKilominx(int size, Static4D quat, Static3D move, DistortedTexture texture,
|
48 |
|
|
MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
|
49 |
29b82486
|
Leszek Koltunski
|
{
|
50 |
ecf3d6e3
|
Leszek Koltunski
|
super(size, size, quat, move, texture, mesh, effects, res, scrWidth);
|
51 |
29b82486
|
Leszek Koltunski
|
}
|
52 |
|
|
|
53 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
|
55 |
|
|
void initializeCenterFaceMap()
|
56 |
|
|
{
|
57 |
|
|
mCenterFaceMap = new int[]
|
58 |
|
|
{
|
59 |
|
|
0,0,0,0,1,
|
60 |
|
|
1,0,1,1,0,
|
61 |
|
|
2,0,1,1,0,
|
62 |
|
|
2,2,1,0,2,
|
63 |
|
|
2,1,0,0,1,
|
64 |
|
|
1,2,0,1,0,
|
65 |
|
|
0,1,0,1,1,
|
66 |
|
|
0,1,0,2,0,
|
67 |
|
|
2,1,2,2,2,
|
68 |
|
|
1,0,2,1,2,
|
69 |
|
|
2,1,0,1,2,
|
70 |
|
|
2,2,2,2,2
|
71 |
|
|
};
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
|
|
76 |
|
|
private int numCubitsPerCorner(int numLayers)
|
77 |
|
|
{
|
78 |
|
|
return 3*((numLayers-3)/2)*((numLayers-5)/2) + (numLayers<5 ? 0:1);
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82 |
|
|
|
83 |
|
|
private int numCubitsPerEdge(int numLayers)
|
84 |
|
|
{
|
85 |
|
|
return numLayers<5 ? 0 : 2*(numLayers-4);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
4e1dc313
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
|
|
|
90 |
|
|
protected int getResource(int numLayers)
|
91 |
|
|
{
|
92 |
|
|
switch(numLayers)
|
93 |
|
|
{
|
94 |
|
|
case 3: return R.raw.kilo3;
|
95 |
|
|
case 5: return R.raw.kilo5;
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
return 0;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
protected int getNumStickerTypes(int numLayers)
|
104 |
|
|
{
|
105 |
|
|
return numLayers<5 ? 1 : numLayers/2 + 1;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
protected float[][] getCuts(int numLayers)
|
111 |
|
|
{
|
112 |
|
|
return genericGetCuts(numLayers,0.5f);
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116 |
|
|
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
|
117 |
|
|
// Appropriate one: QUATS[QUAT_INDICES[corner]].
|
118 |
|
|
|
119 |
|
|
private void computeBasicCornerVectors(int corner)
|
120 |
|
|
{
|
121 |
|
|
if( mQuatCornerIndices==null ) initializeQuatIndices();
|
122 |
|
|
if( mQuats==null ) initializeQuats();
|
123 |
|
|
if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
|
124 |
|
|
|
125 |
|
|
Static4D quat = mQuats[mQuatCornerIndices[corner]];
|
126 |
|
|
|
127 |
|
|
mCurrCornerV[0] = QuatHelper.rotateVectorByQuat(mBasicCornerV[0],quat);
|
128 |
|
|
mCurrCornerV[1] = QuatHelper.rotateVectorByQuat(mBasicCornerV[1],quat);
|
129 |
|
|
mCurrCornerV[2] = QuatHelper.rotateVectorByQuat(mBasicCornerV[2],quat);
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133 |
|
|
|
134 |
|
|
private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
|
135 |
|
|
{
|
136 |
|
|
if( mCorners==null ) initializeCorners();
|
137 |
|
|
if( mCurrCornerV==null || mBasicCornerV==null ) initializeCornerV();
|
138 |
|
|
|
139 |
|
|
float D = numLayers/3.0f;
|
140 |
|
|
float[] corn = mCorners[corner];
|
141 |
|
|
|
142 |
|
|
if( part==0 )
|
143 |
|
|
{
|
144 |
|
|
return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
|
145 |
|
|
}
|
146 |
|
|
else
|
147 |
|
|
{
|
148 |
|
|
float E = D/(0.5f*(numLayers-1)); // ?? maybe 0.5*
|
149 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
150 |
|
|
int block = (part-1) % N;
|
151 |
|
|
int index = (part-1) / N;
|
152 |
|
|
Static4D pri = mCurrCornerV[index];
|
153 |
|
|
Static4D sec = mCurrCornerV[(index+2)%3];
|
154 |
|
|
|
155 |
|
|
int layers= (numLayers-5)/2;
|
156 |
|
|
int multP = (block % layers) + 1;
|
157 |
|
|
int multS = (block / layers);
|
158 |
|
|
|
159 |
|
|
return new float[] {
|
160 |
|
|
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
|
161 |
|
|
corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
|
162 |
|
|
corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
|
163 |
|
|
};
|
164 |
|
|
}
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168 |
|
|
|
169 |
|
|
private float[] computeCenter(int numLayers, int center, int part)
|
170 |
|
|
{
|
171 |
|
|
if( mCenterCoords==null ) initializeCenterCoords();
|
172 |
|
|
if( mCorners ==null ) initializeCorners();
|
173 |
|
|
if( mCenterMap ==null ) initializeCenterMap();
|
174 |
|
|
|
175 |
|
|
int corner = mCenterMap[center][part];
|
176 |
|
|
float[] cent = mCenterCoords[center];
|
177 |
|
|
float[] corn = mCorners[corner];
|
178 |
|
|
float D = numLayers/3.0f;
|
179 |
|
|
float F = 1.0f - (2.0f*numLayers-6.0f)/(numLayers-1)*COS54*COS54;
|
180 |
|
|
|
181 |
|
|
return new float[]
|
182 |
|
|
{
|
183 |
|
|
D * ( cent[0] + (corn[0]-cent[0])*F),
|
184 |
|
|
D * ( cent[1] + (corn[1]-cent[1])*F),
|
185 |
|
|
D * ( cent[2] + (corn[2]-cent[2])*F)
|
186 |
|
|
};
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190 |
|
|
|
191 |
|
|
private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
192 |
|
|
{
|
193 |
|
|
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
|
194 |
|
|
return part - 2*(part/4);
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198 |
|
|
|
199 |
|
|
private float[] computeEdge(int numLayers, int edge, int part)
|
200 |
|
|
{
|
201 |
|
|
if( mCenterCoords==null ) initializeCenterCoords();
|
202 |
|
|
if( mCorners==null ) initializeCorners();
|
203 |
|
|
if( mEdgeMap==null ) initializeEdgeMap();
|
204 |
|
|
|
205 |
|
|
float D = numLayers/3.0f;
|
206 |
|
|
float[] c1 = mCorners[ mEdgeMap[edge][0] ];
|
207 |
|
|
float[] c2 = mCorners[ mEdgeMap[edge][1] ];
|
208 |
|
|
|
209 |
|
|
int leftRight = 2*(part%2) -1;
|
210 |
|
|
part /= 2;
|
211 |
|
|
|
212 |
|
|
if( part==0 )
|
213 |
|
|
{
|
214 |
|
|
float T = 0.5f + leftRight/(numLayers-1.0f);
|
215 |
|
|
float x = D * (T*c1[0]+(1.0f-T)*c2[0]);
|
216 |
|
|
float y = D * (T*c1[1]+(1.0f-T)*c2[1]);
|
217 |
|
|
float z = D * (T*c1[2]+(1.0f-T)*c2[2]);
|
218 |
|
|
|
219 |
|
|
return new float[] { x, y, z };
|
220 |
|
|
}
|
221 |
|
|
else
|
222 |
|
|
{
|
223 |
|
|
int mult = (part+1)/2;
|
224 |
|
|
int dir = (part+1)%2;
|
225 |
|
|
float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
|
226 |
|
|
float x = 0.5f * D * (c1[0]+c2[0]);
|
227 |
|
|
float y = 0.5f * D * (c1[1]+c2[1]);
|
228 |
|
|
float z = 0.5f * D * (c1[2]+c2[2]);
|
229 |
|
|
|
230 |
|
|
float vX = D*center[0] - x;
|
231 |
|
|
float vY = D*center[1] - y;
|
232 |
|
|
float vZ = D*center[2] - z;
|
233 |
|
|
|
234 |
|
|
float T = 0.5f + leftRight*(mult*SIN18 + 1.0f)/(numLayers-1);
|
235 |
|
|
|
236 |
|
|
x = D * (T*c1[0]+(1.0f-T)*c2[0]);
|
237 |
|
|
y = D * (T*c1[1]+(1.0f-T)*c2[1]);
|
238 |
|
|
z = D * (T*c1[2]+(1.0f-T)*c2[2]);
|
239 |
|
|
|
240 |
|
|
float H = mult*D*COS18/(numLayers-1);
|
241 |
|
|
H /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
242 |
|
|
|
243 |
|
|
return new float[] { x + H*vX, y + H*vY, z + H*vZ };
|
244 |
|
|
}
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
248 |
|
|
|
249 |
|
|
protected float[][] getCubitPositions(int numLayers)
|
250 |
|
|
{
|
251 |
|
|
if( mCorners==null ) initializeCorners();
|
252 |
|
|
if( numLayers<5 ) return mCorners;
|
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 |
|
|
for(int center=0; center<NUM_CENTERS; center++)
|
281 |
|
|
{
|
282 |
|
|
for(int part=0; part<numCubitsPerCenter; part++, index++)
|
283 |
|
|
{
|
284 |
|
|
CENTERS[index] = computeCenter(numLayers,center, part);
|
285 |
|
|
}
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
return CENTERS;
|
289 |
|
|
}
|
290 |
|
|
|
291 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
292 |
|
|
|
293 |
|
|
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
294 |
|
|
{
|
295 |
|
|
if( mQuatCornerIndices==null || mQuatEdgeIndices==null ) initializeQuatIndices();
|
296 |
|
|
if( mCenterMap==null ) initializeCenterMap();
|
297 |
|
|
|
298 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
299 |
|
|
{
|
300 |
|
|
int corner = cubit/numCubitsPerCorner;
|
301 |
|
|
return mQuatCornerIndices[corner];
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
305 |
|
|
{
|
306 |
|
|
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
|
307 |
|
|
return mQuatEdgeIndices[edge];
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
if( numCubitsPerCorner==0 )
|
311 |
|
|
{
|
312 |
|
|
return mQuatCornerIndices[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 center=mCenterMap[face][index];
|
321 |
|
|
return mQuatCornerIndices[center];
|
322 |
|
|
}
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
326 |
|
|
|
327 |
|
|
protected ObjectShape getObjectShape(int cubit, int numLayers)
|
328 |
|
|
{
|
329 |
|
|
int variant = getCubitVariant(cubit,numLayers);
|
330 |
|
|
int numVariants = getNumCubitVariants(numLayers);
|
331 |
|
|
|
332 |
|
|
if( variant==0 )
|
333 |
|
|
{
|
334 |
|
|
float width = numLayers/(numLayers-1.0f);
|
335 |
|
|
float A = (2*SQ3/3)*SIN54;
|
336 |
|
|
float B = 0.4f;
|
337 |
|
|
double X = width*COS18*SIN_HALFD;
|
338 |
|
|
double Y = width*SIN18;
|
339 |
|
|
double Z = width*COS18*COS_HALFD;
|
340 |
|
|
|
341 |
|
|
double[][] vertices = new double[][]
|
342 |
|
|
{
|
343 |
|
|
{ 0.0, 0.0 , 0.0 },
|
344 |
|
|
{ X, Y , -Z },
|
345 |
|
|
{ 0.0, 2*Y ,-2*Z },
|
346 |
|
|
{ -X, Y , -Z },
|
347 |
|
|
{ 0.0, 0.0-width, 0.0 },
|
348 |
|
|
{ X, Y-width, -Z },
|
349 |
|
|
{ 0.0, 2*Y-width,-2*Z },
|
350 |
|
|
{ -X, Y-width, -Z },
|
351 |
|
|
};
|
352 |
|
|
|
353 |
|
|
int[][] vertIndexes = new int[][]
|
354 |
|
|
{
|
355 |
|
|
{4,5,1,0},
|
356 |
|
|
{7,4,0,3},
|
357 |
|
|
{0,1,2,3},
|
358 |
|
|
{4,5,6,7},
|
359 |
|
|
{6,5,1,2},
|
360 |
|
|
{7,6,2,3}
|
361 |
|
|
};
|
362 |
|
|
|
363 |
|
|
float[][] bands = new float[][]
|
364 |
|
|
{
|
365 |
|
|
{0.04f,34,0.3f,0.2f, 3, 1, 0},
|
366 |
|
|
{0.00f, 0,0.0f,0.0f, 2, 1, 0}
|
367 |
|
|
};
|
368 |
|
|
|
369 |
|
|
int[] bandIndices = new int[] { 0,0,0,1,1,1};
|
370 |
|
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
371 |
|
|
int[] cornerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
|
372 |
|
|
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
|
373 |
|
|
int[] centerIndices = new int[] { 0,-1,-1,-1,-1,-1,-1,-1 };
|
374 |
|
|
|
375 |
|
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
376 |
|
|
}
|
377 |
|
|
if( variant<numVariants-1 )
|
378 |
|
|
{
|
379 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
380 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
381 |
|
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
382 |
|
|
float tmpVal= numLayers/(numLayers-1.0f);
|
383 |
|
|
float height= tmpVal*COS18;
|
384 |
|
|
float width = tmpVal + (type/2)*tmpVal*SIN18;
|
385 |
|
|
boolean left = (type%2)==0;
|
386 |
|
|
|
387 |
|
|
double X = height*SIN_HALFD;
|
388 |
|
|
double Y = height*SIN18/COS18;
|
389 |
|
|
double Z = height*COS_HALFD;
|
390 |
|
|
|
391 |
|
|
double[][] vertices = new double[][]
|
392 |
|
|
{
|
393 |
|
|
{ 0.0, 0.0 , 0.0 },
|
394 |
|
|
{ X, Y , -Z },
|
395 |
|
|
{ 0.0, 2*Y ,-2*Z },
|
396 |
|
|
{ -X, Y , -Z },
|
397 |
|
|
{ 0.0, -width, 0.0 },
|
398 |
|
|
{ X, -width, -Z },
|
399 |
|
|
{ 0.0, -width,-2*Z },
|
400 |
|
|
{ -X, -width, -Z },
|
401 |
|
|
};
|
402 |
|
|
|
403 |
|
|
int[][] vertIndexes = new int[][]
|
404 |
|
|
{
|
405 |
|
|
{4,5,1,0},
|
406 |
|
|
{7,4,0,3},
|
407 |
|
|
{7,6,2,3},
|
408 |
|
|
{6,5,1,2},
|
409 |
|
|
{0,1,2,3},
|
410 |
|
|
{4,5,6,7}
|
411 |
|
|
};
|
412 |
|
|
|
413 |
|
|
if( !left )
|
414 |
|
|
{
|
415 |
|
|
int tmp, len = vertices.length;
|
416 |
|
|
for(int i=0; i<len; i++) vertices[i][1] = -vertices[i][1];
|
417 |
|
|
|
418 |
|
|
len = vertIndexes.length;
|
419 |
|
|
for(int i=0; i<len; i++)
|
420 |
|
|
{
|
421 |
|
|
tmp = vertIndexes[i][0];
|
422 |
|
|
vertIndexes[i][0] = vertIndexes[i][3];
|
423 |
|
|
vertIndexes[i][3] = tmp;
|
424 |
|
|
tmp = vertIndexes[i][1];
|
425 |
|
|
vertIndexes[i][1] = vertIndexes[i][2];
|
426 |
|
|
vertIndexes[i][2] = tmp;
|
427 |
|
|
}
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
int numBands0 = numLayers<=5 ? 4 : 3;
|
431 |
|
|
int numBands1 = numLayers<=5 ? 3 : 2;
|
432 |
|
|
|
433 |
|
|
float[][] bands = new float[][]
|
434 |
|
|
{
|
435 |
|
|
{0.04f,34,0.2f,0.2f,numBands0,1,1},
|
436 |
|
|
{0.00f, 0,0.0f,0.0f,numBands1,0,0}
|
437 |
|
|
};
|
438 |
|
|
|
439 |
|
|
int[] bandIndices = new int[] { 0,0,1,1,1,1};
|
440 |
|
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
441 |
|
|
int[] cornerIndices = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
|
442 |
|
|
float[][] centers = new float[][] { {0.0f, -width/2, (float)(-2*Z)} };
|
443 |
|
|
int[] centerIndices = new int[] { 0,-1,-1,-1, 0,-1,-1,-1 };
|
444 |
|
|
|
445 |
|
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
446 |
|
|
}
|
447 |
|
|
else
|
448 |
|
|
{
|
449 |
|
|
float width = (1+0.5f*(numLayers-3)*SIN18)*numLayers/(numLayers-1);
|
450 |
|
|
|
451 |
|
|
double X = width*COS18*SIN_HALFD;
|
452 |
|
|
double Y = width*SIN18;
|
453 |
|
|
double Z = width*COS18*COS_HALFD;
|
454 |
|
|
double H = width*(SIN54/COS54);
|
455 |
|
|
double H3= H/COS_HALFD;
|
456 |
|
|
double X3= H*SIN_HALFD;
|
457 |
|
|
double Z3= H*COS_HALFD;
|
458 |
|
|
double C = 1/(COS54*Math.sqrt(2-2*SIN18));
|
459 |
|
|
int N = numLayers==3 ? 4 : 3;
|
460 |
|
|
int E = numLayers==3 ? 1 : 0;
|
461 |
|
|
|
462 |
|
|
double[][] vertices = new double[][]
|
463 |
|
|
{
|
464 |
|
|
{ 0.0, 0.0 , 0.0 },
|
465 |
|
|
{ X, Y , -Z },
|
466 |
|
|
{ 0.0,C*2*Y ,-2*C*Z },
|
467 |
|
|
{ -X, Y , -Z },
|
468 |
|
|
{ 0.0,-width, 0.0 },
|
469 |
|
|
{ X3,-width, -Z3 },
|
470 |
|
|
{ 0.0,-width, -H3 },
|
471 |
|
|
{ -X3,-width, -Z3 }
|
472 |
|
|
};
|
473 |
|
|
|
474 |
|
|
int[][] vertIndexes = new int[][]
|
475 |
|
|
{
|
476 |
|
|
{4,5,1,0},
|
477 |
|
|
{7,4,0,3},
|
478 |
|
|
{0,1,2,3},
|
479 |
|
|
{7,6,2,3},
|
480 |
|
|
{6,5,1,2},
|
481 |
|
|
{4,5,6,7}
|
482 |
|
|
};
|
483 |
|
|
|
484 |
|
|
float[][] bands = new float[][]
|
485 |
|
|
{
|
486 |
|
|
{0.04f,17,0.3f,0.2f,N,1,E},
|
487 |
|
|
{0.00f,17,0.3f,0.2f,N,1,E}
|
488 |
|
|
};
|
489 |
|
|
|
490 |
|
|
float A = (2*SQ3/3)*SIN54;
|
491 |
|
|
float B = 0.4f;
|
492 |
|
|
|
493 |
|
|
int[] bandIndices = new int[] { 0,0,0,1,1,1};
|
494 |
|
|
float[][] corners = new float[][] { {0.03f,0.10f} };
|
495 |
|
|
int[] cornerIndices = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
|
496 |
|
|
float[][] centers = new float[][] { {0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B} };
|
497 |
|
|
int[] centerIndices = new int[] { 0, 0,-1, 0, 0,-1,-1,-1 };
|
498 |
|
|
|
499 |
|
|
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
500 |
|
|
}
|
501 |
|
|
}
|
502 |
|
|
|
503 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
504 |
|
|
|
505 |
|
|
protected Static4D getQuat(int cubit, int numLayers)
|
506 |
|
|
{
|
507 |
|
|
if( mQuats==null ) initializeQuats();
|
508 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
509 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
510 |
|
|
|
511 |
|
|
return mQuats[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
515 |
|
|
|
516 |
|
|
protected int getNumCubitVariants(int numLayers)
|
517 |
|
|
{
|
518 |
61aa85e4
|
Leszek Koltunski
|
switch(numLayers)
|
519 |
|
|
{
|
520 |
|
|
case 3: return 1;
|
521 |
|
|
case 5: return 4;
|
522 |
|
|
}
|
523 |
29b82486
|
Leszek Koltunski
|
|
524 |
61aa85e4
|
Leszek Koltunski
|
return 1;
|
525 |
29b82486
|
Leszek Koltunski
|
}
|
526 |
|
|
|
527 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
528 |
|
|
|
529 |
|
|
protected int getCubitVariant(int cubit, int numLayers)
|
530 |
|
|
{
|
531 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
532 |
|
|
|
533 |
|
|
if( cubit<NUM_CORNERS*numCubitsPerCorner ) return 0;
|
534 |
|
|
|
535 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
536 |
|
|
|
537 |
|
|
if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
538 |
|
|
{
|
539 |
|
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
540 |
|
|
return type+1;
|
541 |
|
|
}
|
542 |
|
|
|
543 |
61aa85e4
|
Leszek Koltunski
|
return getNumCubitVariants(numLayers)-1;
|
544 |
29b82486
|
Leszek Koltunski
|
}
|
545 |
|
|
|
546 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
547 |
|
|
|
548 |
|
|
int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
|
549 |
|
|
{
|
550 |
|
|
if( mCornerFaceMap==null ) initializeCornerFaceMap();
|
551 |
|
|
if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
|
552 |
|
|
|
553 |
|
|
int part = cubit % numCubitsPerCorner;
|
554 |
|
|
int corner= cubit / numCubitsPerCorner;
|
555 |
|
|
|
556 |
|
|
if( part==0 )
|
557 |
|
|
{
|
558 |
|
|
return mCornerFaceMap[corner][cubitface];
|
559 |
|
|
}
|
560 |
|
|
else
|
561 |
|
|
{
|
562 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
563 |
|
|
int block = (part-1) % N;
|
564 |
|
|
int index = (part-1) / N;
|
565 |
|
|
|
566 |
|
|
if( block< (numLayers-3)/2 )
|
567 |
|
|
{
|
568 |
|
|
switch(index)
|
569 |
|
|
{
|
570 |
|
|
case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
571 |
|
|
case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
572 |
|
|
case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
573 |
|
|
}
|
574 |
|
|
}
|
575 |
|
|
else
|
576 |
|
|
{
|
577 |
|
|
switch(index)
|
578 |
|
|
{
|
579 |
|
|
case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
580 |
|
|
case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
581 |
|
|
case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
582 |
|
|
}
|
583 |
|
|
}
|
584 |
|
|
}
|
585 |
|
|
|
586 |
|
|
return NUM_TEXTURES;
|
587 |
|
|
}
|
588 |
|
|
|
589 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
590 |
|
|
|
591 |
|
|
int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
|
592 |
|
|
{
|
593 |
|
|
if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
|
594 |
|
|
|
595 |
|
|
int part = edge % numCubitsPerEdge;
|
596 |
|
|
int variant = edge / numCubitsPerEdge;
|
597 |
|
|
if( mEdgeMap==null ) initializeEdgeMap();
|
598 |
|
|
|
599 |
|
|
part /=2;
|
600 |
|
|
|
601 |
|
|
return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACE_COLORS : NUM_TEXTURES;
|
602 |
|
|
}
|
603 |
|
|
|
604 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
605 |
|
|
|
606 |
|
|
int getCenterColor(int center, int cubitface, int numLayers)
|
607 |
|
|
{
|
608 |
|
|
if( mCenterFaceMap==null ) initializeCenterFaceMap();
|
609 |
|
|
if( mCornerFaceMap==null ) initializeCornerFaceMap();
|
610 |
|
|
|
611 |
|
|
if( numLayers==3 )
|
612 |
|
|
{
|
613 |
|
|
return cubitface>=0 && cubitface<3 ? mCornerFaceMap[center][cubitface] : NUM_TEXTURES;
|
614 |
|
|
}
|
615 |
|
|
|
616 |
|
|
return cubitface==mCenterFaceMap[center] ? center/5 + NUM_FACE_COLORS*(numLayers-1)/2 : NUM_TEXTURES;
|
617 |
|
|
}
|
618 |
|
|
|
619 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
620 |
|
|
|
621 |
|
|
protected int getFaceColor(int cubit, int cubitface, int numLayers)
|
622 |
|
|
{
|
623 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
624 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
625 |
|
|
|
626 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
627 |
|
|
{
|
628 |
|
|
return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
|
629 |
|
|
}
|
630 |
|
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
631 |
|
|
{
|
632 |
|
|
int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
|
633 |
|
|
return getEdgeColor(edge,cubitface,numCubitsPerEdge);
|
634 |
|
|
}
|
635 |
|
|
else
|
636 |
|
|
{
|
637 |
|
|
int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
|
638 |
|
|
return getCenterColor( center, cubitface, numLayers);
|
639 |
|
|
}
|
640 |
|
|
}
|
641 |
|
|
|
642 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
643 |
|
|
|
644 |
|
|
protected ObjectSticker retSticker(int face)
|
645 |
|
|
{
|
646 |
|
|
if( mStickers==null )
|
647 |
|
|
{
|
648 |
|
|
float[][] STICKERS = new float[][]
|
649 |
|
|
{
|
650 |
|
|
{ -0.36616942f, -0.36327124f, 0.5f, -0.36327124f, 0.23233888f, 0.4605048f, -0.36616942f, 0.26603764f },
|
651 |
|
|
{ -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
|
652 |
|
|
{ -0.3249197f, -0.39442718f, 0.3249197f, -0.39442718f, 0.3249197f, 0.5f, -0.3249197f, 0.2888544f }
|
653 |
|
|
};
|
654 |
|
|
|
655 |
|
|
float CENTER_CORR = 0.87f;
|
656 |
|
|
float C = 1.14f; // make the 'center' sticker artificially larger, so that we paint over the area in the center of the face.
|
657 |
|
|
|
658 |
|
|
STICKERS[0][0] *= C;
|
659 |
|
|
STICKERS[0][1] *= C;
|
660 |
|
|
STICKERS[0][2] *= C;
|
661 |
|
|
STICKERS[0][3] *= C;
|
662 |
|
|
STICKERS[0][4] *= C;
|
663 |
|
|
STICKERS[0][5] *= C;
|
664 |
|
|
STICKERS[0][6] *= C;
|
665 |
|
|
STICKERS[0][7] *= C;
|
666 |
|
|
|
667 |
|
|
STICKERS[0][2] *= CENTER_CORR;
|
668 |
|
|
STICKERS[0][3] *= CENTER_CORR;
|
669 |
|
|
|
670 |
|
|
mStickers = new ObjectSticker[STICKERS.length];
|
671 |
|
|
|
672 |
|
|
float R = 0.10f;
|
673 |
|
|
final float[][] radii = { {R,R,R,R},{R,R,R,R},{R,R,R,R} };
|
674 |
|
|
final float[] strokes = { 0.20f, 0.11f, 0.10f };
|
675 |
|
|
|
676 |
|
|
for(int s=0; s<STICKERS.length; s++)
|
677 |
|
|
{
|
678 |
|
|
mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
|
679 |
|
|
}
|
680 |
|
|
}
|
681 |
|
|
|
682 |
|
|
return mStickers[getStickerIndex(face)];
|
683 |
|
|
}
|
684 |
|
|
|
685 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
686 |
|
|
|
687 |
|
|
private int getStickerIndex(int face)
|
688 |
|
|
{
|
689 |
|
|
int variant = face/NUM_FACE_COLORS;
|
690 |
|
|
int numLayers = getNumLayers();
|
691 |
|
|
|
692 |
|
|
if( variant == (numLayers-1)/2 || numLayers==3 ) return 0;
|
693 |
|
|
if( variant==0 ) return 1;
|
694 |
|
|
|
695 |
|
|
return 2;
|
696 |
|
|
}
|
697 |
|
|
|
698 |
61aa85e4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
699 |
|
|
|
700 |
c8bc83d9
|
Leszek Koltunski
|
public ObjectType intGetObjectType(int numLayers)
|
701 |
61aa85e4
|
Leszek Koltunski
|
{
|
702 |
|
|
switch(numLayers)
|
703 |
|
|
{
|
704 |
8005e762
|
Leszek Koltunski
|
case 3: return ObjectType.KILO_3;
|
705 |
|
|
case 5: return ObjectType.KILO_5;
|
706 |
61aa85e4
|
Leszek Koltunski
|
}
|
707 |
|
|
|
708 |
8005e762
|
Leszek Koltunski
|
return ObjectType.KILO_3;
|
709 |
61aa85e4
|
Leszek Koltunski
|
}
|
710 |
|
|
|
711 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
712 |
|
|
|
713 |
|
|
public int getObjectName(int numLayers)
|
714 |
|
|
{
|
715 |
|
|
if( numLayers==3 ) return R.string.minx2;
|
716 |
|
|
if( numLayers==5 ) return R.string.minx4;
|
717 |
|
|
|
718 |
|
|
return 0;
|
719 |
|
|
}
|
720 |
|
|
|
721 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
722 |
|
|
|
723 |
|
|
public int getInventor(int numLayers)
|
724 |
|
|
{
|
725 |
|
|
if( numLayers==3 ) return R.string.minx2_inventor;
|
726 |
|
|
if( numLayers==5 ) return R.string.minx4_inventor;
|
727 |
|
|
|
728 |
|
|
return 0;
|
729 |
|
|
}
|
730 |
|
|
|
731 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
732 |
|
|
|
733 |
|
|
public int getComplexity(int numLayers)
|
734 |
|
|
{
|
735 |
|
|
return 3;
|
736 |
|
|
}
|
737 |
|
|
}
|