Revision 7695a3be
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
71 | 71 |
private boolean mDragging, mBeginningRotation, mContinuingRotation; |
72 | 72 |
private int mScreenWidth, mScreenHeight, mScreenMin; |
73 | 73 |
|
74 |
private float mRotAngle; |
|
74 | 75 |
private int mPtrID1, mPtrID2; |
75 | 76 |
private int mNumFingersDown; |
76 | 77 |
private float mX, mY; |
... | ... | |
362 | 363 |
|
363 | 364 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
364 | 365 |
|
365 |
private void drag(float x, float y) |
|
366 |
private void drag(MotionEvent event, float x, float y)
|
|
366 | 367 |
{ |
367 |
mTemp.set(quatMultiply(quatFromDrag(mX-x,y-mY), mQuat)); |
|
368 |
if( mPtrID1!=INVALID_POINTER_ID && mPtrID2!=INVALID_POINTER_ID) |
|
369 |
{ |
|
370 |
int pointer = event.findPointerIndex(mPtrID2); |
|
371 |
|
|
372 |
float pX = event.getX(pointer); |
|
373 |
float pY = event.getY(pointer); |
|
374 |
|
|
375 |
float x2 = (pX - mScreenWidth*0.5f)/mScreenMin; |
|
376 |
float y2 = (mScreenHeight*0.5f -pY)/mScreenMin; |
|
377 |
|
|
378 |
float angleNow = getAngle(x,y,x2,y2); |
|
379 |
float angleDiff = angleNow-mRotAngle; |
|
380 |
float sinA =-(float)Math.sin(angleDiff); |
|
381 |
float cosA = (float)Math.cos(angleDiff); |
|
382 |
|
|
383 |
Static4D dragQuat = quatMultiply(new Static4D(0,0,sinA,cosA), mQuat); |
|
384 |
mTemp.set(dragQuat); |
|
385 |
|
|
386 |
mRotAngle = angleNow; |
|
387 |
} |
|
388 |
else |
|
389 |
{ |
|
390 |
Static4D dragQuat = quatMultiply(quatFromDrag(mX-x,y-mY), mQuat); |
|
391 |
mTemp.set(dragQuat); |
|
392 |
} |
|
393 |
|
|
368 | 394 |
mPreRender.setQuatOnNextRender(); |
369 | 395 |
mX = x; |
370 | 396 |
mY = y; |
... | ... | |
455 | 481 |
mContinuingRotation= true; |
456 | 482 |
} |
457 | 483 |
|
484 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
485 |
|
|
486 |
private float getAngle(float x1, float y1, float x2, float y2) |
|
487 |
{ |
|
488 |
return (float) Math.atan2(y1-y2, x1-x2); |
|
489 |
} |
|
490 |
|
|
458 | 491 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
459 | 492 |
|
460 | 493 |
private void actionMove(MotionEvent event) |
461 | 494 |
{ |
462 | 495 |
int pointer = event.findPointerIndex(mPtrID1 != INVALID_POINTER_ID ? mPtrID1:mPtrID2); |
463 | 496 |
|
497 |
if( pointer<0 ) return; |
|
498 |
|
|
464 | 499 |
float pX = event.getX(pointer); |
465 | 500 |
float pY = event.getY(pointer); |
466 | 501 |
|
... | ... | |
480 | 515 |
} |
481 | 516 |
else if( mDragging ) |
482 | 517 |
{ |
483 |
drag(x,y); |
|
518 |
drag(event,x,y);
|
|
484 | 519 |
} |
485 | 520 |
else |
486 | 521 |
{ |
... | ... | |
535 | 570 |
if( mPtrID1==INVALID_POINTER_ID ) |
536 | 571 |
{ |
537 | 572 |
mPtrID1 = event.getPointerId(index); |
538 |
float x = event.getX(index); |
|
539 |
float y = event.getY(index); |
|
573 |
float x = event.getX(); |
|
574 |
float y = event.getY(); |
|
575 |
|
|
576 |
if( mPtrID2 != INVALID_POINTER_ID ) |
|
577 |
{ |
|
578 |
int pointer = event.findPointerIndex(mPtrID2); |
|
579 |
|
|
580 |
float x2 = event.getX(pointer); |
|
581 |
float y2 = event.getY(pointer); |
|
582 |
|
|
583 |
mRotAngle = getAngle(x,-y,x2,-y2); |
|
584 |
} |
|
540 | 585 |
|
541 | 586 |
mX = (x - mScreenWidth*0.5f)/mScreenMin; |
542 | 587 |
mY = (mScreenHeight*0.5f -y)/mScreenMin; |
... | ... | |
545 | 590 |
{ |
546 | 591 |
mPtrID2 = event.getPointerId(index); |
547 | 592 |
|
548 |
if( mBeginningRotation || mContinuingRotation ) |
|
593 |
float x = event.getX(); |
|
594 |
float y = event.getY(); |
|
595 |
|
|
596 |
if( mPtrID2 != INVALID_POINTER_ID ) |
|
549 | 597 |
{ |
550 |
float x = event.getX(); |
|
551 |
float y = event.getY(); |
|
598 |
int pointer = event.findPointerIndex(mPtrID2); |
|
599 |
|
|
600 |
float x2 = event.getX(pointer); |
|
601 |
float y2 = event.getY(pointer); |
|
552 | 602 |
|
603 |
mRotAngle = getAngle(x,-y,x2,-y2); |
|
604 |
} |
|
605 |
|
|
606 |
if( mBeginningRotation || mContinuingRotation ) |
|
607 |
{ |
|
553 | 608 |
mX = (x - mScreenWidth*0.5f)/mScreenMin; |
554 | 609 |
mY = (mScreenHeight*0.5f -y)/mScreenMin; |
555 | 610 |
} |
... | ... | |
575 | 630 |
|
576 | 631 |
int index = event.getActionIndex(); |
577 | 632 |
|
578 |
if( index==0 )
|
|
633 |
if( index==event.findPointerIndex(mPtrID1) )
|
|
579 | 634 |
{ |
580 | 635 |
mPtrID1 = INVALID_POINTER_ID; |
581 | 636 |
int pointer = event.findPointerIndex(mPtrID2); |
582 |
float x1 = event.getX(pointer); |
|
583 |
float y1 = event.getY(pointer); |
|
584 | 637 |
|
585 |
mX = (x1 - mScreenWidth*0.5f)/mScreenMin; |
|
586 |
mY = (mScreenHeight*0.5f -y1)/mScreenMin; |
|
638 |
if( pointer>=0 ) |
|
639 |
{ |
|
640 |
float x1 = event.getX(pointer); |
|
641 |
float y1 = event.getY(pointer); |
|
642 |
|
|
643 |
mX = (x1 - mScreenWidth*0.5f)/mScreenMin; |
|
644 |
mY = (mScreenHeight*0.5f -y1)/mScreenMin; |
|
645 |
} |
|
587 | 646 |
} |
588 |
else |
|
647 |
else if( index==event.findPointerIndex(mPtrID2) )
|
|
589 | 648 |
{ |
590 | 649 |
mPtrID2 = INVALID_POINTER_ID; |
591 | 650 |
} |
Also available in: Unified diff
Two-fingered object rotation seems to be finished.