Project

General

Profile

« Previous | Next » 

Revision 9205f15e

Added by Leszek Koltunski over 3 years ago

Simplify RubikSurfaceView and the touchscreen control.

View differences:

src/main/java/org/distorted/control/RubikControlWhole.java
64 64

  
65 65
  private MeshQuad mQuad;
66 66
  private DistortedTexture mTextureShad, mTextureCirc;
67

  
68 67
  private Dynamic3D mDynMoveHand1, mDynMoveShad1;
69 68
  private Dynamic3D mDynScaleHand1, mDynScaleShad1;
70
  private MatrixEffectMove mMoveHand1, mMoveShad1;
71
  private MatrixEffectScale mScaleHand1, mScaleShad1;
72

  
73 69
  private Dynamic3D mDynMoveHand2, mDynMoveShad2;
74 70
  private Dynamic3D mDynScaleHand2, mDynScaleShad2;
75
  private MatrixEffectMove mMoveHand2, mMoveShad2;
76
  private MatrixEffectScale mScaleHand2, mScaleShad2;
77

  
78 71
  private Dynamic3D mDyn1, mDyn2, mDyn3, mDyn4;
79 72
  private Static3D mPosition1, mPosition2, mPosition3, mPosition4;
80 73
  private float[] tmpBuffer;
......
740 733
    mDynScaleShad1.setMode(Dynamic.MODE_PATH);
741 734
    mDynScaleShad1.setConvexity(0.0f);
742 735

  
743
    mMoveHand1 = new MatrixEffectMove(mDynMoveHand1);
744
    mMoveShad1 = new MatrixEffectMove(mDynMoveShad1);
745
    mScaleHand1= new MatrixEffectScale(mDynScaleHand1);
746
    mScaleShad1= new MatrixEffectScale(mDynScaleShad1);
736
    MatrixEffectMove  moveHand1 = new MatrixEffectMove(mDynMoveHand1);
737
    MatrixEffectMove  moveShad1 = new MatrixEffectMove(mDynMoveShad1);
738
    MatrixEffectScale scaleHand1= new MatrixEffectScale(mDynScaleHand1);
739
    MatrixEffectScale scaleShad1= new MatrixEffectScale(mDynScaleShad1);
747 740

  
748
    mEffects[0].apply(mScaleShad1);
749
    mEffects[0].apply(mMoveShad1);
750
    mEffects[2].apply(mScaleHand1);
751
    mEffects[2].apply(mMoveHand1);
741
    mEffects[0].apply(scaleShad1);
742
    mEffects[0].apply(moveShad1);
743
    mEffects[2].apply(scaleHand1);
744
    mEffects[2].apply(moveHand1);
752 745

  
753 746
    mDynMoveHand2 = new Dynamic3D(time,0.5f);
754 747
    mDynMoveHand2.setMode(Dynamic.MODE_PATH);
......
763 756
    mDynScaleShad2.setMode(Dynamic.MODE_PATH);
764 757
    mDynScaleShad2.setConvexity(0.0f);
765 758

  
766
    mMoveHand2 = new MatrixEffectMove(mDynMoveHand2);
767
    mMoveShad2 = new MatrixEffectMove(mDynMoveShad2);
768
    mScaleHand2= new MatrixEffectScale(mDynScaleHand2);
769
    mScaleShad2= new MatrixEffectScale(mDynScaleShad2);
759
    MatrixEffectMove  moveHand2 = new MatrixEffectMove(mDynMoveHand2);
760
    MatrixEffectMove  moveShad2 = new MatrixEffectMove(mDynMoveShad2);
761
    MatrixEffectScale scaleHand2= new MatrixEffectScale(mDynScaleHand2);
762
    MatrixEffectScale scaleShad2= new MatrixEffectScale(mDynScaleShad2);
770 763

  
771
    mEffects[1].apply(mScaleShad2);
772
    mEffects[1].apply(mMoveShad2);
773
    mEffects[3].apply(mScaleHand2);
774
    mEffects[3].apply(mMoveHand2);
764
    mEffects[1].apply(scaleShad2);
765
    mEffects[1].apply(moveShad2);
766
    mEffects[3].apply(scaleHand2);
767
    mEffects[3].apply(moveHand2);
775 768

  
776 769
    DistortedScreen screen = mControl.getScreen();
777 770
    int wid= screen.getWidth();
......
862 855
    {
863 856
    switch(stage)
864 857
      {
865
      case  1: setEffectsStage2(); break;
866
      case  2: setEffectsStage3(); break;
867
      case  3: setEffectsStage4(); break;
868
      case  4: setEffectsStage5(); break;
869
      case  5: setEffectsStage6(); break;
870
      case  6: setEffectsStage7(); break;
871
      case  7: setEffectsStage8(); break;
872
      case  8: setEffectsStage9(); break;
858
      case  1: setEffectsStage2() ; break;
859
      case  2: setEffectsStage3() ; break;
860
      case  3: setEffectsStage4() ; break;
861
      case  4: setEffectsStage5() ; break;
862
      case  5: setEffectsStage6() ; break;
863
      case  6: setEffectsStage7() ; break;
864
      case  7: setEffectsStage8() ; break;
865
      case  8: setEffectsStage9() ; break;
873 866
      case  9: setEffectsStage10(); break;
874 867
      case 10: setEffectsStage11(); break;
875 868
      case 11: setEffectsStage12(); break;
src/main/java/org/distorted/main/RubikSurfaceView.java
66 66
    private int mScreenWidth, mScreenHeight, mScreenMin;
67 67

  
68 68
    private float mRotAngle, mInitDistance;
69
    private int mPtrID1, mPtrID2;
70
    private float mX, mY;
71 69
    private float mStartRotX, mStartRotY;
72 70
    private float mAxisX, mAxisY;
73 71
    private float mRotationFactor;
......
80 78
    private int mFirstIndex, mLastIndex;
81 79
    private int mDensity;
82 80

  
81
    private int mPointer1, mPointer2;
82
    private float mX1, mY1, mX2, mY2, mX, mY;
83

  
83 84
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
84 85
    private static final Static4D mTemp= new Static4D(0,0,0,1);
85 86

  
......
350 351

  
351 352
///////////////////////////////////////////////////////////////////////////////////////////////////
352 353

  
353
    private void drag(MotionEvent event, float x, float y)
354
    private void drag(float x, float y)
354 355
      {
355
      if( mPtrID1!=INVALID_POINTER_ID && mPtrID2!=INVALID_POINTER_ID)
356
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
356 357
        {
357
        int pointer = event.findPointerIndex(mPtrID2);
358
        float pX,pY;
359

  
360
        try
361
          {
362
          pX = event.getX(pointer);
363
          pY = event.getY(pointer);
364
          }
365
        catch(IllegalArgumentException ex)
366
          {
367
          mPtrID1=INVALID_POINTER_ID;
368
          mPtrID2=INVALID_POINTER_ID;
369

  
370
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
371
          crashlytics.setCustomKey("DragError", "pointer="+pointer );
372
          crashlytics.recordException(ex);
373

  
374
          return;
375
          }
376

  
377
        float x2 = (pX - mScreenWidth*0.5f)/mScreenMin;
378
        float y2 = (mScreenHeight*0.5f -pY)/mScreenMin;
358
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
359
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
379 360

  
380 361
        float angleNow = getAngle(x,y,x2,y2);
381 362
        float angleDiff = angleNow-mRotAngle;
......
509 490

  
510 491
///////////////////////////////////////////////////////////////////////////////////////////////////
511 492

  
512
    private void actionMove(MotionEvent event)
493
    void initialize()
513 494
      {
514
      int pointer = event.findPointerIndex(mPtrID1 != INVALID_POINTER_ID ? mPtrID1:mPtrID2);
515

  
516
      if( pointer<0 ) return;
517

  
518
      float pX = event.getX(pointer);
519
      float pY = event.getY(pointer);
520

  
521
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
522
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
523

  
524
      if( mBeginningRotation )
525
        {
526
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
527
          {
528
          beginRotation(x,y);
529
          }
530
        }
531
      else if( mContinuingRotation )
532
        {
533
        continueRotation(x,y);
534
        }
535
      else if( mDragging )
536
        {
537
        drag(event,x,y);
538
        }
539
      else
540
        {
541
        setUpDragOrRotate(false,x,y);
542
        }
495
      mPointer1 = INVALID_POINTER_ID;
496
      mPointer2 = INVALID_POINTER_ID;
543 497
      }
544 498

  
545 499
///////////////////////////////////////////////////////////////////////////////////////////////////
546 500

  
547
    private void actionDown(MotionEvent event)
501
    private void prepareDown(MotionEvent event)
548 502
      {
549
      mPtrID1 = event.getPointerId(0);
550

  
551
      float x = event.getX();
552
      float y = event.getY();
553

  
554
      mX = (x - mScreenWidth*0.5f)/mScreenMin;
555
      mY = (mScreenHeight*0.5f -y)/mScreenMin;
556

  
557
      setUpDragOrRotate(true,mX,mY);
503
      mPointer1 = event.getPointerId(0);
504
      mX1 = event.getX();
505
      mY1 = event.getY();
506
      mPointer2 = INVALID_POINTER_ID;
558 507
      }
559 508

  
560 509
///////////////////////////////////////////////////////////////////////////////////////////////////
561 510

  
562
    private void actionUp(MotionEvent event)
511
    private void prepareMove(MotionEvent event)
563 512
      {
564
      mPtrID1 = INVALID_POINTER_ID;
565
      mPtrID2 = INVALID_POINTER_ID;
513
      int index1 = event.findPointerIndex(mPointer1);
566 514

  
567
      if( mContinuingRotation )
515
      if( index1>=0 )
568 516
        {
569
        finishRotation();
517
        mX1 = event.getX(index1);
518
        mY1 = event.getY(index1);
570 519
        }
571 520

  
572
      if( mLastCubitColor>=0 )
521
      int index2 = event.findPointerIndex(mPointer2);
522

  
523
      if( index2>=0 )
573 524
        {
574
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
575
        mLastCubitColor = -1;
525
        mX2 = event.getX(index2);
526
        mY2 = event.getY(index2);
576 527
        }
577 528
      }
578 529

  
579 530
///////////////////////////////////////////////////////////////////////////////////////////////////
580 531

  
581
    private void actionDown2(MotionEvent event)
532
    private void prepareUp()
582 533
      {
583
      int index = event.getActionIndex();
584

  
585
      if( mPtrID1==INVALID_POINTER_ID )
586
        {
587
        mPtrID1 = event.getPointerId(index);
588
        float x = event.getX();
589
        float y = event.getY();
590

  
591
        if( mPtrID2 != INVALID_POINTER_ID )
592
          {
593
          int pointer = event.findPointerIndex(mPtrID2);
594

  
595
          try
596
            {
597
            float x2 = event.getX(pointer);
598
            float y2 = event.getY(pointer);
599

  
600
            mRotAngle = getAngle(x,-y,x2,-y2);
601
            mInitDistance = -1;
602
            }
603
          catch(IllegalArgumentException ex)
604
            {
605
            mPtrID1=INVALID_POINTER_ID;
606
            mPtrID2=INVALID_POINTER_ID;
607

  
608
            FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
609
            crashlytics.setCustomKey("DragError", "pointer="+pointer );
610
            crashlytics.recordException(ex);
611

  
612
            return;
613
            }
614
          }
615

  
616
        mX = (x - mScreenWidth*0.5f)/mScreenMin;
617
        mY = (mScreenHeight*0.5f -y)/mScreenMin;
618
        }
619
      else if( mPtrID2==INVALID_POINTER_ID )
620
        {
621
        mPtrID2 = event.getPointerId(index);
622

  
623
        float x = event.getX();
624
        float y = event.getY();
625

  
626
        if( mPtrID2 != INVALID_POINTER_ID )
627
          {
628
          int pointer = event.findPointerIndex(mPtrID2);
629

  
630
          try
631
            {
632
            float x2 = event.getX(pointer);
633
            float y2 = event.getY(pointer);
634

  
635
            mRotAngle = getAngle(x,-y,x2,-y2);
636
            mInitDistance = -1;
637
            }
638
          catch(IllegalArgumentException ex)
639
            {
640
            mPtrID1=INVALID_POINTER_ID;
641
            mPtrID2=INVALID_POINTER_ID;
642

  
643
            FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
644
            crashlytics.setCustomKey("DragError", "pointer="+pointer );
645
            crashlytics.recordException(ex);
646

  
647
            return;
648
            }
649
          }
650

  
651
        if( mBeginningRotation || mContinuingRotation )
652
          {
653
          mX = (x - mScreenWidth*0.5f)/mScreenMin;
654
          mY = (mScreenHeight*0.5f -y)/mScreenMin;
655
          }
656
        }
657

  
658
      if( mBeginningRotation )
659
        {
660
        mContinuingRotation = false;
661
        mBeginningRotation  = false;
662
        mDragging           = true;
663
        }
664
      else if( mContinuingRotation )
665
        {
666
        finishRotation();
667
        }
534
      mPointer1 = INVALID_POINTER_ID;
535
      mPointer2 = INVALID_POINTER_ID;
668 536
      }
669 537

  
670 538
///////////////////////////////////////////////////////////////////////////////////////////////////
671 539

  
672
    private void actionUp2(MotionEvent event)
540
    private void prepareDown2(MotionEvent event)
673 541
      {
674 542
      int index = event.getActionIndex();
675 543

  
676
      if( index==event.findPointerIndex(mPtrID1) )
544
      if( mPointer1==INVALID_POINTER_ID )
677 545
        {
678
        mPtrID1 = INVALID_POINTER_ID;
679
        int pointer = event.findPointerIndex(mPtrID2);
680

  
681
        if( pointer>=0 )
682
          {
683
          float x1 = event.getX(pointer);
684
          float y1 = event.getY(pointer);
685

  
686
          mX = (x1 - mScreenWidth*0.5f)/mScreenMin;
687
          mY = (mScreenHeight*0.5f -y1)/mScreenMin;
688
          }
546
        mPointer1 = event.getPointerId(index);
547
        mX1 = event.getX(index);
548
        mY1 = event.getY(index);
689 549
        }
690
      else if( index==event.findPointerIndex(mPtrID2) )
550
      else if( mPointer2==INVALID_POINTER_ID )
691 551
        {
692
        mPtrID2 = INVALID_POINTER_ID;
552
        mPointer2 = event.getPointerId(index);
553
        mX2 = event.getX(index);
554
        mY2 = event.getY(index);
693 555
        }
694 556
      }
695 557

  
696 558
///////////////////////////////////////////////////////////////////////////////////////////////////
697 559

  
698
    void initialize()
560
    private void prepareUp2(MotionEvent event)
699 561
      {
700
      mPtrID1 = INVALID_POINTER_ID;
701
      mPtrID2 = INVALID_POINTER_ID;
562
      int index = event.getActionIndex();
563

  
564
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
565
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
702 566
      }
703 567

  
704 568
///////////////////////////////////////////////////////////////////////////////////////////////////
......
757 621
        }
758 622
      }
759 623

  
624
///////////////////////////////////////////////////////////////////////////////////////////////////
625

  
626
    public void actionMove(int p1, float x1, float y1, int p2, float x2, float y2)
627
      {
628
      float pX = p1 != INVALID_POINTER_ID ? x1 : x2;
629
      float pY = p1 != INVALID_POINTER_ID ? y1 : y2;
630

  
631
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
632
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
633

  
634
      if( mBeginningRotation )
635
        {
636
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
637
          {
638
          beginRotation(x,y);
639
          }
640
        }
641
      else if( mContinuingRotation )
642
        {
643
        continueRotation(x,y);
644
        }
645
      else if( mDragging )
646
        {
647
        drag(x,y);
648
        }
649
      else
650
        {
651
        setUpDragOrRotate(false,x,y);
652
        }
653
      }
654

  
655
///////////////////////////////////////////////////////////////////////////////////////////////////
656

  
657
    public void actionDown(float x1, float y1)
658
      {
659
      mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
660
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
661

  
662
      setUpDragOrRotate(true,mX,mY);
663
      }
664

  
665
///////////////////////////////////////////////////////////////////////////////////////////////////
666

  
667
    public void actionUp()
668
      {
669
      if( mContinuingRotation )
670
        {
671
        finishRotation();
672
        }
673

  
674
      if( mLastCubitColor>=0 )
675
        {
676
        mPreRender.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
677
        mLastCubitColor = -1;
678
        }
679
      }
680

  
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682

  
683
    public void actionDown2(float x1, float y1, float x2, float y2)
684
      {
685
      mRotAngle = getAngle(x1,-y1, x2,-y2);
686
      mInitDistance = -1;
687

  
688
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
689
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
690

  
691
      if( mBeginningRotation )
692
        {
693
        mContinuingRotation = false;
694
        mBeginningRotation  = false;
695
        mDragging           = true;
696
        }
697
      else if( mContinuingRotation )
698
        {
699
        finishRotation();
700
        }
701
      }
702

  
703
///////////////////////////////////////////////////////////////////////////////////////////////////
704

  
705
    public void actionUp2(int p1, float x1, float y1, int p2, float x2, float y2)
706
      {
707
      if( p1==INVALID_POINTER_ID )
708
        {
709
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
710
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
711
        }
712
      if( p2==INVALID_POINTER_ID )
713
        {
714
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
715
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
716
        }
717
      }
718

  
760 719
///////////////////////////////////////////////////////////////////////////////////////////////////
761 720

  
762 721
    @Override
......
766 725

  
767 726
      switch(action)
768 727
         {
769
         case MotionEvent.ACTION_DOWN        : actionDown(event) ; break;
770
         case MotionEvent.ACTION_MOVE        : actionMove(event) ; break;
771
         case MotionEvent.ACTION_UP          : actionUp(event)   ; break;
772
         case MotionEvent.ACTION_POINTER_DOWN: actionDown2(event); break;
773
         case MotionEvent.ACTION_POINTER_UP  : actionUp2(event)  ; break;
728
         case MotionEvent.ACTION_DOWN        : prepareDown(event);
729
                                               actionDown(mX1, mY1);
730
                                               break;
731
         case MotionEvent.ACTION_MOVE        : prepareMove(event);
732
                                               actionMove(mPointer1, mX1, mY1, mPointer2, mX2, mY2);
733
                                               break;
734
         case MotionEvent.ACTION_UP          : prepareUp();
735
                                               actionUp();
736
                                               break;
737
         case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
738
                                               actionDown2(mX1, mY1, mX2, mY2);
739
                                               break;
740
         case MotionEvent.ACTION_POINTER_UP  : prepareUp2(event);
741
                                               actionUp2(mPointer1, mX1, mY1, mPointer2, mX2, mY2);
742
                                               break;
774 743
         }
775 744

  
776 745
      return true;

Also available in: Unified diff