Project

General

Profile

« Previous | Next » 

Revision 1d6c1eea

Added by Leszek Koltunski about 4 years ago

Work around a rare crash on startup

View differences:

src/main/java/org/distorted/objects/Cubit.java
110 110
    return ret;
111 111
    }
112 112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
  private void modifyCurrentPosition(Static4D quat)
116
    {
117
    float cubitCenterX = mCurrentPosition.get0();
118
    float cubitCenterY = mCurrentPosition.get1();
119
    float cubitCenterZ = mCurrentPosition.get2();
120

  
121
    Static4D cubitCenter =  new Static4D(cubitCenterX, cubitCenterY, cubitCenterZ, 0);
122
    Static4D rotatedCenter = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat);
123

  
124
    float rotatedX = rotatedCenter.get0();
125
    float rotatedY = rotatedCenter.get1();
126
    float rotatedZ = rotatedCenter.get2();
127

  
128
    mCurrentPosition.set(rotatedX, rotatedY, rotatedZ);
129
    mParent.clampPos(mCurrentPosition);
130

  
131
    computeRotationRow();
132
    }
133

  
134 113
///////////////////////////////////////////////////////////////////////////////////////////////////
135 114
// cast current position on axis; use mStart and mStep to compute the rotation row for each axis.
136 115

  
......
157 136
    return mOrigPosition;
158 137
    }
159 138

  
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

  
141
  void modifyCurrentPosition(Static4D quat)
142
    {
143
    float cubitCenterX = mCurrentPosition.get0();
144
    float cubitCenterY = mCurrentPosition.get1();
145
    float cubitCenterZ = mCurrentPosition.get2();
146

  
147
    Static4D cubitCenter =  new Static4D(cubitCenterX, cubitCenterY, cubitCenterZ, 0);
148
    Static4D rotatedCenter = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat);
149

  
150
    float rotatedX = rotatedCenter.get0();
151
    float rotatedY = rotatedCenter.get1();
152
    float rotatedZ = rotatedCenter.get2();
153

  
154
    mCurrentPosition.set(rotatedX, rotatedY, rotatedZ);
155
    mParent.clampPos(mCurrentPosition);
156

  
157
    computeRotationRow();
158
    }
159

  
160 160
///////////////////////////////////////////////////////////////////////////////////////////////////
161 161

  
162 162
  int computeAssociation()
......
187 187
    {
188 188
    String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
189 189
    mQuatIndex = preferences.getInt("q_"+number, 0);
190
    modifyCurrentPosition(mParent.QUATS[mQuatIndex]);
191 190

  
192
    return mQuatIndex;
191
    if( mQuatIndex < mParent.QUATS.length )
192
      {
193
      modifyCurrentPosition(mParent.QUATS[mQuatIndex]);
194
      return mQuatIndex;
195
      }
196

  
197
    return -1;
193 198
    }
194 199

  
195 200
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyObject.java
556 556
    for(int i=0; i<NUM_CUBITS; i++)
557 557
      {
558 558
      int index = CUBITS[i].restorePreferences(preferences);
559

  
560
      if( index<0 )
561
        {
562
        for(int j=0; j<NUM_CUBITS; j++)
563
          {
564
          CUBITS[j].modifyCurrentPosition(QUATS[0]);
565
          mMesh.setEffectAssociation(j, CUBITS[j].computeAssociation(),0);
566
          }
567
        break;
568
        }
569

  
559 570
      mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),index);
560 571
      }
561 572
    }

Also available in: Unified diff