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