Revision f925d455
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/objectlib/main/ObjectType.java | ||
---|---|---|
99 | 99 |
DINO_3 ( TwistyDino6.class , 10, R.drawable.dino_3, true, 0, new InitData(new int[] {3,3,3,3})), |
100 | 100 |
DIN4_3 ( TwistyDino4.class , 9, R.drawable.din4_3, true, 30, new InitData(new int[] {3,3,3,3})), |
101 | 101 |
|
102 |
CA_333 ( TwistyCamouflage.class , 32, R.drawable.din4_3, true, 50, new InitData(new int[] {3,3,3}, TwistyCamouflage.CAM_333)),
|
|
102 |
CA_333 ( TwistyCamouflage.class , 32, R.drawable.din4_3, true, 50, new InitData(new int[] {4,4,4}, TwistyCamouflage.CAM_333)),
|
|
103 | 103 |
|
104 | 104 |
PDUO_2 ( TwistyPyraminxDuo.class , 4, R.drawable.pduo_2, false, 0, new InitData(new int[] {2,2,2,2})), |
105 | 105 |
PDIA_3 ( TwistyPyraminxDiamond.class, 12, R.drawable.pdia_3, false, 40, new InitData(new int[] {3,3,3})), |
src/main/java/org/distorted/objectlib/objects/TwistyBandagedAbstract.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.objects; |
11 | 11 |
|
12 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID; |
|
13 | 12 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT; |
14 | 13 |
|
15 |
import org.distorted.library.effect.EffectName; |
|
16 |
import org.distorted.library.main.DistortedLibrary; |
|
17 | 14 |
import org.distorted.library.type.Static3D; |
18 | 15 |
import org.distorted.library.type.Static4D; |
19 |
import org.distorted.objectlib.helpers.FactoryBandagedCubit; |
|
20 |
import org.distorted.objectlib.helpers.ObjectFaceShape; |
|
21 | 16 |
import org.distorted.objectlib.helpers.ObjectShape; |
22 | 17 |
import org.distorted.objectlib.helpers.ObjectSignature; |
23 |
import org.distorted.objectlib.helpers.ObjectVertexEffects; |
|
24 | 18 |
import org.distorted.objectlib.main.InitData; |
25 | 19 |
import org.distorted.objectlib.scrambling.ScrambleState; |
26 | 20 |
import org.distorted.objectlib.shape.ShapeHexahedron; |
... | ... | |
32 | 26 |
|
33 | 27 |
public abstract class TwistyBandagedAbstract extends ShapeHexahedron |
34 | 28 |
{ |
35 |
private static final int CUBIT_111 = 0; |
|
36 |
private static final int CUBIT_211 = 1; |
|
37 |
private static final int CUBIT_311 = 2; |
|
38 |
private static final int CUBIT_221 = 3; |
|
39 |
private static final int CUBIT_222 = 4; |
|
40 |
private static final int CUBIT_OTH = 5; |
|
41 |
|
|
42 | 29 |
// the three rotation axis of a 3x3 Cube. Must be normalized. |
43 | 30 |
static final Static3D[] ROT_AXIS = new Static3D[] |
44 | 31 |
{ |
... | ... | |
47 | 34 |
new Static3D(0,0,1) |
48 | 35 |
}; |
49 | 36 |
|
50 |
private static final int[][] mDims = new int[][] |
|
51 |
{ |
|
52 |
{1,1,1}, // has to be X>=Z>=Y so that all |
|
53 |
{2,1,1}, // the faces are horizontal |
|
54 |
{3,1,1}, |
|
55 |
{2,1,2}, |
|
56 |
{2,2,2}, |
|
57 |
}; |
|
58 |
|
|
59 | 37 |
private int[][] mBasicAngle; |
60 |
private Static4D[] mInitQuats; |
|
61 | 38 |
private float[][] mCuts; |
62 |
private int[] mCubitVariantMap; |
|
63 |
private int[] mTypeVariantMap; |
|
64 | 39 |
private int[][] mSolvedQuatsAbstract; |
65 | 40 |
|
66 | 41 |
protected ObjectShape[] mTmpShapes; |
... | ... | |
75 | 50 |
super(data, meshState, iconMode, size, quat, move, scale, stream); |
76 | 51 |
} |
77 | 52 |
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
abstract float[][] getVertices(int variant); |
|
81 |
|
|
82 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 54 |
// return 0 if cubit is 'external' (it has at least two walls which belong to two different faces |
84 | 55 |
// of the cuboid, faces which do not both rotate along the same axis! So: it is an edge, a corner, |
... | ... | |
113 | 84 |
return 0; |
114 | 85 |
} |
115 | 86 |
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
float[][] getPositions() |
|
90 |
{ |
|
91 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
92 |
return mPosition; |
|
93 |
} |
|
94 |
|
|
116 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
117 | 96 |
// If we have a flat cuboid than retCubitSolvedStatus() wrongly reports that the internal cubits |
118 | 97 |
// are edges (they do have two non-black faces after all!) which leads to wrong solvedQuats and |
... | ... | |
203 | 182 |
return 2; |
204 | 183 |
} |
205 | 184 |
|
206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
207 |
|
|
208 |
private int getType(float[] pos) |
|
209 |
{ |
|
210 |
switch(pos.length) |
|
211 |
{ |
|
212 |
case 3: return CUBIT_111; |
|
213 |
case 6: return CUBIT_211; |
|
214 |
case 9: boolean x1 = (pos[0]==pos[3] && pos[0]==pos[6]); |
|
215 |
boolean y1 = (pos[1]==pos[4] && pos[1]==pos[7]); |
|
216 |
boolean z1 = (pos[2]==pos[5] && pos[2]==pos[8]); |
|
217 |
return ( (x1&&y1) || (x1&&z1) || (y1&&z1) ) ? CUBIT_311 : CUBIT_OTH; |
|
218 |
case 12: float x = (pos[0]+pos[3]+pos[6]+pos[ 9])/4; |
|
219 |
float y = (pos[1]+pos[4]+pos[7]+pos[10])/4; |
|
220 |
float z = (pos[2]+pos[5]+pos[8]+pos[11])/4; |
|
221 |
float d1 = (pos[0]-x)*(pos[0]-x) + (pos[ 1]-y)*(pos[ 1]-y) + (pos[ 2]-z)*(pos[ 2]-z); |
|
222 |
float d2 = (pos[3]-x)*(pos[3]-x) + (pos[ 4]-y)*(pos[ 4]-y) + (pos[ 5]-z)*(pos[ 5]-z); |
|
223 |
float d3 = (pos[6]-x)*(pos[6]-x) + (pos[ 7]-y)*(pos[ 7]-y) + (pos[ 8]-z)*(pos[ 8]-z); |
|
224 |
float d4 = (pos[9]-x)*(pos[9]-x) + (pos[10]-y)*(pos[10]-y) + (pos[11]-z)*(pos[11]-z); |
|
225 |
return ( d1==0.5f && d2==0.5f && d3==0.5f && d4==0.5f ) ? CUBIT_221 : CUBIT_OTH; |
|
226 |
case 24: float x3 = pos[0]; |
|
227 |
float y3 = pos[1]; |
|
228 |
float z3 = pos[2]; |
|
229 |
float x4=-10,y4=-10,z4=-10; |
|
230 |
int i; |
|
231 |
|
|
232 |
for(i=0; i<8; i++) |
|
233 |
{ |
|
234 |
if( pos[3*i]!=x3 && pos[3*i+1]!=y3 && pos[3*i+2]!=z3 ) |
|
235 |
{ |
|
236 |
x4 = pos[3*i ]; |
|
237 |
y4 = pos[3*i+1]; |
|
238 |
z4 = pos[3*i+2]; |
|
239 |
break; |
|
240 |
} |
|
241 |
} |
|
242 |
if( i==9 ) return CUBIT_OTH; |
|
243 |
|
|
244 |
float dX = x4-x3; |
|
245 |
float dY = y4-y3; |
|
246 |
float dZ = z4-z3; |
|
247 |
|
|
248 |
if( (dX==1.0f || dX==-1.0f) && (dY==1.0f || dY==-1.0f) && (dZ==1.0f || dZ==-1.0f) ) |
|
249 |
{ |
|
250 |
for(i=0; i<8; i++) |
|
251 |
{ |
|
252 |
if( (pos[3*i ]!=x3 && pos[3*i ]!=x4) || |
|
253 |
(pos[3*i+1]!=y3 && pos[3*i+1]!=y4) || |
|
254 |
(pos[3*i+2]!=z3 && pos[3*i+2]!=z4) ) return CUBIT_OTH; |
|
255 |
} |
|
256 |
|
|
257 |
return CUBIT_222; |
|
258 |
} |
|
259 |
|
|
260 |
default: return CUBIT_OTH; |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
265 |
|
|
266 |
private int getQuatIndex(int cubit) |
|
267 |
{ |
|
268 |
float[][] positions = getPositions(); |
|
269 |
int len = positions.length; |
|
270 |
|
|
271 |
if( cubit>=0 && cubit<len ) |
|
272 |
{ |
|
273 |
float[] pos = positions[cubit]; |
|
274 |
int type = getType(pos); |
|
275 |
|
|
276 |
switch(type) |
|
277 |
{ |
|
278 |
case CUBIT_222: |
|
279 |
case CUBIT_111: return 0; |
|
280 |
case CUBIT_211: |
|
281 |
case CUBIT_311: return (pos[1]==pos[4]) ? (pos[0]==pos[3] ? 2 : 0) : 3; |
|
282 |
case CUBIT_221: if( pos[0]==pos[3] && pos[0]==pos[6] ) return 3; |
|
283 |
if( pos[1]==pos[4] && pos[1]==pos[7] ) return 0; |
|
284 |
if( pos[2]==pos[5] && pos[2]==pos[8] ) return 1; |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
return 0; |
|
289 |
} |
|
290 |
|
|
291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
292 |
|
|
293 |
protected int[] getDim(int variant) |
|
294 |
{ |
|
295 |
int type,numTypes = mDims.length; |
|
296 |
for(type=0; type<numTypes; type++) if( mTypeVariantMap[type]==variant ) break; |
|
297 |
return type<numTypes ? mDims[type] : null; |
|
298 |
} |
|
299 |
|
|
300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
301 |
|
|
302 |
protected void produceTmpShape(int variant) |
|
303 |
{ |
|
304 |
float[][] positions = getPositions(); |
|
305 |
int cubit,numCubits = positions.length; |
|
306 |
|
|
307 |
for(cubit=0; cubit<numCubits; cubit++) |
|
308 |
{ |
|
309 |
if( mCubitVariantMap[cubit]==variant ) break; |
|
310 |
} |
|
311 |
|
|
312 |
if( cubit>=numCubits ) |
|
313 |
{ |
|
314 |
android.util.Log.e("D", "unknown variant: "+variant); |
|
315 |
} |
|
316 |
else |
|
317 |
{ |
|
318 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
319 |
mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]); |
|
320 |
} |
|
321 |
} |
|
322 |
|
|
323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
324 |
|
|
325 |
public ObjectShape getObjectShape(int variant) |
|
326 |
{ |
|
327 |
if( getDim(variant)!=null ) |
|
328 |
{ |
|
329 |
int[][] indices = |
|
330 |
{ |
|
331 |
{2,3,1,0}, |
|
332 |
{7,6,4,5}, |
|
333 |
{4,0,1,5}, |
|
334 |
{7,3,2,6}, |
|
335 |
{6,2,0,4}, |
|
336 |
{3,7,5,1}, |
|
337 |
}; |
|
338 |
|
|
339 |
return new ObjectShape( getVertices(variant), indices); |
|
340 |
} |
|
341 |
|
|
342 |
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants]; |
|
343 |
if( mTmpShapes[variant]==null )produceTmpShape(variant); |
|
344 |
return mTmpShapes[variant]; |
|
345 |
} |
|
346 |
|
|
347 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
348 |
|
|
349 |
public ObjectFaceShape getObjectFaceShape(int variant) |
|
350 |
{ |
|
351 |
int[] numLayers = getNumLayers(); |
|
352 |
int size = (numLayers[0]+numLayers[1]+numLayers[2])/3; |
|
353 |
int[] dim = getDim(variant); |
|
354 |
|
|
355 |
if( dim!=null ) |
|
356 |
{ |
|
357 |
int X = dim[0]; |
|
358 |
int Y = dim[1]; |
|
359 |
int Z = dim[2]; |
|
360 |
|
|
361 |
float height = isInIconMode() ? 0.001f : size<=5 ? 0.048f : 0.020f; |
|
362 |
int[] bandIndices= { 0,0,1,1,2,2 }; |
|
363 |
|
|
364 |
int maxXY = Math.max(X,Y); |
|
365 |
int maxXZ = Math.max(X,Z); |
|
366 |
int maxYZ = Math.max(Y,Z); |
|
367 |
|
|
368 |
int angle = 45; |
|
369 |
float R = 0.25f; |
|
370 |
float S = 0.50f; |
|
371 |
float N = size<=4 ? 5 : size<=5 ? 4 : 3; |
|
372 |
|
|
373 |
float[][] bands = |
|
374 |
{ |
|
375 |
{height/maxYZ,angle,R,S,N,0,0}, |
|
376 |
{height/maxXZ,angle,R,S,N,0,0}, |
|
377 |
{height/maxXY,angle,R,S,N,0,0} |
|
378 |
}; |
|
379 |
|
|
380 |
return new ObjectFaceShape(bands,bandIndices,null); |
|
381 |
} |
|
382 |
|
|
383 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
384 |
return factory.createIrregularFaceShape(variant, isInIconMode() ); |
|
385 |
} |
|
386 |
|
|
387 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
388 |
|
|
389 |
public ObjectVertexEffects getVertexEffects(int variant) |
|
390 |
{ |
|
391 |
int[] numLayers = getNumLayers(); |
|
392 |
int size = (numLayers[0]+numLayers[1]+numLayers[2])/3; |
|
393 |
boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode()); |
|
394 |
|
|
395 |
if( getDim(variant)!=null ) |
|
396 |
{ |
|
397 |
float[][] vertices = getVertices(variant); |
|
398 |
float strength = -0.04f; |
|
399 |
|
|
400 |
float[][] variables = |
|
401 |
{ |
|
402 |
{ 0, strength*vertices[0][0], strength*vertices[0][1], strength*vertices[0][2], 1 }, |
|
403 |
{ 0, strength*vertices[1][0], strength*vertices[1][1], strength*vertices[1][2], 1 }, |
|
404 |
{ 0, strength*vertices[2][0], strength*vertices[2][1], strength*vertices[2][2], 1 }, |
|
405 |
{ 0, strength*vertices[3][0], strength*vertices[3][1], strength*vertices[3][2], 1 }, |
|
406 |
{ 0, strength*vertices[4][0], strength*vertices[4][1], strength*vertices[4][2], 1 }, |
|
407 |
{ 0, strength*vertices[5][0], strength*vertices[5][1], strength*vertices[5][2], 1 }, |
|
408 |
{ 0, strength*vertices[6][0], strength*vertices[6][1], strength*vertices[6][2], 1 }, |
|
409 |
{ 0, strength*vertices[7][0], strength*vertices[7][1], strength*vertices[7][2], 1 }, |
|
410 |
}; |
|
411 |
|
|
412 |
String name = EffectName.DEFORM.name(); |
|
413 |
float[] reg = {0,0,0,0.15f}; |
|
414 |
|
|
415 |
String[] names = {name,name,name,name,name,name,name,name}; |
|
416 |
float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg}; |
|
417 |
boolean[] uses = {round,round,round,round,round,round,round,round}; |
|
418 |
|
|
419 |
return new ObjectVertexEffects(names,variables,vertices,regions,uses); |
|
420 |
} |
|
421 |
|
|
422 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
423 |
return factory.createVertexEffects(variant,round); |
|
424 |
} |
|
425 |
|
|
426 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
427 |
|
|
428 |
public float[][] getCubitPositions(int[] numLayers) |
|
429 |
{ |
|
430 |
return getPositions(); |
|
431 |
} |
|
432 |
|
|
433 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
434 |
|
|
435 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
|
436 |
{ |
|
437 |
if( mInitQuats ==null ) |
|
438 |
{ |
|
439 |
mInitQuats = new Static4D[] |
|
440 |
{ |
|
441 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f), // NULL |
|
442 |
new Static4D( SQ2/2, 0.0f, 0.0f, -SQ2/2), // X |
|
443 |
new Static4D( 0.0f, SQ2/2, 0.0f, -SQ2/2), // Y |
|
444 |
new Static4D( 0.0f, 0.0f, SQ2/2, -SQ2/2), // Z |
|
445 |
new Static4D( -0.5f, +0.5f, -0.5f, +0.5f), // ZX |
|
446 |
new Static4D( +0.5f, +0.5f, +0.5f, -0.5f), // YX |
|
447 |
}; |
|
448 |
} |
|
449 |
|
|
450 |
return mInitQuats[getQuatIndex(cubit)]; |
|
451 |
} |
|
452 |
|
|
453 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
454 |
|
|
455 |
public int getNumCubitVariants(int[] numLayers) |
|
456 |
{ |
|
457 |
if( mNumVariants==0 ) |
|
458 |
{ |
|
459 |
float[][] positions = getPositions(); |
|
460 |
boolean C111=false; |
|
461 |
boolean C211=false; |
|
462 |
boolean C311=false; |
|
463 |
boolean C221=false; |
|
464 |
boolean C222=false; |
|
465 |
|
|
466 |
int numCubits = positions.length; |
|
467 |
mCubitVariantMap = new int[numCubits]; |
|
468 |
|
|
469 |
int numTypes = mDims.length; |
|
470 |
mTypeVariantMap = new int[numTypes]; |
|
471 |
for(int i=0; i<numTypes; i++) mTypeVariantMap[i] = -1; |
|
472 |
|
|
473 |
for (int cubit=0; cubit<numCubits; cubit++) |
|
474 |
{ |
|
475 |
int type = getType(positions[cubit]); |
|
476 |
|
|
477 |
switch (type) |
|
478 |
{ |
|
479 |
case CUBIT_111: if (!C111) { C111 = true; mTypeVariantMap[CUBIT_111]=mNumVariants++; } |
|
480 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_111]; |
|
481 |
break; |
|
482 |
case CUBIT_211: if (!C211) { C211 = true; mTypeVariantMap[CUBIT_211]=mNumVariants++; } |
|
483 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_211]; |
|
484 |
break; |
|
485 |
case CUBIT_311: if (!C311) { C311 = true; mTypeVariantMap[CUBIT_311]=mNumVariants++; } |
|
486 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_311]; |
|
487 |
break; |
|
488 |
case CUBIT_221: if (!C221) { C221 = true; mTypeVariantMap[CUBIT_221]=mNumVariants++; } |
|
489 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_221]; |
|
490 |
break; |
|
491 |
case CUBIT_222: if (!C222) { C222 = true; mTypeVariantMap[CUBIT_222]=mNumVariants++; } |
|
492 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_222]; |
|
493 |
break; |
|
494 |
default : mCubitVariantMap[cubit] = mNumVariants++; |
|
495 |
} |
|
496 |
} |
|
497 |
|
|
498 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
499 |
factory.prepare(mNumVariants,numLayers[0],numLayers[1],numLayers[2]); |
|
500 |
} |
|
501 |
|
|
502 |
return mNumVariants; |
|
503 |
} |
|
504 |
|
|
505 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
506 |
|
|
507 |
public int getCubitVariant(int cubit, int[] numLayers) |
|
508 |
{ |
|
509 |
return mCubitVariantMap[cubit]; |
|
510 |
} |
|
511 |
|
|
512 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
513 | 186 |
|
514 | 187 |
public float[][] getCuts(int[] numLayers) |
... | ... | |
549 | 222 |
return layerRotatable; |
550 | 223 |
} |
551 | 224 |
|
552 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
553 |
|
|
554 |
public int getTouchControlType() |
|
555 |
{ |
|
556 |
return TC_CUBOID; |
|
557 |
} |
|
558 |
|
|
559 | 225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
560 | 226 |
|
561 | 227 |
public int getTouchControlSplit() |
... | ... | |
591 | 257 |
|
592 | 258 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
593 | 259 |
|
594 |
public float getStickerRadius() |
|
595 |
{ |
|
596 |
return 0.10f; |
|
597 |
} |
|
598 |
|
|
599 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
600 |
|
|
601 |
public float getStickerStroke() |
|
260 |
public float[][] getStickerAngles() |
|
602 | 261 |
{ |
603 |
return isInIconMode() ? 0.16f : 0.08f;
|
|
262 |
return null;
|
|
604 | 263 |
} |
605 | 264 |
|
606 | 265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
607 | 266 |
|
608 |
public float[][] getStickerAngles()
|
|
267 |
public float[][] getCubitPositions(int[] numLayers)
|
|
609 | 268 |
{ |
610 |
return null;
|
|
269 |
return getPositions();
|
|
611 | 270 |
} |
612 | 271 |
|
613 | 272 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
614 |
// PUBLIC API |
|
615 | 273 |
|
616 | 274 |
public Static3D[] getRotationAxis() |
617 | 275 |
{ |
... | ... | |
645 | 303 |
|
646 | 304 |
return mBasicAngle; |
647 | 305 |
} |
648 |
|
|
649 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
650 |
|
|
651 |
float[][] getPositions() |
|
652 |
{ |
|
653 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
654 |
return mPosition; |
|
655 |
} |
|
656 | 306 |
} |
src/main/java/org/distorted/objectlib/objects/TwistyBandagedCuboid.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.objects; |
11 | 11 |
|
12 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID; |
|
13 |
|
|
12 | 14 |
import java.io.InputStream; |
13 | 15 |
|
16 |
import org.distorted.library.effect.EffectName; |
|
17 |
import org.distorted.library.main.DistortedLibrary; |
|
14 | 18 |
import org.distorted.library.type.Static3D; |
15 | 19 |
import org.distorted.library.type.Static4D; |
16 | 20 |
|
21 |
import org.distorted.objectlib.helpers.FactoryBandagedCubit; |
|
22 |
import org.distorted.objectlib.helpers.ObjectFaceShape; |
|
17 | 23 |
import org.distorted.objectlib.helpers.ObjectSignature; |
24 |
import org.distorted.objectlib.helpers.ObjectVertexEffects; |
|
18 | 25 |
import org.distorted.objectlib.main.InitData; |
19 | 26 |
import org.distorted.objectlib.helpers.ObjectShape; |
20 | 27 |
import org.distorted.objectlib.main.ObjectType; |
... | ... | |
25 | 32 |
{ |
26 | 33 |
private static final String OBJECT_NAME = "LOCAL_BANDAGED"; |
27 | 34 |
|
35 |
private static final int CUBIT_111 = 0; |
|
36 |
private static final int CUBIT_211 = 1; |
|
37 |
private static final int CUBIT_311 = 2; |
|
38 |
private static final int CUBIT_221 = 3; |
|
39 |
private static final int CUBIT_222 = 4; |
|
40 |
private static final int CUBIT_OTH = 5; |
|
41 |
|
|
42 |
private static final int[][] mDims = new int[][] |
|
43 |
{ |
|
44 |
{1,1,1}, // has to be X>=Z>=Y so that all |
|
45 |
{2,1,1}, // the faces are horizontal |
|
46 |
{3,1,1}, |
|
47 |
{2,1,2}, |
|
48 |
{2,2,2}, |
|
49 |
}; |
|
50 |
|
|
28 | 51 |
public static final float[][] POS_1 = new float[][] |
29 | 52 |
{ |
30 | 53 |
{-1.0f, -1.0f, +0.0f, |
... | ... | |
120 | 143 |
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, -1.0f} |
121 | 144 |
}; |
122 | 145 |
|
146 |
private int[] mCubitVariantMap; |
|
147 |
private int[] mTypeVariantMap; |
|
148 |
private Static4D[] mInitQuats; |
|
149 |
|
|
123 | 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 151 |
|
125 | 152 |
public static int getType(String shortName, String longName) |
... | ... | |
143 | 170 |
|
144 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
145 | 172 |
|
146 |
float[][] getVertices(int variant) |
|
173 |
private int getType(float[] pos) |
|
174 |
{ |
|
175 |
switch(pos.length) |
|
176 |
{ |
|
177 |
case 3: return CUBIT_111; |
|
178 |
case 6: return CUBIT_211; |
|
179 |
case 9: boolean x1 = (pos[0]==pos[3] && pos[0]==pos[6]); |
|
180 |
boolean y1 = (pos[1]==pos[4] && pos[1]==pos[7]); |
|
181 |
boolean z1 = (pos[2]==pos[5] && pos[2]==pos[8]); |
|
182 |
return ( (x1&&y1) || (x1&&z1) || (y1&&z1) ) ? CUBIT_311 : CUBIT_OTH; |
|
183 |
case 12: float x = (pos[0]+pos[3]+pos[6]+pos[ 9])/4; |
|
184 |
float y = (pos[1]+pos[4]+pos[7]+pos[10])/4; |
|
185 |
float z = (pos[2]+pos[5]+pos[8]+pos[11])/4; |
|
186 |
float d1 = (pos[0]-x)*(pos[0]-x) + (pos[ 1]-y)*(pos[ 1]-y) + (pos[ 2]-z)*(pos[ 2]-z); |
|
187 |
float d2 = (pos[3]-x)*(pos[3]-x) + (pos[ 4]-y)*(pos[ 4]-y) + (pos[ 5]-z)*(pos[ 5]-z); |
|
188 |
float d3 = (pos[6]-x)*(pos[6]-x) + (pos[ 7]-y)*(pos[ 7]-y) + (pos[ 8]-z)*(pos[ 8]-z); |
|
189 |
float d4 = (pos[9]-x)*(pos[9]-x) + (pos[10]-y)*(pos[10]-y) + (pos[11]-z)*(pos[11]-z); |
|
190 |
return ( d1==0.5f && d2==0.5f && d3==0.5f && d4==0.5f ) ? CUBIT_221 : CUBIT_OTH; |
|
191 |
case 24: float x3 = pos[0]; |
|
192 |
float y3 = pos[1]; |
|
193 |
float z3 = pos[2]; |
|
194 |
float x4=-10,y4=-10,z4=-10; |
|
195 |
int i; |
|
196 |
|
|
197 |
for(i=0; i<8; i++) |
|
198 |
{ |
|
199 |
if( pos[3*i]!=x3 && pos[3*i+1]!=y3 && pos[3*i+2]!=z3 ) |
|
200 |
{ |
|
201 |
x4 = pos[3*i ]; |
|
202 |
y4 = pos[3*i+1]; |
|
203 |
z4 = pos[3*i+2]; |
|
204 |
break; |
|
205 |
} |
|
206 |
} |
|
207 |
if( i==9 ) return CUBIT_OTH; |
|
208 |
|
|
209 |
float dX = x4-x3; |
|
210 |
float dY = y4-y3; |
|
211 |
float dZ = z4-z3; |
|
212 |
|
|
213 |
if( (dX==1.0f || dX==-1.0f) && (dY==1.0f || dY==-1.0f) && (dZ==1.0f || dZ==-1.0f) ) |
|
214 |
{ |
|
215 |
for(i=0; i<8; i++) |
|
216 |
{ |
|
217 |
if( (pos[3*i ]!=x3 && pos[3*i ]!=x4) || |
|
218 |
(pos[3*i+1]!=y3 && pos[3*i+1]!=y4) || |
|
219 |
(pos[3*i+2]!=z3 && pos[3*i+2]!=z4) ) return CUBIT_OTH; |
|
220 |
} |
|
221 |
|
|
222 |
return CUBIT_222; |
|
223 |
} |
|
224 |
|
|
225 |
default: return CUBIT_OTH; |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
230 |
|
|
231 |
private int getQuatIndex(int cubit) |
|
232 |
{ |
|
233 |
float[][] positions = getPositions(); |
|
234 |
int len = positions.length; |
|
235 |
|
|
236 |
if( cubit>=0 && cubit<len ) |
|
237 |
{ |
|
238 |
float[] pos = positions[cubit]; |
|
239 |
int type = getType(pos); |
|
240 |
|
|
241 |
switch(type) |
|
242 |
{ |
|
243 |
case CUBIT_222: |
|
244 |
case CUBIT_111: return 0; |
|
245 |
case CUBIT_211: |
|
246 |
case CUBIT_311: return (pos[1]==pos[4]) ? (pos[0]==pos[3] ? 2 : 0) : 3; |
|
247 |
case CUBIT_221: if( pos[0]==pos[3] && pos[0]==pos[6] ) return 3; |
|
248 |
if( pos[1]==pos[4] && pos[1]==pos[7] ) return 0; |
|
249 |
if( pos[2]==pos[5] && pos[2]==pos[8] ) return 1; |
|
250 |
} |
|
251 |
} |
|
252 |
|
|
253 |
return 0; |
|
254 |
} |
|
255 |
|
|
256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
257 |
|
|
258 |
private int[] getDim(int variant) |
|
259 |
{ |
|
260 |
int type,numTypes = mDims.length; |
|
261 |
for(type=0; type<numTypes; type++) if( mTypeVariantMap[type]==variant ) break; |
|
262 |
return type<numTypes ? mDims[type] : null; |
|
263 |
} |
|
264 |
|
|
265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
266 |
|
|
267 |
private void produceTmpShape(int variant) |
|
268 |
{ |
|
269 |
float[][] positions = getPositions(); |
|
270 |
int cubit,numCubits = positions.length; |
|
271 |
|
|
272 |
for(cubit=0; cubit<numCubits; cubit++) |
|
273 |
{ |
|
274 |
if( mCubitVariantMap[cubit]==variant ) break; |
|
275 |
} |
|
276 |
|
|
277 |
if( cubit>=numCubits ) |
|
278 |
{ |
|
279 |
android.util.Log.e("D", "unknown variant: "+variant); |
|
280 |
} |
|
281 |
else |
|
282 |
{ |
|
283 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
284 |
mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]); |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
289 |
// PUBLIC API |
|
290 |
|
|
291 |
public int getTouchControlType() |
|
292 |
{ |
|
293 |
return TC_CUBOID; |
|
294 |
} |
|
295 |
|
|
296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
297 |
|
|
298 |
public ObjectShape getObjectShape(int variant) |
|
299 |
{ |
|
300 |
if( getDim(variant)!=null ) |
|
301 |
{ |
|
302 |
int[][] indices = |
|
303 |
{ |
|
304 |
{2,3,1,0}, |
|
305 |
{7,6,4,5}, |
|
306 |
{4,0,1,5}, |
|
307 |
{7,3,2,6}, |
|
308 |
{6,2,0,4}, |
|
309 |
{3,7,5,1}, |
|
310 |
}; |
|
311 |
|
|
312 |
return new ObjectShape( getVertices(variant), indices); |
|
313 |
} |
|
314 |
|
|
315 |
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants]; |
|
316 |
if( mTmpShapes[variant]==null ) produceTmpShape(variant); |
|
317 |
return mTmpShapes[variant]; |
|
318 |
} |
|
319 |
|
|
320 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
321 |
|
|
322 |
public ObjectFaceShape getObjectFaceShape(int variant) |
|
323 |
{ |
|
324 |
int[] numLayers = getNumLayers(); |
|
325 |
int size = (numLayers[0]+numLayers[1]+numLayers[2])/3; |
|
326 |
int[] dim = getDim(variant); |
|
327 |
|
|
328 |
if( dim!=null ) |
|
329 |
{ |
|
330 |
int X = dim[0]; |
|
331 |
int Y = dim[1]; |
|
332 |
int Z = dim[2]; |
|
333 |
|
|
334 |
float height = isInIconMode() ? 0.001f : size<=5 ? 0.048f : 0.020f; |
|
335 |
int[] bandIndices= { 0,0,1,1,2,2 }; |
|
336 |
|
|
337 |
int maxXY = Math.max(X,Y); |
|
338 |
int maxXZ = Math.max(X,Z); |
|
339 |
int maxYZ = Math.max(Y,Z); |
|
340 |
|
|
341 |
int angle = 45; |
|
342 |
float R = 0.25f; |
|
343 |
float S = 0.50f; |
|
344 |
float N = size<=4 ? 5 : size<=5 ? 4 : 3; |
|
345 |
|
|
346 |
float[][] bands = |
|
347 |
{ |
|
348 |
{height/maxYZ,angle,R,S,N,0,0}, |
|
349 |
{height/maxXZ,angle,R,S,N,0,0}, |
|
350 |
{height/maxXY,angle,R,S,N,0,0} |
|
351 |
}; |
|
352 |
|
|
353 |
return new ObjectFaceShape(bands,bandIndices,null); |
|
354 |
} |
|
355 |
|
|
356 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
357 |
return factory.createIrregularFaceShape(variant, isInIconMode() ); |
|
358 |
} |
|
359 |
|
|
360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
361 |
|
|
362 |
public ObjectVertexEffects getVertexEffects(int variant) |
|
363 |
{ |
|
364 |
int[] numLayers = getNumLayers(); |
|
365 |
int size = (numLayers[0]+numLayers[1]+numLayers[2])/3; |
|
366 |
boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode()); |
|
367 |
|
|
368 |
if( getDim(variant)!=null ) |
|
369 |
{ |
|
370 |
float[][] vertices = getVertices(variant); |
|
371 |
float strength = -0.04f; |
|
372 |
|
|
373 |
float[][] variables = |
|
374 |
{ |
|
375 |
{ 0, strength*vertices[0][0], strength*vertices[0][1], strength*vertices[0][2], 1 }, |
|
376 |
{ 0, strength*vertices[1][0], strength*vertices[1][1], strength*vertices[1][2], 1 }, |
|
377 |
{ 0, strength*vertices[2][0], strength*vertices[2][1], strength*vertices[2][2], 1 }, |
|
378 |
{ 0, strength*vertices[3][0], strength*vertices[3][1], strength*vertices[3][2], 1 }, |
|
379 |
{ 0, strength*vertices[4][0], strength*vertices[4][1], strength*vertices[4][2], 1 }, |
|
380 |
{ 0, strength*vertices[5][0], strength*vertices[5][1], strength*vertices[5][2], 1 }, |
|
381 |
{ 0, strength*vertices[6][0], strength*vertices[6][1], strength*vertices[6][2], 1 }, |
|
382 |
{ 0, strength*vertices[7][0], strength*vertices[7][1], strength*vertices[7][2], 1 }, |
|
383 |
}; |
|
384 |
|
|
385 |
String name = EffectName.DEFORM.name(); |
|
386 |
float[] reg = {0,0,0,0.15f}; |
|
387 |
|
|
388 |
String[] names = {name,name,name,name,name,name,name,name}; |
|
389 |
float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg}; |
|
390 |
boolean[] uses = {round,round,round,round,round,round,round,round}; |
|
391 |
|
|
392 |
return new ObjectVertexEffects(names,variables,vertices,regions,uses); |
|
393 |
} |
|
394 |
|
|
395 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
396 |
return factory.createVertexEffects(variant,round); |
|
397 |
} |
|
398 |
|
|
399 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
400 |
|
|
401 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
|
402 |
{ |
|
403 |
if( mInitQuats ==null ) |
|
404 |
{ |
|
405 |
mInitQuats = new Static4D[] |
|
406 |
{ |
|
407 |
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f), // NULL |
|
408 |
new Static4D( SQ2/2, 0.0f, 0.0f, -SQ2/2), // X |
|
409 |
new Static4D( 0.0f, SQ2/2, 0.0f, -SQ2/2), // Y |
|
410 |
new Static4D( 0.0f, 0.0f, SQ2/2, -SQ2/2), // Z |
|
411 |
new Static4D( -0.5f, +0.5f, -0.5f, +0.5f), // ZX |
|
412 |
new Static4D( +0.5f, +0.5f, +0.5f, -0.5f), // YX |
|
413 |
}; |
|
414 |
} |
|
415 |
|
|
416 |
return mInitQuats[getQuatIndex(cubit)]; |
|
417 |
} |
|
418 |
|
|
419 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
420 |
|
|
421 |
public int getNumCubitVariants(int[] numLayers) |
|
422 |
{ |
|
423 |
if( mNumVariants==0 ) |
|
424 |
{ |
|
425 |
float[][] positions = getPositions(); |
|
426 |
boolean C111=false; |
|
427 |
boolean C211=false; |
|
428 |
boolean C311=false; |
|
429 |
boolean C221=false; |
|
430 |
boolean C222=false; |
|
431 |
|
|
432 |
int numCubits = positions.length; |
|
433 |
mCubitVariantMap = new int[numCubits]; |
|
434 |
|
|
435 |
int numTypes = mDims.length; |
|
436 |
mTypeVariantMap = new int[numTypes]; |
|
437 |
for(int i=0; i<numTypes; i++) mTypeVariantMap[i] = -1; |
|
438 |
|
|
439 |
for (int cubit=0; cubit<numCubits; cubit++) |
|
440 |
{ |
|
441 |
int type = getType(positions[cubit]); |
|
442 |
|
|
443 |
switch (type) |
|
444 |
{ |
|
445 |
case CUBIT_111: if (!C111) { C111 = true; mTypeVariantMap[CUBIT_111]=mNumVariants++; } |
|
446 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_111]; |
|
447 |
break; |
|
448 |
case CUBIT_211: if (!C211) { C211 = true; mTypeVariantMap[CUBIT_211]=mNumVariants++; } |
|
449 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_211]; |
|
450 |
break; |
|
451 |
case CUBIT_311: if (!C311) { C311 = true; mTypeVariantMap[CUBIT_311]=mNumVariants++; } |
|
452 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_311]; |
|
453 |
break; |
|
454 |
case CUBIT_221: if (!C221) { C221 = true; mTypeVariantMap[CUBIT_221]=mNumVariants++; } |
|
455 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_221]; |
|
456 |
break; |
|
457 |
case CUBIT_222: if (!C222) { C222 = true; mTypeVariantMap[CUBIT_222]=mNumVariants++; } |
|
458 |
mCubitVariantMap[cubit]=mTypeVariantMap[CUBIT_222]; |
|
459 |
break; |
|
460 |
default : mCubitVariantMap[cubit] = mNumVariants++; |
|
461 |
} |
|
462 |
} |
|
463 |
|
|
464 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
|
465 |
factory.prepare(mNumVariants,numLayers[0],numLayers[1],numLayers[2]); |
|
466 |
} |
|
467 |
|
|
468 |
return mNumVariants; |
|
469 |
} |
|
470 |
|
|
471 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
472 |
|
|
473 |
public int getCubitVariant(int cubit, int[] numLayers) |
|
474 |
{ |
|
475 |
return mCubitVariantMap[cubit]; |
|
476 |
} |
|
477 |
|
|
478 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
479 |
|
|
480 |
private float[][] getVertices(int variant) |
|
147 | 481 |
{ |
148 | 482 |
int[] dim = getDim(variant); |
149 | 483 |
|
... | ... | |
174 | 508 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
175 | 509 |
// PUBLIC API |
176 | 510 |
|
511 |
public float getStickerRadius() |
|
512 |
{ |
|
513 |
return 0.10f; |
|
514 |
} |
|
515 |
|
|
516 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
517 |
|
|
518 |
public float getStickerStroke() |
|
519 |
{ |
|
520 |
return isInIconMode() ? 0.16f : 0.08f; |
|
521 |
} |
|
522 |
|
|
523 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
524 |
|
|
177 | 525 |
public String getShortName() |
178 | 526 |
{ |
179 | 527 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
src/main/java/org/distorted/objectlib/objects/TwistyCamouflage.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.objects; |
11 | 11 |
|
12 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD; |
|
13 |
|
|
14 |
import org.distorted.library.effect.EffectName; |
|
12 | 15 |
import org.distorted.library.type.Static3D; |
13 | 16 |
import org.distorted.library.type.Static4D; |
17 |
import org.distorted.objectlib.helpers.ObjectFaceShape; |
|
18 |
import org.distorted.objectlib.helpers.ObjectShape; |
|
14 | 19 |
import org.distorted.objectlib.helpers.ObjectSignature; |
20 |
import org.distorted.objectlib.helpers.ObjectVertexEffects; |
|
15 | 21 |
import org.distorted.objectlib.main.InitData; |
16 | 22 |
import org.distorted.objectlib.main.ObjectType; |
17 | 23 |
|
... | ... | |
23 | 29 |
{ |
24 | 30 |
public static final float[][] CAM_333 = new float[][] |
25 | 31 |
{ |
26 |
// TODO: define centers of the Camouflage 3x3x3 cube. |
|
32 |
getCenters( -1.0f, 1.0f, 1.0f, 2, 2, 2), |
|
33 |
|
|
34 |
getCenters( 0.5f, 1.0f, 1.0f, 1, 2, 2), |
|
35 |
getCenters( 1.5f, 1.0f, 1.0f, 1, 2, 2), |
|
36 |
getCenters( -1.0f,-0.5f, 1.0f, 2, 1, 2), |
|
37 |
getCenters( -1.0f,-1.5f, 1.0f, 2, 1, 2), |
|
38 |
getCenters( -1.0f, 1.0f,-0.5f, 2, 2, 1), |
|
39 |
getCenters( -1.0f, 1.0f,-1.5f, 2, 2, 1), |
|
40 |
|
|
41 |
getCenters( -1.0f,-1.5f,-0.5f, 2, 1, 1), |
|
42 |
getCenters( -1.0f,-1.5f,-1.5f, 2, 1, 1), |
|
43 |
getCenters( -1.0f,-0.5f,-0.5f, 2, 1, 1), |
|
44 |
getCenters( -1.0f,-0.5f,-1.5f, 2, 1, 1), |
|
45 |
getCenters( 0.5f, 1.0f,-1.5f, 1, 2, 1), |
|
46 |
getCenters( 1.5f, 1.0f,-1.5f, 1, 2, 1), |
|
47 |
getCenters( 0.5f, 1.0f,-0.5f, 1, 2, 1), |
|
48 |
getCenters( 1.5f, 1.0f,-0.5f, 1, 2, 1), |
|
49 |
getCenters( 0.5f,-0.5f, 1.0f, 1, 1, 2), |
|
50 |
getCenters( 1.5f,-0.5f, 1.0f, 1, 1, 2), |
|
51 |
getCenters( 0.5f,-1.5f, 1.0f, 1, 1, 2), |
|
52 |
getCenters( 1.5f,-1.5f, 1.0f, 1, 1, 2), |
|
53 |
|
|
54 |
getCenters( 0.5f,-0.5f,-1.5f, 1, 1, 1), |
|
55 |
getCenters( 1.5f,-0.5f,-1.5f, 1, 1, 1), |
|
56 |
getCenters( 0.5f,-1.5f,-1.5f, 1, 1, 1), |
|
57 |
getCenters( 1.5f,-1.5f,-1.5f, 1, 1, 1), |
|
58 |
getCenters( 0.5f,-1.5f,-0.5f, 1, 1, 1), |
|
59 |
getCenters( 1.5f,-0.5f,-0.5f, 1, 1, 1), |
|
60 |
getCenters( 1.5f,-1.5f,-0.5f, 1, 1, 1), |
|
61 |
}; |
|
62 |
|
|
63 |
private static final int[][] DIMS = new int[][] |
|
64 |
{ |
|
65 |
{2,2,2}, |
|
66 |
{1,2,2}, |
|
67 |
{2,1,2}, |
|
68 |
{2,2,1}, |
|
69 |
{2,1,1}, |
|
70 |
{1,2,1}, |
|
71 |
{1,1,2}, |
|
72 |
{1,1,1}, |
|
27 | 73 |
}; |
28 | 74 |
|
75 |
private static final float[][] OFFSETS = new float[][] |
|
76 |
{ |
|
77 |
{ 0.0f, 0.0f, 0.0f}, |
|
78 |
{ 0.5f, 0.0f, 0.0f}, |
|
79 |
{-0.5f, 0.0f, 0.0f}, |
|
80 |
{ 0.0f, 0.5f, 0.0f}, |
|
81 |
{ 0.0f,-0.5f, 0.0f}, |
|
82 |
{ 0.0f, 0.0f, 0.5f}, |
|
83 |
{ 0.0f, 0.0f,-0.5f}, |
|
84 |
{ 0.0f,-0.5f,-0.5f}, |
|
85 |
{ 0.5f, 0.0f,-0.5f}, |
|
86 |
{ 0.5f,-0.5f, 0.0f}, |
|
87 |
{ 0.5f,-0.5f,-0.5f}, |
|
88 |
}; |
|
89 |
|
|
90 |
private int[] mDimsIndices, mOffsIndices; |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
private static float[] getCenters( float x, float y, float z, int xd, int yd, int zd ) |
|
95 |
{ |
|
96 |
float XS = 0.5f*(1-xd) + x; |
|
97 |
float YS = 0.5f*(1-yd) + y; |
|
98 |
float ZS = 0.5f*(1-zd) + z; |
|
99 |
|
|
100 |
int index=0; |
|
101 |
float[] result = new float[3*xd*yd*zd]; |
|
102 |
|
|
103 |
for(int i=0; i<xd; i++) |
|
104 |
for(int j=0; j<yd; j++) |
|
105 |
for(int k=0; k<zd; k++) |
|
106 |
{ |
|
107 |
result[3*index ] = XS+i; |
|
108 |
result[3*index+1] = YS+j; |
|
109 |
result[3*index+2] = ZS+k; |
|
110 |
index++; |
|
111 |
} |
|
112 |
|
|
113 |
return result; |
|
114 |
} |
|
115 |
|
|
29 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 117 |
|
31 | 118 |
public TwistyCamouflage(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream) |
... | ... | |
35 | 122 |
|
36 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
37 | 124 |
|
38 |
float[][] getVertices(int variant)
|
|
125 |
private int getDimsIndex(int variant)
|
|
39 | 126 |
{ |
40 | 127 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
41 | 128 |
|
42 | 129 |
if( mPosition==CAM_333 ) |
43 | 130 |
{ |
44 |
// TODO: vertices of the Camouflage 3x3x3 |
|
131 |
if( mDimsIndices==null ) mDimsIndices = new int[] |
|
132 |
{ 0, |
|
133 |
1,0,2,0,3,0, |
|
134 |
3,0,4,2,1,0,5,3,6,2,1,0, |
|
135 |
6,2,1,0,5,4,3 }; |
|
45 | 136 |
} |
46 | 137 |
|
47 |
return null; |
|
138 |
return mDimsIndices[variant]; |
|
139 |
} |
|
140 |
|
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
private int getOffsetsIndex(int variant) |
|
144 |
{ |
|
145 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
146 |
|
|
147 |
if( mPosition==CAM_333 ) |
|
148 |
{ |
|
149 |
if( mOffsIndices==null ) mOffsIndices = new int[] |
|
150 |
{ 0, |
|
151 |
0,1,0,4,0,6, |
|
152 |
4,7,0,6,6,8,0,1,0,1,4,9, |
|
153 |
6,8,7,10,4,1,9 }; |
|
154 |
} |
|
155 |
|
|
156 |
return mOffsIndices[variant]; |
|
157 |
} |
|
158 |
|
|
159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
160 |
|
|
161 |
private float[][] getVertices(int variant) |
|
162 |
{ |
|
163 |
int indexD = getDimsIndex(variant); |
|
164 |
|
|
165 |
int X=DIMS[indexD][0]; |
|
166 |
int Y=DIMS[indexD][1]; |
|
167 |
int Z=DIMS[indexD][2]; |
|
168 |
|
|
169 |
int indexO = getOffsetsIndex(variant); |
|
170 |
|
|
171 |
float XF = OFFSETS[indexO][0]; |
|
172 |
float YF = OFFSETS[indexO][1]; |
|
173 |
float ZF = OFFSETS[indexO][2]; |
|
174 |
|
|
175 |
return new float[][] |
|
176 |
{ |
|
177 |
{ 0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF}, |
|
178 |
{ 0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF}, |
|
179 |
{ 0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF}, |
|
180 |
{ 0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF}, |
|
181 |
{-0.5f*X +XF, 0.5f*Y +YF, 0.5f*Z +ZF}, |
|
182 |
{-0.5f*X +XF, 0.5f*Y +YF,-0.5f*Z +ZF}, |
|
183 |
{-0.5f*X +XF,-0.5f*Y +YF, 0.5f*Z +ZF}, |
|
184 |
{-0.5f*X +XF,-0.5f*Y +YF,-0.5f*Z +ZF} |
|
185 |
}; |
|
48 | 186 |
} |
49 | 187 |
|
50 | 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 189 |
// PUBLIC API |
52 | 190 |
|
191 |
public int getTouchControlType() |
|
192 |
{ |
|
193 |
return TC_CHANGING_SHAPEMOD; |
|
194 |
} |
|
195 |
|
|
196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
197 |
|
|
198 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
|
199 |
{ |
|
200 |
return mObjectQuats[0]; |
|
201 |
} |
|
202 |
|
|
203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
204 |
|
|
205 |
public ObjectShape getObjectShape(int variant) |
|
206 |
{ |
|
207 |
int[][] indices = |
|
208 |
{ |
|
209 |
{2,3,1,0}, |
|
210 |
{7,6,4,5}, |
|
211 |
{4,0,1,5}, |
|
212 |
{7,3,2,6}, |
|
213 |
{6,2,0,4}, |
|
214 |
{3,7,5,1}, |
|
215 |
}; |
|
216 |
|
|
217 |
return new ObjectShape( getVertices(variant), indices); |
|
218 |
} |
|
219 |
|
|
220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
221 |
|
|
222 |
public ObjectFaceShape getObjectFaceShape(int variant) |
|
223 |
{ |
|
224 |
int index = getDimsIndex(variant); |
|
225 |
|
|
226 |
int X = DIMS[index][0]; |
|
227 |
int Y = DIMS[index][1]; |
|
228 |
int Z = DIMS[index][2]; |
|
229 |
|
|
230 |
float height = isInIconMode() ? 0.001f : 0.03f; |
|
231 |
int[] bandIndices= { 0,0,1,1,2,2 }; |
|
232 |
|
|
233 |
int maxXY = Math.max(X,Y); |
|
234 |
int maxXZ = Math.max(X,Z); |
|
235 |
int maxYZ = Math.max(Y,Z); |
|
236 |
|
|
237 |
int angle = 45; |
|
238 |
float R = 0.10f; |
|
239 |
float S = 0.25f; |
|
240 |
float N = 4; |
|
241 |
|
|
242 |
float[][] bands = |
|
243 |
{ |
|
244 |
{height/maxYZ,angle,R,S,N,0,0}, |
|
245 |
{height/maxXZ,angle,R,S,N,0,0}, |
|
246 |
{height/maxXY,angle,R,S,N,0,0} |
|
247 |
}; |
|
248 |
|
|
249 |
return new ObjectFaceShape(bands,bandIndices,null); |
|
250 |
} |
|
251 |
|
|
252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
|
|
254 |
public ObjectVertexEffects getVertexEffects(int variant) |
|
255 |
{ |
|
256 |
boolean round = false; |
|
257 |
float[][] vertices = getVertices(variant); |
|
258 |
float A = -0.03f; |
|
259 |
|
|
260 |
float[][] variables = |
|
261 |
{ |
|
262 |
{ 0, A, A, A, 1 }, |
|
263 |
{ 0, A, A,-A, 1 }, |
|
264 |
{ 0, A,-A, A, 1 }, |
|
265 |
{ 0, A,-A,-A, 1 }, |
|
266 |
{ 0,-A, A, A, 1 }, |
|
267 |
{ 0,-A, A,-A, 1 }, |
|
268 |
{ 0,-A,-A, A, 1 }, |
|
269 |
{ 0,-A,-A,-A, 1 }, |
|
270 |
}; |
|
271 |
|
|
272 |
String name = EffectName.DEFORM.name(); |
|
273 |
float[] reg = {0,0,0,0.10f}; |
|
274 |
|
|
275 |
String[] names = {name,name,name,name,name,name,name,name}; |
|
276 |
float[][] regions = {reg,reg,reg,reg,reg,reg,reg,reg}; |
|
277 |
boolean[] uses = {round,round,round,round,round,round,round,round}; |
|
278 |
|
|
279 |
return new ObjectVertexEffects(names,variables,vertices,regions,uses); |
|
280 |
} |
|
281 |
|
|
282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
283 |
|
|
284 |
public int getCubitVariant(int cubit, int[] numLayers) |
|
285 |
{ |
|
286 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
287 |
|
|
288 |
if( mPosition==CAM_333 ) |
|
289 |
{ |
|
290 |
return cubit; |
|
291 |
} |
|
292 |
|
|
293 |
return 0; |
|
294 |
} |
|
295 |
|
|
296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
297 |
|
|
298 |
public int getNumCubitVariants(int[] numLayers) |
|
299 |
{ |
|
300 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
|
301 |
|
|
302 |
if( mPosition==CAM_333 ) return 26; |
|
303 |
|
|
304 |
return 0; |
|
305 |
} |
|
306 |
|
|
307 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
308 |
|
|
309 |
public float getStickerRadius() |
|
310 |
{ |
|
311 |
return 0.18f; |
|
312 |
} |
|
313 |
|
|
314 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
315 |
|
|
316 |
public float getStickerStroke() |
|
317 |
{ |
|
318 |
return isInIconMode() ? 0.25f : 0.15f; |
|
319 |
} |
|
320 |
|
|
321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
322 |
|
|
53 | 323 |
public String getShortName() |
54 | 324 |
{ |
55 | 325 |
if( mPosition==null ) mPosition = getInitData().getPos(); |
Also available in: Unified diff
Progress with the Camouflage 3x3x3.