Project

General

Profile

« Previous | Next » 

Revision 4da7d87a

Added by Leszek Koltunski almost 4 years ago

Simplify dragging. Now there's only 1 Quat, rather than the old way with two (Accumulated, Current).

View differences:

src/main/java/org/distorted/main/RubikSurfaceView.java
50 50
    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
51 51
    // given face by SWIPING_SENSITIVITY/2 degrees.
52 52
    private final static int SWIPING_SENSITIVITY  = 240;
53
    // Moving the finger by 0.33 of an inch will start a Rotation.
54
    private final static float ROTATION_SENSITIVITY =  0.33f;
55
    // Every 0.33 of an inch the direction of cube drag will reset.
56
    private final static float DIRECTION_SENSITIVITY=  0.33f;
53
    // Moving the finger by 0.3 of an inch will start a Rotation.
54
    private final static float ROTATION_SENSITIVITY = 0.3f;
57 55

  
58 56
    // Where did we get this sqrt(3)/2 ? From the (default, i.e. 60 degrees - see InternalOutputSurface!)
59 57
    // FOV of the projection matrix of the Node onto the Screen.
......
86 84
    private int mFirstIndex, mLastIndex;
87 85
    private int mDensity;
88 86

  
89
    private static Static4D mQuatCurrent    = new Static4D(0,0,0,1);
90
    private static Static4D mQuatAccumulated= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
91
    private static Static4D mTempCurrent    = new Static4D(0,0,0,1);
92
    private static Static4D mTempAccumulated= new Static4D(0,0,0,1);
87
    private static Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
88
    private static Static4D mTemp= new Static4D(0,0,0,1);
93 89

  
94 90
///////////////////////////////////////////////////////////////////////////////////////////////////
95 91

  
......
124 120

  
125 121
///////////////////////////////////////////////////////////////////////////////////////////////////
126 122

  
127
    void setQuatAccumulated()
123
    void setQuat()
128 124
      {
129
      mQuatAccumulated.set(mTempAccumulated);
125
      mQuat.set(mTemp);
130 126
      }
131 127

  
132 128
///////////////////////////////////////////////////////////////////////////////////////////////////
133 129

  
134
    void setQuatCurrent()
130
    Static4D getQuat()
135 131
      {
136
      mQuatCurrent.set(mTempCurrent);
137
      }
138

  
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

  
141
    Static4D getQuatAccumulated()
142
      {
143
      return mQuatAccumulated;
144
      }
145

  
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

  
148
    Static4D getQuatCurrent()
149
      {
150
      return mQuatCurrent;
132
      return mQuat;
151 133
      }
152 134

  
153 135
///////////////////////////////////////////////////////////////////////////////////////////////////
......
200 182
    private void computeCurrentAxis(Static3D axis)
201 183
      {
202 184
      Static4D axis4D = new Static4D(axis.get0(), axis.get1(), axis.get2(), 0);
203
      Static4D result = rotateVectorByQuat(axis4D, mQuatAccumulated);
185
      Static4D result = rotateVectorByQuat(axis4D, mQuat);
204 186

  
205 187
      mAxisX =result.get0();
206 188
      mAxisY =result.get1();
......
338 320
      else
339 321
        {
340 322
        Static4D touchPoint1 = new Static4D(x, y, 0, 0);
341
        Static4D rotatedTouchPoint1= rotateVectorByInvertedQuat(touchPoint1, mQuatAccumulated);
342
        Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuatAccumulated);
323
        Static4D rotatedTouchPoint1= rotateVectorByInvertedQuat(touchPoint1, mQuat);
324
        Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
343 325

  
344 326
        if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint1,rotatedCamera) )
345 327
          {
......
380 362

  
381 363
    private void drag(float x, float y)
382 364
      {
383
      if( retFingerDragDistanceInInches(mX,mY,x,y) > DIRECTION_SENSITIVITY )
384
        {
385
        mX = x;
386
        mY = y;
387
        mTempAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated));
388
        mTempCurrent.set(0f, 0f, 0f, 1f);
389
        mPreRender.setQuatCurrentOnNextRender();
390
        mPreRender.setQuatAccumulatedOnNextRender();
391
        }
392

  
393
      mTempCurrent.set(quatFromDrag(mX-x,y-mY));
394
      mPreRender.setQuatCurrentOnNextRender();
365
      mTemp.set(quatMultiply(quatFromDrag(mX-x,y-mY), mQuat));
366
      mPreRender.setQuatOnNextRender();
367
      mX = x;
368
      mY = y;
395 369
      }
396 370

  
397 371
///////////////////////////////////////////////////////////////////////////////////////////////////
......
443 417
      mStartRotY = y;
444 418

  
445 419
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
446
      Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuatAccumulated);
420
      Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuat);
447 421

  
448 422
      Static2D res = mMovement.newRotation(rotatedTouchPoint2);
449 423
      RubikObject object = mPreRender.getObject();
......
486 460
      float x = (event.getX() - mScreenWidth*0.5f)/mScreenMin;
487 461
      float y = (mScreenHeight*0.5f -event.getY())/mScreenMin;
488 462

  
489

  
490 463
      //android.util.Log.e("view", "num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
491 464

  
492

  
493 465
      if( mBeginningRotation )
494 466
        {
495 467
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
......
517 489
      {
518 490
      mNumFingersDown++;
519 491

  
520
      //android.util.Log.e("view", "down1 num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
492
      int index = event.getActionIndex();
493
      float x = event.getX();
494
      float y = event.getY();
521 495

  
522
      mX = (event.getX() - mScreenWidth*0.5f)/mScreenMin;
523
      mY = (mScreenHeight*0.5f -event.getY())/mScreenMin;
496
      android.util.Log.e("view", "down1 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
497

  
498
      mX = (x - mScreenWidth*0.5f)/mScreenMin;
499
      mY = (mScreenHeight*0.5f -y)/mScreenMin;
524 500

  
525 501
      setUpDragOrRotate(true,mX,mY);
526 502
      }
......
531 507
      {
532 508
      mNumFingersDown--;
533 509

  
534
      //android.util.Log.e("view", "up1 num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
510
      int index = event.getActionIndex();
511
      float x = event.getX();
512
      float y = event.getY();
535 513

  
536
      if( mDragging )
537
        {
538
        mTempAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated));
539
        mTempCurrent.set(0f, 0f, 0f, 1f);
540
        mPreRender.setQuatCurrentOnNextRender();
541
        mPreRender.setQuatAccumulatedOnNextRender();
542
        }
514
      android.util.Log.e("view", "up1 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
543 515

  
544 516
      if( mContinuingRotation )
545 517
        {
......
569 541
        finishRotation();
570 542
        }
571 543

  
572
      //android.util.Log.e("view", "down2 num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
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);
573 549
      }
574 550

  
575 551
///////////////////////////////////////////////////////////////////////////////////////////////////
......
578 554
      {
579 555
      mNumFingersDown--;
580 556

  
581
      //android.util.Log.e("view", "up2 num fingers: "+mNumFingersDown+" x="+event.getX()+" y="+event.getY());
557
      int index = event.getActionIndex();
558
      float x = event.getX();
559
      float y = event.getY();
560

  
561
      android.util.Log.e("view", "up2 num fingers: "+mNumFingersDown+" index="+index+" x="+x+" y="+y);
582 562
      }
583 563

  
584 564
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff