Revision 8ba7aeb1
Added by Leszek Koltunski over 4 years ago
| src/main/java/org/distorted/control/RubikControl.java | ||
|---|---|---|
| 23 | 23 |
import org.distorted.library.main.DistortedScreen; |
| 24 | 24 |
import org.distorted.library.message.EffectListener; |
| 25 | 25 |
import org.distorted.main.RubikActivity; |
| 26 |
import org.distorted.main.RubikSurfaceView; |
|
| 26 | 27 |
|
| 27 | 28 |
import java.lang.ref.WeakReference; |
| 28 | 29 |
|
| ... | ... | |
| 46 | 47 |
return act!=null ? act.getScreen() : null; |
| 47 | 48 |
} |
| 48 | 49 |
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
RubikSurfaceView getSurfaceView() |
|
| 53 |
{
|
|
| 54 |
RubikActivity act = mRefAct.get(); |
|
| 55 |
return act!=null ? act.getSurfaceView() : null; |
|
| 56 |
} |
|
| 57 |
|
|
| 49 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 50 | 59 |
|
| 51 | 60 |
private void addWholeObjects() |
| src/main/java/org/distorted/control/RubikControlWhole.java | ||
|---|---|---|
| 34 | 34 |
import org.distorted.library.type.Static3D; |
| 35 | 35 |
import org.distorted.main.R; |
| 36 | 36 |
import org.distorted.main.RubikActivity; |
| 37 |
import org.distorted.main.RubikSurfaceView; |
|
| 37 | 38 |
|
| 38 | 39 |
import java.io.IOException; |
| 39 | 40 |
import java.io.InputStream; |
| ... | ... | |
| 55 | 56 |
private static final int[] DYN = { 2, 1, 1, 1, 2, 2, 4, 2, 2, 2, 2, 2, 4};
|
| 56 | 57 |
|
| 57 | 58 |
private float X0, X1, X2, Y1, D, s001, s014, s033, F; |
| 59 |
private int mWidth, mHeight; |
|
| 58 | 60 |
|
| 59 | 61 |
private final RubikControl mControl; |
| 60 | 62 |
private DistortedEffects[] mEffects; |
| ... | ... | |
| 274 | 276 |
|
| 275 | 277 |
mDynMoveHand1.add(mPosition1); |
| 276 | 278 |
mDynMoveShad1.add(mPosition1); |
| 279 |
|
|
| 280 |
RubikSurfaceView view = mControl.getSurfaceView(); |
|
| 281 |
float x = point1.get0() + mWidth*0.5f; |
|
| 282 |
float y = mHeight*0.5f - point1.get1(); |
|
| 283 |
view.prepareDown(); |
|
| 284 |
view.actionDown(x,y); |
|
| 277 | 285 |
} |
| 278 | 286 |
|
| 279 | 287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 767 | 775 |
mEffects[3].apply(moveHand2); |
| 768 | 776 |
|
| 769 | 777 |
DistortedScreen screen = mControl.getScreen(); |
| 770 |
int wid= screen.getWidth();
|
|
| 771 |
int hei= screen.getHeight();
|
|
| 772 |
|
|
| 773 |
X0 = wid*0.55f;
|
|
| 774 |
X1 = wid*0.45f;
|
|
| 775 |
X2 = wid*0.35f;
|
|
| 776 |
Y1 = hei*0.28f;
|
|
| 777 |
D = wid*0.01f;
|
|
| 778 |
s001 = wid*0.0001f;
|
|
| 779 |
s014 = wid*0.14f;
|
|
| 780 |
s033 = wid*0.33f;
|
|
| 778 |
mWidth = screen.getWidth();
|
|
| 779 |
mHeight= screen.getHeight();
|
|
| 780 |
|
|
| 781 |
X0 = mWidth*0.65f;
|
|
| 782 |
X1 = mWidth*0.50f;
|
|
| 783 |
X2 = mWidth*0.35f;
|
|
| 784 |
Y1 = mHeight*0.28f;
|
|
| 785 |
D = mWidth*0.01f;
|
|
| 786 |
s001 = mWidth*0.0001f;
|
|
| 787 |
s014 = mWidth*0.14f;
|
|
| 788 |
s033 = mWidth*0.33f;
|
|
| 781 | 789 |
F = 0.60f; |
| 782 | 790 |
} |
| 783 | 791 |
|
| ... | ... | |
| 886 | 894 |
{
|
| 887 | 895 |
case 1: boolean finished1 = mDyn1.get( tmpBuffer,0, time, mDiffTime); |
| 888 | 896 |
mPosition1.set(tmpBuffer[0], tmpBuffer[1], tmpBuffer[2]); |
| 889 |
if( finished1 ) stageFinished(mCurrentStage); |
|
| 897 |
|
|
| 898 |
if( mCurrentStage==3 ) |
|
| 899 |
{
|
|
| 900 |
RubikSurfaceView view = mControl.getSurfaceView(); |
|
| 901 |
float x = tmpBuffer[0]+mWidth*0.5f; |
|
| 902 |
float y = mHeight*0.5f-tmpBuffer[1]; |
|
| 903 |
view.actionMove(x,y); |
|
| 904 |
} |
|
| 905 |
|
|
| 906 |
if( finished1 ) |
|
| 907 |
{
|
|
| 908 |
if( mCurrentStage==3 ) |
|
| 909 |
{
|
|
| 910 |
RubikSurfaceView view = mControl.getSurfaceView(); |
|
| 911 |
view.prepareUp(); |
|
| 912 |
view.actionUp(); |
|
| 913 |
} |
|
| 914 |
|
|
| 915 |
stageFinished(mCurrentStage); |
|
| 916 |
} |
|
| 890 | 917 |
break; |
| 891 | 918 |
case 2: boolean finished2_1 = mDyn1.get( tmpBuffer,0, time, mDiffTime); |
| 892 | 919 |
boolean finished2_2 = mDyn2.get( tmpBuffer,3, time, mDiffTime); |
| src/main/java/org/distorted/main/RubikActivity.java | ||
|---|---|---|
| 396 | 396 |
|
| 397 | 397 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 398 | 398 |
|
| 399 |
public int getScreenWidthInPixels()
|
|
| 399 |
public RubikPreRender getPreRender()
|
|
| 400 | 400 |
{
|
| 401 |
return mScreenWidth; |
|
| 401 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
| 402 |
return view.getPreRender(); |
|
| 402 | 403 |
} |
| 403 | 404 |
|
| 404 | 405 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 405 | 406 |
|
| 406 |
public int getScreenHeightInPixels()
|
|
| 407 |
public RubikSurfaceView getSurfaceView()
|
|
| 407 | 408 |
{
|
| 408 |
return mScreenHeight;
|
|
| 409 |
return findViewById(R.id.rubikSurfaceView);
|
|
| 409 | 410 |
} |
| 410 | 411 |
|
| 411 | 412 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 412 | 413 |
|
| 413 |
public RubikPreRender getPreRender()
|
|
| 414 |
public int getScreenWidthInPixels()
|
|
| 414 | 415 |
{
|
| 415 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
| 416 |
return view.getPreRender(); |
|
| 416 |
return mScreenWidth; |
|
| 417 |
} |
|
| 418 |
|
|
| 419 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 420 |
|
|
| 421 |
public int getScreenHeightInPixels() |
|
| 422 |
{
|
|
| 423 |
return mScreenHeight; |
|
| 417 | 424 |
} |
| 418 | 425 |
|
| 419 | 426 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/main/RubikSurfaceView.java | ||
|---|---|---|
| 80 | 80 |
|
| 81 | 81 |
private int mPointer1, mPointer2; |
| 82 | 82 |
private float mX1, mY1, mX2, mY2, mX, mY; |
| 83 |
private boolean mIsAutomatic; |
|
| 83 | 84 |
|
| 84 | 85 |
private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); |
| 85 | 86 |
private static final Static4D mTemp= new Static4D(0,0,0,1); |
| ... | ... | |
| 342 | 343 |
{
|
| 343 | 344 |
final RubikActivity act = (RubikActivity)getContext(); |
| 344 | 345 |
|
| 345 |
mDragging = !act.isLocked();
|
|
| 346 |
mDragging = (!act.isLocked() || mIsAutomatic);
|
|
| 346 | 347 |
mBeginningRotation = false; |
| 347 | 348 |
mContinuingRotation = false; |
| 348 | 349 |
} |
| ... | ... | |
| 529 | 530 |
|
| 530 | 531 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 531 | 532 |
|
| 532 |
private void prepareUp() |
|
| 533 |
private void prepareUp(MotionEvent event)
|
|
| 533 | 534 |
{
|
| 534 | 535 |
mPointer1 = INVALID_POINTER_ID; |
| 535 | 536 |
mPointer2 = INVALID_POINTER_ID; |
| ... | ... | |
| 575 | 576 |
|
| 576 | 577 |
if(!isInEditMode()) |
| 577 | 578 |
{
|
| 579 |
mIsAutomatic = false; |
|
| 580 |
|
|
| 578 | 581 |
mLastCubitColor = -1; |
| 579 | 582 |
mCurrRotSpeed = 0.0f; |
| 580 | 583 |
|
| ... | ... | |
| 623 | 626 |
|
| 624 | 627 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 625 | 628 |
|
| 626 |
public void actionMove(int p1, float x1, float y1, int p2, float x2, float y2)
|
|
| 629 |
public void prepareDown()
|
|
| 627 | 630 |
{
|
| 628 |
float pX = p1 != INVALID_POINTER_ID ? x1 : x2; |
|
| 629 |
float pY = p1 != INVALID_POINTER_ID ? y1 : y2; |
|
| 631 |
mIsAutomatic = true; |
|
| 632 |
mPointer1 = 0; |
|
| 633 |
mPointer2 = INVALID_POINTER_ID; |
|
| 634 |
} |
|
| 635 |
|
|
| 636 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 637 |
|
|
| 638 |
public void prepareUp() |
|
| 639 |
{
|
|
| 640 |
mIsAutomatic = false; |
|
| 641 |
mPointer1 = INVALID_POINTER_ID; |
|
| 642 |
mPointer2 = INVALID_POINTER_ID; |
|
| 643 |
} |
|
| 644 |
|
|
| 645 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 646 |
|
|
| 647 |
public void actionMove(float pX, float pY) |
|
| 648 |
{
|
|
| 649 |
//android.util.Log.e("D", "ACTION MOVE x="+pX+" y="+pY+" mDragging="+mDragging);
|
|
| 630 | 650 |
|
| 631 | 651 |
float x = (pX - mScreenWidth*0.5f)/mScreenMin; |
| 632 | 652 |
float y = (mScreenHeight*0.5f -pY)/mScreenMin; |
| ... | ... | |
| 654 | 674 |
|
| 655 | 675 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 656 | 676 |
|
| 657 |
public void actionDown(float x1, float y1)
|
|
| 677 |
public void actionDown(float x, float y)
|
|
| 658 | 678 |
{
|
| 659 |
mX = (x1 - mScreenWidth*0.5f)/mScreenMin; |
|
| 660 |
mY = (mScreenHeight*0.5f - y1)/mScreenMin; |
|
| 679 |
//android.util.Log.e("D", "ACTION DOWN x="+x+" y="+y);
|
|
| 680 |
|
|
| 681 |
mX = (x - mScreenWidth*0.5f)/mScreenMin; |
|
| 682 |
mY = (mScreenHeight*0.5f - y)/mScreenMin; |
|
| 661 | 683 |
|
| 662 | 684 |
setUpDragOrRotate(true,mX,mY); |
| 663 | 685 |
} |
| ... | ... | |
| 666 | 688 |
|
| 667 | 689 |
public void actionUp() |
| 668 | 690 |
{
|
| 691 |
//android.util.Log.e("D", "ACTION UP");
|
|
| 692 |
|
|
| 669 | 693 |
if( mContinuingRotation ) |
| 670 | 694 |
{
|
| 671 | 695 |
finishRotation(); |
| ... | ... | |
| 702 | 726 |
|
| 703 | 727 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 704 | 728 |
|
| 705 |
public void actionUp2(int p1, float x1, float y1, int p2, float x2, float y2)
|
|
| 729 |
public void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
|
|
| 706 | 730 |
{
|
| 707 |
if( p1==INVALID_POINTER_ID )
|
|
| 731 |
if( p1isUp )
|
|
| 708 | 732 |
{
|
| 709 | 733 |
mX = (x2 - mScreenWidth*0.5f)/mScreenMin; |
| 710 | 734 |
mY = (mScreenHeight*0.5f - y2)/mScreenMin; |
| 711 | 735 |
} |
| 712 |
if( p2==INVALID_POINTER_ID )
|
|
| 736 |
if( p2isUp )
|
|
| 713 | 737 |
{
|
| 714 | 738 |
mX = (x1 - mScreenWidth*0.5f)/mScreenMin; |
| 715 | 739 |
mY = (mScreenHeight*0.5f - y1)/mScreenMin; |
| ... | ... | |
| 729 | 753 |
actionDown(mX1, mY1); |
| 730 | 754 |
break; |
| 731 | 755 |
case MotionEvent.ACTION_MOVE : prepareMove(event); |
| 732 |
actionMove(mPointer1, mX1, mY1, mPointer2, mX2, mY2); |
|
| 756 |
float x = mPointer1 != INVALID_POINTER_ID ? mX1 : mX2; |
|
| 757 |
float y = mPointer1 != INVALID_POINTER_ID ? mY1 : mY2; |
|
| 758 |
actionMove(x,y); |
|
| 733 | 759 |
break; |
| 734 |
case MotionEvent.ACTION_UP : prepareUp(); |
|
| 760 |
case MotionEvent.ACTION_UP : prepareUp(event);
|
|
| 735 | 761 |
actionUp(); |
| 736 | 762 |
break; |
| 737 | 763 |
case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event); |
| 738 | 764 |
actionDown2(mX1, mY1, mX2, mY2); |
| 739 | 765 |
break; |
| 740 | 766 |
case MotionEvent.ACTION_POINTER_UP : prepareUp2(event); |
| 741 |
actionUp2(mPointer1, mX1, mY1, mPointer2, mX2, mY2); |
|
| 767 |
boolean p1isUp = mPointer1==INVALID_POINTER_ID; |
|
| 768 |
boolean p2isUp = mPointer2==INVALID_POINTER_ID; |
|
| 769 |
actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2); |
|
| 742 | 770 |
break; |
| 743 | 771 |
} |
| 744 | 772 |
|
Also available in: Unified diff
RubikControl: rotate the cube.