Revision 2fcad75d
Added by Leszek Koltunski almost 4 years ago
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 |
} |
Also available in: Unified diff
Bugfixes.