|
1 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2 |
// Copyright 2023 Leszek Koltunski //
|
|
3 |
// //
|
|
4 |
// This file is part of Magic Cube. //
|
|
5 |
// //
|
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
|
8 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
9 |
|
|
10 |
package org.distorted.objectlib.objects;
|
|
11 |
|
|
12 |
import static org.distorted.objectlib.objects.TwistyMegaminx.MEGA_D;
|
|
13 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_TETRAHEDRON;
|
|
14 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
|
|
15 |
|
|
16 |
import org.distorted.library.effect.EffectName;
|
|
17 |
import org.distorted.library.main.DistortedLibrary;
|
|
18 |
import org.distorted.library.type.Static3D;
|
|
19 |
import org.distorted.library.type.Static4D;
|
|
20 |
import org.distorted.objectlib.bandaged.FactoryBandagedMegaminx;
|
|
21 |
import org.distorted.objectlib.bandaged.FactoryBandagedPyraminx;
|
|
22 |
import org.distorted.objectlib.helpers.ObjectFaceShape;
|
|
23 |
import org.distorted.objectlib.helpers.ObjectShape;
|
|
24 |
import org.distorted.objectlib.helpers.ObjectSignature;
|
|
25 |
import org.distorted.objectlib.helpers.ObjectVertexEffects;
|
|
26 |
import org.distorted.objectlib.main.InitAssets;
|
|
27 |
import org.distorted.objectlib.main.InitData;
|
|
28 |
import org.distorted.objectlib.scrambling.ObjectScrambler;
|
|
29 |
import org.distorted.objectlib.shape.ShapeDodecahedron;
|
|
30 |
import org.distorted.objectlib.shape.ShapeTetrahedron;
|
|
31 |
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
|
|
32 |
|
|
33 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
34 |
|
|
35 |
public class TwistyBandagedMegaminx extends TwistyDodecahedron
|
|
36 |
{
|
|
37 |
public static final String OBJECT_NAME_MEGAMINX = "LOCAL_MEGAMINX";
|
|
38 |
|
|
39 |
// TODO
|
|
40 |
private static final int OCT_1 = 0;
|
|
41 |
private static final int TET_1 = 1;
|
|
42 |
private static final int OTHER = 2;
|
|
43 |
|
|
44 |
private static final int NUM_TYPES = 2; // OCT_1 and TET_1
|
|
45 |
|
|
46 |
private int[] mCubitVariantMap;
|
|
47 |
private int[] mTypeVariantMap;
|
|
48 |
private ObjectShape[] mTmpShapes;
|
|
49 |
private int mNumVariants;
|
|
50 |
private float[][] mPosition;
|
|
51 |
private ObjectSignature mSignature;
|
|
52 |
|
|
53 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
54 |
|
|
55 |
private float[][] getPositions()
|
|
56 |
{
|
|
57 |
if( mPosition==null ) mPosition = getInitData().getPos();
|
|
58 |
return mPosition;
|
|
59 |
}
|
|
60 |
|
|
61 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
62 |
// TODO
|
|
63 |
|
|
64 |
private int getType(float[] pos, int numLayers)
|
|
65 |
{
|
|
66 |
return OTHER;
|
|
67 |
}
|
|
68 |
|
|
69 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
70 |
|
|
71 |
private int getType(int variant)
|
|
72 |
{
|
|
73 |
for(int t=0; t<NUM_TYPES; t++)
|
|
74 |
if( mTypeVariantMap[t]==variant ) return t;
|
|
75 |
|
|
76 |
return -1;
|
|
77 |
}
|
|
78 |
|
|
79 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
80 |
|
|
81 |
private void produceTmpShape(int variant)
|
|
82 |
{
|
|
83 |
float[][] positions = getPositions();
|
|
84 |
int cubit,numCubits = positions.length;
|
|
85 |
|
|
86 |
for(cubit=0; cubit<numCubits; cubit++)
|
|
87 |
{
|
|
88 |
if( mCubitVariantMap[cubit]==variant ) break;
|
|
89 |
}
|
|
90 |
|
|
91 |
if( cubit>=numCubits )
|
|
92 |
{
|
|
93 |
android.util.Log.e("D", "unknown variant: "+variant);
|
|
94 |
}
|
|
95 |
else
|
|
96 |
{
|
|
97 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance();
|
|
98 |
mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]);
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
103 |
|
|
104 |
private float[][] getVertices(int variant)
|
|
105 |
{
|
|
106 |
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
|
|
107 |
if( mTmpShapes[variant]==null ) produceTmpShape(variant);
|
|
108 |
return mTmpShapes[variant].getVertices();
|
|
109 |
}
|
|
110 |
|
|
111 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
112 |
// PUBLIC API
|
|
113 |
|
|
114 |
public TwistyBandagedMegaminx(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
|
|
115 |
{
|
|
116 |
super(meshState, iconMode, quat, move, scale, data, asset);
|
|
117 |
}
|
|
118 |
|
|
119 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
120 |
// Computing scramble states of many a bandaged objects takes way too long time and too much space.
|
|
121 |
// Return null here and turn to construction of scramble tables just-in-time (scrambleType=2)
|
|
122 |
|
|
123 |
public int[][] getScrambleEdges()
|
|
124 |
{
|
|
125 |
return null;
|
|
126 |
}
|
|
127 |
|
|
128 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
129 |
|
|
130 |
@Override
|
|
131 |
public int[][] getScrambleAlgorithms()
|
|
132 |
{
|
|
133 |
return super.getScrambleAlgorithms();
|
|
134 |
}
|
|
135 |
|
|
136 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
137 |
|
|
138 |
@Override
|
|
139 |
public int getScrambleType()
|
|
140 |
{
|
|
141 |
return ObjectScrambler.SCRAMBLING_BANDAGED;
|
|
142 |
}
|
|
143 |
|
|
144 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
145 |
|
|
146 |
public ObjectShape getObjectShape(int variant)
|
|
147 |
{
|
|
148 |
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
|
|
149 |
if( mTmpShapes[variant]==null ) produceTmpShape(variant);
|
|
150 |
return mTmpShapes[variant];
|
|
151 |
}
|
|
152 |
|
|
153 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
154 |
|
|
155 |
public ObjectFaceShape getObjectFaceShape(int variant)
|
|
156 |
{
|
|
157 |
int type = getType(variant);
|
|
158 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance();
|
|
159 |
|
|
160 |
if( type>=0 )
|
|
161 |
{
|
|
162 |
int[] numLayers = getNumLayers();
|
|
163 |
boolean iconMode = isInIconMode();
|
|
164 |
float[][] bands = factory.getBands(iconMode,numLayers);
|
|
165 |
|
|
166 |
int numFaces = type==TET_1 ? 4:8; // TODO
|
|
167 |
|
|
168 |
int[] bandIndices= new int[numFaces];
|
|
169 |
for(int i=0; i<numFaces; i++) bandIndices[i] = 1;
|
|
170 |
return new ObjectFaceShape(bands,bandIndices,null);
|
|
171 |
}
|
|
172 |
|
|
173 |
return factory.createIrregularFaceShape(variant, isInIconMode() );
|
|
174 |
}
|
|
175 |
|
|
176 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
177 |
|
|
178 |
public ObjectVertexEffects getVertexEffects(int variant)
|
|
179 |
{
|
|
180 |
int[] numLayers = getNumLayers();
|
|
181 |
int size = numLayers[0];
|
|
182 |
boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
|
|
183 |
int type = getType(variant);
|
|
184 |
|
|
185 |
if( type>=0 )
|
|
186 |
{
|
|
187 |
float[][] vertices = getVertices(variant);
|
|
188 |
int numV = vertices.length;
|
|
189 |
float S = -0.04f;
|
|
190 |
|
|
191 |
String name = EffectName.DEFORM.name();
|
|
192 |
float[] reg = {0,0,0,0.15f};
|
|
193 |
|
|
194 |
float[][] variables = new float[numV][];
|
|
195 |
String[] names = new String[numV];
|
|
196 |
float[][] regions = new float[numV][];
|
|
197 |
boolean[] uses = new boolean[numV];
|
|
198 |
|
|
199 |
for(int i=0; i<numV; i++)
|
|
200 |
{
|
|
201 |
float[] v = vertices[i];
|
|
202 |
variables[i] = new float[] { 0, S*v[0], S*v[1], S*v[2], 1 };
|
|
203 |
names[i] = name;
|
|
204 |
regions[i] = reg;
|
|
205 |
uses[i] = round;
|
|
206 |
}
|
|
207 |
|
|
208 |
return new ObjectVertexEffects(names,variables,vertices,regions,uses);
|
|
209 |
}
|
|
210 |
|
|
211 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance();
|
|
212 |
return factory.createVertexEffects(variant,round);
|
|
213 |
}
|
|
214 |
|
|
215 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
216 |
|
|
217 |
public Static4D getCubitQuats(int cubit, int[] numLayers)
|
|
218 |
{
|
|
219 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance();
|
|
220 |
return factory.getElementQuat(numLayers,cubit);
|
|
221 |
}
|
|
222 |
|
|
223 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
224 |
// TODO
|
|
225 |
|
|
226 |
public int getNumCubitVariants(int[] numLayers)
|
|
227 |
{
|
|
228 |
if( mNumVariants==0 )
|
|
229 |
{
|
|
230 |
float[][] positions = getPositions();
|
|
231 |
boolean T1=false;
|
|
232 |
boolean O1=false;
|
|
233 |
|
|
234 |
int numCubits = positions.length;
|
|
235 |
mCubitVariantMap = new int[numCubits];
|
|
236 |
|
|
237 |
mTypeVariantMap = new int[NUM_TYPES];
|
|
238 |
for(int i=0; i<NUM_TYPES; i++) mTypeVariantMap[i] = -1;
|
|
239 |
|
|
240 |
for (int cubit=0; cubit<numCubits; cubit++)
|
|
241 |
{
|
|
242 |
int type = getType(positions[cubit],numLayers[0]);
|
|
243 |
|
|
244 |
switch (type)
|
|
245 |
{
|
|
246 |
case TET_1: if (!T1) { T1 = true; mTypeVariantMap[TET_1]=mNumVariants++; }
|
|
247 |
mCubitVariantMap[cubit] = mTypeVariantMap[TET_1];
|
|
248 |
break;
|
|
249 |
case OCT_1: if (!O1) { O1 = true; mTypeVariantMap[OCT_1]=mNumVariants++; }
|
|
250 |
mCubitVariantMap[cubit] = mTypeVariantMap[OCT_1];
|
|
251 |
break;
|
|
252 |
default : mCubitVariantMap[cubit] = mNumVariants++;
|
|
253 |
}
|
|
254 |
}
|
|
255 |
|
|
256 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance();
|
|
257 |
factory.prepare(mNumVariants,numLayers);
|
|
258 |
}
|
|
259 |
|
|
260 |
return mNumVariants;
|
|
261 |
}
|
|
262 |
|
|
263 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
264 |
|
|
265 |
public float[][] getCubitPositions(int[] numLayers)
|
|
266 |
{
|
|
267 |
return getPositions();
|
|
268 |
}
|
|
269 |
|
|
270 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
271 |
|
|
272 |
public float[][] getCuts(int[] numLayers)
|
|
273 |
{
|
|
274 |
int size = numLayers[0];
|
|
275 |
float dist = (size%2==0) ? 0.5f : 0.5f-MEGA_D;
|
|
276 |
return genericGetCuts(size,dist);
|
|
277 |
}
|
|
278 |
|
|
279 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
280 |
|
|
281 |
public int getCubitVariant(int cubit, int[] numLayers)
|
|
282 |
{
|
|
283 |
return mCubitVariantMap[cubit];
|
|
284 |
}
|
|
285 |
|
|
286 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
287 |
|
|
288 |
public float getStickerRadius()
|
|
289 |
{
|
|
290 |
return 0.10f;
|
|
291 |
}
|
|
292 |
|
|
293 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
294 |
|
|
295 |
public float getStickerStroke()
|
|
296 |
{
|
|
297 |
return isInIconMode() ? 0.16f : 0.08f;
|
|
298 |
}
|
|
299 |
|
|
300 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
301 |
|
|
302 |
public float[][][] getStickerAngles()
|
|
303 |
{
|
|
304 |
return null;
|
|
305 |
}
|
|
306 |
|
|
307 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
308 |
|
|
309 |
public String getShortName()
|
|
310 |
{
|
|
311 |
if( mSignature==null ) mSignature = getSignature();
|
|
312 |
int[] numLayers = getNumLayers();
|
|
313 |
return "M"+numLayers[0]+"_"+mSignature.getString();
|
|
314 |
}
|
|
315 |
|
|
316 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
317 |
// TODO
|
|
318 |
|
|
319 |
public ObjectSignature getSignature()
|
|
320 |
{
|
|
321 |
if( mSignature==null )
|
|
322 |
{
|
|
323 |
int[] numLayers = getNumLayers();
|
|
324 |
mSignature = new ObjectSignature(numLayers[0],mPosition);
|
|
325 |
}
|
|
326 |
return mSignature;
|
|
327 |
}
|
|
328 |
|
|
329 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
330 |
|
|
331 |
public String getObjectName()
|
|
332 |
{
|
|
333 |
return OBJECT_NAME_MEGAMINX;
|
|
334 |
}
|
|
335 |
|
|
336 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
337 |
|
|
338 |
public String getInventor()
|
|
339 |
{
|
|
340 |
return "??";
|
|
341 |
}
|
|
342 |
|
|
343 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
344 |
|
|
345 |
public int getYearOfInvention()
|
|
346 |
{
|
|
347 |
return 0;
|
|
348 |
}
|
|
349 |
|
|
350 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
351 |
|
|
352 |
public int getComplexity()
|
|
353 |
{
|
|
354 |
return 4;
|
|
355 |
}
|
|
356 |
|
|
357 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
358 |
|
|
359 |
public String[][] getTutorials()
|
|
360 |
{
|
|
361 |
return null;
|
|
362 |
}
|
|
363 |
}
|
progress with TwistyBandagedMegaminx.