Revision 00a28d71
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objectlib/main/TwistyObject.java | ||
---|---|---|
114 | 114 |
private int[] mNumCuts; |
115 | 115 |
private float[][] mOrigPos; |
116 | 116 |
private Static4D[] mOrigQuat; |
117 |
private Static4D[] mMixupModeQuats; |
|
118 |
private boolean mIsInMixupMode; |
|
117 | 119 |
private Static4D mQuat; |
118 | 120 |
private final int[] mNumLayers; |
119 | 121 |
private final float mSize; |
... | ... | |
233 | 235 |
mObjectScale = new Static3D(scale,scale,scale); |
234 | 236 |
setObjectRatioNow(scale,720); |
235 | 237 |
|
238 |
mEffects = new DistortedEffects(); |
|
239 |
createQuaternionEffects(); |
|
240 |
|
|
236 | 241 |
MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale); |
237 | 242 |
MatrixEffectQuaternion quatEffect = new MatrixEffectQuaternion(mQuat, CENTER); |
238 | 243 |
MatrixEffectMove moveEffect = new MatrixEffectMove(move); |
... | ... | |
243 | 248 |
setUpTextures(fromDMESH,fromJSON); |
244 | 249 |
createDataStructuresForSolved(); |
245 | 250 |
|
246 |
mEffects = new DistortedEffects(); |
|
247 |
|
|
248 |
for( int q=0; q<mNumQuats; q++) |
|
249 |
{ |
|
250 |
VertexEffectQuaternion vq = new VertexEffectQuaternion(mObjectQuats[q],CENTER); |
|
251 |
vq.setMeshAssociation(0,q); |
|
252 |
mEffects.apply(vq); |
|
253 |
} |
|
254 |
|
|
255 | 251 |
mEffects.apply(mRotateEffect); |
256 | 252 |
mEffects.apply(quatEffect); |
257 | 253 |
mEffects.apply(scaleEffect); |
... | ... | |
260 | 256 |
mNode = new DistortedNode(mTexture,mEffects,mMesh); |
261 | 257 |
} |
262 | 258 |
|
259 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
260 |
|
|
261 |
private void createQuaternionEffects() |
|
262 |
{ |
|
263 |
if( mNumQuats<=ObjectControl.MAX_QUATS ) |
|
264 |
{ |
|
265 |
mIsInMixupMode = false; |
|
266 |
|
|
267 |
for( int q=0; q<mNumQuats; q++) |
|
268 |
{ |
|
269 |
VertexEffectQuaternion vq = new VertexEffectQuaternion(mObjectQuats[q],CENTER); |
|
270 |
vq.setMeshAssociation(0,q); |
|
271 |
mEffects.apply(vq); |
|
272 |
} |
|
273 |
} |
|
274 |
else if( mNumCubits<=ObjectControl.MAX_QUATS ) |
|
275 |
{ |
|
276 |
mIsInMixupMode = true; |
|
277 |
mMixupModeQuats = new Static4D[mNumCubits]; |
|
278 |
|
|
279 |
for( int q=0; q<mNumCubits; q++) |
|
280 |
{ |
|
281 |
mMixupModeQuats[q] = new Static4D(mObjectQuats[0]); |
|
282 |
VertexEffectQuaternion vq = new VertexEffectQuaternion(mMixupModeQuats[q],CENTER); |
|
283 |
vq.setMeshAssociation(0,q); |
|
284 |
mEffects.apply(vq); |
|
285 |
} |
|
286 |
} |
|
287 |
else |
|
288 |
{ |
|
289 |
android.util.Log.e("D", "object has too many quaternions ("+mNumQuats+") or too many cubits ("+mNumCubits+")"); |
|
290 |
} |
|
291 |
} |
|
292 |
|
|
263 | 293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
264 | 294 |
|
265 | 295 |
private Static3D getPos(float[] origPos) |
... | ... | |
359 | 389 |
{ |
360 | 390 |
android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString()); |
361 | 391 |
} |
362 |
|
|
363 |
for(int i=0; i<mNumCubits; i++) |
|
364 |
{ |
|
365 |
mCubits[i] = new Cubit(this,mOrigPos[i], mNumAxis); |
|
366 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0); |
|
367 |
} |
|
368 | 392 |
} |
369 | 393 |
else |
370 | 394 |
{ |
... | ... | |
372 | 396 |
|
373 | 397 |
for(int i=0; i<mNumCubits; i++) |
374 | 398 |
{ |
375 |
mCubits[i] = new Cubit(this,mOrigPos[i], mNumAxis); |
|
376 | 399 |
cubitMesh[i] = createCubitMesh(i,mNumLayers,meshState,mNumCubitFaces); |
377 | 400 |
Static3D pos = getPos(mOrigPos[i]); |
378 | 401 |
cubitMesh[i].apply(new MatrixEffectMove(pos),1,0); |
379 |
cubitMesh[i].setEffectAssociation(0, mCubits[i].computeAssociation(), 0); |
|
380 | 402 |
} |
381 | 403 |
|
382 | 404 |
mMesh = new MeshJoined(cubitMesh); |
383 | 405 |
} |
406 |
|
|
407 |
for(int i=0; i<mNumCubits; i++) |
|
408 |
{ |
|
409 |
mCubits[i] = new Cubit(this,mOrigPos[i], mNumAxis); |
|
410 |
setCubitQuat(i,mCubits[i].computeAssociation(),0); |
|
411 |
} |
|
384 | 412 |
} |
385 | 413 |
|
386 | 414 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
983 | 1011 |
if( belongsToRotation(j,axis,rowBitmap) ) |
984 | 1012 |
{ |
985 | 1013 |
index = mCubits[j].removeRotationNow(quat); |
986 |
mMesh.setEffectAssociation(j, mCubits[j].computeAssociation(),index);
|
|
1014 |
setCubitQuat(j,mCubits[j].computeAssociation(),index);
|
|
987 | 1015 |
} |
988 | 1016 |
} |
989 | 1017 |
} |
... | ... | |
1172 | 1200 |
if( belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap) ) |
1173 | 1201 |
{ |
1174 | 1202 |
int index = mCubits[i].removeRotationNow(quat); |
1175 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(),index);
|
|
1203 |
setCubitQuat(i,mCubits[i].computeAssociation(),index);
|
|
1176 | 1204 |
} |
1177 | 1205 |
} |
1178 | 1206 |
|
... | ... | |
1329 | 1357 |
} |
1330 | 1358 |
} |
1331 | 1359 |
|
1360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1361 |
|
|
1362 |
private void setCubitQuat(int cubit, int andAssociation, int equAssociation) |
|
1363 |
{ |
|
1364 |
if( !mIsInMixupMode ) |
|
1365 |
{ |
|
1366 |
mMesh.setEffectAssociation(cubit,andAssociation,equAssociation); |
|
1367 |
} |
|
1368 |
else |
|
1369 |
{ |
|
1370 |
mMesh.setEffectAssociation(cubit,andAssociation,cubit); |
|
1371 |
Static4D tmp = mObjectQuats[equAssociation]; |
|
1372 |
mMixupModeQuats[cubit].set(tmp); |
|
1373 |
} |
|
1374 |
} |
|
1375 |
|
|
1332 | 1376 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1333 | 1377 |
|
1334 | 1378 |
synchronized void restorePreferences(SharedPreferences preferences) |
... | ... | |
1343 | 1387 |
if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats ) |
1344 | 1388 |
{ |
1345 | 1389 |
mCubits[i].modifyCurrentPosition(mObjectQuats[mQuatDebug[i]]); |
1346 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(),mQuatDebug[i]);
|
|
1390 |
setCubitQuat(i,mCubits[i].computeAssociation(),mQuatDebug[i]);
|
|
1347 | 1391 |
} |
1348 | 1392 |
else |
1349 | 1393 |
{ |
... | ... | |
1356 | 1400 |
for(int i=0; i<mNumCubits; i++) |
1357 | 1401 |
{ |
1358 | 1402 |
mCubits[i].solve(); |
1359 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(),0);
|
|
1403 |
setCubitQuat(i,mCubits[i].computeAssociation(),0);
|
|
1360 | 1404 |
} |
1361 | 1405 |
} |
1362 | 1406 |
} |
... | ... | |
1643 | 1687 |
for(int i=0; i<mNumCubits; i++) |
1644 | 1688 |
{ |
1645 | 1689 |
mCubits[i].solve(); |
1646 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0);
|
|
1690 |
setCubitQuat(i,mCubits[i].computeAssociation(),0);
|
|
1647 | 1691 |
} |
1648 | 1692 |
} |
1649 | 1693 |
|
Also available in: Unified diff
Big step towards the Mixup Cube.