Revision 221a4090
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/objects/TwistyPyraminx.java | ||
---|---|---|
193 | 193 |
|
194 | 194 |
private int faceColor(int cubit, int axis) |
195 | 195 |
{ |
196 |
float row = CUBITS[cubit].mRotationRow[axis]; |
|
197 |
return row*row < 0.1f ? axis : NUM_FACES; |
|
196 |
return CUBITS[cubit].mRotationRow[axis] == 0 ? axis : NUM_FACES; |
|
198 | 197 |
} |
199 | 198 |
|
200 | 199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
333 | 332 |
return true; |
334 | 333 |
} |
335 | 334 |
|
336 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
337 |
// return if the Cubit, when rotated with its own mQuatScramble, would have looked any different |
|
338 |
// then if it were rotated by quaternion 'quat'. |
|
339 |
// No it is not so simple as the quats need to be the same - imagine a 4x4x4 cube where the two |
|
340 |
// middle squares get interchanged. No visible difference! |
|
341 |
// |
|
342 |
// So: this is true iff the cubit |
|
343 |
// a) is a corner or edge and the quaternions are the same |
|
344 |
// b) is inside one of the faces and after rotations by both quats it ends up on the same face. |
|
345 |
|
|
346 |
private boolean thereIsNoVisibleDifference(Cubit cubit, int quatIndex) |
|
347 |
{ |
|
348 |
if ( cubit.mQuatIndex == quatIndex ) return true; |
|
349 |
|
|
350 |
int belongsToHowManyFaces = 0; |
|
351 |
int numLayers = getNumLayers()-1; |
|
352 |
float row; |
|
353 |
final float MAX_ERROR = 0.01f; |
|
354 |
|
|
355 |
for(int i=0; i<NUM_AXIS; i++) |
|
356 |
{ |
|
357 |
row = cubit.mRotationRow[i]; |
|
358 |
if( (row <MAX_ERROR && row >-MAX_ERROR) || |
|
359 |
(row-numLayers<MAX_ERROR && row-numLayers>-MAX_ERROR) ) belongsToHowManyFaces++; |
|
360 |
} |
|
361 |
|
|
362 |
switch(belongsToHowManyFaces) |
|
363 |
{ |
|
364 |
case 0 : return true ; // 'inside' cubit that does not lie on any face |
|
365 |
case 1 : // cubit that lies inside one of the faces |
|
366 |
Static3D orig = cubit.getOrigPosition(); |
|
367 |
Static4D quat1 = QUATS[quatIndex]; |
|
368 |
Static4D quat2 = QUATS[cubit.mQuatIndex]; |
|
369 |
|
|
370 |
Static4D cubitCenter = new Static4D( orig.get0(), orig.get1(), orig.get2(), 0); |
|
371 |
Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 ); |
|
372 |
Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 ); |
|
373 |
|
|
374 |
float row1, row2; |
|
375 |
float x1 = rotated1.get0(); |
|
376 |
float y1 = rotated1.get1(); |
|
377 |
float z1 = rotated1.get2(); |
|
378 |
float x2 = rotated2.get0(); |
|
379 |
float y2 = rotated2.get1(); |
|
380 |
float z2 = rotated2.get2(); |
|
381 |
|
|
382 |
for(int i=0; i<NUM_AXIS; i++) |
|
383 |
{ |
|
384 |
row1 = computeRow(x1,y1,z1,i); |
|
385 |
row2 = computeRow(x2,y2,z2,i); |
|
386 |
|
|
387 |
if( (row1==0 && row2==0) || (row1==numLayers && row2==numLayers) ) return true; |
|
388 |
} |
|
389 |
return false; |
|
390 |
|
|
391 |
default: return false; // edge or corner |
|
392 |
} |
|
393 |
} |
|
394 |
|
|
395 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
335 |
//////////////////////////////////////////////////////////////////////// |
|
396 | 336 |
// only needed for solvers - there are no Pyraminx solvers ATM) |
397 | 337 |
|
398 | 338 |
public String retObjectString() |
Also available in: Unified diff
Simplification with objects.