Revision dfdb26a9
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/objects/TwistyCube.java | ||
---|---|---|
71 | 71 |
super(numL, numL[0], quat, move, texture, mesh, effects, res, scrWidth); |
72 | 72 |
} |
73 | 73 |
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
private int[] createEdges(int size, int vertex) |
|
77 |
{ |
|
78 |
int[] ret = new int[9*size]; |
|
79 |
|
|
80 |
for(int l=0; l<size; l++) |
|
81 |
{ |
|
82 |
ret[9*l ] = l; |
|
83 |
ret[9*l+1] =-1; |
|
84 |
ret[9*l+2] = vertex; |
|
85 |
ret[9*l+3] = l; |
|
86 |
ret[9*l+4] = 1; |
|
87 |
ret[9*l+5] = vertex; |
|
88 |
ret[9*l+6] = l; |
|
89 |
ret[9*l+7] = 2; |
|
90 |
ret[9*l+8] = vertex; |
|
91 |
} |
|
92 |
|
|
93 |
return ret; |
|
94 |
} |
|
95 |
|
|
74 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
75 | 97 |
|
76 | 98 |
protected ScrambleState[] getScrambleStates() |
... | ... | |
106 | 128 |
} |
107 | 129 |
|
108 | 130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
131 |
// TODO |
|
109 | 132 |
|
110 | 133 |
protected int getResource(int[] numLayers) |
111 | 134 |
{ |
... | ... | |
120 | 143 |
return 0; |
121 | 144 |
} |
122 | 145 |
|
123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 |
|
|
125 |
private int[] createEdges(int size, int vertex) |
|
126 |
{ |
|
127 |
int[] ret = new int[9*size]; |
|
128 |
|
|
129 |
for(int l=0; l<size; l++) |
|
130 |
{ |
|
131 |
ret[9*l ] = l; |
|
132 |
ret[9*l+1] =-1; |
|
133 |
ret[9*l+2] = vertex; |
|
134 |
ret[9*l+3] = l; |
|
135 |
ret[9*l+4] = 1; |
|
136 |
ret[9*l+5] = vertex; |
|
137 |
ret[9*l+6] = l; |
|
138 |
ret[9*l+7] = 2; |
|
139 |
ret[9*l+8] = vertex; |
|
140 |
} |
|
141 |
|
|
142 |
return ret; |
|
143 |
} |
|
144 |
|
|
145 | 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
146 | 147 |
|
147 | 148 |
private void initializeQuats() |
... | ... | |
186 | 187 |
return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status], mQuats); |
187 | 188 |
} |
188 | 189 |
|
189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
190 |
|
|
191 |
private int getNumCornersAndEdges(int numLayers) |
|
192 |
{ |
|
193 |
return numLayers==1 ? 1 : 12*(numLayers-2) + 8; |
|
194 |
} |
|
195 |
|
|
196 | 190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
197 | 191 |
|
198 | 192 |
protected ObjectShape getObjectShape(int cubit, int[] numLayers) |
... | ... | |
266 | 260 |
} |
267 | 261 |
} |
268 | 262 |
|
263 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
264 |
|
|
265 |
private int getCenterNum(int cubit, int[] numLayers) |
|
266 |
{ |
|
267 |
int num = cubit - getNumCornersAndEdges(numLayers); |
|
268 |
|
|
269 |
if( num>=0 ) |
|
270 |
{ |
|
271 |
int numLR = (numLayers[1]-2)*(numLayers[2]-2); |
|
272 |
if( num< numLR ) return 0; |
|
273 |
if( num<2*numLR ) return 1; |
|
274 |
num -= 2*numLR; |
|
275 |
|
|
276 |
int numTD = (numLayers[0]-2)*(numLayers[2]-2); |
|
277 |
if( num< numTD ) return 2; |
|
278 |
if( num<2*numTD ) return 3; |
|
279 |
num -= 2*numTD; |
|
280 |
|
|
281 |
int numFB = (numLayers[0]-2)*(numLayers[1]-2); |
|
282 |
if( num< numFB ) return 4; |
|
283 |
if( num<2*numFB ) return 5; |
|
284 |
} |
|
285 |
|
|
286 |
return -1; |
|
287 |
} |
|
288 |
|
|
289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
290 |
|
|
291 |
private int getNumCornersAndEdges(int[] numLayers) |
|
292 |
{ |
|
293 |
int x = numLayers[0]; |
|
294 |
int y = numLayers[1]; |
|
295 |
int z = numLayers[2]; |
|
296 |
|
|
297 |
return ( x==1 || y==1 || z==1 ) ? x*y*z : 4*( (x-2)+(y-2)+(z-2) ) + 8; |
|
298 |
} |
|
299 |
|
|
269 | 300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
270 | 301 |
|
271 | 302 |
protected float[][] getCubitPositions(int[] numLayers) |
272 | 303 |
{ |
273 |
int numL = numLayers[0]; |
|
304 |
final int X = numLayers[0]; |
|
305 |
final int Y = numLayers[1]; |
|
306 |
final int Z = numLayers[2]; |
|
307 |
|
|
308 |
final float lenX = 0.5f*(X-1); |
|
309 |
final float lenY = 0.5f*(Y-1); |
|
310 |
final float lenZ = 0.5f*(Z-1); |
|
274 | 311 |
|
275 |
if( numL==1 ) return new float[][] {{ 0.0f, 0.0f, 0.0f }}; |
|
312 |
if( X==1 || Y==1 || Z==1 ) |
|
313 |
{ |
|
314 |
int numCubits = X*Y*Z; |
|
315 |
float[][] tmp = new float[numCubits][]; |
|
316 |
|
|
317 |
// TODO ... |
|
318 |
} |
|
276 | 319 |
|
277 |
int numCubits = getNumCornersAndEdges(numL) + 6*(numL-2)*(numL-2);
|
|
320 |
int numCubits = X*Y*Z - (X-2)*(Y-2)*(Z-2);
|
|
278 | 321 |
float[][] tmp = new float[numCubits][]; |
279 | 322 |
|
280 |
final float LEN = 0.5f*(numL-1); |
|
281 | 323 |
int currentPosition = 0; |
282 | 324 |
|
283 |
tmp[currentPosition++] = new float[] {-LEN,-LEN,-LEN};
|
|
284 |
tmp[currentPosition++] = new float[] {-LEN,-LEN,+LEN};
|
|
285 |
tmp[currentPosition++] = new float[] {-LEN,+LEN,-LEN};
|
|
286 |
tmp[currentPosition++] = new float[] {-LEN,+LEN,+LEN};
|
|
287 |
tmp[currentPosition++] = new float[] {+LEN,-LEN,-LEN};
|
|
288 |
tmp[currentPosition++] = new float[] {+LEN,-LEN,+LEN};
|
|
289 |
tmp[currentPosition++] = new float[] {+LEN,+LEN,-LEN};
|
|
290 |
tmp[currentPosition++] = new float[] {+LEN,+LEN,+LEN};
|
|
291 |
|
|
292 |
for(int i=1; i<numL-1; i++)
|
|
293 |
tmp[currentPosition++] = new float[] { i-LEN, -LEN, -LEN };
|
|
294 |
for(int i=1; i<numL-1; i++)
|
|
295 |
tmp[currentPosition++] = new float[] { i-LEN, -LEN, +LEN };
|
|
296 |
for(int i=1; i<numL-1; i++)
|
|
297 |
tmp[currentPosition++] = new float[] { i-LEN, +LEN, -LEN };
|
|
298 |
for(int i=1; i<numL-1; i++)
|
|
299 |
tmp[currentPosition++] = new float[] { i-LEN, +LEN, +LEN };
|
|
300 |
for(int i=1; i<numL-1; i++)
|
|
301 |
tmp[currentPosition++] = new float[] { -LEN, i-LEN, -LEN };
|
|
302 |
for(int i=1; i<numL-1; i++)
|
|
303 |
tmp[currentPosition++] = new float[] { -LEN, i-LEN, +LEN };
|
|
304 |
for(int i=1; i<numL-1; i++)
|
|
305 |
tmp[currentPosition++] = new float[] { +LEN, i-LEN, -LEN };
|
|
306 |
for(int i=1; i<numL-1; i++)
|
|
307 |
tmp[currentPosition++] = new float[] { +LEN, i-LEN, +LEN };
|
|
308 |
for(int i=1; i<numL-1; i++)
|
|
309 |
tmp[currentPosition++] = new float[] { -LEN, -LEN, i-LEN };
|
|
310 |
for(int i=1; i<numL-1; i++)
|
|
311 |
tmp[currentPosition++] = new float[] { -LEN, +LEN, i-LEN };
|
|
312 |
for(int i=1; i<numL-1; i++)
|
|
313 |
tmp[currentPosition++] = new float[] { +LEN, -LEN, i-LEN };
|
|
314 |
for(int i=1; i<numL-1; i++)
|
|
315 |
tmp[currentPosition++] = new float[] { +LEN, +LEN, i-LEN };
|
|
316 |
|
|
317 |
for(int y=1; y<numL-1; y++)
|
|
318 |
for(int z=1; z<numL-1; z++)
|
|
319 |
tmp[currentPosition++] = new float[] {+LEN,y-LEN,z-LEN};
|
|
320 |
|
|
321 |
for(int y=1; y<numL-1; y++)
|
|
322 |
for(int z=1; z<numL-1; z++)
|
|
323 |
tmp[currentPosition++] = new float[] {-LEN,y-LEN,z-LEN};
|
|
324 |
|
|
325 |
for(int x=1; x<numL-1; x++)
|
|
326 |
for(int z=1; z<numL-1; z++)
|
|
327 |
tmp[currentPosition++] = new float[] {x-LEN,+LEN,z-LEN};
|
|
328 |
|
|
329 |
for(int x=1; x<numL-1; x++)
|
|
330 |
for(int z=1; z<numL-1; z++)
|
|
331 |
tmp[currentPosition++] = new float[] {x-LEN,-LEN,z-LEN};
|
|
332 |
|
|
333 |
for(int x=1; x<numL-1; x++)
|
|
334 |
for(int y=1; y<numL-1; y++)
|
|
335 |
tmp[currentPosition++] = new float[] {x-LEN,y-LEN,+LEN};
|
|
336 |
|
|
337 |
for(int x=1; x<numL-1; x++)
|
|
338 |
for(int y=1; y<numL-1; y++)
|
|
339 |
tmp[currentPosition++] = new float[] {x-LEN,y-LEN,-LEN};
|
|
325 |
tmp[currentPosition++] = new float[] {-lenX,-lenY,-lenZ};
|
|
326 |
tmp[currentPosition++] = new float[] {-lenX,-lenY,+lenZ};
|
|
327 |
tmp[currentPosition++] = new float[] {-lenX,+lenY,-lenZ};
|
|
328 |
tmp[currentPosition++] = new float[] {-lenX,+lenY,+lenZ};
|
|
329 |
tmp[currentPosition++] = new float[] {+lenX,-lenY,-lenZ};
|
|
330 |
tmp[currentPosition++] = new float[] {+lenX,-lenY,+lenZ};
|
|
331 |
tmp[currentPosition++] = new float[] {+lenX,+lenY,-lenZ};
|
|
332 |
tmp[currentPosition++] = new float[] {+lenX,+lenY,+lenZ};
|
|
333 |
|
|
334 |
for(int i=1; i<X-1; i++)
|
|
335 |
tmp[currentPosition++] = new float[] { i-lenX, -lenY, -lenZ };
|
|
336 |
for(int i=1; i<X-1; i++)
|
|
337 |
tmp[currentPosition++] = new float[] { i-lenX, -lenY, +lenZ };
|
|
338 |
for(int i=1; i<X-1; i++)
|
|
339 |
tmp[currentPosition++] = new float[] { i-lenX, +lenY, -lenZ };
|
|
340 |
for(int i=1; i<X-1; i++)
|
|
341 |
tmp[currentPosition++] = new float[] { i-lenX, +lenY, +lenZ };
|
|
342 |
for(int i=1; i<Y-1; i++)
|
|
343 |
tmp[currentPosition++] = new float[] { -lenX, i-lenY, -lenZ };
|
|
344 |
for(int i=1; i<Y-1; i++)
|
|
345 |
tmp[currentPosition++] = new float[] { -lenX, i-lenY, +lenZ };
|
|
346 |
for(int i=1; i<Y-1; i++)
|
|
347 |
tmp[currentPosition++] = new float[] { +lenX, i-lenY, -lenZ };
|
|
348 |
for(int i=1; i<Y-1; i++)
|
|
349 |
tmp[currentPosition++] = new float[] { +lenX, i-lenY, +lenZ };
|
|
350 |
for(int i=1; i<Z-1; i++)
|
|
351 |
tmp[currentPosition++] = new float[] { -lenX, -lenY, i-lenZ };
|
|
352 |
for(int i=1; i<Z-1; i++)
|
|
353 |
tmp[currentPosition++] = new float[] { -lenX, +lenY, i-lenZ };
|
|
354 |
for(int i=1; i<Z-1; i++)
|
|
355 |
tmp[currentPosition++] = new float[] { +lenX, -lenY, i-lenZ };
|
|
356 |
for(int i=1; i<Z-1; i++)
|
|
357 |
tmp[currentPosition++] = new float[] { +lenX, +lenY, i-lenZ };
|
|
358 |
|
|
359 |
for(int y=1; y<Y-1; y++)
|
|
360 |
for(int z=1; z<Z-1; z++)
|
|
361 |
tmp[currentPosition++] = new float[] {+lenX,y-lenY,z-lenZ};
|
|
362 |
|
|
363 |
for(int y=1; y<Y-1; y++)
|
|
364 |
for(int z=1; z<Z-1; z++)
|
|
365 |
tmp[currentPosition++] = new float[] {-lenX,y-lenY,z-lenZ};
|
|
366 |
|
|
367 |
for(int x=1; x<X-1; x++)
|
|
368 |
for(int z=1; z<Z-1; z++)
|
|
369 |
tmp[currentPosition++] = new float[] {x-lenX,+lenY,z-lenZ};
|
|
370 |
|
|
371 |
for(int x=1; x<X-1; x++)
|
|
372 |
for(int z=1; z<Z-1; z++)
|
|
373 |
tmp[currentPosition++] = new float[] {x-lenX,-lenY,z-lenZ};
|
|
374 |
|
|
375 |
for(int x=1; x<X-1; x++)
|
|
376 |
for(int y=1; y<Y-1; y++)
|
|
377 |
tmp[currentPosition++] = new float[] {x-lenX,y-lenY,+lenZ};
|
|
378 |
|
|
379 |
for(int x=1; x<X-1; x++)
|
|
380 |
for(int y=1; y<Y-1; y++)
|
|
381 |
tmp[currentPosition++] = new float[] {x-lenX,y-lenY,-lenZ};
|
|
340 | 382 |
|
341 | 383 |
return tmp; |
342 | 384 |
} |
... | ... | |
347 | 389 |
{ |
348 | 390 |
if( mQuats ==null ) initializeQuats(); |
349 | 391 |
|
350 |
int numL = numLayers[0]; |
|
351 |
int num = cubit - getNumCornersAndEdges(numL); |
|
392 |
int centerNum = getCenterNum(cubit,numLayers); |
|
352 | 393 |
|
353 |
if( num>=0 )
|
|
394 |
switch(centerNum)
|
|
354 | 395 |
{ |
355 |
int face = num/((numL-2)*(numL-2)); |
|
356 |
|
|
357 |
switch(face) |
|
358 |
{ |
|
359 |
case 0: return mQuats[13]; |
|
360 |
case 1: return mQuats[12]; |
|
361 |
case 2: return mQuats[ 8]; |
|
362 |
case 3: return mQuats[ 9]; |
|
363 |
case 4: return mQuats[ 0]; |
|
364 |
case 5: return mQuats[ 1]; |
|
365 |
} |
|
396 |
case 0 : return mQuats[13]; |
|
397 |
case 1 : return mQuats[12]; |
|
398 |
case 2 : return mQuats[ 8]; |
|
399 |
case 3 : return mQuats[ 9]; |
|
400 |
case 4 : return mQuats[ 0]; |
|
401 |
case 5 : return mQuats[ 1]; |
|
402 |
default: return mQuats[ 0]; |
|
366 | 403 |
} |
367 |
|
|
368 |
return mQuats[0]; |
|
369 | 404 |
} |
370 | 405 |
|
371 | 406 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
379 | 414 |
|
380 | 415 |
protected int getCubitVariant(int cubit, int[] numLayers) |
381 | 416 |
{ |
382 |
return cubit < getNumCornersAndEdges(numLayers[0]) ? 0 : 1;
|
|
417 |
return cubit < getNumCornersAndEdges(numLayers) ? 0 : 1; |
|
383 | 418 |
} |
384 | 419 |
|
385 | 420 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
386 | 421 |
|
387 | 422 |
protected int getFaceColor(int cubit, int cubitface, int[] numLayers) |
388 | 423 |
{ |
389 |
int numL = numLayers[0]; |
|
390 |
int cornersAndEdges = getNumCornersAndEdges(numL); |
|
424 |
int centerNum = getCenterNum(cubit,numLayers); |
|
391 | 425 |
|
392 |
if( cubit<cornersAndEdges )
|
|
426 |
if( centerNum<0 )
|
|
393 | 427 |
{ |
394 |
return CUBITS[cubit].getRotRow(cubitface/2) == (cubitface%2==0 ? (1<<(numL-1)):1) ? cubitface : NUM_TEXTURES; |
|
428 |
int axis = cubitface/2; |
|
429 |
return CUBITS[cubit].getRotRow(axis) == (cubitface%2==0 ? (1<<(numLayers[axis]-1)):1) ? cubitface : NUM_TEXTURES; |
|
395 | 430 |
} |
396 | 431 |
else |
397 | 432 |
{ |
398 |
int numCentersPerFace = (numL-2)*(numL-2); |
|
399 |
return cubitface == 4 ? (cubit-cornersAndEdges)/numCentersPerFace : NUM_TEXTURES; |
|
433 |
return cubitface == 4 ? centerNum : NUM_TEXTURES; |
|
400 | 434 |
} |
401 | 435 |
} |
402 | 436 |
|
... | ... | |
443 | 477 |
|
444 | 478 |
protected float[][] getCuts(int[] numLayers) |
445 | 479 |
{ |
446 |
int numL = numLayers[0]; |
|
447 |
if( numL<2 ) return null; |
|
448 |
|
|
449 | 480 |
if( mCuts==null ) |
450 | 481 |
{ |
451 |
mCuts = new float[3][numL-1]; |
|
482 |
mCuts = new float[3][]; |
|
483 |
|
|
484 |
int lenX = numLayers[0]; |
|
485 |
|
|
486 |
if( lenX>=2 ) |
|
487 |
{ |
|
488 |
mCuts[0] = new float[lenX-1]; |
|
489 |
for(int i=0; i<lenX-1; i++) mCuts[0][i] = (2-lenX)*0.5f + i; |
|
490 |
} |
|
491 |
else |
|
492 |
{ |
|
493 |
mCuts[0] = null; |
|
494 |
} |
|
452 | 495 |
|
453 |
for(int i=0; i<numL-1; i++) |
|
496 |
int lenY = numLayers[1]; |
|
497 |
|
|
498 |
if( lenY>=2 ) |
|
499 |
{ |
|
500 |
mCuts[1] = new float[lenY-1]; |
|
501 |
for(int i=0; i<lenY-1; i++) mCuts[1][i] = (2-lenY)*0.5f + i; |
|
502 |
} |
|
503 |
else |
|
504 |
{ |
|
505 |
mCuts[1] = null; |
|
506 |
} |
|
507 |
|
|
508 |
int lenZ = numLayers[2]; |
|
509 |
|
|
510 |
if( lenZ>=2 ) |
|
511 |
{ |
|
512 |
mCuts[2] = new float[lenZ-1]; |
|
513 |
for(int i=0; i<lenZ-1; i++) mCuts[2][i] = (2-lenZ)*0.5f + i; |
|
514 |
} |
|
515 |
else |
|
454 | 516 |
{ |
455 |
float cut = (2-numL)*0.5f + i; |
|
456 |
mCuts[0][i] = cut; |
|
457 |
mCuts[1][i] = cut; |
|
458 |
mCuts[2][i] = cut; |
|
517 |
mCuts[2] = null; |
|
459 | 518 |
} |
460 | 519 |
} |
461 | 520 |
|
... | ... | |
509 | 568 |
} |
510 | 569 |
|
511 | 570 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
571 |
// TODO |
|
512 | 572 |
|
513 | 573 |
public Movement getMovement() |
514 | 574 |
{ |
... | ... | |
526 | 586 |
|
527 | 587 |
public int[] getBasicAngle() |
528 | 588 |
{ |
529 |
if( mBasicAngle==null ) mBasicAngle = new int[] { 4,4,4 }; |
|
589 |
if( mBasicAngle==null ) |
|
590 |
{ |
|
591 |
int[] num = getNumLayers(); |
|
592 |
int x = num[1]==num[2] ? 4 : 2; |
|
593 |
int y = num[0]==num[2] ? 4 : 2; |
|
594 |
int z = num[0]==num[1] ? 4 : 2; |
|
595 |
|
|
596 |
mBasicAngle = new int[] { x,y,z }; |
|
597 |
} |
|
530 | 598 |
return mBasicAngle; |
531 | 599 |
} |
532 | 600 |
|
533 | 601 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
602 |
// TODO |
|
534 | 603 |
|
535 | 604 |
public ObjectType intGetObjectType(int[] numLayers) |
536 | 605 |
{ |
537 | 606 |
switch(numLayers[0]) |
538 | 607 |
{ |
539 |
case 2: return ObjectType.CUBE_2;
|
|
540 |
case 3: return ObjectType.CUBE_3;
|
|
608 |
case 2: return numLayers[1]==2 ? ObjectType.CUBE_2 : ObjectType.CU_223;
|
|
609 |
case 3: return numLayers[1]==3 ? ObjectType.CUBE_3 : ObjectType.CU_334;
|
|
541 | 610 |
case 4: return ObjectType.CUBE_4; |
542 | 611 |
case 5: return ObjectType.CUBE_5; |
543 | 612 |
} |
Also available in: Unified diff
First attempt at cuboids. 2x2x3 and 3x3x4 mostly working :)