Revision 9621255f
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
173 | 173 |
|
174 | 174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
175 | 175 |
|
176 |
private void setUpDragOrRotate(float x, float y) |
|
176 |
private void setUpDragOrRotate(boolean down, float x, float y)
|
|
177 | 177 |
{ |
178 | 178 |
int mode = RubikState.getMode(); |
179 | 179 |
|
... | ... | |
201 | 201 |
else if( mode==MODE_REPLACE ) |
202 | 202 |
{ |
203 | 203 |
mBeginningRotation= false; |
204 |
RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass(); |
|
205 |
int cubit = mMovement.getTouchedCubit(); |
|
206 |
int face = mMovement.getTouchedFace(); |
|
207 |
int color = solver.getCurrentColor(); |
|
208 |
mPostRender.setTextureMap( cubit, face, color ); |
|
204 |
|
|
205 |
if( down ) |
|
206 |
{ |
|
207 |
RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass(); |
|
208 |
int face = mMovement.getTouchedFace(); |
|
209 |
float[] point = mMovement.getTouchedPoint3D(); |
|
210 |
int color = solver.getCurrentColor(); |
|
211 |
RubikObject object = mPostRender.getObject(); |
|
212 |
int cubit = object.getCubit(point); |
|
213 |
|
|
214 |
mPostRender.setTextureMap( cubit, face, color ); |
|
215 |
} |
|
209 | 216 |
} |
210 | 217 |
} |
211 | 218 |
else |
... | ... | |
337 | 344 |
{ |
338 | 345 |
case MotionEvent.ACTION_DOWN: mX = x; |
339 | 346 |
mY = y; |
340 |
setUpDragOrRotate(x,y); |
|
347 |
setUpDragOrRotate(true,x,y);
|
|
341 | 348 |
break; |
342 | 349 |
case MotionEvent.ACTION_MOVE: if( mBeginningRotation ) |
343 | 350 |
{ |
... | ... | |
357 | 364 |
computeCurrentAxis( object.getRotationAxis()[axis] ); |
358 | 365 |
mRotationFactor = object.returnRotationFactor(offset); |
359 | 366 |
|
360 |
object.beginNewRotation( axis, object.returnRowFromOffset(offset) );
|
|
367 |
object.beginNewRotation( axis, (int)(object.returnMultiplier()*offset) );
|
|
361 | 368 |
|
362 | 369 |
if( RubikState.getCurrentState()==RubikState.SOLV ) |
363 | 370 |
{ |
... | ... | |
391 | 398 |
} |
392 | 399 |
else |
393 | 400 |
{ |
394 |
setUpDragOrRotate(x,y); |
|
401 |
setUpDragOrRotate(false,x,y);
|
|
395 | 402 |
} |
396 | 403 |
break; |
397 | 404 |
case MotionEvent.ACTION_UP : if( mDragging ) |
src/main/java/org/distorted/objects/Cubit.java | ||
---|---|---|
407 | 407 |
return mRotateEffect.getID(); |
408 | 408 |
} |
409 | 409 |
|
410 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
411 |
|
|
412 |
float getDistSquared(float[] point) |
|
413 |
{ |
|
414 |
float dx = mCurrentPosition.get0() - point[0]; |
|
415 |
float dy = mCurrentPosition.get1() - point[1]; |
|
416 |
float dz = mCurrentPosition.get2() - point[2]; |
|
417 |
|
|
418 |
return dx*dx + dy*dy + dz*dz; |
|
419 |
} |
|
420 |
|
|
410 | 421 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
411 | 422 |
|
412 | 423 |
MeshBase getMesh() |
src/main/java/org/distorted/objects/RubikCube.java | ||
---|---|---|
214 | 214 |
|
215 | 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
216 | 216 |
|
217 |
public int returnRowFromOffset(float offset)
|
|
217 |
public float returnMultiplier()
|
|
218 | 218 |
{ |
219 |
return (int)(getSize()*offset);
|
|
219 |
return getSize();
|
|
220 | 220 |
} |
221 | 221 |
|
222 | 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/RubikObject.java | ||
---|---|---|
535 | 535 |
setupPosition(moves); |
536 | 536 |
} |
537 | 537 |
|
538 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
539 |
|
|
540 |
public int getCubit(float[] point3D) |
|
541 |
{ |
|
542 |
float dist, minDist = Float. MAX_VALUE; |
|
543 |
int currentBest=-1; |
|
544 |
float multiplier = returnMultiplier(); |
|
545 |
|
|
546 |
point3D[0] *= multiplier; |
|
547 |
point3D[1] *= multiplier; |
|
548 |
point3D[2] *= multiplier; |
|
549 |
|
|
550 |
for(int i=0; i<NUM_CUBITS; i++) |
|
551 |
{ |
|
552 |
dist = mCubits[i].getDistSquared(point3D); |
|
553 |
if( dist<minDist ) |
|
554 |
{ |
|
555 |
minDist = dist; |
|
556 |
currentBest = i; |
|
557 |
} |
|
558 |
} |
|
559 |
|
|
560 |
return currentBest; |
|
561 |
} |
|
562 |
|
|
538 | 563 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
539 | 564 |
|
540 | 565 |
public RubikObjectList getObjectList() |
... | ... | |
553 | 578 |
abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side); |
554 | 579 |
public abstract Static3D[] getRotationAxis(); |
555 | 580 |
public abstract int getBasicAngle(); |
556 |
public abstract int returnRowFromOffset(float offset);
|
|
581 |
public abstract float returnMultiplier();
|
|
557 | 582 |
public abstract float returnRotationFactor(float offset); |
558 | 583 |
} |
src/main/java/org/distorted/objects/RubikObjectMovement.java | ||
---|---|---|
292 | 292 |
} |
293 | 293 |
|
294 | 294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
295 |
// TODO |
|
296 | 295 |
|
297 |
public int getTouchedCubit()
|
|
296 |
public float[] getTouchedPoint3D()
|
|
298 | 297 |
{ |
299 |
return 0;
|
|
298 |
return mTouch;
|
|
300 | 299 |
} |
301 | 300 |
} |
src/main/java/org/distorted/objects/RubikPyraminx.java | ||
---|---|---|
305 | 305 |
|
306 | 306 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
307 | 307 |
|
308 |
public int returnRowFromOffset(float offset)
|
|
308 |
public float returnMultiplier()
|
|
309 | 309 |
{ |
310 |
return (int)(getSize()*offset/(SQ3/2));
|
|
310 |
return getSize()/(SQ3/2);
|
|
311 | 311 |
} |
312 | 312 |
|
313 | 313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Progress with the 3x3x3 Solver.