Project

General

Profile

« Previous | Next » 

Revision 12ad3fca

Added by Leszek Koltunski about 4 years ago

Progress with object Movement - almost finished.

View differences:

src/main/java/org/distorted/object/RubikObjectMovement.java
27 27

  
28 28
public abstract class RubikObjectMovement
29 29
  {
30
  int mRotationVect, mLastTouchedAxis;
31

  
32
  private float[] mPoint, mCamera, mDiff, mTouch;
30
  private int mLastTouchedAxis;
31
  private float[] mPoint, mCamera, mTouch;
33 32
  private float[] mPoint2D, mMove2D;
34 33
  private float[][][] mCastAxis;
35 34
  private int mLastTouchedLR;
36 35
  private int mNumAxis, mNumFacesPerAxis;
37
  private int[] mPossible;
38 36
  private float mDistanceCenterFace3D, mDistanceCenterFace2D;
39 37
  private Static3D[] mAxis;
40 38

  
41 39
///////////////////////////////////////////////////////////////////////////////////////////////////
42 40

  
43 41
  abstract boolean isInsideFace(float[] point);
44
  abstract float returnAngle(float[] vect, int[] possible);
45
  abstract void fillPossibleRotations(int axis, int[] output);
46 42

  
47 43
///////////////////////////////////////////////////////////////////////////////////////////////////
48 44

  
......
50 46
    {
51 47
    mPoint = new float[3];
52 48
    mCamera= new float[3];
53
    mDiff  = new float[3];
54 49
    mTouch = new float[3];
55 50

  
56 51
    mPoint2D = new float[2];
......
61 56
    mNumFacesPerAxis = numFacesPerAxis;
62 57
    mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces
63 58
    mDistanceCenterFace2D = distance2D; // distance from the center of a face to its edge
64
    mPossible = new int[mNumAxis-1];
65 59

  
66 60
    // mCastAxis[1][2]{0,1} are the 2D coords of the 2nd axis cast onto the face defined by the
67 61
    // 1st pair (axis,lr)
......
107 101
///////////////////////////////////////////////////////////////////////////////////////////////////
108 102
// find the casted axis with which our move2D vector forms an angle closest to 90 deg.
109 103

  
110
  private int computeRotationVect(int axis, int lr, float[] move2D)
104
  private int computeRotationIndex(int axis, int lr, float[] move2D)
111 105
    {
112 106
    float cosAngle, minCosAngle = Float.MAX_VALUE;
113 107
    int minIndex=-1;
......
238 232
    output[1] = v0*y0 + v1*y1 + v2*y2;
239 233
    }
240 234

  
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

  
243
  private String getFaceColor(int axis)
244
    {
245
    switch(axis)
246
      {
247
      case 0: return "yellow (bottom) ";
248
      case 1: return "green (back) ";
249
      case 2: return "blue (right) ";
250
      case 3: return "red (left) ";
251
      }
252

  
253
    return null;
254
    }
255

  
256 235
///////////////////////////////////////////////////////////////////////////////////////////////////
257 236
// PUBLIC API
258 237
///////////////////////////////////////////////////////////////////////////////////////////////////
......
276 255
          castTouchPointOntoFace(mAxis[mLastTouchedAxis], mLastTouchedLR, mTouch);
277 256
          convertTo2Dcoords(mTouch, mAxis[mLastTouchedAxis], mLastTouchedLR, mPoint2D);
278 257

  
279
          if( isInsideFace(mPoint2D) )
280
            {
281
            fillPossibleRotations(mLastTouchedAxis, mPossible);
282
            return true;
283
            }
258
          if( isInsideFace(mPoint2D) ) return true;
284 259
          }
285 260
        }
286 261
      }
......
302 277
    mMove2D[0] -= mPoint2D[0];
303 278
    mMove2D[1] -= mPoint2D[1];
304 279

  
305
    mRotationVect= computeRotationVect(mLastTouchedAxis, mLastTouchedLR, mMove2D);
306
    int index = mLastTouchedAxis*mNumFacesPerAxis+mLastTouchedLR;
307
    float offset = computeOffset(mPoint2D, mCastAxis[index][mRotationVect]);
308

  
309
    return new Static2D(mRotationVect,offset);
310
    }
311

  
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

  
314
  public float continueRotation(Static4D rotatedTouchPoint)
315
    {
316
    mDiff[0] = rotatedTouchPoint.get0()/RubikObject.OBJECT_SCREEN_RATIO - mPoint[0];
317
    mDiff[1] = rotatedTouchPoint.get1()/RubikObject.OBJECT_SCREEN_RATIO - mPoint[1];
318
    mDiff[2] = rotatedTouchPoint.get2()/RubikObject.OBJECT_SCREEN_RATIO - mPoint[2];
280
    int rotIndex = computeRotationIndex(mLastTouchedAxis, mLastTouchedLR, mMove2D);
281
    int index    = mLastTouchedAxis*mNumFacesPerAxis+mLastTouchedLR;
282
    float offset = computeOffset(mPoint2D, mCastAxis[index][rotIndex]);
319 283

  
320
    return (mLastTouchedLR-0.5f)*returnAngle(mDiff, mPossible);
284
    return new Static2D(rotIndex,offset);
321 285
    }
322 286
  }

Also available in: Unified diff