Project

General

Profile

« Previous | Next » 

Revision 001cc0e4

Added by Leszek Koltunski about 4 years ago

Fix a potential crasher ( do not set up a callback for end of rotation effect on the very first cubit that belongs to a rotation if all belonging cubits have not been set up yet )

View differences:

src/main/java/org/distorted/objects/Cubit.java
21 21

  
22 22
import android.content.SharedPreferences;
23 23

  
24
import com.google.firebase.crashlytics.FirebaseCrashlytics;
25

  
26 24
import org.distorted.library.effect.MatrixEffectMove;
27 25
import org.distorted.library.effect.MatrixEffectQuaternion;
28 26
import org.distorted.library.effect.MatrixEffectRotate;
......
40 38

  
41 39
class Cubit
42 40
  {
41
  private static final int POST_ROTATION_MILLISEC = 500;
43 42
  private static final Static3D matrCenter = new Static3D(0,0,0);
44 43

  
45 44
  private final Static3D mOrigPosition;
......
50 49
  private MatrixEffectRotate mRotateEffect;
51 50
  private Static3D mCurrentPosition;
52 51
  private int mNumAxis;
52
  private Dynamic1D mRotationAngle;
53 53

  
54
  Dynamic1D mRotationAngle;
55 54
  DistortedNode mNode;
56 55
  DistortedEffects mEffect;
57 56
  Static4D mQuatScramble;
......
300 299

  
301 300
///////////////////////////////////////////////////////////////////////////////////////////////////
302 301

  
303
  long finishRotationNow(EffectListener listener)
302
  void removeRotationNow(Static4D quat)
304 303
    {
305
    int pointNum = mRotationAngle.getNumPoints();
306

  
307
    if( pointNum>=1 )
308
      {
309
      float startingAngle = mRotationAngle.getPoint(pointNum-1).get0();
310
      int nearestAngleInDegrees = mParent.computeNearestAngle(startingAngle);
311
      mParent.mRotationAngleStatic.set0(startingAngle);
312
      mParent.mRotationAngleFinal.set0(nearestAngleInDegrees);
313
      mParent.mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
314
      return setUpCallback(listener);
315
      }
316
    else
317
      {
318
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
319
      crashlytics.setCustomKey("points", "finish, points in RotationAngle: "+pointNum );
320
      return 0;
321
      }
304
    mRotationAngle.removeAll();
305
    mQuatScramble.set(RubikSurfaceView.quatMultiply(quat,mQuatScramble));
306
    normalizeScrambleQuat( mQuatScramble );
307
    modifyCurrentPosition(quat);
322 308
    }
323 309

  
324 310
///////////////////////////////////////////////////////////////////////////////////////////////////
325 311

  
326
  Static4D returnRotationQuat(int axis)
312
  void beginNewRotation(int axis)
327 313
    {
328
    int pointNum = mRotationAngle.getNumPoints();
314
    mRotationAxis.set( mParent.ROTATION_AXIS[axis] );
315
    mRotationAngle.add(mParent.mRotationAngleStatic);
316
    }
329 317

  
330
    if( pointNum>=1 )
331
      {
332
      float axisX = mParent.ROTATION_AXIS[axis].get0();
333
      float axisY = mParent.ROTATION_AXIS[axis].get1();
334
      float axisZ = mParent.ROTATION_AXIS[axis].get2();
335

  
336
      float startingAngle = mRotationAngle.getPoint(pointNum-1).get0();
337
      int nearestAngleInDegrees = mParent.computeNearestAngle(startingAngle);
338
      double nearestAngleInRadians = nearestAngleInDegrees*Math.PI/180;
339
      float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
340
      float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
341
      return new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
342
      }
343
    else
344
      {
345
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
346
      crashlytics.setCustomKey("points", "return, points in RotationAngle: "+pointNum );
347
      return null;
348
      }
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

  
320
  void addNewRotation(int axis, long durationMillis, int angle)
321
    {
322
    mRotationAxis.set( mParent.ROTATION_AXIS[axis] );
323
    mRotationAngle.setDuration(durationMillis);
324
    mRotationAngle.resetToBeginning();
325
    mRotationAngle.add(new Static1D(0));
326
    mRotationAngle.add(new Static1D(angle));
349 327
    }
350 328

  
351 329
///////////////////////////////////////////////////////////////////////////////////////////////////
352 330

  
353
  void removeRotationNow(Static4D quat)
331
  void resetRotationAngle()
354 332
    {
333
    mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
334
    mRotationAngle.resetToBeginning();
355 335
    mRotationAngle.removeAll();
356
    mQuatScramble.set(RubikSurfaceView.quatMultiply(quat,mQuatScramble));
357
    normalizeScrambleQuat( mQuatScramble );
358
    modifyCurrentPosition(quat);
336
    mRotationAngle.add(mParent.mRotationAngleStatic);
337
    mRotationAngle.add(mParent.mRotationAngleMiddle);
338
    mRotationAngle.add(mParent.mRotationAngleFinal);
359 339
    }
360 340

  
361 341
///////////////////////////////////////////////////////////////////////////////////////////////////
......
378 358
    computeRotationRow();
379 359
    }
380 360

  
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

  
383
  void beginNewRotation(int axis)
384
    {
385
    mRotationAxis.set( mParent.ROTATION_AXIS[axis] );
386
    mRotationAngle.add(mParent.mRotationAngleStatic);
387
    }
388

  
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390

  
391
  void addNewRotation(int axis, long durationMillis, int angle)
392
    {
393
    mRotationAxis.set( mParent.ROTATION_AXIS[axis] );
394
    mRotationAngle.setDuration(durationMillis);
395
    mRotationAngle.resetToBeginning();
396
    mRotationAngle.add(new Static1D(0));
397
    mRotationAngle.add(new Static1D(angle));
398
    }
399

  
400 361
///////////////////////////////////////////////////////////////////////////////////////////////////
401 362

  
402 363
  long setUpCallback(EffectListener listener)

Also available in: Unified diff