Revision 0fbf344e
Added by Leszek Koltunski 9 months ago
src/main/java/org/distorted/objectlib/main/TwistyObjectControllable.java | ||
---|---|---|
58 | 58 |
private boolean mGhostAxisInverted; |
59 | 59 |
private boolean[] mGhostCubitRotated; |
60 | 60 |
private float[] mGhostQuat; |
61 |
private int[][] mGhostAxisJumpedTo; |
|
61 |
private int[][][] mGhostAxisJumpedTo;
|
|
62 | 62 |
|
63 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 64 |
|
... | ... | |
222 | 222 |
mGhostQuat[1] = axisY*sinA; |
223 | 223 |
mGhostQuat[2] = axisZ*sinA; |
224 | 224 |
mGhostQuat[3] = cosA; |
225 |
|
|
226 |
if( mGhostAxisInverted ) |
|
227 |
{ |
|
228 |
mGhostQuat[0] *= -1; |
|
229 |
mGhostQuat[1] *= -1; |
|
230 |
mGhostQuat[2] *= -1; |
|
231 |
} |
|
225 | 232 |
} |
226 | 233 |
|
227 | 234 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
236 | 243 |
} |
237 | 244 |
|
238 | 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
246 |
// x = mGhostAxisJumpedTo[a][1][q] := |
|
247 |
// |
|
248 |
// if mGhostAxis is currently 'a', and it is Inverted ('1') and we rotate to by quaternion 'q', then |
|
249 |
// the new mGhostAxis is going to be 'x/2' and it is inverted iff (x%2)==1. |
|
239 | 250 |
|
240 | 251 |
private void computeGhostAxisJumps() |
241 | 252 |
{ |
242 |
mGhostAxisJumpedTo = new int[mNumAxis][mNumQuats]; |
|
253 |
mGhostAxisJumpedTo = new int[mNumAxis][2][mNumQuats];
|
|
243 | 254 |
|
244 | 255 |
float[] point1 = new float[3]; |
245 | 256 |
float[] point2 = new float[3]; |
... | ... | |
264 | 275 |
QuatHelper.rotateVectorByQuat(tmp2,point2[0],point2[1],point2[2],1,quat); |
265 | 276 |
QuatHelper.rotateVectorByQuat(tmp3,point3[0],point3[1],point3[2],1,quat); |
266 | 277 |
|
267 |
mGhostAxisJumpedTo[a][q] = getAxisInverted(tmp1,tmp2,tmp3); |
|
278 |
int result = getAxisInverted(tmp1,tmp2,tmp3); |
|
279 |
mGhostAxisJumpedTo[a][0][q] = result; |
|
280 |
mGhostAxisJumpedTo[a][1][q] = result^0x1; // change the last bit, i.e. [1] is inverted iff [0] is not. |
|
268 | 281 |
|
269 | 282 |
//int g = mGhostAxisJumpedTo[a][q]; |
270 | 283 |
//android.util.Log.e("D", "axis "+a+" quat "+q+" : new ghostAxis: "+(g/2)+" inverted: "+(g%2==1)); |
... | ... | |
378 | 391 |
if( mGhostAngle!=0 && axis!=mGhostAxis && mGhostRowBitmap==((1<<(mGhostNumRows))-1) ) |
379 | 392 |
{ |
380 | 393 |
rotAx = (mGhostAxisInverted ? mGhostRotInvAxis[mGhostAxis][axis] : mGhostRotatedAxis[mGhostAxis][axis]); |
381 |
|
|
382 |
float x = rotAx.get0(); |
|
383 |
float y = rotAx.get1(); |
|
384 |
float z = rotAx.get2(); |
|
385 |
android.util.Log.e("D", "rotAx: "+x+" "+y+" "+z+" axis: "+axis+" inverted: "+mGhostAxisInverted); |
|
386 | 394 |
} |
387 | 395 |
|
388 | 396 |
return rotAx; |
... | ... | |
593 | 601 |
float cosHalf = (float)Math.cos(radians/2); |
594 | 602 |
float[] quat = new float[] {ax*sinHalf,ay*sinHalf,az*sinHalf,cosHalf}; |
595 | 603 |
int quatIndex = normalizeScrambleQuat(quat); |
596 |
int result = mGhostAxisJumpedTo[mGhostAxis][quatIndex]; |
|
604 |
int currInv = mGhostAxisInverted ? 1:0; |
|
605 |
int result = mGhostAxisJumpedTo[mGhostAxis][currInv][quatIndex]; |
|
597 | 606 |
|
598 | 607 |
int inverted = result%2; |
599 | 608 |
mGhostAxis = result/2; |
600 | 609 |
|
601 |
computeGhostQuaternion(); |
|
602 |
|
|
603 | 610 |
Static3D currGhostAxis = mAxis[mGhostAxis]; |
604 | 611 |
float x = currGhostAxis.get0(); |
605 | 612 |
float y = currGhostAxis.get1(); |
606 | 613 |
float z = currGhostAxis.get2(); |
607 | 614 |
mGhostEffectAxis.set(x,y,z); |
608 | 615 |
|
609 |
//android.util.Log.e("D", "new ghost axis: "+mGhostAxis+" inverted: "+(inverted==1));
|
|
616 |
if( (inverted==1)^mGhostAxisInverted ) invertGhostRotBitmap();
|
|
610 | 617 |
|
611 |
if( inverted==1 ) |
|
612 |
{ |
|
613 |
float sa = mGhostStatic.get0(); |
|
614 |
mGhostStatic.set0(-sa); |
|
615 |
mGhostRowBitmap = invertGhostRotBitmap(); |
|
616 |
} |
|
618 |
computeGhostQuaternion(); |
|
617 | 619 |
} |
618 | 620 |
|
619 | 621 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
620 | 622 |
|
621 |
private int invertGhostRotBitmap()
|
|
623 |
private void invertGhostRotBitmap()
|
|
622 | 624 |
{ |
623 |
mGhostAxisInverted = !mGhostAxisInverted; |
|
625 |
float sa = mGhostStatic.get0(); |
|
626 |
mGhostStatic.set0(-sa); |
|
624 | 627 |
|
625 |
mGhostQuat[0] *= -1; // |
|
626 |
mGhostQuat[1] *= -1; // TouchControl needs this |
|
627 |
mGhostQuat[2] *= -1; // |
|
628 |
mGhostAxisInverted = !mGhostAxisInverted; |
|
628 | 629 |
|
629 | 630 |
int inve = 0; |
630 | 631 |
int mask = 1; |
... | ... | |
635 | 636 |
mask *=2; |
636 | 637 |
} |
637 | 638 |
|
638 |
return inve;
|
|
639 |
mGhostRowBitmap = inve;
|
|
639 | 640 |
} |
640 | 641 |
|
641 | 642 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
All manual control over 4x2x2 and 2x2x2 Ghosts should be working now. Remaining:
- automatic moves (forcing the initial unblocking)
- remembering the state of a ghost