Project

General

Profile

« Previous | Next » 

Revision 935f3663

Added by Leszek Koltunski over 3 years ago

Fix the way we continue rotation: when rotating a layer, we need to be doing it with respect to the RotAxis which has been first casted to the touched face, and only then this casted one is casted to the surface of the screen.

Before we were casting the rotAxis directly to the screen without the intermediate casting to the face, which doesn't really work in case of the Dino: if the touched face is rotated away by quite a lot, the rotAxis is then completely counterintuitive.

View differences:

src/main/java/org/distorted/main/RubikSurfaceView.java
164 164
      }
165 165

  
166 166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
// cast the 3D axis we are currently rotating along to the 2D in-screen-surface axis
167
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
168
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
168 169

  
169
    private void computeCurrentAxis(Static3D axis)
170
    private void computeCurrentAxis(Static4D axis)
170 171
      {
171
      Static4D axis4D = new Static4D(axis.get0(), axis.get1(), axis.get2(), 0);
172
      Static4D result = rotateVectorByQuat(axis4D, mQuat);
172
      Static4D result = rotateVectorByQuat(axis, mQuat);
173 173

  
174 174
      mAxisX =result.get0();
175 175
      mAxisY =result.get1();
......
468 468
      float offset = res.get1();
469 469
      mCurrentRow  = object.computeRowFromOffset(offset);
470 470

  
471
      computeCurrentAxis( object.getRotationAxis()[mCurrentAxis] );
471
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
472 472
      mRotationFactor = object.returnRotationFactor(offset);
473 473

  
474 474
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
src/main/java/org/distorted/objects/RubikMovement.java
30 30
  private int mLastTouchedFace, mNumFaceAxis;
31 31
  private float[] mPoint, mCamera, mTouch;
32 32
  private float[] mPoint2D, mMove2D;
33
  private float[][][] mCastAxis;
33
  private float[][][] mCastedRotAxis;
34
  private Static4D[][] mCastedRotAxis4D;
34 35
  private int[] mEnabledRotAxis;
35 36
  private float mDistanceCenterFace3D, mDistanceCenterFace2D;
36 37
  private Static3D[] mFaceAxis;
......
59 60
    mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces
60 61
    mDistanceCenterFace2D = distance2D; // distance from the center of a face to its edge
61 62

  
62
    // mCastAxis[1][2]{0,1} are the 2D coords of the 2nd axis cast onto the face defined by the
63
    // mCastedRotAxis[1][2]{0,1} are the 2D coords of the 2nd axis cast onto the face defined by the
63 64
    // 1st pair (axis,lr)
64
    mCastAxis = new float[mNumFaceAxis][rotAxis.length][2];
65
    mCastedRotAxis   = new float[mNumFaceAxis][rotAxis.length][2];
66
    mCastedRotAxis4D = new Static4D[mNumFaceAxis][rotAxis.length];
67

  
68
    float fx,fy,fz,f;
65 69

  
66 70
    for( int casted=0; casted<rotAxis.length; casted++)
67 71
      {
......
72 76

  
73 77
      for( int face=0; face<mNumFaceAxis; face++)
74 78
        {
75
        convertTo2Dcoords( mPoint, mFaceAxis[face], mCastAxis[face][casted]);
76
        normalize2D(mCastAxis[face][casted]);
79
        convertTo2Dcoords( mPoint, mFaceAxis[face], mCastedRotAxis[face][casted]);
80
        normalize2D(mCastedRotAxis[face][casted]);
81

  
82
        fx = faceAxis[face].get0();
83
        fy = faceAxis[face].get1();
84
        fz = faceAxis[face].get2();
85
        f  = mPoint[0]*fx + mPoint[1]*fy + mPoint[2]*fz;
86
        mCastedRotAxis4D[face][casted] = new Static4D( mPoint[0]-f*fx, mPoint[1]-f*fy, mPoint[2]-f*fz, 0);
77 87
        }
78 88
      }
79 89
    }
......
114 124
    for(int axis=1; axis<=numAxis; axis++)
115 125
      {
116 126
      index = enabled[axis];
117
      cosAngle = m0*mCastAxis[faceAxis][index][0] + m1*mCastAxis[faceAxis][index][1];
127
      cosAngle = m0*mCastedRotAxis[faceAxis][index][0] + m1*mCastedRotAxis[faceAxis][index][1];
118 128
      if( cosAngle<0 ) cosAngle = -cosAngle;
119 129

  
120 130
      if( cosAngle<minCosAngle )
......
271 281

  
272 282
    computeEnabledAxis(mLastTouchedFace, mPoint2D, mEnabledRotAxis);
273 283
    int rotIndex = computeRotationIndex(mLastTouchedFace, mMove2D, mEnabledRotAxis);
274
    float offset = computeOffset(mPoint2D, mCastAxis[mLastTouchedFace][rotIndex]);
284
    float offset = computeOffset(mPoint2D, mCastedRotAxis[mLastTouchedFace][rotIndex]);
275 285

  
276 286
    return new Static2D(rotIndex,offset);
277 287
    }
278 288

  
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

  
291
  public Static4D getCastedRotAxis(int rotIndex)
292
    {
293
    return mCastedRotAxis4D[mLastTouchedFace][rotIndex];
294
    }
295

  
279 296
///////////////////////////////////////////////////////////////////////////////////////////////////
280 297

  
281 298
  public int getTouchedFace()

Also available in: Unified diff