Revision 001cc0e4
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/objects/RubikObject.java | ||
|---|---|---|
| 34 | 34 |
import org.distorted.library.mesh.MeshBase; |
| 35 | 35 |
import org.distorted.library.mesh.MeshRectangles; |
| 36 | 36 |
import org.distorted.library.message.EffectListener; |
| 37 |
import org.distorted.library.type.Dynamic1D; |
|
| 38 | 37 |
import org.distorted.library.type.Static1D; |
| 39 | 38 |
import org.distorted.library.type.Static3D; |
| 40 | 39 |
import org.distorted.library.type.Static4D; |
| ... | ... | |
| 51 | 50 |
|
| 52 | 51 |
static float OBJECT_SCREEN_RATIO; |
| 53 | 52 |
|
| 54 |
private static final int POST_ROTATION_MILLISEC = 500; |
|
| 55 | 53 |
private final int NUM_CUBITS; |
| 56 | 54 |
private int mRotRowBitmap; |
| 57 | 55 |
private int mRotAxis; |
| ... | ... | |
| 205 | 203 |
return diff*diff < MAX_ERROR; |
| 206 | 204 |
} |
| 207 | 205 |
|
| 208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 209 |
|
|
| 210 |
private void resetRotationAngle(Dynamic1D rotationAngle) |
|
| 211 |
{
|
|
| 212 |
rotationAngle.setDuration(POST_ROTATION_MILLISEC); |
|
| 213 |
rotationAngle.resetToBeginning(); |
|
| 214 |
rotationAngle.removeAll(); |
|
| 215 |
rotationAngle.add(mRotationAngleStatic); |
|
| 216 |
rotationAngle.add(mRotationAngleMiddle); |
|
| 217 |
rotationAngle.add(mRotationAngleFinal); |
|
| 218 |
} |
|
| 219 |
|
|
| 220 | 206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 221 | 207 |
// note the minus in front of the sin() - we rotate counterclockwise |
| 222 | 208 |
// when looking towards the direction where the axis increases in values. |
| ... | ... | |
| 368 | 354 |
for(int i=0; i<NUM_CUBITS; i++) mCubits[i].restorePreferences(preferences); |
| 369 | 355 |
} |
| 370 | 356 |
|
| 371 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 372 |
|
|
| 373 |
public long finishRotationNow(EffectListener listener) |
|
| 374 |
{
|
|
| 375 |
boolean first = true; |
|
| 376 |
long effectID=0; |
|
| 377 |
|
|
| 378 |
for(int i=0; i<NUM_CUBITS; i++) |
|
| 379 |
{
|
|
| 380 |
if( belongsToRotation(i,mRotAxis,mRotRowBitmap) ) |
|
| 381 |
{
|
|
| 382 |
if( first ) |
|
| 383 |
{
|
|
| 384 |
first=false; |
|
| 385 |
effectID = mCubits[i].finishRotationNow(listener); |
|
| 386 |
} |
|
| 387 |
resetRotationAngle(mCubits[i].mRotationAngle); |
|
| 388 |
} |
|
| 389 |
} |
|
| 390 |
|
|
| 391 |
return effectID; |
|
| 392 |
} |
|
| 393 |
|
|
| 394 | 357 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 395 | 358 |
|
| 396 | 359 |
public void releaseResources() |
| ... | ... | |
| 490 | 453 |
public long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener ) |
| 491 | 454 |
{
|
| 492 | 455 |
long effectID=0; |
| 493 |
boolean first = true;
|
|
| 456 |
int firstCubit = -1;
|
|
| 494 | 457 |
|
| 495 | 458 |
mRotAxis = axis; |
| 496 | 459 |
mRotRowBitmap = rowBitmap; |
| ... | ... | |
| 501 | 464 |
if( belongsToRotation(i,mRotAxis,mRotRowBitmap) ) |
| 502 | 465 |
{
|
| 503 | 466 |
mCubits[i].addNewRotation(axis,durationMillis,angle); |
| 504 |
|
|
| 505 |
if( first ) |
|
| 506 |
{
|
|
| 507 |
first = false; |
|
| 508 |
effectID = mCubits[i].setUpCallback(listener); |
|
| 509 |
} |
|
| 467 |
if( firstCubit<0 ) firstCubit = i; |
|
| 510 | 468 |
} |
| 511 | 469 |
|
| 470 |
if( firstCubit>=0 ) effectID = mCubits[firstCubit].setUpCallback(listener); |
|
| 471 |
|
|
| 512 | 472 |
return effectID; |
| 513 | 473 |
} |
| 514 | 474 |
|
| 475 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 476 |
|
|
| 477 |
public long finishRotationNow(EffectListener listener) |
|
| 478 |
{
|
|
| 479 |
int firstCubit= -1; |
|
| 480 |
long effectID = 0; |
|
| 481 |
|
|
| 482 |
for(int i=0; i<NUM_CUBITS; i++) |
|
| 483 |
{
|
|
| 484 |
if( belongsToRotation(i,mRotAxis,mRotRowBitmap) ) |
|
| 485 |
{
|
|
| 486 |
if( firstCubit<0 ) |
|
| 487 |
{
|
|
| 488 |
firstCubit=i; |
|
| 489 |
|
|
| 490 |
float angle = mRotationAngleStatic.get0(); |
|
| 491 |
int nearestAngleInDegrees = computeNearestAngle(angle); |
|
| 492 |
mRotationAngleStatic.set0(angle); |
|
| 493 |
mRotationAngleFinal.set0(nearestAngleInDegrees); |
|
| 494 |
mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f ); |
|
| 495 |
} |
|
| 496 |
mCubits[i].resetRotationAngle(); |
|
| 497 |
} |
|
| 498 |
} |
|
| 499 |
|
|
| 500 |
if( firstCubit>=0 ) effectID = mCubits[firstCubit].setUpCallback(listener); |
|
| 501 |
|
|
| 502 |
return effectID; |
|
| 503 |
} |
|
| 504 |
|
|
| 515 | 505 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 516 | 506 |
|
| 517 | 507 |
public void removeRotationNow() |
| ... | ... | |
| 525 | 515 |
if( first ) |
| 526 | 516 |
{
|
| 527 | 517 |
first = false; |
| 528 |
quat = mCubits[i].returnRotationQuat(mRotAxis); |
|
| 518 |
|
|
| 519 |
float angle = mRotationAngleFinal.get0(); |
|
| 520 |
int nearestAngleInDegrees = computeNearestAngle(angle); |
|
| 521 |
double nearestAngleInRadians = nearestAngleInDegrees*Math.PI/180; |
|
| 522 |
float sinA =-(float)Math.sin(nearestAngleInRadians*0.5); |
|
| 523 |
float cosA = (float)Math.cos(nearestAngleInRadians*0.5); |
|
| 524 |
float axisX = ROTATION_AXIS[mRotAxis].get0(); |
|
| 525 |
float axisY = ROTATION_AXIS[mRotAxis].get1(); |
|
| 526 |
float axisZ = ROTATION_AXIS[mRotAxis].get2(); |
|
| 527 |
quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA); |
|
| 529 | 528 |
} |
| 530 | 529 |
|
| 531 | 530 |
mCubits[i].removeRotationNow(quat); |
Also available in: Unified diff
Fix a potential crasher ( do not set up a callback for end of rotation effect on the very first cubit that belongs to a rotation if all belonging cubits have not been set up yet )