Revision f925d455
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/objectlib/objects/TwistyBandagedAbstract.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.objects; |
11 | 11 |
|
12 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID; |
|
13 | 12 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT; |
14 | 13 |
|
15 |
import org.distorted.library.effect.EffectName; |
|
16 |
import org.distorted.library.main.DistortedLibrary; |
|
17 | 14 |
import org.distorted.library.type.Static3D; |
18 | 15 |
import org.distorted.library.type.Static4D; |
19 |
import org.distorted.objectlib.helpers.FactoryBandagedCubit; |
|
20 |
import org.distorted.objectlib.helpers.ObjectFaceShape; |
|
21 | 16 |
import org.distorted.objectlib.helpers.ObjectShape; |
22 | 17 |
import org.distorted.objectlib.helpers.ObjectSignature; |
23 |
import org.distorted.objectlib.helpers.ObjectVertexEffects; |
|
24 | 18 |
import org.distorted.objectlib.main.InitData; |
25 | 19 |
import org.distorted.objectlib.scrambling.ScrambleState; |
26 | 20 |
import org.distorted.objectlib.shape.ShapeHexahedron; |
... | ... | |
32 | 26 |
|
33 | 27 |
public abstract class TwistyBandagedAbstract extends ShapeHexahedron |
34 | 28 |
{ |
35 |
private static final int CUBIT_111 = 0; |
|
36 |
private static final int CUBIT_211 = 1; |
|
37 |
private static final int CUBIT_311 = 2; |
|
38 |
private static final int CUBIT_221 = 3; |
|
39 |
private static final int CUBIT_222 = 4; |
|
40 |
private static final int CUBIT_OTH = 5; |
|
41 |
|
|
42 | 29 |
// the three rotation axis of a 3x3 Cube. Must be normalized. |
43 | 30 |
static final Static3D[] ROT_AXIS = new Static3D[] |
44 | 31 |
{ |
... | ... | |
47 | 34 |
new Static3D(0,0,1) |
48 | 35 |
}; |
49 | 36 |
|
50 |
private static final int[][] mDims = new int[][] |
|
51 |
{ |
|
52 |
{1,1,1}, // has to be X>=Z>=Y so that all |
|
53 |
{2,1,1}, // the faces are horizontal |
|
54 |
{3,1,1}, |
|
55 |
{2,1,2}, |
|
56 |
{2,2,2}, |
|
57 |
}; |
|
58 |
|
|
59 | 37 |
private int[][] mBasicAngle; |
60 |
private Static4D[] mInitQuats; |
|
61 | 38 |
private float[][] mCuts; |
62 |
private int[] mCubitVariantMap; |
|
63 |
private int[] mTypeVariantMap; |
|
64 | 39 |
private int[][] mSolvedQuatsAbstract; |
65 | 40 |
|
66 | 41 |
protected ObjectShape[] mTmpShapes; |
... | ... | |
75 | 50 |
super(data, meshState, iconMode, size, quat, move, scale, stream); |
76 | 51 |
} |
77 | 52 |
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
abstract float[][] getVertices(int variant); |
|
81 |
|
|
82 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 54 |
// return 0 if cubit is 'external' (it has at least two walls which belong to two different faces |
84 | 55 |
// of the cuboid, faces which do not both rotate along the same axis! So: it is an edge, a corner, |
... | ... | |
113 | 84 |
return 0; |
114 | 85 |
} |
115 | 86 |
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
float[][] getPositions() |
|
90 |
{ |
|
91 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
92 |
return mPosition; |
|
93 |
} |
|
94 |
|
|
116 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
117 | 96 |
// If we have a flat cuboid than retCubitSolvedStatus() wrongly reports that the internal cubits |
118 | 97 |
// are edges (they do have two non-black faces after all!) which leads to wrong solvedQuats and |
... | ... | |
203 | 182 |
return 2; |
204 | 183 |
} |
205 | 184 |
|
206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
207 |
|
|
208 |
private int getType(float[] pos) |
|
209 |
{ |
|
210 |
switch(pos.length) |
|
211 |
{ |
|
212 |
case 3: return CUBIT_111; |
|
213 |
case 6: return CUBIT_211; |
|
214 |
case 9: boolean x1 = (pos[0]==pos[3] && pos[0]==pos[6]); |
|
215 |
boolean y1 = (pos[1]==pos[4] && pos[1]==pos[7]); |
|
216 |
boolean z1 = (pos[2]==pos[5] && pos[2]==pos[8]); |
|
217 |
return ( (x1&&y1) || (x1&&z1) || (y1&&z1) ) ? CUBIT_311 : CUBIT_OTH; |
|
218 |
case 12: float x = (pos[0]+pos[3]+pos[6]+pos[ 9])/4; |
|
219 |
float y = (pos[1]+pos[4]+pos[7]+pos[10])/4; |
|
220 |
float z = (pos[2]+pos[5]+pos[8]+pos[11])/4; |
|
221 |
float d1 = (pos[0]-x)*(pos[0]-x) + (pos[ 1]-y)*(pos[ 1]-y) + (pos[ 2]-z)*(pos[ 2]-z); |
|
222 |
float d2 = (pos[3]-x)*(pos[3]-x) + (pos[ 4]-y)*(pos[ 4]-y) + (pos[ 5]-z)*(pos[ 5]-z); |
|
223 |
float d3 = (pos[6]-x)*(pos[6]-x) + (pos[ 7]-y)*(pos[ 7]-y) + (pos[ 8]-z)*(pos[ 8]-z); |
|
224 |
float d4 = (pos[9]-x)*(pos[9]-x) + (pos[10]-y)*(pos[10]-y) + (pos[11]-z)*(pos[11]-z); |
|
225 |
return ( d1==0.5f && d2==0.5f && d3==0.5f && d4==0.5f ) ? CUBIT_221 : CUBIT_OTH; |
|
226 |
case 24: float x3 = pos[0]; |
|
227 |
float y3 = pos[1]; |
|
228 |
float z3 = pos[2]; |
|
229 |
float x4=-10,y4=-10,z4=-10; |
|
230 |
int i; |
|
231 |
|
|
232 |
for(i=0; i<8; i++) |
|
233 |
{ |
|
234 |
if( pos[3*i]!=x3 && pos[3*i+1]!=y3 && pos[3*i+2]!=z3 ) |
|
235 |
{ |
|
236 |
x4 = pos[3*i ]; |
|
237 |
y4 = pos[3*i+1]; |
|
238 |
z4 = pos[3*i+2]; |
|
239 |
break; |
|
240 |
} |
|
241 |
} |
|
242 |
if( i==9 ) return CUBIT_OTH; |
|
243 |
|
|
244 |
float dX = x4-x3; |
|
245 |
float dY = y4-y3; |
|
246 |
float dZ = z4-z3; |
|
247 |
|
|
248 |
if( (dX==1.0f || dX==-1.0f) && (dY==1.0f || dY==-1.0f) && (dZ==1.0f || dZ==-1.0f) ) |
|
249 |
{ |
|
250 |
for(i=0; i<8; i++) |
|
251 |
{ |
|
252 |
if( (pos[3*i ]!=x3 && pos[3*i ]!=x4) || |
|
253 |
(pos[3*i+1]!=y3 && pos[3*i+1]!=y4) || |
|
254 |
(pos[3*i+2]!=z3 && pos[3*i+2]!=z4) ) return CUBIT_OTH; |
|
255 |
} |
|
256 |
|
|
257 |
return CUBIT_222; |
|
258 |
} |
|
259 |
|
|
260 |
default: return CUBIT_OTH; |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
265 |
|
|
266 |
private int getQuatIndex(int cubit) |
|
267 |
{ |
|
268 |
float[][] positions = getPositions(); |
|
269 |
int len = positions.length; |
|
270 |
|
|
271 |
if( cubit>=0 && cubit<len ) |
|
272 |
{ |
|
273 |
float[] pos = positions[cubit]; |
|
274 |
int type = getType(pos); |
|
275 |
|
|
276 |
switch(type) |
|
277 |
{ |
|
278 |
case CUBIT_222: |
|
279 |
case CUBIT_111: return 0; |
|
280 |
case CUBIT_211: |
|
281 |
case CUBIT_311: return (pos[1]==pos[4]) ? (pos[0]==pos[3] ? 2 : 0) : 3; |
|
282 |
case CUBIT_221: if( pos[0]==pos[3] && pos[0]==pos[6] ) return 3; |
|
283 |
if( pos[1]==pos[4] && pos[1]==pos[7] ) return 0; |
|
284 |
if( pos[2]==pos[5] && pos[2]==pos[8] ) return 1; |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
return 0; |
|
289 |
} |
|
290 |
|
|
291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
292 |
|
|
293 |
protected int[] getDim(int variant) |
|
294 |
{ |
|
295 |
int type,numTypes = mDims.length; |
|
296 |
for(type=0; type<numTypes; type++) if( mTypeVariantMap[type]==variant ) break; |
|
297 |
return type<numTypes ? mDims[type] : null; |
|
298 |
} |
|
299 |
|
|
300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
301 |
|
|
302 |
protected void produceTmpShape(int variant) |
|
303 |
{ |
|
304 |
float[][] positions = getPositions(); |
|
305 |
int cubit,numCubits = positions.length; |
|
306 |
|
|
307 |
for(cubit=0; cubit<numCubits; cubit++) |
|
308 |
{ |
|
309 |
if( mCubitVariantMap[cubit]==variant ) break; |
|
310 |
} |
|
311 |
|
|
312 |
if( cubit>=numCubits ) |
|
313 |
{ |
|
314 |
android.util.Log.e("D", "unknown variant: "+variant); |
|
315 |
} |
|
316 |
else |
|
317 |
{ |
|
318 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
319 |
mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]); |
|
320 |
} |
|
321 |
} |
|
322 |
|
|
323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
324 |
|
|
325 |
public ObjectShape getObjectShape(int variant) |
|
326 |
{ |
|
327 |
if( getDim(variant)!=null ) |
|
328 |
{ |
|
329 |
int[][] indices = |
|
330 |
{ |
|
331 |
{2,3,1,0}, |
|
332 |
{7,6,4,5}, |
|
333 |
{4,0,1,5}, |
|
334 |
{7,3,2,6}, |
|
335 |
{6,2,0,4}, |
|
336 |
{3,7,5,1}, |
|
337 |
}; |
|
338 |
|
|
339 |
return new ObjectShape( getVertices(variant), indices); |
|
340 |
} |
|
341 |
|
|
342 |
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants]; |
|
343 |
if( mTmpShapes[variant]==null )produceTmpShape(variant); |
|
344 |
return mTmpShapes[variant]; |
|
345 |
} |
|
346 |
|
|
347 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
348 |
|
|
349 |
public ObjectFaceShape getObjectFaceShape(int variant) |
|
350 |
{ |
|
351 |
int[] numLayers = getNumLayers(); |
|
352 |
int size = (numLayers[0]+numLayers[1]+numLayers[2])/3; |
|
353 |
int[] dim = getDim(variant); |
|
354 |
|
|
355 |
if( dim!=null ) |
|
356 |
{ |
|
357 |
int X = dim[0]; |
|
358 |
int Y = dim[1]; |
|
359 |
int Z = dim[2]; |
|
360 |
|
|
361 |
float height = isInIconMode() ? 0.001f : size<=5 ? 0.048f : 0.020f; |
|
362 |
int[] bandIndices= { 0,0,1,1,2,2 }; |
|
363 |
|
|
364 |
int maxXY = Math.max(X,Y); |
|
365 |
int maxXZ = Math.max(X,Z); |
|
366 |
int maxYZ = Math.max(Y,Z); |
|
367 |
|
|
368 |
int angle = 45; |
|
369 |
float R = 0.25f; |
|
370 |
float S = 0.50f; |
|
371 |
float N = size<=4 ? 5 : size<=5 ? 4 : 3; |
|
372 |
|
|
373 |
float[][] bands = |
|
374 |
{ |
|
375 |
{height/maxYZ,angle,R,S,N,0,0}, |
|
376 |
{height/maxXZ,angle,R,S,N,0,0}, |
|
377 |
{height/maxXY,angle,R,S,N,0,0} |
|
378 |
}; |
|
379 |
|
|
380 |
return new ObjectFaceShape(bands,bandIndices,null); |
|
381 |
} |
|
382 |
|
|
383 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
384 |
return factory.createIrregularFaceShape(variant, isInIconMode() ); |
|
385 |
} |
|
386 |
|
|
387 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
388 |
|
|
389 |
public ObjectVertexEffects getVertexEffects(int variant) |
|
390 |
{ |
|
391 |
int[] numLayers = getNumLayers(); |
|
392 |
int size = (numLayers[0]+numLayers[1]+numLayers[2])/3; |
|
393 |
boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode()); |
|
394 |
|
|
395 |
if( getDim(variant)!=null ) |
|
396 |
{ |
|
397 |
float[][] vertices = getVertices(variant); |
|
398 |
float strength = -0.04f; |
|
399 |
|
|
400 |
float[][] variables = |
|
401 |
{ |
|
402 |
{ 0, strength*vertices[0][0], strength*vertices[0][1], strength*vertices[0][2], 1 }, |
|
403 |
{ 0, strength*vertices[1][0], strength*vertices[1][1], strength*vertices[1][2], 1 }, |
|
404 |
{ 0, strength*vertices[2][0], strength*vertices[2][1], strength*vertices[2][2], 1 }, |
|
405 |
{ 0, strength*vertices[3][0], strength*vertices[3][1], strength*vertices[3][2], 1 }, |
|
406 |
{ 0, strength*vertices[4][0], strength*vertices[4][1], strength*vertices[4][2], 1 }, |
|
407 |
{ 0, strength*vertices[5][0], strength*vertices[5][1], strength*vertices[5][2], 1 }, |
|
408 |
{ 0, strength*vertices[6][0], strength*vertices[6][1], strength*vertices[6][2], 1 }, |
|
409 |
{ 0, strength*vertices[7][0], strength*vertices[7][1], strength*vertices[7][2], 1 }, |
|
410 |
}; |
|
411 |
|
|
412 |
String name = EffectName.DEFORM.name(); |
|
413 |
float[] reg = {0,0,0,0.15f}; |
|
414 |
|
|
415 |
String[] names = {name,name,name,name,name,name,name,name}; |
|
416 |
float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg}; |
|
417 |
boolean[] uses = {round,round,round,round,round,round,round,round}; |
|
418 |
|
|
419 |
return new ObjectVertexEffects(names,variables,vertices,regions,uses); |
|
420 |
} |
|
421 |
|
|
422 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
423 |
return factory.createVertexEffects(variant,round); |
|
424 |
} |
|
425 |
|
|
426 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
427 |
|
|
428 |
public float[][] getCubitPositions(int[] numLayers) |
|
429 |
{ |
|
430 |
return getPositions(); |
|
431 |
} |
|
432 |
|
|
433 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
434 |
|
|
435 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
|
436 |
{ |
|
437 |
if( mInitQuats ==null ) |
|
438 |
{ |
|
439 |
mInitQuats = new Static4D[] |
|
440 |
{ |
|
441 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f), // NULL |
|
442 |
new Static4D( SQ2/2, 0.0f, 0.0f, -SQ2/2), // X |
|
443 |
new Static4D( 0.0f, SQ2/2, 0.0f, -SQ2/2), // Y |
|
444 |
new Static4D( 0.0f, 0.0f, SQ2/2, -SQ2/2), // Z |
|
445 |
new Static4D( -0.5f, +0.5f, -0.5f, +0.5f), // ZX |
|
446 |
new Static4D( +0.5f, +0.5f, +0.5f, -0.5f), // YX |
|
447 |
}; |
|
448 |
} |
|
449 |
|
|
450 |
return mInitQuats[getQuatIndex(cubit)]; |
|
451 |
} |
|
452 |
|
|
453 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
454 |
|
|
455 |
public int getNumCubitVariants(int[] numLayers) |
|
456 |
{ |
|
457 |
if( mNumVariants==0 ) |
|
458 |
{ |
|
459 |
float[][] positions = getPositions(); |
|
460 |
boolean C111=false; |
|
461 |
boolean C211=false; |
|
462 |
boolean C311=false; |
|
463 |
boolean C221=false; |
|
464 |
boolean C222=false; |
|
465 |
|
|
466 |
int numCubits = positions.length; |
|
467 |
mCubitVariantMap = new int[numCubits]; |
|
468 |
|
|
469 |
int numTypes = mDims.length; |
|
470 |
mTypeVariantMap = new int[numTypes]; |
|
471 |
for(int i=0; i<numTypes; i++) mTypeVariantMap[i] = -1; |
|
472 |
|
|
473 |
for (int cubit=0; cubit<numCubits; cubit++) |
|
474 |
{ |
|
475 |
int type = getType(positions[cubit]); |
|
476 |
|
|
477 |
switch (type) |
|
478 |
{ |
|
479 |
case CUBIT_111: if (!C111) { C111 = true; mTypeVariantMap[CUBIT_111]=mNumVariants++; } |
|
480 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_111]; |
|
481 |
break; |
|
482 |
case CUBIT_211: if (!C211) { C211 = true; mTypeVariantMap[CUBIT_211]=mNumVariants++; } |
|
483 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_211]; |
|
484 |
break; |
|
485 |
case CUBIT_311: if (!C311) { C311 = true; mTypeVariantMap[CUBIT_311]=mNumVariants++; } |
|
486 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_311]; |
|
487 |
break; |
|
488 |
case CUBIT_221: if (!C221) { C221 = true; mTypeVariantMap[CUBIT_221]=mNumVariants++; } |
|
489 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_221]; |
|
490 |
break; |
|
491 |
case CUBIT_222: if (!C222) { C222 = true; mTypeVariantMap[CUBIT_222]=mNumVariants++; } |
|
492 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_222]; |
|
493 |
break; |
|
494 |
default : mCubitVariantMap[cubit] = mNumVariants++; |
|
495 |
} |
|
496 |
} |
|
497 |
|
|
498 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
499 |
factory.prepare(mNumVariants,numLayers[0],numLayers[1],numLayers[2]); |
|
500 |
} |
|
501 |
|
|
502 |
return mNumVariants; |
|
503 |
} |
|
504 |
|
|
505 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
506 |
|
|
507 |
public int getCubitVariant(int cubit, int[] numLayers) |
|
508 |
{ |
|
509 |
return mCubitVariantMap[cubit]; |
|
510 |
} |
|
511 |
|
|
512 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
513 | 186 |
|
514 | 187 |
public float[][] getCuts(int[] numLayers) |
... | ... | |
549 | 222 |
return layerRotatable; |
550 | 223 |
} |
551 | 224 |
|
552 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
553 |
|
|
554 |
public int getTouchControlType() |
|
555 |
{ |
|
556 |
return TC_CUBOID; |
|
557 |
} |
|
558 |
|
|
559 | 225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
560 | 226 |
|
561 | 227 |
public int getTouchControlSplit() |
... | ... | |
591 | 257 |
|
592 | 258 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
593 | 259 |
|
594 |
public float getStickerRadius() |
|
595 |
{ |
|
596 |
return 0.10f; |
|
597 |
} |
|
598 |
|
|
599 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
600 |
|
|
601 |
public float getStickerStroke() |
|
260 |
public float[][] getStickerAngles() |
|
602 | 261 |
{ |
603 |
return isInIconMode() ? 0.16f : 0.08f;
|
|
262 |
return null;
|
|
604 | 263 |
} |
605 | 264 |
|
606 | 265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
607 | 266 |
|
608 |
public float[][] getStickerAngles()
|
|
267 |
public float[][] getCubitPositions(int[] numLayers)
|
|
609 | 268 |
{ |
610 |
return null;
|
|
269 |
return getPositions();
|
|
611 | 270 |
} |
612 | 271 |
|
613 | 272 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
614 |
// PUBLIC API |
|
615 | 273 |
|
616 | 274 |
public Static3D[] getRotationAxis() |
617 | 275 |
{ |
... | ... | |
645 | 303 |
|
646 | 304 |
return mBasicAngle; |
647 | 305 |
} |
648 |
|
|
649 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
650 |
|
|
651 |
float[][] getPositions() |
|
652 |
{ |
|
653 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
654 |
return mPosition; |
|
655 |
} |
|
656 | 306 |
} |
Also available in: Unified diff
Progress with the Camouflage 3x3x3.