Revision a4af26c1
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/objectlib/main/TwistyObject.java | ||
---|---|---|
318 | 318 |
FactoryCubit factory = FactoryCubit.getInstance(); |
319 | 319 |
factory.clear(); |
320 | 320 |
|
321 |
displayCubitQuats(); |
|
322 |
|
|
321 | 323 |
mOrigQuat = new Static4D[mNumCubits]; |
322 | 324 |
for(int i=0; i<mNumCubits; i++) mOrigQuat[i] = getCubitQuats(i,mNumLayers); |
323 | 325 |
|
... | ... | |
516 | 518 |
return nonBlackIndex; |
517 | 519 |
} |
518 | 520 |
|
521 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
522 |
|
|
523 |
private boolean sticksOut(Static3D[] faceAxis, float[] dist, float x, float y, float z ) |
|
524 |
{ |
|
525 |
final float MAXERR = 0.05f; |
|
526 |
int numAxis = dist.length; |
|
527 |
float NUM = mNumLayers[0]; |
|
528 |
|
|
529 |
for(int i=0; i<numAxis; i++) |
|
530 |
{ |
|
531 |
Static3D ax = faceAxis[i]; |
|
532 |
float len = ax.get0()*x + ax.get1()*y + ax.get2()*z; |
|
533 |
if( len>NUM*dist[i]+MAXERR ) return true; |
|
534 |
} |
|
535 |
|
|
536 |
return false; |
|
537 |
} |
|
538 |
|
|
539 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
540 |
|
|
541 |
private boolean doesNotStickOut(int variant, float[] pos, float[] tmp, Static4D quat) |
|
542 |
{ |
|
543 |
ObjectShape shape = getObjectShape(variant); |
|
544 |
float[][] vertices = shape.getVertices(); |
|
545 |
Static3D[] axis = getFaceAxis(); |
|
546 |
float[] dist3D = getDist3D(mNumLayers); |
|
547 |
|
|
548 |
for( float[] vertex : vertices) |
|
549 |
{ |
|
550 |
float x = vertex[0]; |
|
551 |
float y = vertex[1]; |
|
552 |
float z = vertex[2]; |
|
553 |
|
|
554 |
QuatHelper.rotateVectorByQuat(tmp, x, y, z, 1, quat); |
|
555 |
|
|
556 |
float mx = tmp[0] + pos[0]; |
|
557 |
float my = tmp[1] + pos[1]; |
|
558 |
float mz = tmp[2] + pos[2]; |
|
559 |
|
|
560 |
if( sticksOut(axis, dist3D, mx,my,mz) ) return false; |
|
561 |
} |
|
562 |
|
|
563 |
return true; |
|
564 |
} |
|
565 |
|
|
519 | 566 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
520 | 567 |
|
521 | 568 |
protected void displayCubitQuats() |
522 | 569 |
{ |
523 | 570 |
StringBuilder builder = new StringBuilder(); |
524 | 571 |
float[] tmp = new float[4]; |
525 |
float MAXERR = 0.01f;
|
|
572 |
float ERR = 0.01f; |
|
526 | 573 |
|
527 | 574 |
for(int cubit=0; cubit<mNumCubits; cubit++) |
528 | 575 |
{ |
576 |
builder.append(cubit); |
|
577 |
builder.append(" : "); |
|
578 |
|
|
529 | 579 |
int refCubit,variant = getCubitVariant(cubit,mNumLayers); |
530 | 580 |
|
531 | 581 |
for(refCubit=0; refCubit<mNumCubits; refCubit++) |
... | ... | |
550 | 600 |
float dy = tmp[1]-curY; |
551 | 601 |
float dz = tmp[2]-curZ; |
552 | 602 |
|
553 |
if( dx>-MAXERR && dx<MAXERR && dy>-MAXERR && dy<MAXERR && dz>-MAXERR && dz<MAXERR )
|
|
603 |
if( dx>-ERR && dx<ERR && dy>-ERR && dy<ERR && dz>-ERR && dz<ERR )
|
|
554 | 604 |
{ |
555 |
builder.append(quat); |
|
556 |
builder.append(','); |
|
605 |
if( doesNotStickOut(variant,curpos,tmp,mObjectQuats[quat]) ) |
|
606 |
{ |
|
607 |
builder.append(quat); |
|
608 |
builder.append(','); |
|
609 |
} |
|
610 |
else |
|
611 |
{ |
|
612 |
android.util.Log.e("D", "cubit: "+cubit+" quat: "+quat+" : center correct, but shape sticks out"); |
|
613 |
} |
|
557 | 614 |
} |
558 | 615 |
} |
559 | 616 |
|
Also available in: Unified diff
Progress with cubit quaternions.