Project

General

Profile

« Previous | Next » 

Revision 2fcad75d

Added by Leszek Koltunski over 4 years ago

Bugfixes.

View differences:

src/main/java/org/distorted/objects/Cubit.java
35 35
  private Static3D mCurrentPosition;
36 36
  private int mNumAxis;
37 37

  
38
  Static4D mQuatScramble;
38
  int mQuatIndex;
39 39
  float[] mRotationRow;
40 40

  
41 41
///////////////////////////////////////////////////////////////////////////////////////////////////
......
48 48

  
49 49
    mParent          = parent;
50 50
    mOrigPosition    = new Static3D(x,y,z);
51
    mQuatScramble    = new Static4D(0,0,0,1);
52

  
53
    mCurrentPosition = position;
51
    mCurrentPosition = new Static3D(x,y,z);
52
    mQuatIndex       = 0;
54 53

  
55 54
    mNumAxis     = mParent.ROTATION_AXIS.length;
56 55
    mRotationRow = new float[mNumAxis];
......
172 171
  void savePreferences(SharedPreferences.Editor editor)
173 172
    {
174 173
    String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
175

  
176
    editor.putFloat("qx_"+number, mQuatScramble.get0());
177
    editor.putFloat("qy_"+number, mQuatScramble.get1());
178
    editor.putFloat("qz_"+number, mQuatScramble.get2());
179
    editor.putFloat("qw_"+number, mQuatScramble.get3());
174
    editor.putInt("q_"+number, mQuatIndex);
180 175
    }
181 176

  
182 177
///////////////////////////////////////////////////////////////////////////////////////////////////
183 178

  
184
  void restorePreferences(SharedPreferences preferences)
179
  int restorePreferences(SharedPreferences preferences)
185 180
    {
186 181
    String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
182
    mQuatIndex = preferences.getInt("q_"+number, 0);
183
    modifyCurrentPosition(mParent.QUATS[mQuatIndex]);
187 184

  
188
    float qx = preferences.getFloat("qx_"+number, 0.0f);
189
    float qy = preferences.getFloat("qy_"+number, 0.0f);
190
    float qz = preferences.getFloat("qz_"+number, 0.0f);
191
    float qw = preferences.getFloat("qw_"+number, 1.0f);
192

  
193
    mQuatScramble.set(qx,qy,qz,qw);
194
    modifyCurrentPosition(mQuatScramble);
185
    return mQuatIndex;
195 186
    }
196 187

  
197 188
///////////////////////////////////////////////////////////////////////////////////////////////////
......
204 195
// a) is a corner or edge and the quaternions are the same
205 196
// b) is inside one of the faces and after rotations by both quats it ends up on the same face.
206 197

  
207
  boolean thereIsNoVisibleDifference(Static4D quat)
198
  boolean thereIsNoVisibleDifference(int quatIndex)
208 199
    {
209
    if ( mQuatScramble.get0()==quat.get0() &&
210
         mQuatScramble.get1()==quat.get1() &&
211
         mQuatScramble.get2()==quat.get2() &&
212
         mQuatScramble.get3()==quat.get3()  ) return true;
200
    if ( mQuatIndex == quatIndex ) return true;
213 201

  
214 202
    int belongsToHowManyFaces = 0;
215 203
    int size = mParent.getSize()-1;
......
231 219
               float cubitCenterY = mCurrentPosition.get1();
232 220
               float cubitCenterZ = mCurrentPosition.get2();
233 221

  
222
               Static4D quat1 = mParent.QUATS[quatIndex];
223
               Static4D quat2 = mParent.QUATS[mQuatIndex];
224

  
234 225
               Static4D cubitCenter = new Static4D(cubitCenterX, cubitCenterY, cubitCenterZ, 0);
235
               Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat);
236
               Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, mQuatScramble );
226
               Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 );
227
               Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 );
237 228

  
238 229
               float row1, row2, row3, row4;
239 230
               float ax,ay,az;
......
272 263

  
273 264
  int removeRotationNow(Static4D quat)
274 265
    {
275
    mQuatScramble.set(RubikSurfaceView.quatMultiply(quat,mQuatScramble));
276
    int index = normalizeScrambleQuat( mQuatScramble );
277
    mQuatScramble.set(mParent.QUATS[index]);
266
    Static4D q = RubikSurfaceView.quatMultiply(quat,mParent.QUATS[mQuatIndex]);
267
    mQuatIndex = normalizeScrambleQuat(q);
278 268

  
279 269
    modifyCurrentPosition(quat);
280 270

  
281
    return index;
271
    return mQuatIndex;
282 272
    }
283 273

  
284 274
///////////////////////////////////////////////////////////////////////////////////////////////////
285 275

  
286 276
  void solve()
287 277
    {
288
    mQuatScramble.set(0,0,0,1);
278
    mQuatIndex = 0;
289 279
    mCurrentPosition.set(mOrigPosition);
290 280
    computeRotationRow();
291 281
    }
src/main/java/org/distorted/objects/RubikObject.java
358 358

  
359 359
  public void restorePreferences(SharedPreferences preferences)
360 360
    {
361
    for(int i=0; i<NUM_CUBITS; i++) mCubits[i].restorePreferences(preferences);
361
    for(int i=0; i<NUM_CUBITS; i++)
362
      {
363
      int index = mCubits[i].restorePreferences(preferences);
364
      mMesh.setEffectAssociation(i,mCubits[i].computeAssociation(),index);
365
      }
362 366
    }
363 367

  
364 368
///////////////////////////////////////////////////////////////////////////////////////////////////
......
397 401

  
398 402
  public boolean isSolved()
399 403
    {
400
    Static4D q = mCubits[0].mQuatScramble;
404
    int index = mCubits[0].mQuatIndex;
401 405

  
402 406
    for(int i=1; i<NUM_CUBITS; i++)
403 407
      {
404
      if( !mCubits[i].thereIsNoVisibleDifference(q) ) return false;
408
      if( !mCubits[i].thereIsNoVisibleDifference(index) ) return false;
405 409
      }
406 410

  
407 411
    return true;

Also available in: Unified diff