Revision a38fe4b2
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objects/TwistyRex.java | ||
---|---|---|
22 | 22 |
import android.content.res.Resources; |
23 | 23 |
|
24 | 24 |
import org.distorted.helpers.FactoryCubit; |
25 |
import org.distorted.helpers.ObjectShape; |
|
25 | 26 |
import org.distorted.helpers.ObjectSticker; |
26 | 27 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
27 | 28 |
import org.distorted.library.main.DistortedEffects; |
... | ... | |
130 | 131 |
|
131 | 132 |
private static final float[][] STICKERS = new float[][] |
132 | 133 |
{ |
133 |
{ -0.5f, 0.1428f, -0.1428f, 0.5f, 0.32f, -0.32f },
|
|
134 |
{ -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
|
|
134 | 135 |
{ -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f }, |
135 |
{ -0.5f, 0.1f, 0.5f, 0.1f, 0.0f, -0.2f }
|
|
136 |
{ -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f }
|
|
136 | 137 |
}; |
137 | 138 |
private static final int NUM_STICKERS = STICKERS.length; |
138 | 139 |
|
... | ... | |
146 | 147 |
final float R3= 0.06f; |
147 | 148 |
final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } }; |
148 | 149 |
final float[][] radii = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} }; |
149 |
final float[] strokes = { 0.06f, 0.07f, 0.04f };
|
|
150 |
final float[] strokes = { 0.06f, 0.07f, 0.05f };
|
|
150 | 151 |
|
151 | 152 |
for(int s=0; s<NUM_STICKERS; s++) |
152 | 153 |
{ |
... | ... | |
273 | 274 |
|
274 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
275 | 276 |
|
276 |
private Static4D getQuat(int cubit) |
|
277 |
ObjectShape getObjectShape(int cubit, int numLayers) |
|
278 |
{ |
|
279 |
int variant = getCubitVariant(cubit,numLayers); |
|
280 |
|
|
281 |
if( variant==0 ) |
|
282 |
{ |
|
283 |
float G = (1-REX_D)*SQ2/2; |
|
284 |
|
|
285 |
double[][] vertices = |
|
286 |
{ |
|
287 |
{ -0.033333f, 0.23333f, 0.0f }, |
|
288 |
{ -0.233333f, 0.03333f, 0.0f }, |
|
289 |
{ +0.216666f,-0.23666f, 0.0f }, |
|
290 |
{ +0.236666f,-0.21666f, 0.0f } |
|
291 |
}; |
|
292 |
|
|
293 |
int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} }; |
|
294 |
float[][] centers= new float[][] { {0.0f,0.0f,-G/3} }; |
|
295 |
float[][] corners= new float[][] { {0.03f,0.10f} }; |
|
296 |
int[] indices= {-1,-1,0,0}; |
|
297 |
int[] bandIndices= new int[] { 0,1 }; |
|
298 |
|
|
299 |
float[][] bands = |
|
300 |
{ |
|
301 |
{+0.016f,10,G/3,0.5f,5,1,1}, |
|
302 |
{+0.230f,45,G/3,0.0f,2,0,0} |
|
303 |
}; |
|
304 |
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null); |
|
305 |
} |
|
306 |
else if( variant==1 ) |
|
307 |
{ |
|
308 |
double[][] vertices = |
|
309 |
{ |
|
310 |
{ -REX_D, 0.0f, 0.0f }, |
|
311 |
{ 0.0f, -REX_D, 0.0f }, |
|
312 |
{ +REX_D, 0.0f, 0.0f }, |
|
313 |
{ 0.0f, +REX_D, 0.0f } |
|
314 |
}; |
|
315 |
|
|
316 |
int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} }; |
|
317 |
int[] indices= {-1,-1,-1,-1}; |
|
318 |
int[] bandIndices= new int[] { 0,1 }; |
|
319 |
|
|
320 |
float[][] bands = |
|
321 |
{ |
|
322 |
{0.025f,10,REX_D/2,0.5f,5,0,0}, |
|
323 |
{0.000f,45,REX_D/2,0.0f,2,0,0} |
|
324 |
}; |
|
325 |
|
|
326 |
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null); |
|
327 |
} |
|
328 |
else |
|
329 |
{ |
|
330 |
float E = 0.5f - REX_D; |
|
331 |
float F = 0.5f; |
|
332 |
float G = (float)Math.sqrt(E*E+F*F); |
|
333 |
|
|
334 |
double[][] vertices = |
|
335 |
{ |
|
336 |
{ -F, 0, 0 }, |
|
337 |
{ 0,-E, 0 }, |
|
338 |
{ +F, 0, 0 }, |
|
339 |
{ 0, 0,-E }, |
|
340 |
}; |
|
341 |
|
|
342 |
int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} }; |
|
343 |
float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} }; |
|
344 |
float[][] corners= new float[][] { {0.06f,0.10f} }; |
|
345 |
int[] indices= {0,-1,0,-1}; |
|
346 |
int[] bandIndices= new int[] { 0,0,1,1 }; |
|
347 |
|
|
348 |
float[][] bands = |
|
349 |
{ |
|
350 |
{0.03f,27,F/3,0.8f,5,2,3}, |
|
351 |
{0.01f,45,G/3,0.2f,3,1,2} |
|
352 |
}; |
|
353 |
|
|
354 |
return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null); |
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
359 |
|
|
360 |
private Static4D getQuat(int cubit, int numLayers) |
|
277 | 361 |
{ |
278 | 362 |
switch(cubit) |
279 | 363 |
{ |
... | ... | |
328 | 412 |
|
329 | 413 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
330 | 414 |
|
331 |
MeshBase createCubitMesh(int cubit, int numLayers)
|
|
415 |
private int getNumCubitVariants(int numLayers)
|
|
332 | 416 |
{ |
333 |
if( mMeshes==null ) |
|
334 |
{ |
|
335 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
336 |
factory.clear(); |
|
337 |
mMeshes = new MeshBase[3]; |
|
338 |
} |
|
339 |
|
|
340 |
MeshBase mesh; |
|
341 |
|
|
342 |
if( cubit<24 ) |
|
343 |
{ |
|
344 |
if( mMeshes[0]==null ) |
|
345 |
{ |
|
346 |
float G = (1-REX_D)*SQ2/2; |
|
347 |
|
|
348 |
double[][] vertices = |
|
349 |
{ |
|
350 |
{ -0.033333f, 0.23333f, 0.0f }, |
|
351 |
{ -0.233333f, 0.03333f, 0.0f }, |
|
352 |
{ +0.216666f,-0.23666f, 0.0f }, |
|
353 |
{ +0.236666f,-0.21666f, 0.0f } |
|
354 |
}; |
|
417 |
return 3; |
|
418 |
} |
|
355 | 419 |
|
356 |
int[][] vertIndexes = |
|
357 |
{ |
|
358 |
{0,1,2,3}, |
|
359 |
{3,2,1,0} |
|
360 |
}; |
|
420 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
361 | 421 |
|
362 |
float[][] centers= new float[][] { {0.0f,0.0f,-G/3} }; |
|
363 |
float[][] corners= new float[][] { {0.03f,0.10f} }; |
|
364 |
int[] indexes= {-1,-1,0,0}; |
|
422 |
int getCubitVariant(int cubit, int numLayers) |
|
423 |
{ |
|
424 |
return cubit<24 ? 0 : (cubit<30?1:2); |
|
425 |
} |
|
365 | 426 |
|
366 |
int[] bandIndexes= new int[] { 0,1 };
|
|
427 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
367 | 428 |
|
368 |
float[][] bands = |
|
369 |
{ |
|
370 |
{+0.016f,10,G/3,0.5f,5,1,1}, |
|
371 |
{+0.230f,45,G/3,0.0f,2,0,0} |
|
372 |
}; |
|
429 |
MeshBase createCubitMesh(int cubit, int numLayers) |
|
430 |
{ |
|
431 |
int variant = getCubitVariant(cubit,numLayers); |
|
373 | 432 |
|
374 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
375 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
376 |
mMeshes[0] = factory.createRoundedSolid(vertices, vertIndexes, |
|
377 |
bands, bandIndexes, |
|
378 |
corners, indexes, |
|
379 |
centers, indexes, |
|
380 |
getNumCubitFaces(), null ); |
|
381 |
} |
|
382 |
mesh = mMeshes[0].copy(true); |
|
383 |
} |
|
384 |
else if( cubit<30 ) |
|
433 |
if( mMeshes==null ) |
|
385 | 434 |
{ |
386 |
if( mMeshes[1]==null ) |
|
387 |
{ |
|
388 |
double[][] vertices = |
|
389 |
{ |
|
390 |
{ -REX_D, 0.0f, 0.0f }, |
|
391 |
{ 0.0f, -REX_D, 0.0f }, |
|
392 |
{ +REX_D, 0.0f, 0.0f }, |
|
393 |
{ 0.0f, +REX_D, 0.0f } |
|
394 |
}; |
|
395 |
|
|
396 |
int[][] vertIndexes= |
|
397 |
{ |
|
398 |
{0,1,2,3}, |
|
399 |
{3,2,1,0} |
|
400 |
}; |
|
401 |
|
|
402 |
float[][] bands = |
|
403 |
{ |
|
404 |
{0.025f,10,REX_D/2,0.5f,5,0,0}, |
|
405 |
{0.000f,45,REX_D/2,0.0f,2,0,0} |
|
406 |
}; |
|
407 |
|
|
408 |
int[] indexes= {-1,-1,-1,-1}; |
|
409 |
int[] bandIndexes= new int[] { 0,1 }; |
|
410 |
|
|
411 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
412 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
413 |
mMeshes[1] = factory.createRoundedSolid(vertices, vertIndexes, |
|
414 |
bands, bandIndexes, |
|
415 |
null, indexes, |
|
416 |
null, indexes, |
|
417 |
getNumCubitFaces(), null ); |
|
418 |
} |
|
419 |
mesh = mMeshes[1].copy(true); |
|
435 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
436 |
factory.clear(); |
|
437 |
mMeshes = new MeshBase[getNumCubitVariants(numLayers)]; |
|
420 | 438 |
} |
421 |
else |
|
422 |
{ |
|
423 |
if( mMeshes[2]==null ) |
|
424 |
{ |
|
425 |
float E = 0.5f - REX_D; |
|
426 |
float F = 0.5f; |
|
427 |
float G = (float)Math.sqrt(E*E+F*F); |
|
428 | 439 |
|
429 |
double[][] vertices = |
|
430 |
{ |
|
431 |
{ -F, 0, 0 }, |
|
432 |
{ 0,-E, 0 }, |
|
433 |
{ +F, 0, 0 }, |
|
434 |
{ 0, 0,-E }, |
|
435 |
}; |
|
436 |
|
|
437 |
int[][] vertIndexes = |
|
438 |
{ |
|
439 |
{0,1,2}, |
|
440 |
{0,2,3}, |
|
441 |
{0,3,1}, |
|
442 |
{1,3,2} |
|
443 |
}; |
|
444 |
|
|
445 |
float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} }; |
|
446 |
float[][] corners= new float[][] { {0.06f,0.10f} }; |
|
447 |
int[] indexes= {0,-1,0,-1}; |
|
448 |
|
|
449 |
int[] bandIndexes= new int[] { 0,0,1,1 }; |
|
450 |
|
|
451 |
float[][] bands = |
|
452 |
{ |
|
453 |
{0.03f,27,F/3,0.8f,5,2,3}, |
|
454 |
{0.01f,45,G/3,0.2f,3,1,2} |
|
455 |
}; |
|
456 |
|
|
457 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
458 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
459 |
mMeshes[2] = factory.createRoundedSolid(vertices, vertIndexes, |
|
460 |
bands, bandIndexes, |
|
461 |
corners, indexes, |
|
462 |
centers, indexes, |
|
463 |
getNumCubitFaces(), null ); |
|
464 |
} |
|
465 |
mesh = mMeshes[2].copy(true); |
|
440 |
if( mMeshes[variant]==null ) |
|
441 |
{ |
|
442 |
ObjectShape shape = getObjectShape(cubit,numLayers); |
|
443 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
444 |
factory.createNewFaceTransform(shape); |
|
445 |
mMeshes[variant] = factory.createRoundedSolid(shape); |
|
466 | 446 |
} |
467 | 447 |
|
468 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) ); |
|
448 |
MeshBase mesh = mMeshes[variant].copy(true); |
|
449 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) ); |
|
469 | 450 |
mesh.apply(quat,0xffffffff,0); |
470 | 451 |
|
471 | 452 |
return mesh; |
Also available in: Unified diff
Convert Rex Cube to the new scheme.