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