Revision be56193c
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/objects/TwistyRex.java | ||
---|---|---|
26 | 26 |
import org.distorted.helpers.FactoryCubit; |
27 | 27 |
import org.distorted.helpers.FactorySticker; |
28 | 28 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
29 |
import org.distorted.library.effect.VertexEffect; |
|
30 |
import org.distorted.library.effect.VertexEffectMove; |
|
31 |
import org.distorted.library.effect.VertexEffectRotate; |
|
32 |
import org.distorted.library.effect.VertexEffectScale; |
|
29 | 33 |
import org.distorted.library.main.DistortedEffects; |
30 | 34 |
import org.distorted.library.main.DistortedTexture; |
31 | 35 |
import org.distorted.library.mesh.MeshBase; |
36 |
import org.distorted.library.mesh.MeshJoined; |
|
37 |
import org.distorted.library.mesh.MeshPolygon; |
|
32 | 38 |
import org.distorted.library.mesh.MeshSquare; |
39 |
import org.distorted.library.type.Static1D; |
|
33 | 40 |
import org.distorted.library.type.Static3D; |
34 | 41 |
import org.distorted.library.type.Static4D; |
35 | 42 |
import org.distorted.main.R; |
36 | 43 |
|
37 | 44 |
import java.util.Random; |
38 | 45 |
|
39 |
import static org.distorted.helpers.FactoryCubit.REX_D; |
|
40 |
|
|
41 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 47 |
|
43 | 48 |
public class TwistyRex extends TwistyObject |
44 | 49 |
{ |
45 | 50 |
private static final int FACES_PER_CUBIT =6; |
46 | 51 |
|
52 |
public static final float REX_D = 0.2f; |
|
53 |
|
|
47 | 54 |
// the four rotation axis of a RubikRex. Must be normalized. |
48 | 55 |
static final Static3D[] ROT_AXIS = new Static3D[] |
49 | 56 |
{ |
... | ... | |
299 | 306 |
return QUATS[0]; |
300 | 307 |
} |
301 | 308 |
|
309 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
310 |
|
|
311 |
MeshBase createFacesRexCorner() |
|
312 |
{ |
|
313 |
MeshBase[] meshes = new MeshBase[2]; |
|
314 |
|
|
315 |
float F = REX_D*SQ2; |
|
316 |
float G = (1-REX_D)*SQ2/2; |
|
317 |
float H = 0.1f; |
|
318 |
float J = +2*G/3 - H*G; |
|
319 |
|
|
320 |
float[] vertices = { -F/2, -G/3, +F/2, -G/3, H*F/2, J, -H*F/2, J}; |
|
321 |
|
|
322 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
323 |
float[] bands0 = factory.computeBands(+0.016f,10,G/3,0.5f,5); |
|
324 |
float[] bands1 = factory.computeBands(-0.230f,45,G/3,0.0f,2); |
|
325 |
|
|
326 |
meshes[0] = new MeshPolygon(vertices,bands0,1,1); |
|
327 |
meshes[0].setEffectAssociation(0,1,0); |
|
328 |
meshes[1] = new MeshPolygon(vertices,bands1,0,0); |
|
329 |
meshes[1].setEffectAssociation(0,2,0); |
|
330 |
|
|
331 |
return new MeshJoined(meshes); |
|
332 |
} |
|
333 |
|
|
334 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
335 |
|
|
336 |
MeshBase createFacesRexFace() |
|
337 |
{ |
|
338 |
MeshBase[] meshes = new MeshBase[2]; |
|
339 |
|
|
340 |
float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D}; |
|
341 |
|
|
342 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
343 |
float[] bands0 = factory.computeBands(0.016f,10,REX_D/2,0.5f,5); |
|
344 |
float[] bands1 = factory.computeBands(0.000f,45,REX_D/2,0.0f,2); |
|
345 |
|
|
346 |
meshes[0] = new MeshPolygon(vertices,bands0,0,0); |
|
347 |
meshes[0].setEffectAssociation(0,1,0); |
|
348 |
meshes[1] = new MeshPolygon(vertices,bands1,0,0); |
|
349 |
meshes[1].setEffectAssociation(0,2,0); |
|
350 |
|
|
351 |
return new MeshJoined(meshes); |
|
352 |
} |
|
353 |
|
|
354 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
355 |
|
|
356 |
MeshBase createFacesRexEdge() |
|
357 |
{ |
|
358 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
359 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
360 |
|
|
361 |
float E = 0.5f - REX_D; |
|
362 |
float F = 0.5f; |
|
363 |
float[] vertices0 = { -F,E/3, 0,-2*E/3, +F,E/3 }; |
|
364 |
float[] bands0 = factory.computeBands(0.03f,27,F/3,0.8f,5); |
|
365 |
|
|
366 |
meshes[0] = new MeshPolygon(vertices0, bands0, 2, 3); |
|
367 |
meshes[0].setEffectAssociation(0,1,0); |
|
368 |
meshes[1] = meshes[0].copy(true); |
|
369 |
meshes[1].setEffectAssociation(0,2,0); |
|
370 |
|
|
371 |
float G = (float)Math.sqrt(E*E+F*F); |
|
372 |
float[] vertices1 = { -2*G/3, -E/3, G/3, -E/3, G/3, 2*E/3 }; |
|
373 |
float[] bands1 = factory.computeBands(0.00f,45,G/3,0.2f,3); |
|
374 |
|
|
375 |
meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2); |
|
376 |
meshes[2].setEffectAssociation(0,4,0); |
|
377 |
meshes[3] = meshes[2].copy(true); |
|
378 |
meshes[3].setEffectAssociation(0,8,0); |
|
379 |
meshes[4] = meshes[2].copy(true); |
|
380 |
meshes[4].setEffectAssociation(0,16,0); |
|
381 |
meshes[5] = meshes[2].copy(true); |
|
382 |
meshes[5].setEffectAssociation(0,32,0); |
|
383 |
|
|
384 |
return new MeshJoined(meshes); |
|
385 |
} |
|
386 |
|
|
387 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
388 |
|
|
389 |
private VertexEffect[] createVertexEffectsRexEdge() |
|
390 |
{ |
|
391 |
float E = 0.5f - REX_D; |
|
392 |
float F = 0.5f; |
|
393 |
float G = (float)Math.sqrt(E*E+F*F); |
|
394 |
float A = (float)((180/Math.PI)*Math.asin(E/G)); |
|
395 |
|
|
396 |
Static3D move1 = new Static3D( 0.0f, -E/3, 0.0f); |
|
397 |
Static3D move2 = new Static3D(2*G/3 -F, +E/3, 0.0f); |
|
398 |
|
|
399 |
Static3D center0= new Static3D(0.0f, 0.0f, 0.0f); |
|
400 |
Static3D center1= new Static3D( -F, 0.0f, 0.0f); |
|
401 |
Static3D center2= new Static3D( +F, 0.0f, 0.0f); |
|
402 |
Static3D axisX = new Static3D(1.0f, 0.0f, 0.0f); |
|
403 |
Static3D axisY = new Static3D(0.0f, 1.0f, 0.0f); |
|
404 |
Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f); |
|
405 |
|
|
406 |
Static1D angle180 = new Static1D(180); |
|
407 |
Static1D angle90 = new Static1D( 90); |
|
408 |
Static1D angle270 = new Static1D(270); |
|
409 |
Static1D angle1 = new Static1D(+A); |
|
410 |
Static1D angle2 = new Static1D(-A); |
|
411 |
|
|
412 |
VertexEffect[] effect = new VertexEffect[12]; |
|
413 |
|
|
414 |
effect[0] = new VertexEffectMove(move1); |
|
415 |
effect[1] = new VertexEffectMove(move2); |
|
416 |
effect[2] = new VertexEffectRotate( angle90, axisX, center0 ); |
|
417 |
effect[3] = new VertexEffectRotate( angle270, axisX, center0 ); |
|
418 |
effect[4] = new VertexEffectRotate( angle180, axisX, center0 ); |
|
419 |
effect[5] = new VertexEffectRotate( angle180, axisY, center0 ); |
|
420 |
effect[6] = new VertexEffectScale( new Static3D(-1, 1, 1) ); |
|
421 |
effect[7] = new VertexEffectScale ( new Static3D( 1,-1, 1) ); |
|
422 |
effect[8] = new VertexEffectRotate( angle1, axisY, center1); |
|
423 |
effect[9] = new VertexEffectRotate( angle2, axisY, center2); |
|
424 |
effect[10]= new VertexEffectRotate( angle2, axisZ, center1); |
|
425 |
effect[11]= new VertexEffectRotate( angle1, axisZ, center2); |
|
426 |
|
|
427 |
effect[0].setMeshAssociation( 3,-1); // meshes 0 & 1 |
|
428 |
effect[1].setMeshAssociation(60,-1); // meshes 2,3,4,5 |
|
429 |
effect[2].setMeshAssociation( 2,-1); // meshes 1 |
|
430 |
effect[3].setMeshAssociation(12,-1); // meshes 2,3 |
|
431 |
effect[4].setMeshAssociation(48,-1); // meshes 4,5 |
|
432 |
effect[5].setMeshAssociation(32,-1); // mesh 5 |
|
433 |
effect[6].setMeshAssociation( 8,-1); // apply to mesh 3 |
|
434 |
effect[7].setMeshAssociation( 2,-1); // apply to mesh 1 |
|
435 |
effect[8].setMeshAssociation(16,-1); // apply to mesh 4 |
|
436 |
effect[9].setMeshAssociation(32,-1); // apply to mesh 5 |
|
437 |
effect[10].setMeshAssociation(4,-1); // apply to mesh 2 |
|
438 |
effect[11].setMeshAssociation(8,-1); // apply to mesh 3 |
|
439 |
|
|
440 |
return effect; |
|
441 |
} |
|
442 |
|
|
443 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
444 |
|
|
445 |
private VertexEffect[] createVertexEffectsRexCorner() |
|
446 |
{ |
|
447 |
Static3D center= new Static3D(0.0f, 0.0f, 0.0f); |
|
448 |
Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f); |
|
449 |
Static1D angle = new Static1D(225); |
|
450 |
|
|
451 |
VertexEffect[] effect = new VertexEffect[1]; |
|
452 |
effect[0] = new VertexEffectRotate(angle, axisZ, center); |
|
453 |
|
|
454 |
return effect; |
|
455 |
} |
|
456 |
|
|
457 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
458 |
|
|
459 |
private MeshBase createRexCornerMesh() |
|
460 |
{ |
|
461 |
MeshBase mesh = createFacesRexCorner(); |
|
462 |
VertexEffect[] effects = createVertexEffectsRexCorner(); |
|
463 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
464 |
|
|
465 |
final float G = (1-REX_D)/3; |
|
466 |
Static3D center = new Static3D(0.0f,0.0f,-G*SQ2/2); |
|
467 |
Static3D[] vertices = new Static3D[1]; |
|
468 |
vertices[0] = new Static3D(+G,-G,+0.0f); |
|
469 |
FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.10f,0.10f); |
|
470 |
|
|
471 |
mesh.mergeEffComponents(); |
|
472 |
mesh.addEmptyTexComponent(); |
|
473 |
mesh.addEmptyTexComponent(); |
|
474 |
mesh.addEmptyTexComponent(); |
|
475 |
mesh.addEmptyTexComponent(); |
|
476 |
|
|
477 |
return mesh; |
|
478 |
} |
|
479 |
|
|
480 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
481 |
|
|
482 |
private MeshBase createRexFaceMesh() |
|
483 |
{ |
|
484 |
MeshBase mesh = createFacesRexFace(); |
|
485 |
|
|
486 |
mesh.mergeEffComponents(); |
|
487 |
mesh.addEmptyTexComponent(); |
|
488 |
mesh.addEmptyTexComponent(); |
|
489 |
mesh.addEmptyTexComponent(); |
|
490 |
mesh.addEmptyTexComponent(); |
|
491 |
|
|
492 |
return mesh; |
|
493 |
} |
|
494 |
|
|
495 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
496 |
|
|
497 |
private MeshBase createRexEdgeMesh() |
|
498 |
{ |
|
499 |
MeshBase mesh = createFacesRexEdge(); |
|
500 |
VertexEffect[] effects = createVertexEffectsRexEdge(); |
|
501 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
502 |
|
|
503 |
Static3D center = new Static3D(0.0f,-0.5f,-0.5f); |
|
504 |
Static3D[] vertices = new Static3D[2]; |
|
505 |
vertices[0] = new Static3D(+0.5f,+0.0f,+0.0f); |
|
506 |
vertices[1] = new Static3D(-0.5f,+0.0f,+0.0f); |
|
507 |
FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.06f,0.10f); |
|
508 |
|
|
509 |
mesh.mergeEffComponents(); |
|
510 |
|
|
511 |
return mesh; |
|
512 |
} |
|
513 |
|
|
302 | 514 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
303 | 515 |
|
304 | 516 |
MeshBase createCubitMesh(int cubit, int numLayers) |
... | ... | |
307 | 519 |
|
308 | 520 |
if( cubit<24 ) |
309 | 521 |
{ |
310 |
if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createRexCornerMesh();
|
|
522 |
if( mCornerMesh==null ) mCornerMesh = createRexCornerMesh(); |
|
311 | 523 |
mesh = mCornerMesh.copy(true); |
312 | 524 |
} |
313 | 525 |
else if( cubit<30 ) |
314 | 526 |
{ |
315 |
if( mFaceMesh==null ) mFaceMesh = FactoryCubit.getInstance().createRexFaceMesh();
|
|
527 |
if( mFaceMesh==null ) mFaceMesh = createRexFaceMesh(); |
|
316 | 528 |
mesh = mFaceMesh.copy(true); |
317 | 529 |
} |
318 | 530 |
else |
319 | 531 |
{ |
320 |
if( mEdgeMesh==null ) mEdgeMesh = FactoryCubit.getInstance().createRexEdgeMesh();
|
|
532 |
if( mEdgeMesh==null ) mEdgeMesh = createRexEdgeMesh(); |
|
321 | 533 |
mesh = mEdgeMesh.copy(true); |
322 | 534 |
} |
323 | 535 |
|
Also available in: Unified diff
Move all the special cubit-creating code out of FactoryCubit and to the Object classes, and thus hopefully finish implementing the new cubit creating engine.