Revision 31cd7256
Added by Leszek Koltunski about 3 years ago
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 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Convert the second and third object, the Pyraminx and the Diamond, to the new Cubit-creating engine.