Revision 31cd7256
Added by Leszek Koltunski about 3 years ago
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.