1 |
e2b9e87e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2021 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 |
|
|
|
24 |
|
|
import org.distorted.helpers.FactoryCubit;
|
25 |
|
|
import org.distorted.library.main.DistortedEffects;
|
26 |
|
|
import org.distorted.library.main.DistortedTexture;
|
27 |
|
|
import org.distorted.library.mesh.MeshBase;
|
28 |
|
|
import org.distorted.library.mesh.MeshSquare;
|
29 |
|
|
import org.distorted.library.type.Static3D;
|
30 |
|
|
import org.distorted.library.type.Static4D;
|
31 |
|
|
|
32 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
|
|
abstract class TwistySquare extends TwistyObject
|
35 |
|
|
{
|
36 |
|
|
static final int LAST_SL = 0; // automatic rotations: last rot was a 'slash' i.e. along ROT_AXIS[1]
|
37 |
|
|
static final int LAST_UP = 1; // last rot was along ROT_AXIS[0], upper layer and forelast was a slash
|
38 |
|
|
static final int LAST_LO = 2; // last rot was along ROT_AXIS[0], lower layer and forelast was a slash
|
39 |
|
|
static final int LAST_UL = 3; // two last rots were along ROT_AXIS[0] (so the next must be a slash)
|
40 |
|
|
|
41 |
|
|
static final float COS15 = (SQ6+SQ2)/4;
|
42 |
|
|
static final float SIN15 = (SQ6-SQ2)/4;
|
43 |
|
|
static final float X = 3*(2-SQ3)/2;
|
44 |
|
|
|
45 |
|
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
46 |
|
|
{
|
47 |
|
|
new Static3D(0,1,0),
|
48 |
|
|
new Static3D(COS15,0,SIN15)
|
49 |
|
|
};
|
50 |
|
|
|
51 |
|
|
static final int[] BASIC_ANGLE = new int[] { 12,2 };
|
52 |
|
|
|
53 |
|
|
static final int[] FACE_COLORS = new int[]
|
54 |
|
|
{
|
55 |
|
|
COLOR_YELLOW, COLOR_WHITE,
|
56 |
|
|
COLOR_BLUE , COLOR_GREEN,
|
57 |
|
|
COLOR_RED , COLOR_ORANGE
|
58 |
|
|
};
|
59 |
|
|
|
60 |
|
|
static final Static4D[] QUATS = new Static4D[]
|
61 |
|
|
{
|
62 |
|
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
63 |
|
|
new Static4D( 0.0f, SIN15, 0.0f, COS15 ),
|
64 |
|
|
new Static4D( 0.0f, 0.5f, 0.0f, SQ3/2 ),
|
65 |
|
|
new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2 ),
|
66 |
|
|
new Static4D( 0.0f, SQ3/2, 0.0f, 0.5f ),
|
67 |
|
|
new Static4D( 0.0f, COS15, 0.0f, SIN15 ),
|
68 |
|
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
69 |
|
|
new Static4D( 0.0f, COS15, 0.0f,-SIN15 ),
|
70 |
|
|
new Static4D( 0.0f, SQ3/2, 0.0f, -0.5f ),
|
71 |
|
|
new Static4D( 0.0f, SQ2/2, 0.0f,-SQ2/2 ),
|
72 |
|
|
new Static4D( 0.0f, 0.5f, 0.0f,-SQ3/2 ),
|
73 |
|
|
new Static4D( 0.0f, SIN15, 0.0f,-COS15 ),
|
74 |
|
|
|
75 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
76 |
|
|
new Static4D( COS15, 0.0f, SIN15, 0.0f ),
|
77 |
|
|
new Static4D( SQ3/2, 0.0f, 0.5f, 0.0f ),
|
78 |
|
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f ),
|
79 |
|
|
new Static4D( 0.5f, 0.0f, SQ3/2, 0.0f ),
|
80 |
|
|
new Static4D( SIN15, 0.0f, COS15, 0.0f ),
|
81 |
|
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
82 |
|
|
new Static4D(-SIN15, 0.0f, COS15, 0.0f ),
|
83 |
|
|
new Static4D( -0.5f, 0.0f, SQ3/2, 0.0f ),
|
84 |
|
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f ),
|
85 |
|
|
new Static4D(-SQ3/2, 0.0f, 0.5f, 0.0f ),
|
86 |
|
|
new Static4D(-COS15, 0.0f, SIN15, 0.0f )
|
87 |
|
|
};
|
88 |
|
|
|
89 |
|
|
static final double[][] VERTICES_MIDDLE = new double[][]
|
90 |
|
|
{
|
91 |
|
|
{ -1.5-X, 0.5, 1.5 },
|
92 |
|
|
{ 0.0, 0.5, 1.5 },
|
93 |
|
|
{ 0.0, 0.5,-1.5 },
|
94 |
|
|
{ -1.5+X, 0.5,-1.5 },
|
95 |
|
|
{ -1.5-X,-0.5, 1.5 },
|
96 |
|
|
{ 0.0,-0.5, 1.5 },
|
97 |
|
|
{ 0.0,-0.5,-1.5 },
|
98 |
|
|
{ -1.5+X,-0.5,-1.5 }
|
99 |
|
|
};
|
100 |
|
|
|
101 |
|
|
static final int[][] VERT_INDEXES_MIDDLE = new int[][]
|
102 |
|
|
{
|
103 |
|
|
{0,1,2,3}, // counterclockwise!
|
104 |
|
|
{4,5,6,7},
|
105 |
|
|
{4,5,1,0},
|
106 |
|
|
{5,6,2,1},
|
107 |
|
|
{6,7,3,2},
|
108 |
|
|
{7,4,0,3}
|
109 |
|
|
};
|
110 |
|
|
|
111 |
|
|
static final double[][] VERTICES_EDGE = new double[][]
|
112 |
|
|
{
|
113 |
|
|
{ -X, 0.5, 0.0 },
|
114 |
|
|
{ +X, 0.5, 0.0 },
|
115 |
|
|
{0.0, 0.5,-1.5 },
|
116 |
|
|
{ -X,-0.5, 0.0 },
|
117 |
|
|
{ +X,-0.5, 0.0 },
|
118 |
|
|
{0.0,-0.5,-1.5 },
|
119 |
|
|
};
|
120 |
|
|
|
121 |
|
|
static final int[][] VERT_INDEXES_EDGE = new int[][]
|
122 |
|
|
{
|
123 |
|
|
{0,1,2}, // counterclockwise!
|
124 |
|
|
{3,4,5},
|
125 |
|
|
{3,4,1,0},
|
126 |
|
|
{4,5,2,1},
|
127 |
|
|
{5,3,0,2}
|
128 |
|
|
};
|
129 |
|
|
|
130 |
|
|
// QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
|
131 |
|
|
static final int[][] QUAT_MULT = new int[][]
|
132 |
|
|
{
|
133 |
|
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
|
134 |
|
|
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
|
135 |
|
|
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
|
136 |
|
|
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
|
137 |
|
|
{ 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
|
138 |
|
|
{ 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
|
139 |
|
|
{ 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
|
140 |
|
|
{ 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
|
141 |
|
|
{ 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
|
142 |
|
|
{ 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
|
143 |
|
|
{ 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
|
144 |
|
|
{ 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
|
145 |
|
|
{ 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,},
|
146 |
|
|
{ 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,},
|
147 |
|
|
{ 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3,},
|
148 |
|
|
{ 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4,},
|
149 |
|
|
{ 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5,},
|
150 |
|
|
{ 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6,},
|
151 |
|
|
{ 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7,},
|
152 |
|
|
{ 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8,},
|
153 |
|
|
{ 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9,},
|
154 |
|
|
{ 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10,},
|
155 |
|
|
{ 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11,},
|
156 |
|
|
{ 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,}
|
157 |
|
|
};
|
158 |
|
|
|
159 |
|
|
static MeshBase[] mMeshes;
|
160 |
|
|
int mLastRot;
|
161 |
|
|
|
162 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163 |
|
|
|
164 |
|
|
TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
165 |
|
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
166 |
|
|
{
|
167 |
|
|
super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171 |
|
|
|
172 |
|
|
MeshBase createMiddleCubitMesh()
|
173 |
|
|
{
|
174 |
|
|
if( mMeshes[0]==null )
|
175 |
|
|
{
|
176 |
|
|
float[][] bands= new float[][]
|
177 |
|
|
{
|
178 |
|
|
{0.040f,35,0.8f,1.0f,5,2,1},
|
179 |
|
|
{0.020f,35,0.8f,1.0f,5,2,1},
|
180 |
|
|
{0.001f,35,0.8f,1.0f,5,2,1}
|
181 |
|
|
};
|
182 |
|
|
int[] bandIndexes = new int[] { 2,2,1,1,0,2 };
|
183 |
|
|
float[][] corners = new float[][] { {0.03f,0.05f} };
|
184 |
|
|
int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
185 |
|
|
float[][] centers = new float[][] { { -0.75f, 0.0f, 0.0f} };
|
186 |
|
|
int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
187 |
|
|
|
188 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
189 |
|
|
factory.createNewFaceTransform(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE);
|
190 |
|
|
mMeshes[0] = factory.createRoundedSolid(VERTICES_MIDDLE, VERT_INDEXES_MIDDLE,
|
191 |
|
|
bands, bandIndexes,
|
192 |
|
|
corners, cornerIndexes,
|
193 |
|
|
centers, centerIndexes,
|
194 |
|
|
getNumCubitFaces() );
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
return mMeshes[0].copy(true);
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201 |
|
|
|
202 |
|
|
MeshBase createEdgeCubitMesh()
|
203 |
|
|
{
|
204 |
|
|
if( mMeshes[1]==null )
|
205 |
|
|
{
|
206 |
|
|
float[][] bands= new float[][]
|
207 |
|
|
{
|
208 |
|
|
{0.038f,35,0.5f,0.9f, 5,2,1},
|
209 |
|
|
{0.001f,35,0.5f,0.9f, 5,2,1}
|
210 |
|
|
};
|
211 |
|
|
int[] bandIndexes = new int[] { 0,1,0,1,1 };
|
212 |
|
|
float[][] corners = new float[][] { {0.04f,0.15f} };
|
213 |
|
|
int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
|
214 |
|
|
float[][] centers = new float[][] { { 0.0f, 0.0f,-0.5f} };
|
215 |
|
|
int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
|
216 |
|
|
|
217 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
218 |
|
|
factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
|
219 |
|
|
mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
|
220 |
|
|
bands, bandIndexes,
|
221 |
|
|
corners, cornerIndexes,
|
222 |
|
|
centers, centerIndexes,
|
223 |
|
|
getNumCubitFaces() );
|
224 |
|
|
}
|
225 |
|
|
return mMeshes[1].copy(true);
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
229 |
|
|
|
230 |
|
|
Static4D[] getQuats()
|
231 |
|
|
{
|
232 |
|
|
return QUATS;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236 |
|
|
|
237 |
|
|
boolean shouldResetTextureMaps()
|
238 |
|
|
{
|
239 |
|
|
return false;
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243 |
|
|
|
244 |
|
|
int getNumFaces()
|
245 |
|
|
{
|
246 |
|
|
return FACE_COLORS.length;
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
250 |
|
|
|
251 |
|
|
int getNumCubitFaces()
|
252 |
|
|
{
|
253 |
|
|
return 6;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257 |
|
|
|
258 |
|
|
float getScreenRatio()
|
259 |
|
|
{
|
260 |
|
|
return 0.5f;
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264 |
|
|
|
265 |
|
|
float returnMultiplier()
|
266 |
|
|
{
|
267 |
|
|
return 1.0f;
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
271 |
|
|
|
272 |
|
|
float[][] getCuts(int numLayers)
|
273 |
|
|
{
|
274 |
|
|
return new float[][] { {-0.5f,+0.5f}, {0.0f} };
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
278 |
|
|
// PUBLIC API
|
279 |
|
|
|
280 |
|
|
public Static3D[] getRotationAxis()
|
281 |
|
|
{
|
282 |
|
|
return ROT_AXIS;
|
283 |
|
|
}
|
284 |
|
|
|
285 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
286 |
|
|
|
287 |
|
|
public int[] getBasicAngle()
|
288 |
|
|
{
|
289 |
|
|
return BASIC_ANGLE;
|
290 |
|
|
}
|
291 |
|
|
|
292 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
293 |
|
|
// only needed for solvers - there are no Square solvers ATM)
|
294 |
|
|
|
295 |
|
|
public String retObjectString()
|
296 |
|
|
{
|
297 |
|
|
return "";
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
}
|