Revision 3e605536
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objects/TwistyDiamond.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.content.res.Resources; |
23 | 23 |
|
24 |
import org.distorted.helpers.FactoryCubit; |
|
25 | 24 |
import org.distorted.helpers.ObjectShape; |
26 | 25 |
import org.distorted.helpers.ObjectSticker; |
27 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
28 | 26 |
import org.distorted.library.main.DistortedEffects; |
29 | 27 |
import org.distorted.library.main.DistortedTexture; |
30 |
import org.distorted.library.mesh.MeshBase; |
|
31 | 28 |
import org.distorted.library.mesh.MeshSquare; |
32 | 29 |
import org.distorted.library.type.Static3D; |
33 | 30 |
import org.distorted.library.type.Static4D; |
... | ... | |
377 | 374 |
return -1; |
378 | 375 |
} |
379 | 376 |
|
380 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
381 |
|
|
382 |
private Static4D getQuat(int cubit, int numLayers) |
|
383 |
{ |
|
384 |
int numO = getNumOctahedrons(numLayers); |
|
385 |
|
|
386 |
if( cubit<numO ) return QUATS[0]; |
|
387 |
|
|
388 |
switch( retFaceTetraBelongsTo(cubit-numO, numLayers) ) |
|
389 |
{ |
|
390 |
case 0: return QUATS[0]; // unit quat |
|
391 |
case 1: return new Static4D(0,-SQ2/2,0,SQ2/2); // 90 along Y |
|
392 |
case 2: return QUATS[1]; // 180 along Y |
|
393 |
case 3: return new Static4D(0,+SQ2/2,0,SQ2/2); // 90 along |
|
394 |
case 4: return new Static4D(0, 0,1, 0); // 180 along Z |
|
395 |
case 5: return new Static4D(SQ2/2, 0,SQ2/2,0); // |
|
396 |
case 6: return new Static4D( 1,0,0, 0); // 180 along X |
|
397 |
case 7: return new Static4D(-SQ2/2,0,SQ2/2,0); // |
|
398 |
} |
|
399 |
|
|
400 |
return null; |
|
401 |
} |
|
402 |
|
|
403 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
404 |
|
|
405 |
private int getNumCubitVariants(int numLayers) |
|
406 |
{ |
|
407 |
return 2; |
|
408 |
} |
|
409 |
|
|
410 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
411 |
|
|
412 |
int getCubitVariant(int cubit, int numLayers) |
|
413 |
{ |
|
414 |
return cubit<getNumOctahedrons(numLayers) ? 0 : 1; |
|
415 |
} |
|
416 |
|
|
417 | 377 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
418 | 378 |
|
419 | 379 |
ObjectShape getObjectShape(int cubit, int numLayers) |
420 | 380 |
{ |
421 | 381 |
int variant = getCubitVariant(cubit,numLayers); |
422 | 382 |
int N = numLayers>3 ? 5:6; |
423 |
int E = numLayers>3 ? 1:2;
|
|
383 |
int E = numLayers>3 ? 0:2;
|
|
424 | 384 |
|
425 | 385 |
if( variant==0 ) |
426 | 386 |
{ |
... | ... | |
446 | 406 |
|
447 | 407 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
448 | 408 |
|
449 |
MeshBase createCubitMesh(int cubit, int numLayers)
|
|
409 |
Static4D getQuat(int cubit, int numLayers)
|
|
450 | 410 |
{ |
451 |
int variant = getCubitVariant(cubit,numLayers);
|
|
411 |
int numO = getNumOctahedrons(numLayers);
|
|
452 | 412 |
|
453 |
if( mMeshes==null ) |
|
454 |
{ |
|
455 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
456 |
factory.clear(); |
|
457 |
mMeshes = new MeshBase[getNumCubitVariants(numLayers)]; |
|
458 |
} |
|
413 |
if( cubit<numO ) return QUATS[0]; |
|
459 | 414 |
|
460 |
if( mMeshes[variant]==null )
|
|
415 |
switch( retFaceTetraBelongsTo(cubit-numO, numLayers) )
|
|
461 | 416 |
{ |
462 |
ObjectShape shape = getObjectShape(cubit,numLayers); |
|
463 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
464 |
factory.createNewFaceTransform(shape); |
|
465 |
mMeshes[variant] = factory.createRoundedSolid(shape); |
|
417 |
case 0: return QUATS[0]; // unit quat |
|
418 |
case 1: return new Static4D(0,-SQ2/2,0,SQ2/2); // 90 along Y |
|
419 |
case 2: return QUATS[1]; // 180 along Y |
|
420 |
case 3: return new Static4D(0,+SQ2/2,0,SQ2/2); // 90 along |
|
421 |
case 4: return new Static4D(0, 0,1, 0); // 180 along Z |
|
422 |
case 5: return new Static4D(SQ2/2, 0,SQ2/2,0); // |
|
423 |
case 6: return new Static4D( 1,0,0, 0); // 180 along X |
|
424 |
case 7: return new Static4D(-SQ2/2,0,SQ2/2,0); // |
|
466 | 425 |
} |
467 | 426 |
|
468 |
MeshBase mesh = mMeshes[variant].copy(true); |
|
469 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) ); |
|
470 |
mesh.apply(quat,0xffffffff,0); |
|
427 |
return null; |
|
428 |
} |
|
429 |
|
|
430 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
471 | 431 |
|
472 |
return mesh; |
|
432 |
int getNumCubitVariants(int numLayers) |
|
433 |
{ |
|
434 |
return 2; |
|
435 |
} |
|
436 |
|
|
437 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
438 |
|
|
439 |
int getCubitVariant(int cubit, int numLayers) |
|
440 |
{ |
|
441 |
return cubit<getNumOctahedrons(numLayers) ? 0 : 1; |
|
473 | 442 |
} |
474 | 443 |
|
475 | 444 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Finally remove cubit creation from the implementation classes and move it to the TwistyObject.