Revision eb389a97
Added by Leszek Koltunski about 5 years ago
| src/main/java/org/distorted/objects/Cubit.java | ||
|---|---|---|
| 36 | 36 |
private int mNumAxis; |
| 37 | 37 |
|
| 38 | 38 |
int mQuatIndex; |
| 39 |
float[] mRotationRow;
|
|
| 39 |
int[] mRotationRow;
|
|
| 40 | 40 |
|
| 41 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 42 | 42 |
|
| ... | ... | |
| 52 | 52 |
mQuatIndex = 0; |
| 53 | 53 |
|
| 54 | 54 |
mNumAxis = mParent.ROTATION_AXIS.length; |
| 55 |
mRotationRow = new float[mNumAxis];
|
|
| 55 |
mRotationRow = new int[mNumAxis];
|
|
| 56 | 56 |
computeRotationRow(); |
| 57 | 57 |
} |
| 58 | 58 |
|
| ... | ... | |
| 111 | 111 |
} |
| 112 | 112 |
|
| 113 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 114 |
// cast current position on axis; use mStart and mStep to compute the rotation row for each axis. |
|
| 115 | 114 |
|
| 116 | 115 |
private void computeRotationRow() |
| 117 | 116 |
{
|
| 118 |
float tmp; |
|
| 119 |
Static3D axis; |
|
| 120 | 117 |
float x = mCurrentPosition.get0(); |
| 121 | 118 |
float y = mCurrentPosition.get1(); |
| 122 | 119 |
float z = mCurrentPosition.get2(); |
| 123 | 120 |
|
| 124 | 121 |
for(int i=0; i<mNumAxis; i++) |
| 125 | 122 |
{
|
| 126 |
axis = mParent.ROTATION_AXIS[i]; |
|
| 127 |
tmp = x*axis.get0() + y*axis.get1() + z*axis.get2(); |
|
| 128 |
mRotationRow[i] = (tmp-mParent.mStart)/mParent.mStep; |
|
| 123 |
mRotationRow[i] = mParent.computeRow(x,y,z,i); |
|
| 129 | 124 |
} |
| 130 | 125 |
} |
| 131 | 126 |
|
| ... | ... | |
| 161 | 156 |
|
| 162 | 157 |
int computeAssociation() |
| 163 | 158 |
{
|
| 164 |
int row, result = 0, accumulativeShift = 0;
|
|
| 159 |
int result = 0, accumulativeShift = 0; |
|
| 165 | 160 |
|
| 166 | 161 |
for(int axis=0; axis<mNumAxis; axis++) |
| 167 | 162 |
{
|
| 168 |
row = (int)(mRotationRow[axis]+0.5f); |
|
| 169 |
result += (1<<(row+accumulativeShift)); |
|
| 163 |
result += (1<<(mRotationRow[axis]+accumulativeShift)); |
|
| 170 | 164 |
accumulativeShift += ObjectList.MAX_OBJECT_SIZE; |
| 171 | 165 |
} |
| 172 | 166 |
|
| src/main/java/org/distorted/objects/TwistyCube.java | ||
|---|---|---|
| 331 | 331 |
Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 ); |
| 332 | 332 |
Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 ); |
| 333 | 333 |
|
| 334 |
float row1, row2, row3, row4; |
|
| 335 |
float ax,ay,az; |
|
| 336 |
Static3D axis; |
|
| 334 |
float row1, row2; |
|
| 337 | 335 |
float x1 = rotated1.get0(); |
| 338 | 336 |
float y1 = rotated1.get1(); |
| 339 | 337 |
float z1 = rotated1.get2(); |
| ... | ... | |
| 343 | 341 |
|
| 344 | 342 |
for(int i=0; i<NUM_AXIS; i++) |
| 345 | 343 |
{
|
| 346 |
axis = ROTATION_AXIS[i]; |
|
| 347 |
ax = axis.get0(); |
|
| 348 |
ay = axis.get1(); |
|
| 349 |
az = axis.get2(); |
|
| 350 |
|
|
| 351 |
row1 = ((x1*ax + y1*ay + z1*az) - mStart) / mStep; |
|
| 352 |
row2 = ((x2*ax + y2*ay + z2*az) - mStart) / mStep; |
|
| 353 |
row3 = row1 - size; |
|
| 354 |
row4 = row2 - size; |
|
| 355 |
|
|
| 356 |
if( (row1<MAX_ERROR && row1>-MAX_ERROR && row2<MAX_ERROR && row2>-MAX_ERROR) || |
|
| 357 |
(row3<MAX_ERROR && row3>-MAX_ERROR && row4<MAX_ERROR && row4>-MAX_ERROR) ) |
|
| 358 |
{
|
|
| 359 |
return true; |
|
| 360 |
} |
|
| 344 |
row1 = computeRow(x1,y1,z1,i); |
|
| 345 |
row2 = computeRow(x2,y2,z2,i); |
|
| 346 |
|
|
| 347 |
if( (row1==0 && row2==0) || (row1==size || row2==size) ) return true; |
|
| 361 | 348 |
} |
| 362 | 349 |
return false; |
| 363 | 350 |
|
| src/main/java/org/distorted/objects/TwistyObject.java | ||
|---|---|---|
| 106 | 106 |
private Dynamic1D mRotationAngle; |
| 107 | 107 |
private Static3D mRotationAxis; |
| 108 | 108 |
private Static3D mObjectScale; |
| 109 |
private float mStart, mStep; |
|
| 109 | 110 |
|
| 110 |
float mStart, mStep; |
|
| 111 | 111 |
float[] mRowChances; |
| 112 |
|
|
| 113 | 112 |
Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal; |
| 114 | 113 |
DistortedTexture mTexture; |
| 115 |
|
|
| 116 | 114 |
MatrixEffectScale mScaleEffect; |
| 117 | 115 |
MatrixEffectQuaternion mQuatEffect; |
| 118 | 116 |
|
| ... | ... | |
| 299 | 297 |
return ((1<<cubitRow)&rowBitmap)!=0; |
| 300 | 298 |
} |
| 301 | 299 |
|
| 300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 301 |
|
|
| 302 |
int computeRow(float x, float y, float z, int rotIndex) |
|
| 303 |
{
|
|
| 304 |
Static3D axis = ROTATION_AXIS[rotIndex]; |
|
| 305 |
float tmp = x*axis.get0() + y*axis.get1() + z*axis.get2(); |
|
| 306 |
|
|
| 307 |
return (int)((tmp-mStart)/mStep +0.5f); |
|
| 308 |
} |
|
| 309 |
|
|
| 302 | 310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 303 | 311 |
// note the minus in front of the sin() - we rotate counterclockwise |
| 304 | 312 |
// when looking towards the direction where the axis increases in values. |
| src/main/java/org/distorted/objects/TwistyPyraminx.java | ||
|---|---|---|
| 365 | 365 |
Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 ); |
| 366 | 366 |
Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 ); |
| 367 | 367 |
|
| 368 |
float row1, row2, row3, row4; |
|
| 369 |
float ax,ay,az; |
|
| 370 |
Static3D axis; |
|
| 368 |
float row1, row2; |
|
| 371 | 369 |
float x1 = rotated1.get0(); |
| 372 | 370 |
float y1 = rotated1.get1(); |
| 373 | 371 |
float z1 = rotated1.get2(); |
| ... | ... | |
| 377 | 375 |
|
| 378 | 376 |
for(int i=0; i<NUM_AXIS; i++) |
| 379 | 377 |
{
|
| 380 |
axis = ROTATION_AXIS[i]; |
|
| 381 |
ax = axis.get0(); |
|
| 382 |
ay = axis.get1(); |
|
| 383 |
az = axis.get2(); |
|
| 384 |
|
|
| 385 |
row1 = ((x1*ax + y1*ay + z1*az) - mStart) / mStep; |
|
| 386 |
row2 = ((x2*ax + y2*ay + z2*az) - mStart) / mStep; |
|
| 387 |
row3 = row1 - size; |
|
| 388 |
row4 = row2 - size; |
|
| 389 |
|
|
| 390 |
if( (row1<MAX_ERROR && row1>-MAX_ERROR && row2<MAX_ERROR && row2>-MAX_ERROR) || |
|
| 391 |
(row3<MAX_ERROR && row3>-MAX_ERROR && row4<MAX_ERROR && row4>-MAX_ERROR) ) |
|
| 392 |
{
|
|
| 393 |
return true; |
|
| 394 |
} |
|
| 378 |
row1 = computeRow(x1,y1,z1,i); |
|
| 379 |
row2 = computeRow(x2,y2,z2,i); |
|
| 380 |
|
|
| 381 |
if( (row1==0 && row2==0) || (row1==size || row2==size) ) return true; |
|
| 395 | 382 |
} |
| 396 | 383 |
return false; |
| 397 | 384 |
|
| src/main/java/org/distorted/states/RubikStatePlay.java | ||
|---|---|---|
| 573 | 573 |
|
| 574 | 574 |
public void restorePreferences(SharedPreferences preferences) |
| 575 | 575 |
{
|
| 576 |
mObject = preferences.getInt("statePlay_object", DEF_OBJECT);
|
|
| 577 |
mSize = preferences.getInt("statePlay_size" , DEF_SIZE );
|
|
| 576 |
mObject= preferences.getInt("statePlay_object", DEF_OBJECT);
|
|
| 577 |
mSize = preferences.getInt("statePlay_size" , DEF_SIZE );
|
|
| 578 | 578 |
} |
| 579 | 579 |
|
| 580 | 580 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Move computation of the rotation rows to the Object from Cubits.