Revision 4d883a92
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java | ||
---|---|---|
38 | 38 |
import org.distorted.library.main.DistortedTexture; |
39 | 39 |
import org.distorted.library.mesh.MeshBase; |
40 | 40 |
import org.distorted.library.mesh.MeshFile; |
41 |
import org.distorted.library.mesh.MeshPolygon; |
|
42 | 41 |
import org.distorted.library.type.DynamicQuat; |
43 | 42 |
import org.distorted.library.type.Static3D; |
44 | 43 |
import org.distorted.library.type.Static4D; |
... | ... | |
249 | 248 |
return bitmap; |
250 | 249 |
} |
251 | 250 |
|
252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
|
|
254 |
private MeshBase createStaticMesh() |
|
255 |
{ |
|
256 |
final float IVY_D = 0.10f; |
|
257 |
final int IVY_N = 8; |
|
258 |
|
|
259 |
final float angle = (float)Math.PI/(2*IVY_N); |
|
260 |
final float CORR = 1.0f - IVY_D*SQ2; |
|
261 |
final float DIST = 0.4f; |
|
262 |
final float CORR2 = 0.5f; |
|
263 |
float[] vertices = new float[2*(IVY_N+1)+6]; |
|
264 |
|
|
265 |
vertices[0] = ( 0.5f -DIST)*CORR2; |
|
266 |
vertices[1] = (-0.5f+IVY_D-DIST)*CORR2; |
|
267 |
vertices[2] = ( 0.5f -DIST)*CORR2; |
|
268 |
vertices[3] = ( 0.5f -DIST)*CORR2; |
|
269 |
vertices[4] = (-0.5f+IVY_D-DIST)*CORR2; |
|
270 |
vertices[5] = ( 0.5f -DIST)*CORR2; |
|
271 |
|
|
272 |
for(int i=0; i<=IVY_N; i++) |
|
273 |
{ |
|
274 |
float ang = (IVY_N-i)*angle; |
|
275 |
float sin = (float)Math.sin(ang); |
|
276 |
float cos = (float)Math.cos(ang); |
|
277 |
|
|
278 |
vertices[2*i+6] = (CORR*(cos-0.5f)-DIST)*CORR2; |
|
279 |
vertices[2*i+7] = (CORR*(sin-0.5f)-DIST)*CORR2; |
|
280 |
} |
|
281 |
|
|
282 |
float[] bands = new float[] {1.0f, 0.0f, 0.5f, 0.03f, 0.0f, 0.05f}; |
|
283 |
|
|
284 |
MeshBase mesh = new MeshPolygon(vertices,bands,0,0); |
|
285 |
mesh.setShowNormals(true); |
|
286 |
|
|
287 |
return mesh; |
|
288 |
} |
|
289 |
|
|
290 | 251 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
291 | 252 |
|
292 | 253 |
private void createMesh() |
293 | 254 |
{ |
294 | 255 |
int mode = 2; |
295 |
float[][] vertices = null;
|
|
256 |
double[][] vertices = null;
|
|
296 | 257 |
int[][] vertIndexes = null; |
297 | 258 |
float[][] bands = null; |
298 | 259 |
int[] bandIndexes = null; |
299 | 260 |
float[][] corners = null; |
300 | 261 |
int[] cornerIndexes = null; |
301 | 262 |
|
302 |
if( mode==0 ) // CUBE |
|
263 |
///// CUBE //////////////////////////////////////////////////////////////////////////////// |
|
264 |
|
|
265 |
if( mode==0 ) |
|
303 | 266 |
{ |
304 |
vertices = new float[][]
|
|
267 |
vertices = new double[][]
|
|
305 | 268 |
{ |
306 |
{ 0.5f, 0.5f, 0.5f },
|
|
307 |
{ 0.5f, 0.5f,-0.5f },
|
|
308 |
{ 0.5f,-0.5f, 0.5f },
|
|
309 |
{ 0.5f,-0.5f,-0.5f },
|
|
310 |
{-0.5f, 0.5f, 0.5f },
|
|
311 |
{-0.5f, 0.5f,-0.5f },
|
|
312 |
{-0.5f,-0.5f, 0.5f },
|
|
313 |
{-0.5f,-0.5f,-0.5f },
|
|
269 |
{ 0.5, 0.5, 0.5 },
|
|
270 |
{ 0.5, 0.5,-0.5 },
|
|
271 |
{ 0.5,-0.5, 0.5 },
|
|
272 |
{ 0.5,-0.5,-0.5 },
|
|
273 |
{-0.5, 0.5, 0.5 },
|
|
274 |
{-0.5, 0.5,-0.5 },
|
|
275 |
{-0.5,-0.5, 0.5 },
|
|
276 |
{-0.5,-0.5,-0.5 },
|
|
314 | 277 |
}; |
315 | 278 |
|
316 | 279 |
vertIndexes = new int[][] |
... | ... | |
337 | 300 |
|
338 | 301 |
cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 }; |
339 | 302 |
} |
340 |
else if( mode==1 ) // TETRAHEDRON |
|
303 |
|
|
304 |
///// TETRAHEDRON ////////////////////////////////////////////////////////////////////////// |
|
305 |
|
|
306 |
else if( mode==1 ) |
|
341 | 307 |
{ |
342 |
vertices = new float[][]
|
|
308 |
vertices = new double[][]
|
|
343 | 309 |
{ |
344 |
{-0.5f, SQ2/4, 0.0f},
|
|
345 |
{ 0.5f, SQ2/4, 0.0f},
|
|
346 |
{ 0.0f,-SQ2/4, 0.5f},
|
|
347 |
{ 0.0f,-SQ2/4,-0.5f}
|
|
310 |
{-0.5, SQ2/4, 0.0},
|
|
311 |
{ 0.5, SQ2/4, 0.0},
|
|
312 |
{ 0.0,-SQ2/4, 0.5},
|
|
313 |
{ 0.0,-SQ2/4,-0.5}
|
|
348 | 314 |
}; |
349 | 315 |
|
350 | 316 |
vertIndexes = new int[][] |
... | ... | |
369 | 335 |
|
370 | 336 |
cornerIndexes = new int[] { 0,0,0,0 }; |
371 | 337 |
} |
372 |
else if( mode==2 ) // DINO |
|
338 |
|
|
339 |
///// DINO //////////////////////////////////////////////////////////////////////////////// |
|
340 |
|
|
341 |
else if( mode==2 ) |
|
373 | 342 |
{ |
374 |
vertices = new float[][]
|
|
343 |
vertices = new double[][]
|
|
375 | 344 |
{ |
376 |
{-0.5f, 0.0f, 0.0f},
|
|
377 |
{ 0.5f, 0.0f, 0.0f},
|
|
378 |
{ 0.0f,-0.5f, 0.0f},
|
|
379 |
{ 0.0f, 0.0f,-0.5f}
|
|
345 |
{-0.5, 0.0, 0.0},
|
|
346 |
{ 0.5, 0.0, 0.0},
|
|
347 |
{ 0.0,-0.5, 0.0},
|
|
348 |
{ 0.0, 0.0,-0.5}
|
|
380 | 349 |
}; |
381 | 350 |
|
382 | 351 |
vertIndexes = new int[][] |
Also available in: Unified diff
Cubit creation: bugfixes. Cube, Tetrahedron, Dino cubits - all work.