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;
|
... | ... | |
201 |
202 |
|
202 |
203 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203 |
204 |
|
204 |
|
private int getQuat(int cubit)
|
|
205 |
ObjectShape getObjectShape(int cubit, int numLayers)
|
205 |
206 |
{
|
206 |
|
switch(cubit)
|
|
207 |
int variant = getCubitVariant(cubit,numLayers);
|
|
208 |
|
|
209 |
if( variant==0 )
|
207 |
210 |
{
|
208 |
|
case 0: return 0;
|
209 |
|
case 1: return 2;
|
210 |
|
case 2: return 3;
|
211 |
|
case 3: return 1;
|
212 |
|
|
213 |
|
case 4: return 8;
|
214 |
|
case 5: return 11;
|
215 |
|
case 6: return 10;
|
216 |
|
case 7: return 9;
|
217 |
|
case 8: return 0;
|
218 |
|
case 9: return 2;
|
|
211 |
final float angle = (float)Math.PI/(2*IVY_N);
|
|
212 |
final float CORR = 1.0f - 2*IVY_D;
|
|
213 |
|
|
214 |
float[][] centers= new float[][] { {-0.5f,-0.5f,-0.5f} };
|
|
215 |
float[][] corners= new float[][] { {0.03f,0.10f}, {0.02f,0.10f} };
|
|
216 |
int[] cornerIndices= new int[3*(IVY_N+1)+4];
|
|
217 |
int[] centerIndices= new int[3*(IVY_N+1)+4];
|
|
218 |
double[][] vertices= new double[3*(IVY_N+1)+4][3];
|
|
219 |
int[][] vertIndices= new int[6][IVY_N+4];
|
|
220 |
int[] bandIndices = new int[] { 0,0,0,1,1,1 };
|
|
221 |
|
|
222 |
float[][] bands =
|
|
223 |
{
|
|
224 |
{+0.015f,20,0.2f,0.5f,7,1,2},
|
|
225 |
{-0.100f,20,0.2f,0.0f,2,1,2}
|
|
226 |
};
|
|
227 |
|
|
228 |
for(int i=0; i<3*(IVY_N+1); i++)
|
|
229 |
{
|
|
230 |
cornerIndices[i+4] = -1;
|
|
231 |
centerIndices[i+4] = -1;
|
|
232 |
}
|
|
233 |
|
|
234 |
cornerIndices[0] = 1;
|
|
235 |
cornerIndices[1] = 0;
|
|
236 |
cornerIndices[2] = 0;
|
|
237 |
cornerIndices[3] = 0;
|
|
238 |
|
|
239 |
centerIndices[0] = 0;
|
|
240 |
centerIndices[1] = 0;
|
|
241 |
centerIndices[2] = 0;
|
|
242 |
centerIndices[3] = 0;
|
|
243 |
|
|
244 |
vertices[0][0] = 0.0;
|
|
245 |
vertices[0][1] = 0.0;
|
|
246 |
vertices[0][2] = 0.0;
|
|
247 |
vertices[1][0] =-1.0;
|
|
248 |
vertices[1][1] = 0.0;
|
|
249 |
vertices[1][2] = 0.0;
|
|
250 |
vertices[2][0] = 0.0;
|
|
251 |
vertices[2][1] =-1.0;
|
|
252 |
vertices[2][2] = 0.0;
|
|
253 |
vertices[3][0] = 0.0;
|
|
254 |
vertices[3][1] = 0.0;
|
|
255 |
vertices[3][2] =-1.0;
|
|
256 |
|
|
257 |
vertIndices[0][0] = 2;
|
|
258 |
vertIndices[0][1] = 0;
|
|
259 |
vertIndices[0][2] = 1;
|
|
260 |
vertIndices[3][0] = 2;
|
|
261 |
vertIndices[3][1] = 0;
|
|
262 |
vertIndices[3][2] = 1;
|
|
263 |
|
|
264 |
vertIndices[1][0] = 3;
|
|
265 |
vertIndices[1][1] = 0;
|
|
266 |
vertIndices[1][2] = 2;
|
|
267 |
vertIndices[4][0] = 3;
|
|
268 |
vertIndices[4][1] = 0;
|
|
269 |
vertIndices[4][2] = 2;
|
|
270 |
|
|
271 |
vertIndices[2][0] = 1;
|
|
272 |
vertIndices[2][1] = 0;
|
|
273 |
vertIndices[2][2] = 3;
|
|
274 |
vertIndices[5][0] = 1;
|
|
275 |
vertIndices[5][1] = 0;
|
|
276 |
vertIndices[5][2] = 3;
|
|
277 |
|
|
278 |
int N1 = 4;
|
|
279 |
int N2 = N1 + IVY_N + 1;
|
|
280 |
int N3 = N2 + IVY_N + 1;
|
|
281 |
|
|
282 |
for(int i=0; i<=IVY_N; i++)
|
|
283 |
{
|
|
284 |
double cos1 = Math.cos((IVY_N-i)*angle);
|
|
285 |
double sin1 = Math.sin((IVY_N-i)*angle);
|
|
286 |
double cos2 = Math.cos(( i)*angle);
|
|
287 |
double sin2 = Math.sin(( i)*angle);
|
|
288 |
|
|
289 |
vertices[N1+i][0] = CORR*(cos1-0.5) - 0.5;
|
|
290 |
vertices[N1+i][1] = CORR*(sin1-0.5) - 0.5;
|
|
291 |
vertices[N1+i][2] = 0.0;
|
|
292 |
|
|
293 |
vertices[N2+i][0] = 0.0;
|
|
294 |
vertices[N2+i][1] = CORR*(sin2-0.5) - 0.5;
|
|
295 |
vertices[N2+i][2] = CORR*(cos2-0.5) - 0.5;
|
|
296 |
|
|
297 |
vertices[N3+i][0] = CORR*(cos2-0.5) - 0.5;
|
|
298 |
vertices[N3+i][1] = 0.0;
|
|
299 |
vertices[N3+i][2] = CORR*(sin2-0.5) - 0.5;
|
|
300 |
|
|
301 |
vertIndices[0][i+3] = N1 + i;
|
|
302 |
vertIndices[1][i+3] = N2 + i;
|
|
303 |
vertIndices[2][i+3] = N3 + i;
|
|
304 |
vertIndices[3][i+3] = N1 + i;
|
|
305 |
vertIndices[4][i+3] = N2 + i;
|
|
306 |
vertIndices[5][i+3] = N3 + i;
|
|
307 |
}
|
|
308 |
|
|
309 |
float C = 0.5f - SQ2/4;
|
|
310 |
float[] convexCenter = new float[] {-C,-C,-C};
|
|
311 |
return new ObjectShape(vertices,vertIndices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), convexCenter);
|
219 |
312 |
}
|
|
313 |
else
|
|
314 |
{
|
|
315 |
final float angle = (float)Math.PI/(2*IVY_N);
|
|
316 |
final float CORR = 1.0f - 2*IVY_D;
|
|
317 |
double[][] vertices = new double[2*IVY_N][3];
|
|
318 |
int[][] vert_indices = new int[2][2*IVY_N];
|
|
319 |
|
|
320 |
int[] bandIndices= new int[] { 0,1 };
|
|
321 |
int[] indexes = new int[2*IVY_N];
|
|
322 |
float[][] corners= new float[][] { {0.03f,0.10f} };
|
|
323 |
float[][] centers= new float[][] { {-0.0f,-0.0f,-0.5f} };
|
220 |
324 |
|
221 |
|
return 0;
|
|
325 |
for(int i=0; i<IVY_N; i++)
|
|
326 |
{
|
|
327 |
double sin = Math.sin(i*angle);
|
|
328 |
double cos = Math.cos(i*angle);
|
|
329 |
|
|
330 |
vertices[i ][0] = CORR*(0.5f-cos);
|
|
331 |
vertices[i ][1] = CORR*(0.5f-sin);
|
|
332 |
vertices[i ][2] = 0;
|
|
333 |
vertices[i+IVY_N][0] = CORR*(cos-0.5f);
|
|
334 |
vertices[i+IVY_N][1] = CORR*(sin-0.5f);
|
|
335 |
vertices[i+IVY_N][2] = 0;
|
|
336 |
}
|
|
337 |
|
|
338 |
for(int i=0; i<2*IVY_N; i++)
|
|
339 |
{
|
|
340 |
vert_indices[0][i] = i;
|
|
341 |
vert_indices[1][i] = 2*IVY_N-1-i;
|
|
342 |
}
|
|
343 |
|
|
344 |
for(int i=0; i<2*IVY_N; i++)
|
|
345 |
{
|
|
346 |
indexes[i] = -1;
|
|
347 |
}
|
|
348 |
indexes[0] = indexes[IVY_N] = 0;
|
|
349 |
|
|
350 |
float[][] bands =
|
|
351 |
{
|
|
352 |
{+0.03f,35,0.5f,0.5f,5,0,0},
|
|
353 |
{+0.10f,45,0.5f,0.0f,2,0,0}
|
|
354 |
};
|
|
355 |
|
|
356 |
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,indexes,centers,indexes,getNumCubitFaces(), null);
|
|
357 |
}
|
222 |
358 |
}
|
223 |
359 |
|
224 |
360 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225 |
361 |
|
226 |
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
|
362 |
private Static4D getQuat(int cubit, int numLayers)
|
227 |
363 |
{
|
228 |
|
if( mMeshes==null )
|
|
364 |
switch(cubit)
|
229 |
365 |
{
|
230 |
|
FactoryCubit factory = FactoryCubit.getInstance();
|
231 |
|
factory.clear();
|
232 |
|
mMeshes = new MeshBase[2];
|
|
366 |
case 0: return QUATS[0];
|
|
367 |
case 1: return QUATS[2];
|
|
368 |
case 2: return QUATS[3];
|
|
369 |
case 3: return QUATS[1];
|
|
370 |
|
|
371 |
case 4: return QUATS[8];
|
|
372 |
case 5: return QUATS[11];
|
|
373 |
case 6: return QUATS[10];
|
|
374 |
case 7: return QUATS[9];
|
|
375 |
case 8: return QUATS[0];
|
|
376 |
case 9: return QUATS[2];
|
233 |
377 |
}
|
234 |
378 |
|
235 |
|
MeshBase mesh;
|
|
379 |
return QUATS[0];
|
|
380 |
}
|
236 |
381 |
|
237 |
|
if( cubit<4 )
|
238 |
|
{
|
239 |
|
if( mMeshes[0]==null )
|
240 |
|
{
|
241 |
|
final float angle = (float)Math.PI/(2*IVY_N);
|
242 |
|
final float CORR = 1.0f - 2*IVY_D;
|
243 |
|
|
244 |
|
float[][] centers= new float[][] { {-0.5f,-0.5f,-0.5f} };
|
245 |
|
float[][] corners= new float[][] { {0.03f,0.10f}, {0.02f,0.10f} };
|
246 |
|
int[] cornerIndexes= new int[3*(IVY_N+1)+4];
|
247 |
|
int[] centerIndexes= new int[3*(IVY_N+1)+4];
|
248 |
|
double[][] vertices= new double[3*(IVY_N+1)+4][3];
|
249 |
|
int[][] vertIndexes= new int[6][IVY_N+4];
|
250 |
|
int[] bandIndexes= new int[] { 0,0,0,1,1,1 };
|
251 |
|
|
252 |
|
float[][] bands =
|
253 |
|
{
|
254 |
|
{+0.015f,20,0.2f,0.5f,7,1,2},
|
255 |
|
{-0.100f,20,0.2f,0.0f,2,1,2}
|
256 |
|
};
|
|
382 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257 |
383 |
|
258 |
|
for(int i=0; i<3*(IVY_N+1); i++)
|
259 |
|
{
|
260 |
|
cornerIndexes[i+4] = -1;
|
261 |
|
centerIndexes[i+4] = -1;
|
262 |
|
}
|
263 |
|
cornerIndexes[0] = 1;
|
264 |
|
cornerIndexes[1] = 0;
|
265 |
|
cornerIndexes[2] = 0;
|
266 |
|
cornerIndexes[3] = 0;
|
267 |
|
|
268 |
|
centerIndexes[0] = 0;
|
269 |
|
centerIndexes[1] = 0;
|
270 |
|
centerIndexes[2] = 0;
|
271 |
|
centerIndexes[3] = 0;
|
272 |
|
|
273 |
|
vertices[0][0] = 0.0;
|
274 |
|
vertices[0][1] = 0.0;
|
275 |
|
vertices[0][2] = 0.0;
|
276 |
|
vertices[1][0] =-1.0;
|
277 |
|
vertices[1][1] = 0.0;
|
278 |
|
vertices[1][2] = 0.0;
|
279 |
|
vertices[2][0] = 0.0;
|
280 |
|
vertices[2][1] =-1.0;
|
281 |
|
vertices[2][2] = 0.0;
|
282 |
|
vertices[3][0] = 0.0;
|
283 |
|
vertices[3][1] = 0.0;
|
284 |
|
vertices[3][2] =-1.0;
|
285 |
|
|
286 |
|
vertIndexes[0][0] = 2;
|
287 |
|
vertIndexes[0][1] = 0;
|
288 |
|
vertIndexes[0][2] = 1;
|
289 |
|
vertIndexes[3][0] = 2;
|
290 |
|
vertIndexes[3][1] = 0;
|
291 |
|
vertIndexes[3][2] = 1;
|
292 |
|
|
293 |
|
vertIndexes[1][0] = 3;
|
294 |
|
vertIndexes[1][1] = 0;
|
295 |
|
vertIndexes[1][2] = 2;
|
296 |
|
vertIndexes[4][0] = 3;
|
297 |
|
vertIndexes[4][1] = 0;
|
298 |
|
vertIndexes[4][2] = 2;
|
299 |
|
|
300 |
|
vertIndexes[2][0] = 1;
|
301 |
|
vertIndexes[2][1] = 0;
|
302 |
|
vertIndexes[2][2] = 3;
|
303 |
|
vertIndexes[5][0] = 1;
|
304 |
|
vertIndexes[5][1] = 0;
|
305 |
|
vertIndexes[5][2] = 3;
|
306 |
|
|
307 |
|
int N1 = 4;
|
308 |
|
int N2 = N1 + IVY_N + 1;
|
309 |
|
int N3 = N2 + IVY_N + 1;
|
310 |
|
|
311 |
|
for(int i=0; i<=IVY_N; i++)
|
312 |
|
{
|
313 |
|
double cos1 = Math.cos((IVY_N-i)*angle);
|
314 |
|
double sin1 = Math.sin((IVY_N-i)*angle);
|
315 |
|
double cos2 = Math.cos(( i)*angle);
|
316 |
|
double sin2 = Math.sin(( i)*angle);
|
317 |
|
|
318 |
|
vertices[N1+i][0] = CORR*(cos1-0.5) - 0.5;
|
319 |
|
vertices[N1+i][1] = CORR*(sin1-0.5) - 0.5;
|
320 |
|
vertices[N1+i][2] = 0.0;
|
321 |
|
|
322 |
|
vertices[N2+i][0] = 0.0;
|
323 |
|
vertices[N2+i][1] = CORR*(sin2-0.5) - 0.5;
|
324 |
|
vertices[N2+i][2] = CORR*(cos2-0.5) - 0.5;
|
325 |
|
|
326 |
|
vertices[N3+i][0] = CORR*(cos2-0.5) - 0.5;
|
327 |
|
vertices[N3+i][1] = 0.0;
|
328 |
|
vertices[N3+i][2] = CORR*(sin2-0.5) - 0.5;
|
329 |
|
|
330 |
|
vertIndexes[0][i+3] = N1 + i;
|
331 |
|
vertIndexes[1][i+3] = N2 + i;
|
332 |
|
vertIndexes[2][i+3] = N3 + i;
|
333 |
|
vertIndexes[3][i+3] = N1 + i;
|
334 |
|
vertIndexes[4][i+3] = N2 + i;
|
335 |
|
vertIndexes[5][i+3] = N3 + i;
|
336 |
|
}
|
337 |
|
|
338 |
|
float C = 0.5f - SQ2/4;
|
339 |
|
float[] convexCenter = new float[] {-C,-C,-C};
|
340 |
|
|
341 |
|
FactoryCubit factory = FactoryCubit.getInstance();
|
342 |
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
343 |
|
mMeshes[0] = factory.createRoundedSolid(vertices, vertIndexes,
|
344 |
|
bands, bandIndexes,
|
345 |
|
corners, cornerIndexes,
|
346 |
|
centers, centerIndexes,
|
347 |
|
getNumCubitFaces(), convexCenter );
|
348 |
|
}
|
349 |
|
mesh = mMeshes[0].copy(true);
|
350 |
|
}
|
351 |
|
else
|
352 |
|
{
|
353 |
|
if( mMeshes[1]==null )
|
354 |
|
{
|
355 |
|
final float angle = (float)Math.PI/(2*IVY_N);
|
356 |
|
final float CORR = 1.0f - 2*IVY_D;
|
357 |
|
double[][] vertices = new double[2*IVY_N][3];
|
358 |
|
int[][] vert_indices = new int[2][2*IVY_N];
|
|
384 |
private int getNumCubitVariants(int numLayers)
|
|
385 |
{
|
|
386 |
return 2;
|
|
387 |
}
|
359 |
388 |
|
360 |
|
int[] bandIndexes= new int[] { 0,1 };
|
361 |
|
int[] indexes = new int[2*IVY_N];
|
362 |
|
float[][] corners= new float[][] { {0.03f,0.10f} };
|
363 |
|
float[][] centers= new float[][] { {-0.0f,-0.0f,-0.5f} };
|
|
389 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
364 |
390 |
|
365 |
|
for(int i=0; i<IVY_N; i++)
|
366 |
|
{
|
367 |
|
double sin = Math.sin(i*angle);
|
368 |
|
double cos = Math.cos(i*angle);
|
369 |
|
|
370 |
|
vertices[i ][0] = CORR*(0.5f-cos);
|
371 |
|
vertices[i ][1] = CORR*(0.5f-sin);
|
372 |
|
vertices[i ][2] = 0;
|
373 |
|
vertices[i+IVY_N][0] = CORR*(cos-0.5f);
|
374 |
|
vertices[i+IVY_N][1] = CORR*(sin-0.5f);
|
375 |
|
vertices[i+IVY_N][2] = 0;
|
376 |
|
}
|
377 |
|
|
378 |
|
for(int i=0; i<2*IVY_N; i++)
|
379 |
|
{
|
380 |
|
vert_indices[0][i] = i;
|
381 |
|
vert_indices[1][i] = 2*IVY_N-1-i;
|
382 |
|
}
|
|
391 |
int getCubitVariant(int cubit, int numLayers)
|
|
392 |
{
|
|
393 |
return cubit<4 ? 0:1;
|
|
394 |
}
|
383 |
395 |
|
384 |
|
for(int i=0; i<2*IVY_N; i++)
|
385 |
|
{
|
386 |
|
indexes[i] = -1;
|
387 |
|
}
|
388 |
|
indexes[0] = indexes[IVY_N] = 0;
|
|
396 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
389 |
397 |
|
390 |
|
float[][] bands =
|
391 |
|
{
|
392 |
|
{+0.03f,35,0.5f,0.5f,5,0,0},
|
393 |
|
{+0.10f,45,0.5f,0.0f,2,0,0}
|
394 |
|
};
|
|
398 |
MeshBase createCubitMesh(int cubit, int numLayers)
|
|
399 |
{
|
|
400 |
int variant = getCubitVariant(cubit,numLayers);
|
395 |
401 |
|
396 |
|
FactoryCubit factory = FactoryCubit.getInstance();
|
397 |
|
factory.createNewFaceTransform(vertices,vert_indices);
|
398 |
|
mMeshes[1] = factory.createRoundedSolid(vertices, vert_indices,
|
399 |
|
bands, bandIndexes,
|
400 |
|
corners, indexes,
|
401 |
|
centers, indexes,
|
402 |
|
getNumCubitFaces(), null );
|
403 |
|
}
|
404 |
|
mesh = mMeshes[1].copy(true);
|
|
402 |
if( mMeshes==null )
|
|
403 |
{
|
|
404 |
FactoryCubit factory = FactoryCubit.getInstance();
|
|
405 |
factory.clear();
|
|
406 |
mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
|
|
407 |
}
|
|
408 |
|
|
409 |
if( mMeshes[variant]==null )
|
|
410 |
{
|
|
411 |
ObjectShape shape = getObjectShape(cubit,numLayers);
|
|
412 |
FactoryCubit factory = FactoryCubit.getInstance();
|
|
413 |
factory.createNewFaceTransform(shape);
|
|
414 |
mMeshes[variant] = factory.createRoundedSolid(shape);
|
405 |
415 |
}
|
406 |
416 |
|
407 |
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) );
|
|
417 |
MeshBase mesh = mMeshes[variant].copy(true);
|
|
418 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
|
408 |
419 |
mesh.apply(quat,0xffffffff,0);
|
409 |
420 |
|
410 |
421 |
return mesh;
|
Move 1) Helicopter 2) Ivy to the new cubit creation scheme.