Project

General

Profile

« Previous | Next » 

Revision bef47287

Added by Leszek Koltunski about 4 years ago

Progress with object Movement.

View differences:

src/main/java/org/distorted/object/RubikObjectMovement.java
30 30
  float[] mTouch;
31 31
  int mRotationVect, mLastTouchedAxis;
32 32

  
33
  private float[] mPoint, mCamera, mDiff;
33
  private float[] mPoint, mCamera, mDiff, m2Dpoint;
34 34
  private int mLastTouchedLR;
35 35
  private int mNumAxis, mNumFacesPerAxis;
36 36
  private int[] mPossible;
......
53 53
    mDiff  = new float[3];
54 54
    mTouch = new float[3];
55 55

  
56
    m2Dpoint = new float[2];
57

  
56 58
    mAxis = axis;
57 59
    mNumAxis = mAxis.length;
58 60
    mNumFacesPerAxis = numFacesPerAxis;
......
101 103
      }
102 104
    }
103 105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
// Convert the 3D point3D into a 2D point on the same face surface, but in a different
108
// coordinate system: a in-plane 2D coord where the origin is in the point where the axis intersects
109
// the surface, and whose Y axis points 'north' i.e. is in the plane given by the 3D origin, the
110
// original 3D Y axis and our 2D in-plane origin.
111
// If those 3 points constitute a degenerate triangle which does not define a plane - which can only
112
// happen if axis is vertical (or in theory when 2D origin and 3D origin meet, but that would have to
113
// mean that the distance between the center of the Object and its faces is 0) - then we arbitrarily
114
// decide that 2D Y = (0,0,-1) in the North Pole and (0,0,1) in the South Pole)
115

  
116
  private void convertTo2Dcoords(float[] point3D, Static3D axis, int lr, float[] output)
117
    {
118
    float y0,y1,y2, x0,x1,x2;  // base X and Y vectors of the 2D coord system
119
    float a0 = axis.get0();
120
    float a1 = axis.get1();
121
    float a2 = axis.get2();
122

  
123
    if( lr==0 )
124
      {
125
      a0=-a0; a1=-a1; a2=-a2;
126
      }
127

  
128
    if( a0==0.0f && a2==0.0f )
129
      {
130
      y0=0; y1=0; y2=-a1;
131
      }
132
    else if( a1==0.0f )
133
      {
134
      y0=0; y1=1; y2=0;
135
      }
136
    else
137
      {
138
      float norm = (float)(-a1/Math.sqrt(1-a1*a1));
139
      y0 = norm*a0; y1= norm*(a1-1/a1); y2=a2;
140
      }
141

  
142
    x0 = y1*a2 - y2*a1;  //
143
    x1 = y2*a0 - y0*a2;  // (2D coord baseY) x (axis) = 2D coord baseX
144
    x2 = y0*a1 - y1*a0;  //
145

  
146
    float originAlpha = point3D[0]*a0 + point3D[1]*a1 + point3D[2]*a2;
147

  
148
    float origin0 = originAlpha*a0; // coords of the point where axis
149
    float origin1 = originAlpha*a1; // intersects surface plane i.e.
150
    float origin2 = originAlpha*a2; // the origin of our 2D coord system
151

  
152
    float v0 = point3D[0] - origin0;
153
    float v1 = point3D[1] - origin1;
154
    float v2 = point3D[2] - origin2;
155

  
156
    output[0] = v0*x0 + v1*x1 + v2*x2;
157
    output[1] = v0*y0 + v1*y1 + v2*y2;
158
    }
159

  
104 160
///////////////////////////////////////////////////////////////////////////////////////////////////
105 161
// PUBLIC API
106 162
///////////////////////////////////////////////////////////////////////////////////////////////////
......
122 178
        if( faceIsVisible(mAxis[mLastTouchedAxis], mLastTouchedLR) )
123 179
          {
124 180
          castTouchPointOntoFace(mAxis[mLastTouchedAxis], mLastTouchedLR, mTouch);
181
          convertTo2Dcoords(mTouch, mAxis[mLastTouchedAxis], mLastTouchedLR, m2Dpoint);
125 182

  
126
          if( isInsideFace(mTouch) )
183
          if( isInsideFace(m2Dpoint) )
127 184
            {
185
 // android.util.Log.e("move", "touched "+mLastTouchedAxis+" touch point: ("+m2Dpoint[0]+","+m2Dpoint[1]+")");
186

  
128 187
            fillPossibleRotations(mLastTouchedAxis, mPossible);
129 188
            return true;
130 189
            }
......
150 209
    mDiff[2] -= mTouch[2];
151 210

  
152 211
    float offset = fillUpRotationVectAndOffset(mDiff, mPossible);
153

  
154
    mTouch[0] = mPoint[0];
155
    mTouch[1] = mPoint[1];
156
    mTouch[2] = mPoint[2];
157

  
158 212
    return new Static2D(mRotationVect,offset);
159 213
    }
160 214

  
......
162 216

  
163 217
  public float continueRotation(Static4D rotatedTouchPoint)
164 218
    {
165
    mDiff[0] = rotatedTouchPoint.get0()/RubikObject.OBJECT_SCREEN_RATIO - mTouch[0];
166
    mDiff[1] = rotatedTouchPoint.get1()/RubikObject.OBJECT_SCREEN_RATIO - mTouch[1];
167
    mDiff[2] = rotatedTouchPoint.get2()/RubikObject.OBJECT_SCREEN_RATIO - mTouch[2];
219
    mDiff[0] = rotatedTouchPoint.get0()/RubikObject.OBJECT_SCREEN_RATIO - mPoint[0];
220
    mDiff[1] = rotatedTouchPoint.get1()/RubikObject.OBJECT_SCREEN_RATIO - mPoint[1];
221
    mDiff[2] = rotatedTouchPoint.get2()/RubikObject.OBJECT_SCREEN_RATIO - mPoint[2];
168 222

  
169 223
    return (mLastTouchedLR-0.5f)*returnAngle(mDiff, mPossible);
170 224
    }

Also available in: Unified diff