Project

General

Profile

« Previous | Next » 

Revision 4da7d87a

Added by Leszek Koltunski over 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/RubikPreRender.java
45 45

  
46 46
  private RubikSurfaceView mView;
47 47
  private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation,
48
                  mSetQuatCurrent, mSetQuatAccumulated, mChangeObject, mSetupObject, mSolveObject,
49
                  mScrambleObject, mInitializeObject, mSetTextureMap, mResetAllTextureMaps;
48
                  mSetQuat, mChangeObject, mSetupObject, mSolveObject, mScrambleObject,
49
                  mInitializeObject, mSetTextureMap, mResetAllTextureMaps;
50 50
  private boolean mCanRotate, mCanPlay;
51 51
  private boolean mIsSolved;
52 52
  private RubikObjectList mNextObject;
......
77 77
    mRemoveRotation       = false;
78 78
    mRemovePatternRotation= false;
79 79
    mAddRotation          = false;
80
    mSetQuatCurrent       = false;
81
    mSetQuatAccumulated   = false;
80
    mSetQuat              = false;
82 81
    mChangeObject         = false;
83 82
    mSetupObject          = false;
84 83
    mSolveObject          = false;
......
108 107
    Context con = mView.getContext();
109 108
    Resources res = con.getResources();
110 109

  
111
    mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated(), moves, res);
110
    mNewObject = object.create(size, mView.getQuat(), moves, res);
112 111

  
113 112
    if( mNewObject!=null )
114 113
      {
......
318 317

  
319 318
///////////////////////////////////////////////////////////////////////////////////////////////////
320 319

  
321
  private void setQuatCurrentNow()
320
  private void setQuatNow()
322 321
    {
323
    mSetQuatCurrent = false;
324
    mView.setQuatCurrent();
325
    }
326

  
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

  
329
  private void setQuatAccumulatedNow()
330
    {
331
    mSetQuatAccumulated = false;
332
    mView.setQuatAccumulated();
322
    mSetQuat = false;
323
    mView.setQuat();
333 324
    }
334 325

  
335 326
///////////////////////////////////////////////////////////////////////////////////////////////////
......
425 416

  
426 417
///////////////////////////////////////////////////////////////////////////////////////////////////
427 418

  
428
  void setQuatCurrentOnNextRender()
429
    {
430
    mSetQuatCurrent = true;
431
    }
432

  
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

  
435
  void setQuatAccumulatedOnNextRender()
419
  void setQuatOnNextRender()
436 420
    {
437
    mSetQuatAccumulated = true;
421
    mSetQuat = true;
438 422
    }
439 423

  
440 424
///////////////////////////////////////////////////////////////////////////////////////////////////
441 425

  
442 426
  void preRender()
443 427
    {
444
    if( mSetQuatCurrent        ) setQuatCurrentNow();
445
    if( mSetQuatAccumulated    ) setQuatAccumulatedNow();
428
    if( mSetQuat               ) setQuatNow();
446 429
    if( mFinishRotation        ) finishRotationNow();
447 430
    if( mRemoveRotation        ) removeRotationNow();
448 431
    if( mRemovePatternRotation ) removePatternRotationNow();
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
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/RubikCube.java
99 99

  
100 100
///////////////////////////////////////////////////////////////////////////////////////////////////
101 101

  
102
  RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture,
102
  RubikCube(int size, Static4D quat, DistortedTexture texture,
103 103
            MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res)
104 104
    {
105
    super(size, 60, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.CUBE, res);
105
    super(size, 60, quat, texture, mesh, effects, moves, RubikObjectList.CUBE, res);
106 106
    }
107 107

  
108 108
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/RubikObject.java
69 69
  private int mRotAxis;
70 70
  private Static3D[] mOrigPos;
71 71
  private Static3D mNodeScale;
72
  private Static4D mQuatAccumulated;
72
  private Static4D mQuat;
73 73
  private Cubit[] mCubits;
74 74
  private int mSize;
75 75
  private RubikObjectList mList;
......
85 85
  DistortedTexture mTexture;
86 86

  
87 87
  MatrixEffectScale mScaleEffect;
88
  MatrixEffectQuaternion mQuatCEffect;
89
  MatrixEffectQuaternion mQuatAEffect;
88
  MatrixEffectQuaternion mQuatEffect;
90 89

  
91 90
///////////////////////////////////////////////////////////////////////////////////////////////////
92 91

  
93
  RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture,
94
              MeshRectangles nodeMesh, DistortedEffects nodeEffects, int[][] moves, RubikObjectList list, Resources res)
92
  RubikObject(int size, int fov, Static4D quat, DistortedTexture nodeTexture, MeshRectangles nodeMesh,
93
              DistortedEffects nodeEffects, int[][] moves, RubikObjectList list, Resources res)
95 94
    {
96 95
    super(nodeTexture,nodeEffects,nodeMesh);
97 96

  
......
109 108
    mSize = size;
110 109
    computeStartAndStep(mOrigPos);
111 110
    mNodeScale= new Static3D(1,1,1);
112
    mQuatAccumulated = quatAcc;
111
    mQuat = quat;
113 112

  
114 113
    mRotationAngle= new Dynamic1D();
115 114
    mRotationAxis = new Static3D(1,0,0);
......
121 120

  
122 121
    float scale = OBJECT_SCREEN_RATIO*NODE_FBO_SIZE/mSize;
123 122
    mScaleEffect = new MatrixEffectScale(new Static3D(scale,scale,scale));
124
    mQuatCEffect = new MatrixEffectQuaternion(quatCur, CENTER);
125
    mQuatAEffect = new MatrixEffectQuaternion(quatAcc, CENTER);
123
    mQuatEffect  = new MatrixEffectQuaternion(quat, CENTER);
126 124

  
127 125
    MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
128 126
    nodeEffects.apply(nodeScaleEffect);
......
163 161
      }
164 162

  
165 163
    mEffects.apply(mRotateEffect);
166
    mEffects.apply(mQuatAEffect);
167
    mEffects.apply(mQuatCEffect);
164
    mEffects.apply(mQuatEffect);
168 165
    mEffects.apply(mScaleEffect);
169 166

  
170 167
    attach( new DistortedNode(mTexture,mEffects,mMesh) );
......
349 346

  
350 347
  public Static4D getRotationQuat()
351 348
      {
352
      return mQuatAccumulated;
349
      return mQuat;
353 350
      }
354 351

  
355 352
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/RubikObjectList.java
322 322

  
323 323
///////////////////////////////////////////////////////////////////////////////////////////////////
324 324

  
325
  public RubikObject create(int size, Static4D quatCur, Static4D quatAcc, int[][] moves, Resources res)
325
  public RubikObject create(int size, Static4D quat, int[][] moves, Resources res)
326 326
    {
327 327
    DistortedTexture texture = new DistortedTexture();
328 328
    DistortedEffects effects = new DistortedEffects();
......
330 330

  
331 331
    switch(ordinal())
332 332
      {
333
      case 0: return new RubikCube    (size, quatCur, quatAcc, texture, mesh, effects, moves, res);
334
      case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects, moves, res);
333
      case 0: return new RubikCube    (size, quat, texture, mesh, effects, moves, res);
334
      case 1: return new RubikPyraminx(size, quat, texture, mesh, effects, moves, res);
335 335
      }
336 336

  
337 337
    return null;
src/main/java/org/distorted/objects/RubikPyraminx.java
99 99

  
100 100
///////////////////////////////////////////////////////////////////////////////////////////////////
101 101

  
102
  RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture,
102
  RubikPyraminx(int size, Static4D quat, DistortedTexture texture,
103 103
                MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res)
104 104
    {
105
    super(size, 30, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.PYRA, res);
105
    super(size, 30, quat, texture, mesh, effects, moves, RubikObjectList.PYRA, res);
106 106
    }
107 107

  
108 108
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff