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 |
|
|
import android.content.res.Resources;
|
23 |
|
|
import android.graphics.Canvas;
|
24 |
|
|
import android.graphics.Paint;
|
25 |
|
|
|
26 |
749ef882
|
Leszek Koltunski
|
import org.distorted.helpers.FactoryCubit;
|
27 |
|
|
import org.distorted.helpers.FactorySticker;
|
28 |
a64e07d0
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
29 |
|
|
import org.distorted.library.main.DistortedEffects;
|
30 |
|
|
import org.distorted.library.main.DistortedTexture;
|
31 |
|
|
import org.distorted.library.mesh.MeshBase;
|
32 |
|
|
import org.distorted.library.mesh.MeshSquare;
|
33 |
|
|
import org.distorted.library.type.Static3D;
|
34 |
|
|
import org.distorted.library.type.Static4D;
|
35 |
|
|
import org.distorted.main.R;
|
36 |
|
|
import org.distorted.main.RubikSurfaceView;
|
37 |
|
|
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
|
|
public class TwistyMegaminx extends TwistyMinx
|
41 |
|
|
{
|
42 |
e4bf4d02
|
Leszek Koltunski
|
static final float MEGA_D = 0.04f;
|
43 |
a64e07d0
|
Leszek Koltunski
|
|
44 |
e4bf4d02
|
Leszek Koltunski
|
private static final int[] QUAT_CENTER_INDICES =
|
45 |
|
|
{
|
46 |
|
|
16, 18, 22, 1, 20, 13, 14, 15, 0, 12, 2, 3
|
47 |
|
|
};
|
48 |
|
|
|
49 |
d38f1397
|
Leszek Koltunski
|
private static MeshBase[] mCenterMeshes, mCornerMeshes;
|
50 |
|
|
private static MeshBase[][] mEdgeMeshes;
|
51 |
|
|
|
52 |
bb11be2a
|
Leszek Koltunski
|
private static final float[][] STICKERS = new float[][]
|
53 |
|
|
{
|
54 |
|
|
{ -0.36327127f, -0.5f, 0.36327127f, -0.26393202f, 0.36327127f, 0.5f, -0.36327127f, 0.26393202f },
|
55 |
|
|
{ -0.5f, -0.0914315f, 0.5f, -0.4163512f, 0.5f, 0.4163512f, -0.5f, 0.0914315f },
|
56 |
|
|
{ -0.49233657f, -0.18006028f, 0.49233657f, -0.5f, 0.49233657f, 0.5f, -0.49233657f, 0.18006028f },
|
57 |
|
|
{ -0.3002273f, -0.30490047f, 0.3002273f, -0.5f, 0.3002273f, 0.5f, -0.3002273f, 0.30490047f },
|
58 |
|
|
{ -0.29389262f, 0.4045085f, -0.47552824f, -0.1545085f, 0.0f, -0.5f, 0.47552824f, -0.1545085f, 0.29389262f, 0.4045085f }
|
59 |
|
|
};
|
60 |
|
|
|
61 |
a64e07d0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
|
|
TwistyMegaminx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
64 |
|
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
65 |
|
|
{
|
66 |
|
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.MEGA, res, scrWidth);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
private int numCubitsPerCorner(int numLayers)
|
72 |
|
|
{
|
73 |
|
|
return 3*((numLayers-1)/2)*((numLayers-3)/2) + 1;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77 |
|
|
|
78 |
|
|
private int numCubitsPerEdge(int numLayers)
|
79 |
|
|
{
|
80 |
|
|
return numLayers-2;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
ab210d63
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
|
|
float getScreenRatio()
|
86 |
|
|
{
|
87 |
|
|
return 1.07f;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
a64e07d0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
|
|
int getNumStickerTypes(int numLayers)
|
93 |
|
|
{
|
94 |
e4bf4d02
|
Leszek Koltunski
|
return (numLayers+3)/2;
|
95 |
a64e07d0
|
Leszek Koltunski
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
float[] getCuts(int numLayers)
|
100 |
|
|
{
|
101 |
|
|
float[] cuts = new float[numLayers-1];
|
102 |
ede1b68c
|
Leszek Koltunski
|
float D = numLayers*MovementMinx.DIST3D;
|
103 |
bb11be2a
|
Leszek Koltunski
|
float E = 2*SIN54;
|
104 |
a64e07d0
|
Leszek Koltunski
|
float X = 2*D*E/(1+2*E); // height of the 'upper' part of a dodecahedron, i.e. put it on a table,
|
105 |
ede1b68c
|
Leszek Koltunski
|
// its height is then D*2*DIST3D, it has one 'lower' part of height X, one
|
106 |
a64e07d0
|
Leszek Koltunski
|
// 'middle' part of height Y and one upper part of height X again.
|
107 |
|
|
// It's edge length = numLayers/3.0f.
|
108 |
|
|
int num = (numLayers-1)/2;
|
109 |
|
|
float G = X*(0.5f-MEGA_D)/num; // height of one Layer
|
110 |
|
|
|
111 |
|
|
for(int i=0; i<num; i++)
|
112 |
|
|
{
|
113 |
ede1b68c
|
Leszek Koltunski
|
cuts[ i] = -D + (i+0.5f)*G;
|
114 |
a64e07d0
|
Leszek Koltunski
|
cuts[2*num-1-i] = -cuts[i];
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
return cuts;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121 |
|
|
|
122 |
e6cf7283
|
Leszek Koltunski
|
private float[] computeCenter(int center, int numLayers)
|
123 |
a64e07d0
|
Leszek Koltunski
|
{
|
124 |
d38f1397
|
Leszek Koltunski
|
float[] coords = mCenterCoords[center];
|
125 |
e4bf4d02
|
Leszek Koltunski
|
float A = numLayers/3.0f;
|
126 |
|
|
|
127 |
e6cf7283
|
Leszek Koltunski
|
return new float[] { A*coords[0], A*coords[1], A*coords[2] };
|
128 |
a64e07d0
|
Leszek Koltunski
|
}
|
129 |
|
|
|
130 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
d38f1397
|
Leszek Koltunski
|
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
|
132 |
a64e07d0
|
Leszek Koltunski
|
// Appropriate one: QUATS[QUAT_INDICES[corner]].
|
133 |
|
|
|
134 |
d38f1397
|
Leszek Koltunski
|
private void computeBasicCornerVectors(int corner)
|
135 |
a64e07d0
|
Leszek Koltunski
|
{
|
136 |
d38f1397
|
Leszek Koltunski
|
Static4D quat = QUATS[QUAT_CORNER_INDICES[corner]];
|
137 |
a64e07d0
|
Leszek Koltunski
|
|
138 |
d38f1397
|
Leszek Koltunski
|
mCurrCornerV[0] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[0],quat);
|
139 |
|
|
mCurrCornerV[1] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[1],quat);
|
140 |
|
|
mCurrCornerV[2] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[2],quat);
|
141 |
a64e07d0
|
Leszek Koltunski
|
}
|
142 |
|
|
|
143 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144 |
|
|
|
145 |
e6cf7283
|
Leszek Koltunski
|
private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
|
146 |
a64e07d0
|
Leszek Koltunski
|
{
|
147 |
|
|
float D = numLayers/3.0f;
|
148 |
e6cf7283
|
Leszek Koltunski
|
float[] corn = CORNERS[corner];
|
149 |
a64e07d0
|
Leszek Koltunski
|
|
150 |
|
|
if( part==0 )
|
151 |
|
|
{
|
152 |
e6cf7283
|
Leszek Koltunski
|
return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
|
153 |
a64e07d0
|
Leszek Koltunski
|
}
|
154 |
|
|
else
|
155 |
|
|
{
|
156 |
ead91342
|
Leszek Koltunski
|
float E = 2.0f*D*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
|
157 |
a64e07d0
|
Leszek Koltunski
|
int N = (numCubitsPerCorner-1)/3;
|
158 |
6e7146df
|
Leszek Koltunski
|
int block = (part-1) % N;
|
159 |
|
|
int index = (part-1) / N;
|
160 |
d38f1397
|
Leszek Koltunski
|
Static4D pri = mCurrCornerV[index];
|
161 |
|
|
Static4D sec = mCurrCornerV[(index+2)%3];
|
162 |
a64e07d0
|
Leszek Koltunski
|
|
163 |
7764a67a
|
Leszek Koltunski
|
int layers= (numLayers-3)/2;
|
164 |
ead91342
|
Leszek Koltunski
|
int multP = (block % layers) + 1;
|
165 |
|
|
int multS = (block / layers);
|
166 |
a64e07d0
|
Leszek Koltunski
|
|
167 |
e6cf7283
|
Leszek Koltunski
|
return new float[] {
|
168 |
|
|
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E,
|
169 |
|
|
corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E,
|
170 |
|
|
corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E
|
171 |
|
|
};
|
172 |
a64e07d0
|
Leszek Koltunski
|
}
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176 |
|
|
|
177 |
d38f1397
|
Leszek Koltunski
|
private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
178 |
a64e07d0
|
Leszek Koltunski
|
{
|
179 |
d38f1397
|
Leszek Koltunski
|
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
|
180 |
|
|
return (part+1)/2;
|
181 |
|
|
}
|
182 |
a64e07d0
|
Leszek Koltunski
|
|
183 |
d38f1397
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
184 |
|
|
|
185 |
e6cf7283
|
Leszek Koltunski
|
private float[] computeEdge(int numLayers, int edge, int part)
|
186 |
d38f1397
|
Leszek Koltunski
|
{
|
187 |
ead91342
|
Leszek Koltunski
|
float D = numLayers/3.0f;
|
188 |
3d8237cc
|
Leszek Koltunski
|
|
189 |
e6cf7283
|
Leszek Koltunski
|
float[] c1 = CORNERS[ mEdgeMap[edge][0] ];
|
190 |
|
|
float[] c2 = CORNERS[ mEdgeMap[edge][1] ];
|
191 |
ead91342
|
Leszek Koltunski
|
float x = D * (c1[0]+c2[0]) / 2;
|
192 |
|
|
float y = D * (c1[1]+c2[1]) / 2;
|
193 |
|
|
float z = D * (c1[2]+c2[2]) / 2;
|
194 |
d38f1397
|
Leszek Koltunski
|
|
195 |
|
|
if( part==0 )
|
196 |
|
|
{
|
197 |
e6cf7283
|
Leszek Koltunski
|
return new float[] { x, y, z };
|
198 |
d38f1397
|
Leszek Koltunski
|
}
|
199 |
|
|
else
|
200 |
|
|
{
|
201 |
|
|
int mult = (part+1)/2;
|
202 |
|
|
int dir = (part+1)%2;
|
203 |
|
|
float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
|
204 |
|
|
|
205 |
ead91342
|
Leszek Koltunski
|
float vX = D*center[0] - x;
|
206 |
|
|
float vY = D*center[1] - y;
|
207 |
|
|
float vZ = D*center[2] - z;
|
208 |
d38f1397
|
Leszek Koltunski
|
|
209 |
ead91342
|
Leszek Koltunski
|
float A = mult*D*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
|
210 |
|
|
A /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
|
211 |
d38f1397
|
Leszek Koltunski
|
|
212 |
e6cf7283
|
Leszek Koltunski
|
return new float[] { x+A*vX, y+A*vY, z+A*vZ };
|
213 |
d38f1397
|
Leszek Koltunski
|
}
|
214 |
a64e07d0
|
Leszek Koltunski
|
}
|
215 |
|
|
|
216 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
217 |
|
|
|
218 |
e6cf7283
|
Leszek Koltunski
|
float[][] getCubitPositions(int numLayers)
|
219 |
a64e07d0
|
Leszek Koltunski
|
{
|
220 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
221 |
d38f1397
|
Leszek Koltunski
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
222 |
e4bf4d02
|
Leszek Koltunski
|
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS;
|
223 |
a64e07d0
|
Leszek Koltunski
|
int index=0;
|
224 |
|
|
|
225 |
e6cf7283
|
Leszek Koltunski
|
final float[][] CENTERS = new float[numCubits][];
|
226 |
a64e07d0
|
Leszek Koltunski
|
|
227 |
|
|
for(int corner=0; corner<NUM_CORNERS; corner++)
|
228 |
|
|
{
|
229 |
d38f1397
|
Leszek Koltunski
|
computeBasicCornerVectors(corner);
|
230 |
a64e07d0
|
Leszek Koltunski
|
|
231 |
|
|
for(int part=0; part<numCubitsPerCorner; part++, index++)
|
232 |
|
|
{
|
233 |
e6cf7283
|
Leszek Koltunski
|
CENTERS[index] = computeCorner(numCubitsPerCorner,numLayers,corner,part);
|
234 |
a64e07d0
|
Leszek Koltunski
|
}
|
235 |
|
|
}
|
236 |
d38f1397
|
Leszek Koltunski
|
|
237 |
a64e07d0
|
Leszek Koltunski
|
for(int edge=0; edge<NUM_EDGES; edge++)
|
238 |
|
|
{
|
239 |
|
|
for(int part=0; part<numCubitsPerEdge; part++, index++)
|
240 |
|
|
{
|
241 |
e6cf7283
|
Leszek Koltunski
|
CENTERS[index] = computeEdge(numLayers, edge, part );
|
242 |
a64e07d0
|
Leszek Koltunski
|
}
|
243 |
|
|
}
|
244 |
e4bf4d02
|
Leszek Koltunski
|
|
245 |
a64e07d0
|
Leszek Koltunski
|
for(int center=0; center<NUM_CENTERS; center++, index++)
|
246 |
|
|
{
|
247 |
e6cf7283
|
Leszek Koltunski
|
CENTERS[index] = computeCenter(center, numLayers);
|
248 |
a64e07d0
|
Leszek Koltunski
|
}
|
249 |
e4bf4d02
|
Leszek Koltunski
|
|
250 |
a64e07d0
|
Leszek Koltunski
|
return CENTERS;
|
251 |
|
|
}
|
252 |
|
|
|
253 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
254 |
|
|
|
255 |
e4bf4d02
|
Leszek Koltunski
|
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
256 |
a64e07d0
|
Leszek Koltunski
|
{
|
257 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
258 |
|
|
{
|
259 |
|
|
int corner = cubit/numCubitsPerCorner;
|
260 |
d38f1397
|
Leszek Koltunski
|
return QUAT_CORNER_INDICES[corner];
|
261 |
a64e07d0
|
Leszek Koltunski
|
}
|
262 |
|
|
|
263 |
d38f1397
|
Leszek Koltunski
|
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
264 |
|
|
{
|
265 |
|
|
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
|
266 |
|
|
return QUAT_EDGE_INDICES[edge];
|
267 |
|
|
}
|
268 |
|
|
|
269 |
e4bf4d02
|
Leszek Koltunski
|
int center = cubit - NUM_CORNERS*numCubitsPerCorner - NUM_EDGES*numCubitsPerEdge;
|
270 |
|
|
return QUAT_CENTER_INDICES[center];
|
271 |
a64e07d0
|
Leszek Koltunski
|
}
|
272 |
|
|
|
273 |
bb11be2a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
274 |
|
|
|
275 |
|
|
MeshBase createEdgeMesh(int numLayers, float width, float height)
|
276 |
|
|
{
|
277 |
|
|
double W = width/2;
|
278 |
|
|
double X = height*SIN_HALFD;
|
279 |
|
|
double Y = height*SIN18/COS18;
|
280 |
|
|
double Z = height*COS_HALFD;
|
281 |
|
|
|
282 |
|
|
double[][] vertices = new double[][]
|
283 |
|
|
{
|
284 |
|
|
{ 0.0, W , 0.0 },
|
285 |
|
|
{ X, W+Y , -Z },
|
286 |
|
|
{ 0.0, W+2*Y ,-2*Z },
|
287 |
|
|
{ -X, W+Y , -Z },
|
288 |
|
|
{ 0.0, -W , 0.0 },
|
289 |
|
|
{ X,-W-Y , -Z },
|
290 |
|
|
{ 0.0,-W-2*Y ,-2*Z },
|
291 |
|
|
{ -X,-W-Y , -Z },
|
292 |
|
|
};
|
293 |
|
|
|
294 |
|
|
int[][] vertIndexes = new int[][]
|
295 |
|
|
{
|
296 |
|
|
{4,5,1,0},
|
297 |
|
|
{7,4,0,3},
|
298 |
|
|
{7,6,2,3},
|
299 |
|
|
{6,5,1,2},
|
300 |
|
|
{0,1,2,3},
|
301 |
|
|
{4,5,6,7}
|
302 |
|
|
};
|
303 |
|
|
|
304 |
|
|
int N = numLayers<=5 ? 5 : 3;
|
305 |
|
|
|
306 |
|
|
float[][] bands = new float[][]
|
307 |
|
|
{
|
308 |
|
|
{0.04f,34,0.2f,0.2f,N,0,0},
|
309 |
|
|
{0.00f, 0,0.3f,0.2f,2,0,0}
|
310 |
|
|
};
|
311 |
|
|
int[] bandIndexes = new int[] { 0,0,1,1,1,1};
|
312 |
|
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
313 |
|
|
int[] cornerIndexes = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
|
314 |
|
|
float[][] centers = new float[][] { {0.0f, 0.0f, (float)(-2*Z)} };
|
315 |
|
|
int[] centerIndexes = new int[] { -1,-1,-1,-1, -1,-1,-1,-1 };
|
316 |
|
|
|
317 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
318 |
|
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
319 |
|
|
|
320 |
|
|
return factory.createRoundedSolid(vertices, vertIndexes,
|
321 |
|
|
bands, bandIndexes,
|
322 |
|
|
corners, cornerIndexes,
|
323 |
|
|
centers, centerIndexes,
|
324 |
|
|
getNumCubitFaces() );
|
325 |
|
|
}
|
326 |
|
|
|
327 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
328 |
|
|
|
329 |
|
|
MeshBase createCenterMesh(int numLayers, float width)
|
330 |
|
|
{
|
331 |
|
|
final double V = 0.83; // ??
|
332 |
|
|
final double ANGLE = V*Math.PI;
|
333 |
|
|
final double cosA = Math.cos(ANGLE);
|
334 |
|
|
final double sinA = Math.sin(ANGLE);
|
335 |
|
|
|
336 |
|
|
float R = 0.5f*width/COS54;
|
337 |
|
|
float X1 = R*COS54;
|
338 |
|
|
float Y1 = R*SIN54;
|
339 |
|
|
float X2 = R*COS18;
|
340 |
|
|
float Y2 = R*SIN18;
|
341 |
|
|
|
342 |
|
|
double[][] vertices = new double[][]
|
343 |
|
|
{
|
344 |
|
|
{-X1,+Y1*sinA, Y1*cosA},
|
345 |
|
|
{-X2,-Y2*sinA,-Y2*cosA},
|
346 |
|
|
{0.0f,-R*sinA, -R*cosA},
|
347 |
|
|
{+X2,-Y2*sinA,-Y2*cosA},
|
348 |
|
|
{+X1,+Y1*sinA, Y1*cosA}
|
349 |
|
|
};
|
350 |
|
|
|
351 |
|
|
int[][] vertIndexes = new int[][]
|
352 |
|
|
{
|
353 |
|
|
{0,1,2,3,4},
|
354 |
|
|
{0,1,2,3,4}
|
355 |
|
|
};
|
356 |
|
|
|
357 |
|
|
int N = numLayers==3 ? 4 : 3;
|
358 |
|
|
|
359 |
|
|
float[][] bands = new float[][]
|
360 |
|
|
{
|
361 |
|
|
{0.04f,45, R/3,0.2f,N,0,0},
|
362 |
|
|
{0.00f, 0, R/3,0.2f,2,0,0}
|
363 |
|
|
};
|
364 |
|
|
int[] bandIndexes = new int[] { 0,1 };
|
365 |
|
|
float[][] corners = new float[][] { {0.04f,0.10f} };
|
366 |
|
|
int[] cornerIndexes = new int[] { -1,-1,-1,-1, -1 };
|
367 |
|
|
float[][] centers = new float[][] { {0.0f, 0.0f, 0.0f} };
|
368 |
|
|
int[] centerIndexes = new int[] { -1,-1,-1,-1, -1 };
|
369 |
|
|
|
370 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
371 |
|
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
372 |
|
|
|
373 |
|
|
return factory.createRoundedSolid(vertices, vertIndexes,
|
374 |
|
|
bands, bandIndexes,
|
375 |
|
|
corners, cornerIndexes,
|
376 |
|
|
centers, centerIndexes,
|
377 |
|
|
getNumCubitFaces() );
|
378 |
|
|
}
|
379 |
|
|
|
380 |
a64e07d0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
381 |
|
|
|
382 |
|
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
383 |
|
|
{
|
384 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
385 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
386 |
28b54fe3
|
Leszek Koltunski
|
int index = (numLayers-3)/2;
|
387 |
db608887
|
Leszek Koltunski
|
int[] sizes = ObjectList.MEGA.getSizes();
|
388 |
|
|
int variants = sizes.length;
|
389 |
a64e07d0
|
Leszek Koltunski
|
MeshBase mesh;
|
390 |
|
|
|
391 |
d38f1397
|
Leszek Koltunski
|
if( mCornerMeshes==null ) mCornerMeshes = new MeshBase[variants];
|
392 |
db608887
|
Leszek Koltunski
|
if( mEdgeMeshes ==null ) mEdgeMeshes = new MeshBase[variants][(sizes[variants-1]-1)/2];
|
393 |
e4bf4d02
|
Leszek Koltunski
|
if( mCenterMeshes==null ) mCenterMeshes = new MeshBase[variants];
|
394 |
28b54fe3
|
Leszek Koltunski
|
|
395 |
d38f1397
|
Leszek Koltunski
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
396 |
a64e07d0
|
Leszek Koltunski
|
{
|
397 |
d38f1397
|
Leszek Koltunski
|
if( mCornerMeshes[index]==null )
|
398 |
|
|
{
|
399 |
16f34a98
|
Leszek Koltunski
|
float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
|
400 |
5e06e92f
|
Leszek Koltunski
|
mCornerMeshes[index] = createCornerMesh(numLayers, width);
|
401 |
d38f1397
|
Leszek Koltunski
|
}
|
402 |
28b54fe3
|
Leszek Koltunski
|
mesh = mCornerMeshes[index].copy(true);
|
403 |
a64e07d0
|
Leszek Koltunski
|
}
|
404 |
e4bf4d02
|
Leszek Koltunski
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
405 |
a64e07d0
|
Leszek Koltunski
|
{
|
406 |
d38f1397
|
Leszek Koltunski
|
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
|
407 |
|
|
|
408 |
|
|
if( mEdgeMeshes[index][type]==null )
|
409 |
|
|
{
|
410 |
3d8237cc
|
Leszek Koltunski
|
float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f);
|
411 |
|
|
float width = (numLayers/3.0f)*2*MEGA_D + 2*type*height*SIN18/COS18;
|
412 |
|
|
|
413 |
bb11be2a
|
Leszek Koltunski
|
mEdgeMeshes[index][type] = createEdgeMesh(numLayers,width,height);
|
414 |
d38f1397
|
Leszek Koltunski
|
}
|
415 |
|
|
|
416 |
|
|
mesh = mEdgeMeshes[index][type].copy(true);
|
417 |
a64e07d0
|
Leszek Koltunski
|
}
|
418 |
|
|
else
|
419 |
|
|
{
|
420 |
e4bf4d02
|
Leszek Koltunski
|
if( mCenterMeshes[index]==null )
|
421 |
|
|
{
|
422 |
|
|
float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18);
|
423 |
bb11be2a
|
Leszek Koltunski
|
mCenterMeshes[index] = createCenterMesh(numLayers,width);
|
424 |
e4bf4d02
|
Leszek Koltunski
|
}
|
425 |
|
|
|
426 |
|
|
mesh = mCenterMeshes[index].copy(true);
|
427 |
a64e07d0
|
Leszek Koltunski
|
}
|
428 |
e4bf4d02
|
Leszek Koltunski
|
|
429 |
|
|
Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
|
430 |
3d8237cc
|
Leszek Koltunski
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( q, new Static3D(0,0,0) );
|
431 |
a64e07d0
|
Leszek Koltunski
|
mesh.apply(quat,0xffffffff,0);
|
432 |
|
|
|
433 |
|
|
return mesh;
|
434 |
|
|
}
|
435 |
|
|
|
436 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
437 |
|
|
|
438 |
d38f1397
|
Leszek Koltunski
|
int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
|
439 |
a64e07d0
|
Leszek Koltunski
|
{
|
440 |
0e7a13b4
|
Leszek Koltunski
|
if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES;
|
441 |
6e7146df
|
Leszek Koltunski
|
|
442 |
|
|
int part = cubit % numCubitsPerCorner;
|
443 |
a64e07d0
|
Leszek Koltunski
|
int corner= cubit / numCubitsPerCorner;
|
444 |
|
|
|
445 |
6e7146df
|
Leszek Koltunski
|
if( part==0 )
|
446 |
a64e07d0
|
Leszek Koltunski
|
{
|
447 |
6e7146df
|
Leszek Koltunski
|
return mCornerFaceMap[corner][cubitface];
|
448 |
a64e07d0
|
Leszek Koltunski
|
}
|
449 |
|
|
else
|
450 |
|
|
{
|
451 |
|
|
int N = (numCubitsPerCorner-1)/3;
|
452 |
6e7146df
|
Leszek Koltunski
|
int block = (part-1) % N;
|
453 |
|
|
int index = (part-1) / N;
|
454 |
a64e07d0
|
Leszek Koltunski
|
|
455 |
0e7a13b4
|
Leszek Koltunski
|
if( block< (numLayers-3)/2 )
|
456 |
a64e07d0
|
Leszek Koltunski
|
{
|
457 |
6e7146df
|
Leszek Koltunski
|
switch(index)
|
458 |
|
|
{
|
459 |
0e7a13b4
|
Leszek Koltunski
|
case 0: return cubitface==1 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
460 |
|
|
case 1: return cubitface==0 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
461 |
|
|
case 2: return cubitface==2 ? NUM_TEXTURES : mCornerFaceMap[corner][cubitface];
|
462 |
6e7146df
|
Leszek Koltunski
|
}
|
463 |
a64e07d0
|
Leszek Koltunski
|
}
|
464 |
|
|
else
|
465 |
|
|
{
|
466 |
6e7146df
|
Leszek Koltunski
|
switch(index)
|
467 |
|
|
{
|
468 |
0e7a13b4
|
Leszek Koltunski
|
case 0: return cubitface==0 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
469 |
|
|
case 1: return cubitface==2 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
470 |
|
|
case 2: return cubitface==1 ? mCornerFaceMap[corner][cubitface] : NUM_TEXTURES;
|
471 |
6e7146df
|
Leszek Koltunski
|
}
|
472 |
a64e07d0
|
Leszek Koltunski
|
}
|
473 |
|
|
}
|
474 |
6e7146df
|
Leszek Koltunski
|
|
475 |
0e7a13b4
|
Leszek Koltunski
|
return NUM_TEXTURES;
|
476 |
a64e07d0
|
Leszek Koltunski
|
}
|
477 |
|
|
|
478 |
d38f1397
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
479 |
|
|
|
480 |
e4bf4d02
|
Leszek Koltunski
|
int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
|
481 |
d38f1397
|
Leszek Koltunski
|
{
|
482 |
0e7a13b4
|
Leszek Koltunski
|
if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES;
|
483 |
d38f1397
|
Leszek Koltunski
|
|
484 |
e4bf4d02
|
Leszek Koltunski
|
int part = edge % numCubitsPerEdge;
|
485 |
|
|
int variant = edge / numCubitsPerEdge;
|
486 |
d38f1397
|
Leszek Koltunski
|
|
487 |
51df47f3
|
Leszek Koltunski
|
return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + ((part+3)/2)*NUM_FACES : NUM_TEXTURES;
|
488 |
d38f1397
|
Leszek Koltunski
|
}
|
489 |
|
|
|
490 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
491 |
|
|
|
492 |
e4bf4d02
|
Leszek Koltunski
|
int getCenterColor(int center, int cubitface, int numLayers)
|
493 |
d38f1397
|
Leszek Koltunski
|
{
|
494 |
e4bf4d02
|
Leszek Koltunski
|
return cubitface>0 ? NUM_TEXTURES : center + NUM_FACES*(numLayers+1)/2;
|
495 |
d38f1397
|
Leszek Koltunski
|
}
|
496 |
|
|
|
497 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
498 |
|
|
|
499 |
|
|
int getFaceColor(int cubit, int cubitface, int numLayers)
|
500 |
|
|
{
|
501 |
|
|
int numCubitsPerCorner = numCubitsPerCorner(numLayers);
|
502 |
|
|
int numCubitsPerEdge = numCubitsPerEdge(numLayers);
|
503 |
|
|
|
504 |
|
|
if( cubit < NUM_CORNERS*numCubitsPerCorner )
|
505 |
|
|
{
|
506 |
|
|
return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
|
507 |
|
|
}
|
508 |
|
|
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
509 |
|
|
{
|
510 |
e4bf4d02
|
Leszek Koltunski
|
int edge = cubit - NUM_CORNERS*numCubitsPerCorner;
|
511 |
|
|
return getEdgeColor(edge,cubitface,numCubitsPerEdge);
|
512 |
d38f1397
|
Leszek Koltunski
|
}
|
513 |
|
|
else
|
514 |
|
|
{
|
515 |
e4bf4d02
|
Leszek Koltunski
|
int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge;
|
516 |
|
|
return getCenterColor( center, cubitface, numLayers);
|
517 |
d38f1397
|
Leszek Koltunski
|
}
|
518 |
|
|
}
|
519 |
|
|
|
520 |
a64e07d0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
521 |
|
|
|
522 |
|
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
|
523 |
|
|
{
|
524 |
ede1b68c
|
Leszek Koltunski
|
int COLORS = FACE_COLORS.length;
|
525 |
|
|
float R,S;
|
526 |
bb11be2a
|
Leszek Koltunski
|
int index,variant = face/COLORS;
|
527 |
ede1b68c
|
Leszek Koltunski
|
|
528 |
bb11be2a
|
Leszek Koltunski
|
if( variant==0 ) { R = 0.08f; S = 0.10f; index = 0; }
|
529 |
ede1b68c
|
Leszek Koltunski
|
else
|
530 |
|
|
{
|
531 |
|
|
int numLayers = getNumLayers();
|
532 |
|
|
|
533 |
|
|
if( variant < (numLayers+1)/2 )
|
534 |
|
|
{
|
535 |
bb11be2a
|
Leszek Koltunski
|
if( numLayers==3 ) { R = 0.12f; S = 0.12f; index = 1; }
|
536 |
|
|
else
|
537 |
|
|
{
|
538 |
|
|
if( variant==1 ) { R = 0.12f; S = 0.12f; index = 2; }
|
539 |
|
|
else { R = 0.08f; S = 0.08f; index = 3; }
|
540 |
|
|
}
|
541 |
ede1b68c
|
Leszek Koltunski
|
}
|
542 |
bb11be2a
|
Leszek Koltunski
|
else { R = 0.10f; S = 0.07f; index = 4; }
|
543 |
ede1b68c
|
Leszek Koltunski
|
}
|
544 |
|
|
|
545 |
|
|
FactorySticker factory = FactorySticker.getInstance();
|
546 |
bb11be2a
|
Leszek Koltunski
|
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[index], S, FACE_COLORS[face%COLORS], R);
|
547 |
a64e07d0
|
Leszek Koltunski
|
}
|
548 |
|
|
|
549 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
550 |
|
|
// PUBLIC API
|
551 |
|
|
|
552 |
|
|
public boolean isSolved()
|
553 |
|
|
{
|
554 |
|
|
int index = CUBITS[0].mQuatIndex;
|
555 |
|
|
|
556 |
|
|
for(int i=1; i<NUM_CUBITS; i++)
|
557 |
|
|
{
|
558 |
722b2512
|
Leszek Koltunski
|
if( thereIsVisibleDifference(CUBITS[i], index) ) return false;
|
559 |
a64e07d0
|
Leszek Koltunski
|
}
|
560 |
|
|
|
561 |
|
|
return true;
|
562 |
|
|
}
|
563 |
|
|
|
564 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
565 |
|
|
|
566 |
|
|
public int getObjectName(int numLayers)
|
567 |
|
|
{
|
568 |
|
|
if( numLayers==3 ) return R.string.minx3;
|
569 |
f6e46300
|
Leszek Koltunski
|
if( numLayers==5 ) return R.string.minx5;
|
570 |
a64e07d0
|
Leszek Koltunski
|
|
571 |
|
|
return 0;
|
572 |
|
|
}
|
573 |
|
|
|
574 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
575 |
|
|
|
576 |
|
|
public int getInventor(int numLayers)
|
577 |
|
|
{
|
578 |
|
|
if( numLayers==3 ) return R.string.minx3_inventor;
|
579 |
f6e46300
|
Leszek Koltunski
|
if( numLayers==5 ) return R.string.minx5_inventor;
|
580 |
a64e07d0
|
Leszek Koltunski
|
|
581 |
|
|
return 0;
|
582 |
|
|
}
|
583 |
|
|
|
584 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
585 |
|
|
|
586 |
|
|
public int getComplexity(int numLayers)
|
587 |
|
|
{
|
588 |
|
|
if( numLayers==3 ) return 4;
|
589 |
|
|
|
590 |
|
|
return 5;
|
591 |
|
|
}
|
592 |
|
|
}
|