Project

General

Profile

« Previous | Next » 

Revision 092e257b

Added by Leszek Koltunski about 1 year ago

Progress with support for the 'normal' touch-control: speed probes.

View differences:

src/main/java/org/distorted/objectlib/main/ObjectControl.java
58 58
    private float mStartRotX, mStartRotY;
59 59
    private float mRotationFactor;
60 60
    private int mCurrentAxis, mCurrentRow;
61
    private float mCurrentAngle, mCurrRotSpeed;
62
    private final float[] mLastX;
63
    private final float[] mLastY;
61
    private float mCurrentAngle, mAvgRotSpeed;
62
    private final float[] mLastA;
64 63
    private final long[] mLastT;
65 64
    private int mFirstIndex, mLastIndex;
66 65
    private final int mDensity;
......
80 79

  
81 80
///////////////////////////////////////////////////////////////////////////////////////////////////
82 81

  
83
    private void addSpeedProbe(float x, float y)
82
    private void addSpeedProbe(float angle)
84 83
      {
85 84
      long currTime = System.currentTimeMillis();
86 85
      boolean theSame = mLastIndex==mFirstIndex;
......
89 88
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
90 89

  
91 90
      mLastT[mLastIndex] = currTime;
92
      mLastX[mLastIndex] = x;
93
      mLastY[mLastIndex] = y;
91
      mLastA[mLastIndex] = angle;
94 92

  
95 93
      if( mLastIndex==mFirstIndex)
96 94
        {
......
101 99
      if( theSame )
102 100
        {
103 101
        mLastT[mFirstIndex] = currTime;
104
        mLastX[mFirstIndex] = x;
105
        mLastY[mFirstIndex] = y;
102
        mLastA[mFirstIndex] = angle;
106 103
        }
107 104
      }
108 105

  
......
110 107

  
111 108
    private void computeCurrentSpeedInInchesPerSecond()
112 109
      {
113
      long firstTime = mLastT[mFirstIndex];
114
      long lastTime  = mLastT[mLastIndex];
115
      float fX = mLastX[mFirstIndex];
116
      float fY = mLastY[mFirstIndex];
117
      float lX = mLastX[mLastIndex];
118
      float lY = mLastY[mLastIndex];
119

  
120
      long timeDiff = lastTime-firstTime;
110
      long timeDiff = mLastT[mLastIndex]-mLastT[mFirstIndex];
111
      float sum = 0;
112
      for(int i=mFirstIndex; i<=mLastIndex; i++) sum += mLastA[i];
121 113

  
122 114
      mLastIndex = 0;
123 115
      mFirstIndex= 0;
124 116

  
125
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX-lX,fY-lY)/timeDiff : 0;
117
      mAvgRotSpeed = timeDiff>0 ? sum/timeDiff : 0;
118
      if( mAvgRotSpeed<0 ) mAvgRotSpeed = -mAvgRotSpeed;
126 119
      }
127 120

  
128 121
///////////////////////////////////////////////////////////////////////////////////////////////////
......
237 230
        {
238 231
        computeCurrentSpeedInInchesPerSecond();
239 232
        int basic = angles[mCurrentAxis][mCurrentRow];
240
        int angle = object.computeNearestAngle(basic,mCurrentAngle, mCurrRotSpeed);
233
        int angle = object.computeNearestAngle(basic,mCurrentAngle, mAvgRotSpeed);
241 234
        mPreRender.finishRotation(angle);
242 235
        mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
243 236

  
......
273 266
        float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
274 267
        mCurrentAngle = SWIPING_SENSITIVITY*angle;
275 268
        mPreRender.getObject().continueRotation(mCurrentAngle);
276

  
277
        addSpeedProbe(x2,y2);
269
        addSpeedProbe(mCurrentAngle);
278 270
        }
279 271
      else
280 272
        {
281 273
        float rotAngle = computeNormalRotAngle(mNormalTouchPoint[0]-x,mNormalTouchPoint[1]-y);
282 274
        mCurrentAngle = mNormalRotAngle - rotAngle;
283 275
        mPreRender.getObject().continueRotation(mCurrentAngle);
276
        addSpeedProbe(mCurrentAngle);
284 277
        }
285 278
      }
286 279

  
......
353 346
      if( object.beginNewRotation( mCurrentAxis, mCurrentRow ) )
354 347
        {
355 348
        mInterface.onBeginRotation();
356
        addSpeedProbe(x,y);
349
        addSpeedProbe(0);
357 350
        mBeginningRotation = false;
358 351
        mContinuingRotation= true;
359 352
        }
......
569 562
      mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
570 563
      mTemp= new Static4D(0,0,0,1);
571 564

  
572
      mCurrRotSpeed= 0.0f;
565
      mAvgRotSpeed = 0.0f;
573 566
      mLastMode    = -1;
574 567
      mRotateOnCreation = false;
575 568

  
576 569
      mNormalTouchPoint = new float[2];
577 570

  
578
      mLastX = new float[NUM_SPEED_PROBES];
579
      mLastY = new float[NUM_SPEED_PROBES];
571
      mLastA = new float[NUM_SPEED_PROBES];
580 572
      mLastT = new long[NUM_SPEED_PROBES];
581 573
      mFirstIndex= 0;
582 574
      mLastIndex = 0;

Also available in: Unified diff