Revision 60cc43cc
Added by Leszek Koltunski 10 months ago
src/main/java/org/distorted/objectlib/objects/TwistyBandagedMegaminx.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import static org.distorted.objectlib.objects.TwistyMegaminx.MEGA_D; |
13 | 13 |
|
14 |
import org.distorted.library.effect.EffectName; |
|
15 | 14 |
import org.distorted.library.main.DistortedLibrary; |
16 | 15 |
import org.distorted.library.type.Static3D; |
17 | 16 |
import org.distorted.library.type.Static4D; |
... | ... | |
34 | 33 |
public static final int MEGAMINX5 = 5; |
35 | 34 |
|
36 | 35 |
public static final String OBJECT_NAME_MEGAMINX = "LOCAL_MEGAMINX"; |
37 |
public static final char MARKER = 'm'; // keep lowercase
|
|
36 |
public static final char MARKER = 'm'; // keep lowercase |
|
38 | 37 |
|
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; |
|
38 |
private static final Static4D QUAT = new Static4D(0,0,0,1); |
|
43 | 39 |
|
44 |
private static final int NUM_TYPES = 2; // OCT_1 and TET_1 |
|
40 |
private static final int KILO_CENT = 0; |
|
41 |
private static final int MEGA_CENT = 1; |
|
42 |
private static final int CORNER = 2; |
|
43 |
private static final int KILO_EDGE1= 3; |
|
44 |
private static final int KILO_EDGE2= 4; |
|
45 |
private static final int MEGA_EDGE1= 5; |
|
46 |
private static final int MEGA_EDGE2= 6; |
|
47 |
private static final int OTHER = 7; |
|
48 |
|
|
49 |
private static final int NUM_TYPES = 7; |
|
45 | 50 |
|
46 | 51 |
private int[] mCubitVariantMap; |
47 | 52 |
private int[] mTypeVariantMap; |
48 | 53 |
private ObjectShape[] mTmpShapes; |
49 |
private int mNumVariants; |
|
54 |
private int mNumVariants, mNumStandardVariants; |
|
55 |
private int[] mCorrectedNumLayers; |
|
50 | 56 |
private float[][] mPosition; |
51 | 57 |
private float[][] mOrigPosition; // again problem with the (2,3,4,5) numLayersFormat vs the (3,3,5,5) format: |
52 | 58 |
// for FactoryBandagedMegaminx we have to keep the original, 'uncorrected' positions; |
... | ... | |
111 | 117 |
return mPosition; |
112 | 118 |
} |
113 | 119 |
|
114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
115 |
// TODO |
|
116 |
|
|
117 |
private int getType(float[] pos, int numLayers) |
|
118 |
{ |
|
119 |
return OTHER; |
|
120 |
} |
|
121 |
|
|
122 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
123 | 121 |
// numLayers that we get here from BandagedObjectMegaminx are in the format (3,3,5,5) - i.e. one |
124 | 122 |
// that agrees with the format in the previous TwistyKilominx/TwistyMegaminx classes (and in |
... | ... | |
138 | 136 |
return null; |
139 | 137 |
} |
140 | 138 |
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
private int getType(int variant) |
|
144 |
{ |
|
145 |
for(int t=0; t<NUM_TYPES; t++) |
|
146 |
if( mTypeVariantMap[t]==variant ) return t; |
|
147 |
|
|
148 |
return -1; |
|
149 |
} |
|
150 |
|
|
151 | 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
152 | 140 |
|
153 | 141 |
private void produceTmpShape(int variant) |
... | ... | |
179 | 167 |
} |
180 | 168 |
} |
181 | 169 |
|
182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
183 |
|
|
184 |
private float[][] getVertices(int variant) |
|
185 |
{ |
|
186 |
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants]; |
|
187 |
if( mTmpShapes[variant]==null ) produceTmpShape(variant); |
|
188 |
return mTmpShapes[variant].getVertices(); |
|
189 |
} |
|
190 |
|
|
191 | 170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
192 | 171 |
// PUBLIC API |
193 | 172 |
|
... | ... | |
232 | 211 |
|
233 | 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
234 | 213 |
|
235 |
public ObjectFaceShape getObjectFaceShape(int variant)
|
|
214 |
public Static4D getCubitQuats(int cubit, int[] numLayers)
|
|
236 | 215 |
{ |
237 |
int type = getType(variant); |
|
238 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance(); |
|
239 |
|
|
240 |
if( type>=0 ) |
|
241 |
{ |
|
242 |
int param = getInitData().getParam(); |
|
243 |
int[] numLayers = correctNumLayers(param); |
|
216 |
float[] pos = mOrigPosition[cubit]; |
|
217 |
return pos.length>3 ? QUAT : FactoryBandagedMegaminx.getInstance().getCubitQuat(pos[0],pos[1],pos[2]); |
|
218 |
} |
|
244 | 219 |
|
245 |
if( numLayers!=null ) |
|
246 |
{ |
|
247 |
boolean iconMode = isInIconMode(); |
|
248 |
float[][] bands = factory.getBands(iconMode,numLayers); |
|
220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
221 |
/* |
|
222 |
private int getType(int variant) |
|
223 |
{ |
|
224 |
for(int t=0; t<NUM_TYPES; t++) |
|
225 |
if( mTypeVariantMap[t]==variant ) return t; |
|
249 | 226 |
|
250 |
int numFaces = type==TET_1 ? 4 : 8; // TODO |
|
227 |
return -1; |
|
228 |
} |
|
251 | 229 |
|
252 |
int[] bandIndices = new int[numFaces]; |
|
253 |
for(int i = 0; i<numFaces; i++) bandIndices[i] = 1; |
|
254 |
return new ObjectFaceShape(bands, bandIndices, null); |
|
255 |
} |
|
256 |
} |
|
230 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
257 | 231 |
|
258 |
return factory.createIrregularFaceShape(variant, isInIconMode() ); |
|
232 |
private float[][] getVertices(int variant) |
|
233 |
{ |
|
234 |
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants]; |
|
235 |
if( mTmpShapes[variant]==null ) produceTmpShape(variant); |
|
236 |
return mTmpShapes[variant].getVertices(); |
|
259 | 237 |
} |
260 |
|
|
238 |
*/ |
|
261 | 239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
262 | 240 |
|
263 | 241 |
public ObjectVertexEffects getVertexEffects(int variant) |
... | ... | |
265 | 243 |
int[] numLayers = getNumLayers(); |
266 | 244 |
int size = numLayers[0]; |
267 | 245 |
boolean round = (DistortedLibrary.fastCompilationTF() && size<5 && !isInIconMode()); |
246 |
/* |
|
268 | 247 |
int type = getType(variant); |
269 | 248 |
|
270 | 249 |
if( type>=0 ) |
... | ... | |
292 | 271 |
|
293 | 272 |
return new ObjectVertexEffects(names,variables,vertices,regions,uses); |
294 | 273 |
} |
295 |
|
|
274 |
*/ |
|
296 | 275 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance(); |
297 | 276 |
return factory.createVertexEffects(variant,round); |
298 | 277 |
} |
299 | 278 |
|
300 | 279 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
280 |
/* |
|
281 |
private int[] createBandIndices(int type) |
|
282 |
{ |
|
283 |
int[] bandIndices = null; |
|
301 | 284 |
|
302 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
|
285 |
switch(type) |
|
286 |
{ |
|
287 |
case MEGA_CENT : bandIndices = new int[] {1,0,0,0,0,0}; |
|
288 |
break; |
|
289 |
case KILO_EDGE1: |
|
290 |
case KILO_EDGE2: |
|
291 |
case MEGA_EDGE1: |
|
292 |
case MEGA_EDGE2: bandIndices = new int[] {1,1,0,0,0,0}; |
|
293 |
break; |
|
294 |
case KILO_CENT : |
|
295 |
case CORNER : bandIndices = new int[] {1,1,1,0,0,0}; |
|
296 |
break; |
|
297 |
} |
|
298 |
|
|
299 |
return new int[] {0,0,0,0,0,0};//bandIndices; |
|
300 |
} |
|
301 |
*/ |
|
302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
303 |
|
|
304 |
public ObjectFaceShape getObjectFaceShape(int variant) |
|
305 |
{ |
|
306 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance(); |
|
307 |
/* |
|
308 |
int type = getType(variant); |
|
309 |
|
|
310 |
if( type>=0 ) |
|
311 |
{ |
|
312 |
int param = getInitData().getParam(); |
|
313 |
int[] numLayers = correctNumLayers(param); |
|
314 |
|
|
315 |
if( numLayers!=null ) |
|
316 |
{ |
|
317 |
boolean iconMode = isInIconMode(); |
|
318 |
float[][] bands = factory.getBands(iconMode,numLayers); |
|
319 |
int[] bandIndices = createBandIndices(type); |
|
320 |
return new ObjectFaceShape(bands, bandIndices, null); |
|
321 |
} |
|
322 |
} |
|
323 |
*/ |
|
324 |
return factory.createIrregularFaceShape(variant, isInIconMode() ); |
|
325 |
} |
|
326 |
|
|
327 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
328 |
|
|
329 |
private int translateVariant(int size, int variant) |
|
303 | 330 |
{ |
304 |
return new Static4D(0,0,0,1); |
|
331 |
switch(size) |
|
332 |
{ |
|
333 |
case 2: return KILO_CENT; |
|
334 |
case 3: return variant==0 ? CORNER : variant==1 ? MEGA_EDGE1 : MEGA_CENT; |
|
335 |
case 4: switch(variant) |
|
336 |
{ |
|
337 |
case 0: return CORNER; |
|
338 |
case 1: return KILO_EDGE1; |
|
339 |
case 2: return KILO_EDGE2; |
|
340 |
default: return KILO_CENT; |
|
341 |
} |
|
342 |
case 5: switch(variant) |
|
343 |
{ |
|
344 |
case 0: return CORNER; |
|
345 |
case 1: return MEGA_EDGE1; |
|
346 |
case 2: return MEGA_EDGE2; |
|
347 |
default: return MEGA_CENT; |
|
348 |
} |
|
349 |
} |
|
350 |
|
|
351 |
return -1; |
|
305 | 352 |
} |
306 | 353 |
|
307 | 354 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
308 |
// TODO |
|
309 | 355 |
|
310 | 356 |
public int getNumCubitVariants(int[] numLayers) |
311 | 357 |
{ |
312 | 358 |
if( mNumVariants==0 ) |
313 | 359 |
{ |
314 | 360 |
int param = getInitData().getParam(); |
315 |
int[] numL= correctNumLayers(param);
|
|
316 |
int size = numL!=null ? numL[0] : -1;
|
|
361 |
if( mCorrectedNumLayers==null ) mCorrectedNumLayers = correctNumLayers(param);
|
|
362 |
int size = mCorrectedNumLayers==null ? -1 : mCorrectedNumLayers[0];
|
|
317 | 363 |
float[][] positions = getPositions(); |
364 |
boolean T0=false; |
|
318 | 365 |
boolean T1=false; |
319 |
boolean O1=false; |
|
366 |
boolean T2=false; |
|
367 |
boolean T3=false; |
|
368 |
boolean T4=false; |
|
369 |
boolean T5=false; |
|
370 |
boolean T6=false; |
|
371 |
|
|
372 |
float corr=1.0f; |
|
373 |
if( size==2 ) corr=2.0f/3; |
|
374 |
else if( size==4 ) corr=4.0f/5; |
|
320 | 375 |
|
376 |
int numSpecial = 0; |
|
321 | 377 |
int numCubits = positions.length; |
322 | 378 |
mCubitVariantMap = new int[numCubits]; |
323 | 379 |
|
324 | 380 |
mTypeVariantMap = new int[NUM_TYPES]; |
325 | 381 |
for(int i=0; i<NUM_TYPES; i++) mTypeVariantMap[i] = -1; |
326 | 382 |
|
383 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance(); |
|
384 |
|
|
327 | 385 |
for (int cubit=0; cubit<numCubits; cubit++) |
328 | 386 |
{ |
329 |
int type = getType(positions[cubit],size); |
|
387 |
int type = OTHER; |
|
388 |
float[] pos = positions[cubit]; |
|
389 |
|
|
390 |
if( pos.length==3 ) |
|
391 |
{ |
|
392 |
int variant = factory.getElementVariant(mCorrectedNumLayers, corr*pos[0], corr*pos[1], corr*pos[2]); |
|
393 |
type = translateVariant(size, variant); |
|
394 |
} |
|
330 | 395 |
|
331 | 396 |
switch (type) |
332 | 397 |
{ |
333 |
case TET_1: if (!T1) { T1 = true; mTypeVariantMap[TET_1]=mNumVariants++; } |
|
334 |
mCubitVariantMap[cubit] = mTypeVariantMap[TET_1]; |
|
335 |
break; |
|
336 |
case OCT_1: if (!O1) { O1 = true; mTypeVariantMap[OCT_1]=mNumVariants++; } |
|
337 |
mCubitVariantMap[cubit] = mTypeVariantMap[OCT_1]; |
|
338 |
break; |
|
339 |
default : mCubitVariantMap[cubit] = mNumVariants++; |
|
398 |
case KILO_CENT : if (!T0) { T0 = true; mTypeVariantMap[type]=mNumStandardVariants++; } |
|
399 |
mCubitVariantMap[cubit] = mTypeVariantMap[type]; |
|
400 |
break; |
|
401 |
case MEGA_CENT : if (!T1) { T1 = true; mTypeVariantMap[type]=mNumStandardVariants++; } |
|
402 |
mCubitVariantMap[cubit] = mTypeVariantMap[type]; |
|
403 |
break; |
|
404 |
case CORNER : if (!T2) { T2 = true; mTypeVariantMap[type]=mNumStandardVariants++; } |
|
405 |
mCubitVariantMap[cubit] = mTypeVariantMap[type]; |
|
406 |
break; |
|
407 |
case KILO_EDGE1: if (!T3) { T3 = true; mTypeVariantMap[type]=mNumStandardVariants++; } |
|
408 |
mCubitVariantMap[cubit] = mTypeVariantMap[type]; |
|
409 |
break; |
|
410 |
case KILO_EDGE2: if (!T4) { T4 = true; mTypeVariantMap[type]=mNumStandardVariants++; } |
|
411 |
mCubitVariantMap[cubit] = mTypeVariantMap[type]; |
|
412 |
break; |
|
413 |
case MEGA_EDGE1: if (!T5) { T5 = true; mTypeVariantMap[type]=mNumStandardVariants++; } |
|
414 |
mCubitVariantMap[cubit] = mTypeVariantMap[type]; |
|
415 |
break; |
|
416 |
case MEGA_EDGE2: if (!T6) { T6 = true; mTypeVariantMap[type]=mNumStandardVariants++; } |
|
417 |
mCubitVariantMap[cubit] = mTypeVariantMap[type]; |
|
418 |
break; |
|
419 |
default : numSpecial++; |
|
420 |
mCubitVariantMap[cubit] = -numSpecial; |
|
340 | 421 |
} |
341 | 422 |
} |
342 | 423 |
|
343 |
FactoryBandagedMegaminx factory = FactoryBandagedMegaminx.getInstance(); |
|
344 |
factory.prepare(mNumVariants,numL); |
|
424 |
mNumVariants = mNumStandardVariants + numSpecial; |
|
425 |
|
|
426 |
android.util.Log.e("D", "numStandard="+mNumStandardVariants+" numSpecial: "+numSpecial+" numTotal: "+mNumVariants); |
|
427 |
|
|
428 |
numSpecial = mNumStandardVariants; |
|
429 |
|
|
430 |
for (int cubit=0; cubit<numCubits; cubit++) |
|
431 |
if( mCubitVariantMap[cubit]<0 ) |
|
432 |
mCubitVariantMap[cubit] = numSpecial++; |
|
433 |
|
|
434 |
factory.prepare(mNumVariants,mCorrectedNumLayers); |
|
345 | 435 |
} |
346 | 436 |
|
347 | 437 |
return mNumVariants; |
Also available in: Unified diff
progress with TwistyBandagedMegaminx.