Project

General

Profile

« Previous | Next » 

Revision 27e6c301

Added by Leszek Koltunski almost 4 years ago

Progreess porting RubikCube to the new SingleMesh mode.

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
import org.distorted.library.effect.MatrixEffectMove;
27 24
import org.distorted.library.effect.MatrixEffectQuaternion;
28
import org.distorted.library.effect.MatrixEffectRotate;
29 25
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.message.EffectListener;
31
import org.distorted.library.type.Dynamic1D;
32
import org.distorted.library.type.Static1D;
33 26
import org.distorted.library.type.Static3D;
34 27
import org.distorted.library.type.Static4D;
35 28
import org.distorted.main.RubikSurfaceView;
......
38 31

  
39 32
class Cubit
40 33
  {
41
  private static final int POST_ROTATION_MILLISEC = 500;
42 34
  private static final Static3D MATRIX_CENTER = new Static3D(0,0,0);
43 35

  
44 36
  private final Static3D mOrigPosition;
45 37

  
46 38
  private RubikObject mParent;
47
  private Static3D mRotationAxis;
48
  private MatrixEffectRotate mRotateEffect;
49 39
  private Static3D mCurrentPosition;
50 40
  private int mNumAxis;
51
  private Dynamic1D mRotationAngle;
52 41

  
53 42
  DistortedEffects mEffect;
54 43
  Static4D mQuatScramble;
......
62 51
    float y = position.get1();
63 52
    float z = position.get2();
64 53

  
65
    Static3D vector = new Static3D(x,y,z);
66

  
67 54
    mParent          = parent;
68 55
    mOrigPosition    = new Static3D(x,y,z);
69 56
    mQuatScramble    = new Static4D(0,0,0,1);
70
    mRotationAngle   = new Dynamic1D();
71
    mRotationAxis    = new Static3D(1,0,0);
57

  
72 58
    mCurrentPosition = position;
73
    mRotateEffect    = new MatrixEffectRotate(mRotationAngle, mRotationAxis, MATRIX_CENTER);
74 59

  
75 60
    mNumAxis     = mParent.ROTATION_AXIS.length;
76 61
    mRotationRow = new float[mNumAxis];
77 62
    computeRotationRow();
78 63

  
79 64
    mEffect = new DistortedEffects();
80
    mEffect.apply( new MatrixEffectMove(vector) );
81 65
    mEffect.apply( new MatrixEffectQuaternion(mQuatScramble, MATRIX_CENTER));
82
    mEffect.apply(mRotateEffect);
83
    mEffect.apply(mParent.mQuatAEffect);
84
    mEffect.apply(mParent.mQuatCEffect);
85
    mEffect.apply(mParent.mScaleEffect);
86 66
    }
87 67

  
88 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
190 170
      }
191 171
    }
192 172

  
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

  
175
  int computeAssociation()
176
    {
177
    int row, result = 0, accumulativeShift = 0;
178

  
179
    for(int axis=0; axis<mNumAxis; axis++)
180
      {
181
      row = (int)(mRotationRow[axis]+0.5f);
182
      result += (1<<(row+accumulativeShift));
183
      accumulativeShift += RubikObjectList.MAX_SIZE;
184
      }
185

  
186
    return result;
187
    }
188

  
193 189
///////////////////////////////////////////////////////////////////////////////////////////////////
194 190

  
195 191
  void savePreferences(SharedPreferences.Editor editor)
......
295 291

  
296 292
  void removeRotationNow(Static4D quat)
297 293
    {
298
    mRotationAngle.removeAll();
299 294
    mQuatScramble.set(RubikSurfaceView.quatMultiply(quat,mQuatScramble));
300 295
    normalizeScrambleQuat( mQuatScramble );
301 296
    modifyCurrentPosition(quat);
302 297
    }
303 298

  
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

  
306
  void beginNewRotation(int axis)
307
    {
308
    mRotationAxis.set( mParent.ROTATION_AXIS[axis] );
309
    mRotationAngle.add(mParent.mRotationAngleStatic);
310
    }
311

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

  
314
  void addNewRotation(int axis, long durationMillis, int angle)
315
    {
316
    mRotationAxis.set( mParent.ROTATION_AXIS[axis] );
317
    mRotationAngle.setDuration(durationMillis);
318
    mRotationAngle.resetToBeginning();
319
    mRotationAngle.add(new Static1D(0));
320
    mRotationAngle.add(new Static1D(angle));
321
    }
322

  
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

  
325
  void resetRotationAngle()
326
    {
327
    mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
328
    mRotationAngle.resetToBeginning();
329
    mRotationAngle.removeAll();
330
    mRotationAngle.add(mParent.mRotationAngleStatic);
331
    mRotationAngle.add(mParent.mRotationAngleMiddle);
332
    mRotationAngle.add(mParent.mRotationAngleFinal);
333
    }
334

  
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

  
337
  float getAngle()
338
    {
339
    int pointNum = mRotationAngle.getNumPoints();
340

  
341
    if( pointNum>=1 )
342
      {
343
      return mRotationAngle.getPoint(pointNum-1).get0();
344
      }
345
    else
346
      {
347
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
348
      crashlytics.log("points in RotationAngle: "+pointNum);
349
      return 0;
350
      }
351
    }
352

  
353 299
///////////////////////////////////////////////////////////////////////////////////////////////////
354 300

  
355 301
  void solve()
......
359 305
    computeRotationRow();
360 306
    }
361 307

  
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

  
364
  long setUpCallback(EffectListener listener)
365
    {
366
    mRotateEffect.notifyWhenFinished(listener);
367
    return mRotateEffect.getID();
368
    }
369

  
370 308
///////////////////////////////////////////////////////////////////////////////////////////////////
371 309

  
372 310
  float getDistSquared(float[] point)

Also available in: Unified diff