Revision e4bf4d02
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/objects/FactoryCubit.java | ||
---|---|---|
776 | 776 |
float[] bands0 = computeBands(0.04f,34, X1,0.2f,5); |
777 | 777 |
float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2); |
778 | 778 |
|
779 |
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
|
|
779 |
meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0);
|
|
780 | 780 |
meshes[0].setEffectAssociation(0, 1,0); |
781 | 781 |
meshes[1] = meshes[0].copy(true); |
782 | 782 |
meshes[1].setEffectAssociation(0, 2,0); |
783 |
meshes[2] = new MeshPolygon(vertices1, bands1, 1, 4);
|
|
783 |
meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
|
|
784 | 784 |
meshes[2].setEffectAssociation(0, 4,0); |
785 | 785 |
meshes[3] = meshes[2].copy(true); |
786 | 786 |
meshes[3].setEffectAssociation(0, 8,0); |
787 |
meshes[4] = new MeshPolygon(vertices2, bands1, 1, 4);
|
|
787 |
meshes[4] = new MeshPolygon(vertices2, bands1, 0, 0);
|
|
788 | 788 |
meshes[4].setEffectAssociation(0,16,0); |
789 | 789 |
meshes[5] = meshes[4].copy(true); |
790 | 790 |
meshes[5].setEffectAssociation(0,32,0); |
... | ... | |
792 | 792 |
return new MeshJoined(meshes); |
793 | 793 |
} |
794 | 794 |
|
795 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
796 |
|
|
797 |
MeshBase createFacesMegaminxCenter(float width) |
|
798 |
{ |
|
799 |
MeshBase[] meshes = new MeshPolygon[2]; |
|
800 |
|
|
801 |
float R = width/(2*COS54); |
|
802 |
|
|
803 |
float X1 = width/2; |
|
804 |
float Y1 = R*SIN54; |
|
805 |
float X2 = R*COS18; |
|
806 |
float Y2 = R*SIN18; |
|
807 |
|
|
808 |
float[] vertices0 = { -X1,+Y1, -X2,-Y2, 0.0f,-R, +X2,-Y2, +X1,+Y1 }; |
|
809 |
float[] bands0 = computeBands(+0.04f,45, R/3,0.2f,4); |
|
810 |
float[] bands1 = computeBands( 0.00f,34, R/3,0.2f,2); |
|
811 |
|
|
812 |
meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0); |
|
813 |
meshes[0].setEffectAssociation(0,1,0); |
|
814 |
meshes[1] = new MeshPolygon(vertices0, bands1, 0, 0); |
|
815 |
meshes[1].setEffectAssociation(0,2,0); |
|
816 |
|
|
817 |
return new MeshJoined(meshes); |
|
818 |
} |
|
819 |
|
|
795 | 820 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
796 | 821 |
// EFFECTS |
797 | 822 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1451 | 1476 |
return effect; |
1452 | 1477 |
} |
1453 | 1478 |
|
1479 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1480 |
|
|
1481 |
VertexEffect[] createVertexEffectsMegaminxCenter() |
|
1482 |
{ |
|
1483 |
VertexEffect[] effect = new VertexEffect[1]; |
|
1484 |
|
|
1485 |
Static1D angle = new Static1D(DIHEDRAL2); |
|
1486 |
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f); |
|
1487 |
Static3D center= new Static3D( 0, 0, 0); |
|
1488 |
|
|
1489 |
effect[0] = new VertexEffectRotate(angle, axisX, center); |
|
1490 |
|
|
1491 |
return effect; |
|
1492 |
} |
|
1493 |
|
|
1454 | 1494 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1455 | 1495 |
// OBJECTS |
1456 | 1496 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1875 | 1915 |
|
1876 | 1916 |
mesh.mergeEffComponents(); |
1877 | 1917 |
|
1918 |
return mesh; |
|
1919 |
} |
|
1920 |
|
|
1921 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1922 |
|
|
1923 |
MeshBase createMegaminxCenterMesh(float width) |
|
1924 |
{ |
|
1925 |
MeshBase mesh = createFacesMegaminxCenter(width); |
|
1926 |
VertexEffect[] effects = createVertexEffectsMegaminxCenter(); |
|
1927 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1928 |
|
|
1929 |
mesh.mergeEffComponents(); |
|
1930 |
mesh.addEmptyTexComponent(); |
|
1931 |
mesh.addEmptyTexComponent(); |
|
1932 |
mesh.addEmptyTexComponent(); |
|
1933 |
mesh.addEmptyTexComponent(); |
|
1934 |
|
|
1878 | 1935 |
return mesh; |
1879 | 1936 |
} |
1880 | 1937 |
} |
src/main/java/org/distorted/objects/TwistyMegaminx.java | ||
---|---|---|
40 | 40 |
|
41 | 41 |
public class TwistyMegaminx extends TwistyMinx |
42 | 42 |
{ |
43 |
static final float MEGA_D = 0.05f;
|
|
43 |
static final float MEGA_D = 0.04f;
|
|
44 | 44 |
|
45 | 45 |
private static final int NUM_CORNERS = 20; |
46 | 46 |
private static final int NUM_CENTERS = 12; |
... | ... | |
102 | 102 |
{ 3, 15, 3, 5}, |
103 | 103 |
}; |
104 | 104 |
|
105 |
|
|
106 |
private static final int[] QUAT_EDGE_INDICES = |
|
107 |
{ |
|
108 |
56, 40, 43, 59, 0, 55, 10, 17, 25, 49, |
|
109 |
48, 57, 18, 7, 53, 32, 20, 11, 31, 38, |
|
110 |
37, 30, 8, 28, 36, 44, 1, 46, 12, 14 |
|
111 |
}; |
|
112 |
|
|
113 |
private static final int[] QUAT_CENTER_INDICES = |
|
114 |
{ |
|
115 |
16, 18, 22, 1, 20, 13, 14, 15, 0, 12, 2, 3 |
|
116 |
}; |
|
117 |
|
|
105 | 118 |
private static final float[][] mCenterCoords = new float[NUM_CENTERS][3]; |
106 | 119 |
|
107 | 120 |
static |
... | ... | |
175 | 188 |
|
176 | 189 |
int getNumStickerTypes(int numLayers) |
177 | 190 |
{ |
178 |
return numLayers-1; //numLayers;
|
|
191 |
return (numLayers+3)/2;
|
|
179 | 192 |
} |
180 | 193 |
|
181 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
203 | 216 |
|
204 | 217 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
205 | 218 |
|
206 |
private void computeCenter(Static3D[] array, int center)
|
|
219 |
private void computeCenter(Static3D pos, int center, int numLayers)
|
|
207 | 220 |
{ |
208 | 221 |
float[] coords = mCenterCoords[center]; |
209 |
array[center].set( coords[0], coords[1], coords[2]); |
|
222 |
float A = numLayers/3.0f; |
|
223 |
|
|
224 |
pos.set( A*coords[0], A*coords[1], A*coords[2] ); |
|
210 | 225 |
} |
211 | 226 |
|
212 | 227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
298 | 313 |
{ |
299 | 314 |
int numCubitsPerCorner = numCubitsPerCorner(numLayers); |
300 | 315 |
int numCubitsPerEdge = numCubitsPerEdge(numLayers); |
301 |
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge;// + NUM_CENTERS;
|
|
316 |
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS; |
|
302 | 317 |
int index=0; |
303 | 318 |
|
304 | 319 |
final Static3D[] CENTERS = new Static3D[numCubits]; |
... | ... | |
322 | 337 |
computeEdge(CENTERS[index], numLayers, edge, part ); |
323 | 338 |
} |
324 | 339 |
} |
325 |
/* |
|
340 |
|
|
326 | 341 |
for(int center=0; center<NUM_CENTERS; center++, index++) |
327 | 342 |
{ |
328 |
computeCenter(CENTERS,index); |
|
343 |
CENTERS[index] = new Static3D(0,0,0); |
|
344 |
computeCenter(CENTERS[index], center, numLayers); |
|
329 | 345 |
} |
330 |
*/ |
|
346 |
|
|
331 | 347 |
return CENTERS; |
332 | 348 |
} |
333 | 349 |
|
334 | 350 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
335 | 351 |
|
336 |
private int getQuat(int cubit, int numLayers)
|
|
352 |
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
|
337 | 353 |
{ |
338 |
int numCubitsPerCorner = numCubitsPerCorner(numLayers); |
|
339 |
|
|
340 | 354 |
if( cubit < NUM_CORNERS*numCubitsPerCorner ) |
341 | 355 |
{ |
342 | 356 |
int corner = cubit/numCubitsPerCorner; |
343 | 357 |
return QUAT_CORNER_INDICES[corner]; |
344 | 358 |
} |
345 | 359 |
|
346 |
int numCubitsPerEdge = numCubitsPerEdge(numLayers); |
|
347 |
|
|
348 | 360 |
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge ) |
349 | 361 |
{ |
350 | 362 |
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge; |
351 | 363 |
return QUAT_EDGE_INDICES[edge]; |
352 | 364 |
} |
353 | 365 |
|
354 |
/* |
|
355 |
else |
|
356 |
{ |
|
357 |
// TODO: centers |
|
358 |
} |
|
359 |
*/ |
|
360 |
|
|
361 |
return 0; |
|
366 |
int center = cubit - NUM_CORNERS*numCubitsPerCorner - NUM_EDGES*numCubitsPerEdge; |
|
367 |
return QUAT_CENTER_INDICES[center]; |
|
362 | 368 |
} |
363 | 369 |
|
364 | 370 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
374 | 380 |
|
375 | 381 |
if( mCornerMeshes==null ) mCornerMeshes = new MeshBase[variants]; |
376 | 382 |
if( mEdgeMeshes ==null ) mEdgeMeshes = new MeshBase[variants][(sizes[variants-1]-1)/2]; |
383 |
if( mCenterMeshes==null ) mCenterMeshes = new MeshBase[variants]; |
|
377 | 384 |
|
378 | 385 |
if( cubit < NUM_CORNERS*numCubitsPerCorner ) |
379 | 386 |
{ |
... | ... | |
383 | 390 |
} |
384 | 391 |
mesh = mCornerMeshes[index].copy(true); |
385 | 392 |
} |
386 |
else //if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
|
|
393 |
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge ) |
|
387 | 394 |
{ |
388 | 395 |
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge); |
389 | 396 |
|
... | ... | |
397 | 404 |
|
398 | 405 |
mesh = mEdgeMeshes[index][type].copy(true); |
399 | 406 |
} |
400 |
/* |
|
401 | 407 |
else |
402 | 408 |
{ |
403 |
// TODO: centers |
|
409 |
if( mCenterMeshes[index]==null ) |
|
410 |
{ |
|
411 |
float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18); |
|
412 |
mCenterMeshes[index] = FactoryCubit.getInstance().createMegaminxCenterMesh(width); |
|
413 |
} |
|
414 |
|
|
415 |
mesh = mCenterMeshes[index].copy(true); |
|
404 | 416 |
} |
405 |
*/ |
|
406 |
Static4D q = QUATS[getQuat(cubit,numLayers)];
|
|
417 |
|
|
418 |
Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)];
|
|
407 | 419 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( q, new Static3D(0,0,0) ); |
408 | 420 |
mesh.apply(quat,0xffffffff,0); |
409 | 421 |
|
... | ... | |
454 | 466 |
|
455 | 467 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
456 | 468 |
|
457 |
int getEdgeColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner, int numCubitsPerEdge)
|
|
469 |
int getEdgeColor(int edge, int cubitface, int numCubitsPerEdge)
|
|
458 | 470 |
{ |
459 | 471 |
if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES; |
460 | 472 |
|
461 |
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
|
|
462 |
int edge = (cubit - NUM_CORNERS*numCubitsPerCorner) / numCubitsPerEdge;
|
|
473 |
int part = edge % numCubitsPerEdge;
|
|
474 |
int variant = edge / numCubitsPerEdge;
|
|
463 | 475 |
|
464 |
if( part==0 ) |
|
465 |
{ |
|
466 |
return mEdgeMap[edge][cubitface+2]; |
|
467 |
} |
|
468 |
|
|
469 |
return cubitface==((part+1)%2) ? mEdgeMap[edge][cubitface+2] : NUM_TEXTURES; |
|
476 |
return (part==0 || cubitface==((part+1)%2)) ? mEdgeMap[variant][cubitface+2] + (part+1)*NUM_FACES : NUM_TEXTURES; |
|
470 | 477 |
} |
471 | 478 |
|
472 | 479 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
473 |
// TODO |
|
474 | 480 |
|
475 |
int getCenterColor(int cubit, int cubitface, int numLayers)
|
|
481 |
int getCenterColor(int center, int cubitface, int numLayers)
|
|
476 | 482 |
{ |
477 |
return 0;
|
|
483 |
return cubitface>0 ? NUM_TEXTURES : center + NUM_FACES*(numLayers+1)/2;
|
|
478 | 484 |
} |
479 | 485 |
|
480 | 486 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
490 | 496 |
} |
491 | 497 |
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge ) |
492 | 498 |
{ |
493 |
return getEdgeColor(cubit,cubitface,numLayers,numCubitsPerCorner,numCubitsPerEdge); |
|
499 |
int edge = cubit - NUM_CORNERS*numCubitsPerCorner; |
|
500 |
return getEdgeColor(edge,cubitface,numCubitsPerEdge); |
|
494 | 501 |
} |
495 | 502 |
else |
496 | 503 |
{ |
497 |
return getCenterColor(cubit,cubitface,numLayers); |
|
504 |
int center = cubit-NUM_CORNERS*numCubitsPerCorner-NUM_EDGES*numCubitsPerEdge; |
|
505 |
return getCenterColor( center, cubitface, numLayers); |
|
498 | 506 |
} |
499 | 507 |
} |
500 | 508 |
|
src/main/java/org/distorted/objects/TwistyMinx.java | ||
---|---|---|
192 | 192 |
{ 6, 2, 3 }, |
193 | 193 |
}; |
194 | 194 |
|
195 |
static final int[] QUAT_CORNER_INDICES |
|
196 |
= {
|
|
195 |
static final int[] QUAT_CORNER_INDICES =
|
|
196 |
{
|
|
197 | 197 |
0, 2, 3, 1, 40, 31, 41, 30, 39, 35, |
198 | 198 |
36, 34, 56, 32, 43, 21, 48, 28, 42, 23 |
199 | 199 |
}; |
200 | 200 |
|
201 |
static final int[] QUAT_EDGE_INDICES |
|
202 |
= { |
|
203 |
56, 40, 43, 59, 0, 55, 10, 17, 25, 49, |
|
204 |
48, 57, 18, 7, 53, 32, 20, 11, 31, 38, |
|
205 |
37, 30, 8, 28, 36, 44, 1, 46, 12, 14 |
|
206 |
}; |
|
207 |
|
|
208 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
209 | 202 |
|
210 | 203 |
TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh, |
Also available in: Unified diff
Progress with Megaminx.