Project

General

Profile

« Previous | Next » 

Revision 1c7eebdc

Added by Leszek Koltunski about 1 month ago

  • ID 1c7eebdc63efca01f656c07f8600cf2e5efc079a
  • Parent 52375039

common code from all activities to one BaseActivity

View differences:

src/main/java/org/distorted/objectlib/touchcontrol/TouchControlBarrel.java
32 32
  private final float[][] mCastedRotAxis;
33 33
  private float[][] mTouchBorders;
34 34

  
35
  private float mLongitude, mLatitude;
35
  private float mRadius, mHeight;
36 36
  private float mX, mY, mZ;
37 37

  
38 38
  private static final float X = (float)Math.sqrt( (2-SQ2)/(6+SQ2) );
......
78 78
    mTouch = new float[3];
79 79

  
80 80
    int numRotAxis = mRotAxis.length;
81
    mEnabledRotAxis = new int[numRotAxis+1];
81
    mEnabledRotAxis= new int[numRotAxis+1];
82 82
    mCastedRotAxis = new float[numRotAxis][2];
83 83

  
84 84
    mGhostAxisEnabled = -1;
......
155 155
    return len;
156 156
    }
157 157

  
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
// Longitude spans from 0 (at Guinea Bay) increasing to the east all the way to 2PI
160
// Latitude - from -PI/2 (South Pole) to +PI/2 (North Pole)
161

  
162
  private void computeLongitudeAndLatitude(float A, float B, float C)
163
    {
164
    float sqrt = (float)Math.sqrt(B*B - 4*A*C);
165
    float alpha= (-B+sqrt)/(2*A); // this is the closer point
166

  
167
    float cx = mCamera[0];
168
    float cy = mCamera[1];
169
    float cz = mCamera[2];
170

  
171
    float vx = mCamera[0]-mPoint[0];
172
    float vy = mCamera[1]-mPoint[1];
173
    float vz = mCamera[2]-mPoint[2];
174

  
175
    mX = cx + alpha*vx;
176
    mY = cy + alpha*vy;
177
    mZ = cz + alpha*vz;
178

  
179
    mLongitude = mZ==0 ? 0 : (float)Math.atan(mX/mZ);
180
    mLatitude  = (float)Math.asin(2*mY);
181

  
182
    if( mZ<0 ) mLongitude += Math.PI;
183
    else if( mX<0 ) mLongitude += 2*Math.PI;
184
    }
185

  
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187
// this is Masterball-specific. See TwistyMasterball.getEnabled()
188

  
189
  private int returnTouchedFace()
190
    {
191
    float t = (float)(mLongitude + Math.PI/8);
192
    if( t>2*Math.PI ) t-=(2*Math.PI);
193
    int ret = (int)(t/(Math.PI/4));
194
    return ret<8 ? ret : 7;
195
    }
196

  
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
// this is Masterball-specific. No parts in any faces.
199

  
200
  private int returnTouchedPart()
201
    {
202
    return 0;
203
    }
204

  
205 158
///////////////////////////////////////////////////////////////////////////////////////////////////
206 159

  
207 160
  private float computeOffset(int rotIndex)
......
216 169
    {
217 170
    if( mGhostAxisEnabled<0 )
218 171
      {
219
      int face = returnTouchedFace();
220
      int part = returnTouchedPart();
172
      int face = 0;//returnTouchedFace();
173
      int part = 0;//returnTouchedPart();
221 174
      int num = mEnabled[face][0].length;
222 175
      mEnabledRotAxis[0] = num;
223 176
      System.arraycopy(mEnabled[face][part], 0, mEnabledRotAxis, 1, num);
......
229 182
      }
230 183
    }
231 184

  
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

  
187
  private boolean crossesPipe(float radius, float vx, float vy, float vz)
188
    {
189
    return false;
190
    }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

  
194
  private boolean crossesPlane(float nx, float ny, float nz, float d, float vx, float vy, float vz)
195
    {
196
    return false;
197
    }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
  public boolean axisAndFaceAgree(int axisIndex)
202
    {
203
    return false;
204
    }
205

  
232 206
///////////////////////////////////////////////////////////////////////////////////////////////////
233 207

  
234 208
  public int getTouchedCubitFace()
......
250 224
    return 0;
251 225
    }
252 226

  
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228
// simply cast the appropriate rotational axis of the object to the screen surface.
229

  
230
  public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
231
    {
232
    Static3D a = mRotAxis[axisIndex];
233
    getCastedRotAxis(output,quat,a.get0(),a.get1(),a.get2(),0);
234
    }
235

  
253 236
///////////////////////////////////////////////////////////////////////////////////////////////////
254 237

  
255 238
  public boolean objectTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera)
......
265 248
    float vx = mCamera[0]-mPoint[0];
266 249
    float vy = mCamera[1]-mPoint[1];
267 250
    float vz = mCamera[2]-mPoint[2];
251
    float x1=0,y1=0,z1=0;
252
    float x2=0,y2=0,z2=0;
253
    float x3=0,y3=0,z3=0;
254
    float len1=Float.MAX_VALUE;
255
    float len2=Float.MAX_VALUE;
256
    float len3=Float.MAX_VALUE;
257

  
258
    if( crossesPipe(mRadius,vx,vy,vz) )
259
      {
260
      x1 = mX;
261
      y1 = mY;
262
      z1 = mZ;
263
      float dx = mX-mCamera[0];
264
      float dy = mY-mCamera[1];
265
      float dz = mZ-mCamera[2];
266
      len1 = dx*dx + dy*dy + dz*dz;
267
      }
268
    if( crossesPlane(0,1,0,mHeight,vx,vy,vz) )
269
      {
270
      x2 = mX;
271
      y2 = mY;
272
      z2 = mZ;
273
      float dx = mX-mCamera[0];
274
      float dy = mY-mCamera[1];
275
      float dz = mZ-mCamera[2];
276
      len2 = dx*dx + dy*dy + dz*dz;
277
      }
278
    if( crossesPlane(0,-1,0,mHeight,vx,vy,vz) )
279
      {
280
      x3 = mX;
281
      y3 = mY;
282
      z3 = mZ;
283
      float dx = mX-mCamera[0];
284
      float dy = mY-mCamera[1];
285
      float dz = mZ-mCamera[2];
286
      len3 = dx*dx + dy*dy + dz*dz;
287
      }
268 288

  
269
    float R = 0.5f;
270
    float A = vx*vx + vy*vy + vz*vz;
271
    float B = 2*(vx*mCamera[0] + vy*mCamera[1] + vz*mCamera[2]);
272
    float C = (mCamera[0]*mCamera[0] + mCamera[1]*mCamera[1] + mCamera[2]*mCamera[2]) - R*R;
273

  
274
    if( B*B >= 4*A*C )
289
    if( len1<len2 && len1<len3 )
275 290
      {
276
      computeLongitudeAndLatitude(A,B,C);
291
      mX = x1;
292
      mY = y1;
293
      mZ = z1;
294
      return true;
295
      }
296
    if( len2<len1 && len2<len3 )
297
      {
298
      mX = x2;
299
      mY = y2;
300
      mZ = z2;
301
      return true;
302
      }
303
    if( len3<len1 && len3<len2 )
304
      {
305
      mX = x3;
306
      mY = y3;
307
      mZ = z3;
277 308
      return true;
278 309
      }
279 310

  
......
329 360
    output[0] = rotIndex;
330 361
    output[1] = row;
331 362
    }
332

  
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334
// simply cast the appropriate rotational axis of the object to the screen surface.
335

  
336
  public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
337
    {
338
    Static3D a = mRotAxis[axisIndex];
339
    Static4D result = QuatHelper.rotateVectorByQuat(a.get0(),a.get1(),a.get2(),0,quat);
340

  
341
    float cx = result.get0();
342
    float cy = result.get1();
343
    float len= (float)Math.sqrt(cx*cx+cy*cy);
344

  
345
    if( len!=0 )
346
      {
347
      output[0] = cx/len;
348
      output[1] = cy/len;
349
      }
350
    else
351
      {
352
      output[0] = 1;
353
      output[1] = 0;
354
      }
355
    }
356

  
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

  
359
  public boolean axisAndFaceAgree(int axisIndex)
360
    {
361
    return false;
362
    }
363 363
}

Also available in: Unified diff