Revision 31cd7256
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/helpers/FactoryCubit.java | ||
---|---|---|
89 | 89 |
boolean flip; |
90 | 90 |
} |
91 | 91 |
|
92 |
private static final ArrayList<FaceTransform> mFaceTransform = new ArrayList<>(); |
|
92 |
private static final ArrayList<FaceTransform> mNewFaceTransf = new ArrayList<>(); |
|
93 |
private static final ArrayList<FaceTransform> mOldFaceTransf = new ArrayList<>(); |
|
93 | 94 |
private static final ArrayList<StickerCoords> mStickerCoords = new ArrayList<>(); |
94 | 95 |
|
95 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
297 | 298 |
return new MeshJoined(meshes); |
298 | 299 |
} |
299 | 300 |
|
300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
301 |
|
|
302 |
MeshBase createFacesOcta() |
|
303 |
{ |
|
304 |
MeshBase[] meshes = new MeshPolygon[8]; |
|
305 |
|
|
306 |
float E = 0.75f; |
|
307 |
float F = 0.5f; |
|
308 |
float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3}; |
|
309 |
float[] bands = computeBands(0.05f,35,F,0.8f,6); |
|
310 |
|
|
311 |
meshes[0] = new MeshPolygon(vertices, bands, 2,2); |
|
312 |
meshes[0].setEffectAssociation(0,1,0); |
|
313 |
meshes[1] = meshes[0].copy(true); |
|
314 |
meshes[1].setEffectAssociation(0,2,0); |
|
315 |
meshes[2] = meshes[0].copy(true); |
|
316 |
meshes[2].setEffectAssociation(0,4,0); |
|
317 |
meshes[3] = meshes[0].copy(true); |
|
318 |
meshes[3].setEffectAssociation(0,8,0); |
|
319 |
meshes[4] = meshes[0].copy(true); |
|
320 |
meshes[4].setEffectAssociation(0,16,0); |
|
321 |
meshes[5] = meshes[0].copy(true); |
|
322 |
meshes[5].setEffectAssociation(0,32,0); |
|
323 |
meshes[6] = meshes[0].copy(true); |
|
324 |
meshes[6].setEffectAssociation(0,64,0); |
|
325 |
meshes[7] = meshes[0].copy(true); |
|
326 |
meshes[7].setEffectAssociation(0,128,0); |
|
327 |
|
|
328 |
return new MeshJoined(meshes); |
|
329 |
} |
|
330 |
|
|
331 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
332 |
|
|
333 |
MeshBase createFacesTetra() |
|
334 |
{ |
|
335 |
MeshBase[] meshes = new MeshBase[4]; |
|
336 |
|
|
337 |
float E = 0.75f; |
|
338 |
float F = 0.5f; |
|
339 |
float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3}; |
|
340 |
float[] bands = computeBands(0.05f,35,F,0.8f,6); |
|
341 |
|
|
342 |
meshes[0] = new MeshPolygon(vertices, bands, 2,2); |
|
343 |
meshes[0].setEffectAssociation(0,1,0); |
|
344 |
meshes[1] = meshes[0].copy(true); |
|
345 |
meshes[1].setEffectAssociation(0,2,0); |
|
346 |
meshes[2] = meshes[0].copy(true); |
|
347 |
meshes[2].setEffectAssociation(0,4,0); |
|
348 |
meshes[3] = meshes[0].copy(true); |
|
349 |
meshes[3].setEffectAssociation(0,8,0); |
|
350 |
|
|
351 |
return new MeshJoined(meshes); |
|
352 |
} |
|
353 |
|
|
354 | 301 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
355 | 302 |
|
356 | 303 |
MeshBase createFacesDino() |
... | ... | |
971 | 918 |
return effect; |
972 | 919 |
} |
973 | 920 |
|
974 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
975 |
|
|
976 |
VertexEffect[] createVertexEffectsOcta() |
|
977 |
{ |
|
978 |
Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3))); |
|
979 |
Static1D angle1= new Static1D( 90); |
|
980 |
Static1D angle2= new Static1D(180); |
|
981 |
Static1D angle3= new Static1D(270); |
|
982 |
Static3D move1 = new Static3D(0,SQ2/2-SQ3/3,0); |
|
983 |
Static3D axisX = new Static3D(1,0,0); |
|
984 |
Static3D axisY = new Static3D(0,1,0); |
|
985 |
Static3D cent0 = new Static3D(0,0,0); |
|
986 |
Static3D cent1 = new Static3D(0,SQ2/2,0); |
|
987 |
Static3D flipY = new Static3D( 1,-1, 1); |
|
988 |
Static3D scale = new Static3D( 1, 2*SQ3/3, 1); |
|
989 |
|
|
990 |
VertexEffect[] effect = new VertexEffect[7]; |
|
991 |
|
|
992 |
effect[0] = new VertexEffectScale(scale); |
|
993 |
effect[1] = new VertexEffectMove(move1); |
|
994 |
effect[2] = new VertexEffectRotate(alpha , axisX, cent1); |
|
995 |
effect[3] = new VertexEffectRotate(angle1, axisY, cent0); |
|
996 |
effect[4] = new VertexEffectRotate(angle2, axisY, cent0); |
|
997 |
effect[5] = new VertexEffectRotate(angle3, axisY, cent0); |
|
998 |
effect[6] = new VertexEffectScale(flipY); |
|
999 |
|
|
1000 |
effect[3].setMeshAssociation ( 34,-1); // apply to meshes 1 & 5 |
|
1001 |
effect[4].setMeshAssociation ( 68,-1); // apply to meshes 2 & 6 |
|
1002 |
effect[5].setMeshAssociation (136,-1); // apply to meshes 3 & 7 |
|
1003 |
effect[6].setMeshAssociation (240,-1); // apply to meshes 4,5,6,7 |
|
1004 |
|
|
1005 |
return effect; |
|
1006 |
} |
|
1007 |
|
|
1008 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1009 |
|
|
1010 |
VertexEffect[] createVertexEffectsTetra() |
|
1011 |
{ |
|
1012 |
Static3D flipZ = new Static3D( 1, 1,-1); |
|
1013 |
Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3))); |
|
1014 |
Static1D angle1= new Static1D( 90); |
|
1015 |
Static1D angle2= new Static1D(180); |
|
1016 |
Static3D move1 = new Static3D(0,SQ2/4-SQ3/6,0); |
|
1017 |
Static3D axisX = new Static3D(1,0,0); |
|
1018 |
Static3D axisY = new Static3D(0,1,0); |
|
1019 |
Static3D axisZ = new Static3D(0,0,1); |
|
1020 |
Static3D cent0 = new Static3D(0,0,0); |
|
1021 |
Static3D cent1 = new Static3D(0,SQ2/4,0); |
|
1022 |
Static3D scale = new Static3D( 1, 2*SQ3/3, 1); |
|
1023 |
|
|
1024 |
VertexEffect[] effect = new VertexEffect[7]; |
|
1025 |
|
|
1026 |
effect[0] = new VertexEffectScale(scale); |
|
1027 |
effect[1] = new VertexEffectRotate(angle2, axisZ, cent0); |
|
1028 |
effect[2] = new VertexEffectMove(move1); |
|
1029 |
effect[3] = new VertexEffectRotate(alpha , axisX, cent1); |
|
1030 |
effect[4] = new VertexEffectScale(flipZ); |
|
1031 |
effect[5] = new VertexEffectRotate(angle1, axisY, cent0); |
|
1032 |
effect[6] = new VertexEffectRotate(angle2, axisZ, cent0); |
|
1033 |
|
|
1034 |
effect[4].setMeshAssociation(10,-1); // meshes 1 & 3 |
|
1035 |
effect[5].setMeshAssociation(12,-1); // meshes 2 & 3 |
|
1036 |
effect[6].setMeshAssociation(12,-1); // meshes 2 & 3 |
|
1037 |
|
|
1038 |
return effect; |
|
1039 |
} |
|
1040 |
|
|
1041 | 921 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1042 | 922 |
|
1043 | 923 |
VertexEffect[] createVertexEffectsDino() |
... | ... | |
1708 | 1588 |
return mesh; |
1709 | 1589 |
} |
1710 | 1590 |
|
1711 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1712 |
// SKEWB DIAMOND / PYRAMINX |
|
1713 |
|
|
1714 |
public MeshBase createOctaMesh() |
|
1715 |
{ |
|
1716 |
MeshBase mesh = createFacesOcta(); |
|
1717 |
VertexEffect[] effects = createVertexEffectsOcta(); |
|
1718 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1719 |
|
|
1720 |
Static3D roundingCenter = new Static3D(0,0,0); |
|
1721 |
Static3D[] vertices = new Static3D[6]; |
|
1722 |
vertices[0] = new Static3D( 0, SQ2/2, 0 ); |
|
1723 |
vertices[1] = new Static3D( 0.5f, 0, 0.5f ); |
|
1724 |
vertices[2] = new Static3D(-0.5f, 0, 0.5f ); |
|
1725 |
vertices[3] = new Static3D( 0,-SQ2/2, 0 ); |
|
1726 |
vertices[4] = new Static3D(-0.5f, 0,-0.5f ); |
|
1727 |
vertices[5] = new Static3D( 0.5f, 0,-0.5f ); |
|
1728 |
|
|
1729 |
roundCorners(mesh,roundingCenter,vertices,0.06f,0.20f); |
|
1730 |
|
|
1731 |
mesh.mergeEffComponents(); |
|
1732 |
|
|
1733 |
return mesh; |
|
1734 |
} |
|
1735 |
|
|
1736 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1737 |
|
|
1738 |
public MeshBase createTetraMesh() |
|
1739 |
{ |
|
1740 |
MeshBase mesh = createFacesTetra(); |
|
1741 |
VertexEffect[] effects = createVertexEffectsTetra(); |
|
1742 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1743 |
|
|
1744 |
Static3D roundingCenter = new Static3D(0,0,0); |
|
1745 |
Static3D[] verticesRound = new Static3D[4]; |
|
1746 |
verticesRound[0] = new Static3D(-0.5f,+SQ2/4, 0 ); |
|
1747 |
verticesRound[1] = new Static3D(+0.5f,+SQ2/4, 0 ); |
|
1748 |
verticesRound[2] = new Static3D( 0,-SQ2/4,+0.5f); |
|
1749 |
verticesRound[3] = new Static3D( 0,-SQ2/4,-0.5f); |
|
1750 |
roundCorners(mesh,roundingCenter,verticesRound,0.08f,0.15f); |
|
1751 |
|
|
1752 |
mesh.mergeEffComponents(); |
|
1753 |
mesh.addEmptyTexComponent(); |
|
1754 |
mesh.addEmptyTexComponent(); |
|
1755 |
mesh.addEmptyTexComponent(); |
|
1756 |
mesh.addEmptyTexComponent(); |
|
1757 |
|
|
1758 |
return mesh; |
|
1759 |
} |
|
1760 |
|
|
1761 | 1591 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1762 | 1592 |
// DINO |
1763 | 1593 |
|
... | ... | |
2277 | 2107 |
|
2278 | 2108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
2279 | 2109 |
|
2280 |
private void constructNew(FaceTransform info, final double[][] vert3D)
|
|
2110 |
private FaceTransform constructNewTransform(final double[][] vert3D)
|
|
2281 | 2111 |
{ |
2112 |
FaceTransform ft = new FaceTransform(); |
|
2113 |
|
|
2282 | 2114 |
// compute center of gravity |
2283 |
info.vx = 0.0f;
|
|
2284 |
info.vy = 0.0f;
|
|
2285 |
info.vz = 0.0f;
|
|
2115 |
ft.vx = 0.0f;
|
|
2116 |
ft.vy = 0.0f;
|
|
2117 |
ft.vz = 0.0f;
|
|
2286 | 2118 |
int len = vert3D.length; |
2287 | 2119 |
|
2288 | 2120 |
for (double[] vert : vert3D) |
2289 | 2121 |
{ |
2290 |
info.vx += vert[0];
|
|
2291 |
info.vy += vert[1];
|
|
2292 |
info.vz += vert[2];
|
|
2122 |
ft.vx += vert[0];
|
|
2123 |
ft.vy += vert[1];
|
|
2124 |
ft.vz += vert[2];
|
|
2293 | 2125 |
} |
2294 | 2126 |
|
2295 |
info.vx /= len;
|
|
2296 |
info.vy /= len;
|
|
2297 |
info.vz /= len;
|
|
2127 |
ft.vx /= len;
|
|
2128 |
ft.vy /= len;
|
|
2129 |
ft.vz /= len;
|
|
2298 | 2130 |
|
2299 | 2131 |
// move all vertices so that their center of gravity is at (0,0,0) |
2300 | 2132 |
for (int i=0; i<len; i++) |
2301 | 2133 |
{ |
2302 |
vert3D[i][0] -= info.vx;
|
|
2303 |
vert3D[i][1] -= info.vy;
|
|
2304 |
vert3D[i][2] -= info.vz;
|
|
2134 |
vert3D[i][0] -= ft.vx;
|
|
2135 |
vert3D[i][1] -= ft.vy;
|
|
2136 |
vert3D[i][2] -= ft.vz;
|
|
2305 | 2137 |
} |
2306 | 2138 |
|
2307 | 2139 |
// find 3 non-colinear vertices |
... | ... | |
2367 | 2199 |
} |
2368 | 2200 |
|
2369 | 2201 |
// fit the whole thing in a square and remember the scale & 2D vertices |
2370 |
fitInSquare(info, vert3D);
|
|
2202 |
fitInSquare(ft, vert3D);
|
|
2371 | 2203 |
|
2372 | 2204 |
// remember the rotation |
2373 |
info.qx =-mQuat1[0]; |
|
2374 |
info.qy =-mQuat1[1]; |
|
2375 |
info.qz =-mQuat1[2]; |
|
2376 |
info.qw = mQuat1[3]; |
|
2205 |
ft.qx =-mQuat1[0]; |
|
2206 |
ft.qy =-mQuat1[1]; |
|
2207 |
ft.qz =-mQuat1[2]; |
|
2208 |
ft.qw = mQuat1[3]; |
|
2209 |
|
|
2210 |
return ft; |
|
2377 | 2211 |
} |
2378 | 2212 |
|
2379 | 2213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
2421 | 2255 |
} |
2422 | 2256 |
|
2423 | 2257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
2258 |
// valid for 0<angle<2*PI |
|
2424 | 2259 |
|
2425 | 2260 |
private double computeSinHalf(double cos) |
2426 | 2261 |
{ |
... | ... | |
2428 | 2263 |
} |
2429 | 2264 |
|
2430 | 2265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
2266 |
// valid for 0<angle<2*PI |
|
2431 | 2267 |
|
2432 | 2268 |
private double computeCosHalf(double sin, double cos) |
2433 | 2269 |
{ |
... | ... | |
2681 | 2517 |
for(int i=0; i<numTexToBeAdded; i++ ) mesh.addEmptyTexComponent(); |
2682 | 2518 |
} |
2683 | 2519 |
|
2520 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2521 |
|
|
2522 |
private void printTransform(FaceTransform f) |
|
2523 |
{ |
|
2524 |
android.util.Log.e("D", "q=("+f.qx+", "+f.qy+", "+f.qz+", "+f.qw+") v=(" |
|
2525 |
+f.vx+", "+f.vy+", "+f.vz+") scale="+f.scale+" sticker="+f.sticker); |
|
2526 |
} |
|
2527 |
|
|
2684 | 2528 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
2685 | 2529 |
// PUBLIC |
2686 | 2530 |
|
... | ... | |
2713 | 2557 |
|
2714 | 2558 |
public void printFaceTransform() |
2715 | 2559 |
{ |
2716 |
android.util.Log.d("D", "---- FACE TRANSFORM ---"); |
|
2560 |
android.util.Log.d("D", "---- OLD FACE TRANSFORM ---");
|
|
2717 | 2561 |
|
2718 |
int faces = mFaceTransform.size();
|
|
2562 |
int oldfaces = mOldFaceTransf.size();
|
|
2719 | 2563 |
|
2720 |
for(int f=0; f<faces; f++) |
|
2564 |
for(int f=0; f<oldfaces; f++)
|
|
2721 | 2565 |
{ |
2722 |
FaceTransform info = mFaceTransform.get(f); |
|
2566 |
printTransform(mOldFaceTransf.get(f)); |
|
2567 |
} |
|
2568 |
|
|
2569 |
android.util.Log.d("D", "---- NEW FACE TRANSFORM ---"); |
|
2570 |
|
|
2571 |
int newfaces = mNewFaceTransf.size(); |
|
2723 | 2572 |
|
2724 |
android.util.Log.e("D", "q=("+info.qx+", "+info.qy+", "+info.qz+", "+info.qw+") v=(" |
|
2725 |
+info.vx+", "+info.vy+", "+info.vz+") scale="+info.scale+" sticker="+info.sticker); |
|
2573 |
for(int f=0; f<newfaces; f++) |
|
2574 |
{ |
|
2575 |
printTransform(mNewFaceTransf.get(f)); |
|
2726 | 2576 |
} |
2727 | 2577 |
} |
2728 | 2578 |
|
... | ... | |
2731 | 2581 |
public void clear() |
2732 | 2582 |
{ |
2733 | 2583 |
mStickerCoords.clear(); |
2734 |
mFaceTransform.clear(); |
|
2584 |
mNewFaceTransf.clear(); |
|
2585 |
mOldFaceTransf.clear(); |
|
2735 | 2586 |
} |
2736 | 2587 |
|
2737 | 2588 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
2738 | 2589 |
|
2739 | 2590 |
public void createNewFaceTransform( final double[][] vertices, final int[][] indexes) |
2740 | 2591 |
{ |
2741 |
mFaceTransform.clear(); |
|
2592 |
FaceTransform ft; |
|
2593 |
int numNew = mNewFaceTransf.size(); |
|
2594 |
|
|
2595 |
for(int i=0; i<numNew; i++) |
|
2596 |
{ |
|
2597 |
ft = mNewFaceTransf.remove(0); |
|
2598 |
mOldFaceTransf.add(ft); |
|
2599 |
} |
|
2742 | 2600 |
|
2743 | 2601 |
int numFaces = indexes.length; |
2744 |
FaceTransform oldInfo;
|
|
2602 |
int numOld = mOldFaceTransf.size();
|
|
2745 | 2603 |
|
2746 |
for(int face=0; face<numFaces; face++) |
|
2604 |
for (int face=0; face<numFaces; face++)
|
|
2747 | 2605 |
{ |
2748 |
FaceTransform newInfo = new FaceTransform(); |
|
2749 |
int[] index = indexes[face]; |
|
2750 |
double[][] vert = constructVert(vertices,index); |
|
2751 |
constructNew(newInfo,vert); |
|
2606 |
boolean collapsed = false; |
|
2607 |
|
|
2608 |
double[][] vert = constructVert(vertices, indexes[face]); |
|
2609 |
FaceTransform newT = constructNewTransform(vert); |
|
2610 |
|
|
2611 |
for (int old=0; !collapsed && old<numOld; old++) |
|
2612 |
{ |
|
2613 |
ft = mOldFaceTransf.get(old); |
|
2614 |
if (successfullyCollapsedStickers(newT, ft)) collapsed = true; |
|
2615 |
} |
|
2752 | 2616 |
|
2753 |
for(int previous=0; previous<face; previous++)
|
|
2617 |
for (int pre=0; !collapsed && pre<face; pre++)
|
|
2754 | 2618 |
{ |
2755 |
oldInfo = mFaceTransform.get(previous);
|
|
2756 |
if( successfullyCollapsedStickers(newInfo,oldInfo) ) break;
|
|
2619 |
ft = mNewFaceTransf.get(pre);
|
|
2620 |
if (successfullyCollapsedStickers(newT, ft)) collapsed = true;
|
|
2757 | 2621 |
} |
2758 | 2622 |
|
2759 |
mFaceTransform.add(newInfo);
|
|
2623 |
mNewFaceTransf.add(newT);
|
|
2760 | 2624 |
} |
2761 | 2625 |
} |
2762 | 2626 |
|
... | ... | |
2775 | 2639 |
|
2776 | 2640 |
for(int face=0; face<numFaces; face++) |
2777 | 2641 |
{ |
2778 |
fInfo = mFaceTransform.get(face);
|
|
2642 |
fInfo = mNewFaceTransf.get(face);
|
|
2779 | 2643 |
sInfo = mStickerCoords.get(fInfo.sticker); |
2780 | 2644 |
|
2781 | 2645 |
double[] verts = sInfo.vertices; |
... | ... | |
2795 | 2659 |
for(int face=0; face<numFaces; face++) |
2796 | 2660 |
{ |
2797 | 2661 |
int assoc = (1<<face); |
2798 |
fInfo = mFaceTransform.get(face);
|
|
2662 |
fInfo = mNewFaceTransf.get(face);
|
|
2799 | 2663 |
|
2800 | 2664 |
float vx = (float)fInfo.vx; |
2801 | 2665 |
float vy = (float)fInfo.vy; |
src/main/java/org/distorted/objects/TwistyDiamond.java | ||
---|---|---|
94 | 94 |
|
95 | 95 |
private static final int[] mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4}; |
96 | 96 |
|
97 |
private final double[][] VERTICES_TETRA = new double[][] |
|
97 |
private static final double[][] VERTICES_TETRA = new double[][]
|
|
98 | 98 |
{ |
99 | 99 |
{-0.5, SQ2/4, 0.0}, |
100 | 100 |
{ 0.5, SQ2/4, 0.0}, |
... | ... | |
102 | 102 |
{ 0.0,-SQ2/4,-0.5} |
103 | 103 |
}; |
104 | 104 |
|
105 |
private final int[][] VERT_INDEXES_TETRA = new int[][] |
|
105 |
private static final int[][] VERT_INDEXES_TETRA = new int[][]
|
|
106 | 106 |
{ |
107 | 107 |
{2,1,0}, // counterclockwise! |
108 | 108 |
{2,3,1}, |
... | ... | |
110 | 110 |
{3,0,1} |
111 | 111 |
}; |
112 | 112 |
|
113 |
private final double[][] VERTICES_OCTA = new double[][] |
|
113 |
private static final double[][] VERTICES_OCTA = new double[][]
|
|
114 | 114 |
{ |
115 | 115 |
{ 0.5, 0.0, 0.5}, |
116 | 116 |
{ 0.5, 0.0,-0.5}, |
... | ... | |
120 | 120 |
{ 0.0,-SQ2/2, 0.0} |
121 | 121 |
}; |
122 | 122 |
|
123 |
private final int[][] VERT_INDEXES_OCTA = new int[][] |
|
123 |
private static final int[][] VERT_INDEXES_OCTA = new int[][]
|
|
124 | 124 |
{ |
125 | 125 |
{3,0,4}, // counterclockwise! |
126 | 126 |
{0,1,4}, |
... | ... | |
132 | 132 |
{5,3,2} |
133 | 133 |
}; |
134 | 134 |
|
135 |
private static MeshBase mOctaMesh, mTetraMesh; |
|
135 |
private static final float[][] STICKERS = new float[][] |
|
136 |
{ |
|
137 |
{ -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f } |
|
138 |
}; |
|
139 |
|
|
140 |
private static MeshBase[] mMeshes; |
|
136 | 141 |
|
137 | 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
138 | 143 |
|
... | ... | |
146 | 151 |
|
147 | 152 |
double[][] getVertices(int cubitType) |
148 | 153 |
{ |
149 |
if( cubitType==0 ) // Tetrahedron |
|
150 |
{ |
|
151 |
return VERTICES_TETRA; |
|
152 |
} |
|
153 |
if( cubitType==1 ) // Octahedron |
|
154 |
{ |
|
155 |
return VERTICES_OCTA; |
|
156 |
} |
|
157 |
|
|
154 |
if( cubitType==0 ) return VERTICES_OCTA; |
|
155 |
if( cubitType==1 ) return VERTICES_TETRA; |
|
158 | 156 |
return null; |
159 | 157 |
} |
160 | 158 |
|
... | ... | |
162 | 160 |
|
163 | 161 |
int[][] getVertIndexes(int cubitType) |
164 | 162 |
{ |
165 |
if( cubitType==0 ) // Tetrahedron |
|
166 |
{ |
|
167 |
return VERT_INDEXES_TETRA; |
|
168 |
} |
|
169 |
if( cubitType==1 ) // Octahedron |
|
170 |
{ |
|
171 |
return VERT_INDEXES_OCTA; |
|
172 |
} |
|
173 |
|
|
163 |
if( cubitType==0 ) return VERT_INDEXES_OCTA; |
|
164 |
if( cubitType==1 ) return VERT_INDEXES_TETRA; |
|
174 | 165 |
return null; |
175 | 166 |
} |
176 | 167 |
|
... | ... | |
213 | 204 |
|
214 | 205 |
int getNumStickerTypes(int numLayers) |
215 | 206 |
{ |
216 |
return 1;
|
|
207 |
return STICKERS.length;
|
|
217 | 208 |
} |
218 | 209 |
|
219 | 210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
263 | 254 |
|
264 | 255 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
265 | 256 |
|
266 |
private int createOctahedrons(float[][] centers, int index, int layers, float height)
|
|
257 |
private int createOctaPositions(float[][] centers, int index, int layers, float height)
|
|
267 | 258 |
{ |
268 | 259 |
float x = DIST*(layers-1); |
269 | 260 |
float z = DIST*(layers+1); |
... | ... | |
305 | 296 |
|
306 | 297 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
307 | 298 |
|
308 |
private int createTetrahedrons(float[][] centers, int index, int layers, float height)
|
|
299 |
private int createTetraPositions(float[][] centers, int index, int layers, float height)
|
|
309 | 300 |
{ |
310 | 301 |
float x = DIST*(layers-1); |
311 | 302 |
float z = DIST*layers; |
... | ... | |
365 | 356 |
|
366 | 357 |
float[][] CENTERS = new float[numO+numT][3]; |
367 | 358 |
|
368 |
index = createOctahedrons(CENTERS,index,layers,height);
|
|
359 |
index = createOctaPositions(CENTERS,index,layers,height);
|
|
369 | 360 |
|
370 | 361 |
for(int i=layers-1; i>0; i--) |
371 | 362 |
{ |
372 | 363 |
height += SQ2*DIST; |
373 |
index = createOctahedrons(CENTERS,index,i,+height);
|
|
374 |
index = createOctahedrons(CENTERS,index,i,-height);
|
|
364 |
index = createOctaPositions(CENTERS,index,i,+height);
|
|
365 |
index = createOctaPositions(CENTERS,index,i,-height);
|
|
375 | 366 |
} |
376 | 367 |
|
377 | 368 |
height = DIST*SQ2/2; |
378 | 369 |
|
379 | 370 |
for(int i=layers; i>1; i--) |
380 | 371 |
{ |
381 |
index = createTetrahedrons(CENTERS,index,i,+height);
|
|
382 |
index = createTetrahedrons(CENTERS,index,i,-height);
|
|
372 |
index = createTetraPositions(CENTERS,index,i,+height);
|
|
373 |
index = createTetraPositions(CENTERS,index,i,-height);
|
|
383 | 374 |
height += SQ2*DIST; |
384 | 375 |
} |
385 | 376 |
|
... | ... | |
424 | 415 |
|
425 | 416 |
MeshBase createCubitMesh(int cubit, int numLayers) |
426 | 417 |
{ |
418 |
if( mMeshes==null ) |
|
419 |
{ |
|
420 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
421 |
factory.clear(); |
|
422 |
mMeshes = new MeshBase[2]; |
|
423 |
} |
|
424 |
|
|
427 | 425 |
MeshBase mesh; |
428 | 426 |
int numO = getNumOctahedrons(numLayers); |
429 | 427 |
|
430 | 428 |
if( cubit<numO ) |
431 | 429 |
{ |
432 |
if( mOctaMesh==null ) mOctaMesh = FactoryCubit.getInstance().createOctaMesh(); |
|
433 |
mesh = mOctaMesh.copy(true); |
|
430 |
if( mMeshes[0]==null ) |
|
431 |
{ |
|
432 |
float[][] bands = new float[][] { {0.05f,35,0.5f,0.8f,6,2,2} }; |
|
433 |
int[] bandIndexes = new int[] { 0,0,0,0,0,0,0,0 }; |
|
434 |
float[][] corners = new float[][] { {0.04f,0.20f} }; |
|
435 |
int[] cornerIndexes = new int[] { 0,0,0,0,0,0 }; |
|
436 |
|
|
437 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
438 |
|
|
439 |
factory.createNewFaceTransform(VERTICES_OCTA,VERT_INDEXES_OCTA); |
|
440 |
mMeshes[0] = factory.createRoundedSolid(VERTICES_OCTA, VERT_INDEXES_OCTA, |
|
441 |
bands, bandIndexes, |
|
442 |
corners, cornerIndexes, |
|
443 |
getNumCubitFaces() ); |
|
444 |
} |
|
445 |
mesh = mMeshes[0].copy(true); |
|
434 | 446 |
} |
435 | 447 |
else |
436 | 448 |
{ |
437 |
if( mTetraMesh==null ) mTetraMesh = FactoryCubit.getInstance().createTetraMesh(); |
|
438 |
mesh = mTetraMesh.copy(true); |
|
449 |
if( mMeshes[1]==null ) |
|
450 |
{ |
|
451 |
float[][] bands = new float[][] { {0.05f,35,0.5f,0.8f,6,2,2} }; |
|
452 |
int[] bandIndexes = new int[] { 0,0,0,0 }; |
|
453 |
float[][] corners = new float[][] { {0.08f,0.15f} }; |
|
454 |
int[] cornerIndexes = new int[] { 0,0,0,0 }; |
|
455 |
|
|
456 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
457 |
|
|
458 |
factory.createNewFaceTransform(VERTICES_TETRA,VERT_INDEXES_TETRA); |
|
459 |
mMeshes[1] = factory.createRoundedSolid(VERTICES_TETRA, VERT_INDEXES_TETRA, |
|
460 |
bands, bandIndexes, |
|
461 |
corners, cornerIndexes, |
|
462 |
getNumCubitFaces() ); |
|
463 |
} |
|
464 |
mesh = mMeshes[1].copy(true); |
|
439 | 465 |
} |
440 | 466 |
|
441 | 467 |
Static4D sQ = getQuat(cubit,numLayers,numO); |
... | ... | |
480 | 506 |
|
481 | 507 |
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top) |
482 | 508 |
{ |
483 |
float E = 0.75f; |
|
484 |
float F = 0.50f; |
|
485 | 509 |
float R = 0.06f; |
486 | 510 |
float S = 0.07f; |
487 |
float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3}; |
|
488 | 511 |
|
489 | 512 |
FactorySticker factory = FactorySticker.getInstance(); |
490 |
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
|
|
513 |
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
|
|
491 | 514 |
} |
492 | 515 |
|
493 | 516 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyObject.java | ||
---|---|---|
518 | 518 |
{ |
519 | 519 |
double[][] vertices = getVertices(cubit); |
520 | 520 |
int[][] vertIndices = getVertIndexes(cubit); |
521 |
|
|
522 | 521 |
factory.createNewFaceTransform(vertices,vertIndices); |
523 |
factory.printFaceTransform(); |
|
524 | 522 |
} |
525 | 523 |
|
524 |
factory.printFaceTransform(); |
|
526 | 525 |
factory.printStickerCoords(); |
527 | 526 |
} |
528 | 527 |
|
src/main/java/org/distorted/objects/TwistyPyraminx.java | ||
---|---|---|
70 | 70 |
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f) |
71 | 71 |
}; |
72 | 72 |
|
73 |
private final double[][] VERTICES_TETRA = new double[][] |
|
73 |
private static final double[][] VERTICES_TETRA = new double[][]
|
|
74 | 74 |
{ |
75 | 75 |
{-0.5, SQ2/4, 0.0}, |
76 | 76 |
{ 0.5, SQ2/4, 0.0}, |
... | ... | |
78 | 78 |
{ 0.0,-SQ2/4,-0.5} |
79 | 79 |
}; |
80 | 80 |
|
81 |
private final int[][] VERT_INDEXES_TETRA = new int[][] |
|
81 |
private static final int[][] VERT_INDEXES_TETRA = new int[][]
|
|
82 | 82 |
{ |
83 | 83 |
{2,1,0}, // counterclockwise! |
84 |
{2,3,1},
|
|
84 |
{3,0,1},
|
|
85 | 85 |
{3,2,0}, |
86 |
{3,0,1}
|
|
86 |
{2,3,1}
|
|
87 | 87 |
}; |
88 | 88 |
|
89 |
private final double[][] VERTICES_OCTA = new double[][] |
|
89 |
private static final double[][] VERTICES_OCTA = new double[][]
|
|
90 | 90 |
{ |
91 | 91 |
{ 0.5, 0.0, 0.5}, |
92 | 92 |
{ 0.5, 0.0,-0.5}, |
... | ... | |
96 | 96 |
{ 0.0,-SQ2/2, 0.0} |
97 | 97 |
}; |
98 | 98 |
|
99 |
private final int[][] VERT_INDEXES_OCTA = new int[][] |
|
99 |
private static final int[][] VERT_INDEXES_OCTA = new int[][]
|
|
100 | 100 |
{ |
101 | 101 |
{3,0,4}, // counterclockwise! |
102 | 102 |
{0,1,4}, |
... | ... | |
108 | 108 |
{5,3,2} |
109 | 109 |
}; |
110 | 110 |
|
111 |
private static MeshBase mOctaMesh, mTetraMesh; |
|
111 |
private static final float[][] STICKERS = new float[][] |
|
112 |
{ |
|
113 |
{ -0.4330127f, -0.25f, 0.4330127f, -0.25f, 0.0f, 0.5f } |
|
114 |
}; |
|
115 |
|
|
116 |
private static MeshBase[] mMeshes; |
|
112 | 117 |
|
113 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
114 | 119 |
|
... | ... | |
122 | 127 |
|
123 | 128 |
double[][] getVertices(int cubitType) |
124 | 129 |
{ |
125 |
if( cubitType==0 ) // Tetrahedron |
|
126 |
{ |
|
127 |
return VERTICES_TETRA; |
|
128 |
} |
|
129 |
if( cubitType==1 ) // Octahedron |
|
130 |
{ |
|
131 |
return VERTICES_OCTA; |
|
132 |
} |
|
133 |
|
|
130 |
if( cubitType==0 ) return VERTICES_OCTA; |
|
131 |
if( cubitType==1 ) return VERTICES_TETRA; |
|
134 | 132 |
return null; |
135 | 133 |
} |
136 | 134 |
|
... | ... | |
138 | 136 |
|
139 | 137 |
int[][] getVertIndexes(int cubitType) |
140 | 138 |
{ |
141 |
if( cubitType==0 ) // Tetrahedron |
|
142 |
{ |
|
143 |
return VERT_INDEXES_TETRA; |
|
144 |
} |
|
145 |
if( cubitType==1 ) // Octahedron |
|
146 |
{ |
|
147 |
return VERT_INDEXES_OCTA; |
|
148 |
} |
|
149 |
|
|
139 |
if( cubitType==0 ) return VERT_INDEXES_OCTA; |
|
140 |
if( cubitType==1 ) return VERT_INDEXES_TETRA; |
|
150 | 141 |
return null; |
151 | 142 |
} |
152 | 143 |
|
... | ... | |
227 | 218 |
|
228 | 219 |
int getNumStickerTypes(int numLayers) |
229 | 220 |
{ |
230 |
return 1;
|
|
221 |
return STICKERS.length;
|
|
231 | 222 |
} |
232 | 223 |
|
233 | 224 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
265 | 256 |
return false; |
266 | 257 |
} |
267 | 258 |
|
259 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
260 |
|
|
261 |
private int getNumOctahedrons(int numLayers) |
|
262 |
{ |
|
263 |
return (numLayers-1)*numLayers*(numLayers+1)/6; |
|
264 |
} |
|
265 |
|
|
268 | 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
269 | 267 |
|
270 | 268 |
private int faceColor(int cubit, int axis) |
... | ... | |
297 | 295 |
|
298 | 296 |
MeshBase createCubitMesh(int cubit, int numLayers) |
299 | 297 |
{ |
300 |
if( cubit< (numLayers-1)*numLayers*(numLayers+1)/6 )
|
|
298 |
if( mMeshes==null )
|
|
301 | 299 |
{ |
302 |
if( mOctaMesh==null ) mOctaMesh = FactoryCubit.getInstance().createOctaMesh(); |
|
303 |
return mOctaMesh.copy(true); |
|
300 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
301 |
factory.clear(); |
|
302 |
mMeshes = new MeshBase[2]; |
|
303 |
} |
|
304 |
|
|
305 |
MeshBase mesh; |
|
306 |
int numO = getNumOctahedrons(numLayers); |
|
307 |
|
|
308 |
if( cubit<numO ) |
|
309 |
{ |
|
310 |
if( mMeshes[0]==null ) |
|
311 |
{ |
|
312 |
float[][] bands = new float[][] { {0.05f,35,0.5f,0.8f,6,2,2} }; |
|
313 |
int[] bandIndexes = new int[] { 0,0,0,0,0,0,0,0 }; |
|
314 |
float[][] corners = new float[][] { {0.04f,0.20f} }; |
|
315 |
int[] cornerIndexes = new int[] { 0,0,0,0,0,0 }; |
|
316 |
|
|
317 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
318 |
|
|
319 |
factory.createNewFaceTransform(VERTICES_OCTA,VERT_INDEXES_OCTA); |
|
320 |
mMeshes[0] = factory.createRoundedSolid(VERTICES_OCTA, VERT_INDEXES_OCTA, |
|
321 |
bands, bandIndexes, |
|
322 |
corners, cornerIndexes, |
|
323 |
getNumCubitFaces() ); |
|
324 |
} |
|
325 |
mesh = mMeshes[0].copy(true); |
|
304 | 326 |
} |
305 | 327 |
else |
306 | 328 |
{ |
307 |
if( mTetraMesh==null ) mTetraMesh = FactoryCubit.getInstance().createTetraMesh(); |
|
308 |
return mTetraMesh.copy(true); |
|
329 |
if( mMeshes[1]==null ) |
|
330 |
{ |
|
331 |
float[][] bands = new float[][] { {0.05f,35,0.5f,0.8f,6,2,2} }; |
|
332 |
int[] bandIndexes = new int[] { 0,0,0,0 }; |
|
333 |
float[][] corners = new float[][] { {0.06f,0.15f} }; |
|
334 |
int[] cornerIndexes = new int[] { 0,0,0,0 }; |
|
335 |
|
|
336 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
337 |
|
|
338 |
factory.createNewFaceTransform(VERTICES_TETRA,VERT_INDEXES_TETRA); |
|
339 |
mMeshes[1] = factory.createRoundedSolid(VERTICES_TETRA, VERT_INDEXES_TETRA, |
|
340 |
bands, bandIndexes, |
|
341 |
corners, cornerIndexes, |
|
342 |
getNumCubitFaces() ); |
|
343 |
|
|
344 |
factory.printStickerCoords(); |
|
345 |
} |
|
346 |
mesh = mMeshes[1].copy(true); |
|
309 | 347 |
} |
348 |
|
|
349 |
return mesh; |
|
310 | 350 |
} |
311 | 351 |
|
312 | 352 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
313 | 353 |
|
314 | 354 |
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top) |
315 | 355 |
{ |
316 |
float E = 0.75f; |
|
317 |
float F = 0.50f; |
|
318 | 356 |
float R = 0.06f; |
319 | 357 |
float S = 0.08f; |
320 |
float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3}; |
|
321 | 358 |
|
322 | 359 |
FactorySticker factory = FactorySticker.getInstance(); |
323 |
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
|
|
360 |
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
|
|
324 | 361 |
} |
325 | 362 |
|
326 | 363 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Convert the second and third object, the Pyraminx and the Diamond, to the new Cubit-creating engine.