42 |
42 |
public class RubikSurfaceView extends GLSurfaceView
|
43 |
43 |
{
|
44 |
44 |
private static final int NUM_SPEED_PROBES = 10;
|
|
45 |
private static final int INVALID_POINTER_ID = -1;
|
45 |
46 |
|
46 |
47 |
public static final int MODE_ROTATE = 0;
|
47 |
48 |
public static final int MODE_DRAG = 1;
|
... | ... | |
70 |
71 |
private boolean mDragging, mBeginningRotation, mContinuingRotation;
|
71 |
72 |
private int mScreenWidth, mScreenHeight, mScreenMin;
|
72 |
73 |
|
|
74 |
private int mPtrID1, mPtrID2;
|
73 |
75 |
private int mNumFingersDown;
|
74 |
76 |
private float mX, mY;
|
75 |
77 |
private float mStartRotX, mStartRotY;
|
... | ... | |
457 |
459 |
|
458 |
460 |
private void actionMove(MotionEvent event)
|
459 |
461 |
{
|
460 |
|
float x = (event.getX() - mScreenWidth*0.5f)/mScreenMin;
|
461 |
|
float y = (mScreenHeight*0.5f -event.getY())/mScreenMin;
|
|
462 |
int pointer = event.findPointerIndex(mPtrID1 != INVALID_POINTER_ID ? mPtrID1:mPtrID2);
|
462 |
463 |
|
463 |
|
//android.util.Log.e("view", "num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
|
|
464 |
float pX = event.getX(pointer);
|
|
465 |
float pY = event.getY(pointer);
|
|
466 |
|
|
467 |
float x = (pX - mScreenWidth*0.5f)/mScreenMin;
|
|
468 |
float y = (mScreenHeight*0.5f -pY)/mScreenMin;
|
464 |
469 |
|
465 |
470 |
if( mBeginningRotation )
|
466 |
471 |
{
|
... | ... | |
488 |
493 |
private void actionDown(MotionEvent event)
|
489 |
494 |
{
|
490 |
495 |
mNumFingersDown++;
|
|
496 |
mPtrID1 = event.getPointerId(0);
|
491 |
497 |
|
492 |
|
int index = event.getActionIndex();
|
493 |
498 |
float x = event.getX();
|
494 |
499 |
float y = event.getY();
|
495 |
500 |
|
496 |
|
android.util.Log.e("view", "down1 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
|
497 |
|
|
498 |
501 |
mX = (x - mScreenWidth*0.5f)/mScreenMin;
|
499 |
502 |
mY = (mScreenHeight*0.5f -y)/mScreenMin;
|
500 |
503 |
|
... | ... | |
507 |
510 |
{
|
508 |
511 |
mNumFingersDown--;
|
509 |
512 |
|
510 |
|
int index = event.getActionIndex();
|
511 |
|
float x = event.getX();
|
512 |
|
float y = event.getY();
|
513 |
|
|
514 |
|
android.util.Log.e("view", "up1 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
|
|
513 |
mPtrID1 = INVALID_POINTER_ID;
|
|
514 |
mPtrID2 = INVALID_POINTER_ID;
|
515 |
515 |
|
516 |
516 |
if( mContinuingRotation )
|
517 |
517 |
{
|
... | ... | |
530 |
530 |
{
|
531 |
531 |
mNumFingersDown++;
|
532 |
532 |
|
|
533 |
int index = event.getActionIndex();
|
|
534 |
|
|
535 |
if( mPtrID1==INVALID_POINTER_ID )
|
|
536 |
{
|
|
537 |
mPtrID1 = event.getPointerId(index);
|
|
538 |
float x = event.getX(index);
|
|
539 |
float y = event.getY(index);
|
|
540 |
|
|
541 |
mX = (x - mScreenWidth*0.5f)/mScreenMin;
|
|
542 |
mY = (mScreenHeight*0.5f -y)/mScreenMin;
|
|
543 |
}
|
|
544 |
else if( mPtrID2==INVALID_POINTER_ID )
|
|
545 |
{
|
|
546 |
mPtrID2 = event.getPointerId(index);
|
|
547 |
|
|
548 |
if( mBeginningRotation || mContinuingRotation )
|
|
549 |
{
|
|
550 |
float x = event.getX();
|
|
551 |
float y = event.getY();
|
|
552 |
|
|
553 |
mX = (x - mScreenWidth*0.5f)/mScreenMin;
|
|
554 |
mY = (mScreenHeight*0.5f -y)/mScreenMin;
|
|
555 |
}
|
|
556 |
}
|
|
557 |
|
533 |
558 |
if( mBeginningRotation )
|
534 |
559 |
{
|
535 |
560 |
mContinuingRotation = false;
|
... | ... | |
540 |
565 |
{
|
541 |
566 |
finishRotation();
|
542 |
567 |
}
|
543 |
|
|
544 |
|
int index = event.getActionIndex();
|
545 |
|
float x = event.getX();
|
546 |
|
float y = event.getY();
|
547 |
|
|
548 |
|
android.util.Log.e("view", "down2 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
|
549 |
568 |
}
|
550 |
569 |
|
551 |
570 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
555 |
574 |
mNumFingersDown--;
|
556 |
575 |
|
557 |
576 |
int index = event.getActionIndex();
|
558 |
|
float x = event.getX();
|
559 |
|
float y = event.getY();
|
560 |
577 |
|
561 |
|
android.util.Log.e("view", "up2 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
|
|
578 |
if( index==0 )
|
|
579 |
{
|
|
580 |
mPtrID1 = INVALID_POINTER_ID;
|
|
581 |
int pointer = event.findPointerIndex(mPtrID2);
|
|
582 |
float x1 = event.getX(pointer);
|
|
583 |
float y1 = event.getY(pointer);
|
|
584 |
|
|
585 |
mX = (x1 - mScreenWidth*0.5f)/mScreenMin;
|
|
586 |
mY = (mScreenHeight*0.5f -y1)/mScreenMin;
|
|
587 |
}
|
|
588 |
else
|
|
589 |
{
|
|
590 |
mPtrID2 = INVALID_POINTER_ID;
|
|
591 |
}
|
562 |
592 |
}
|
563 |
593 |
|
564 |
594 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
580 |
610 |
mFirstIndex =0;
|
581 |
611 |
mLastIndex =0;
|
582 |
612 |
|
|
613 |
mPtrID1 = INVALID_POINTER_ID;
|
|
614 |
mPtrID2 = INVALID_POINTER_ID;
|
|
615 |
|
583 |
616 |
mNumFingersDown = 0;
|
584 |
617 |
|
585 |
618 |
mRenderer = new RubikRenderer(this);
|
Progress with dragging.