Revision 59c20632
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/main/TwistyObject.java | ||
---|---|---|
60 | 60 |
import java.io.InputStream; |
61 | 61 |
import java.util.Random; |
62 | 62 |
|
63 |
import static org.distorted.objectlib.main.Movement.MOVEMENT_TETRAHEDRON; |
|
64 |
import static org.distorted.objectlib.main.Movement.MOVEMENT_HEXAHEDRON; |
|
65 |
import static org.distorted.objectlib.main.Movement.MOVEMENT_OCTAHEDRON; |
|
66 |
import static org.distorted.objectlib.main.Movement.MOVEMENT_DODECAHEDRON; |
|
67 |
import static org.distorted.objectlib.main.Movement.MOVEMENT_SHAPECHANGE; |
|
68 |
|
|
63 | 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 70 |
|
65 | 71 |
public abstract class TwistyObject extends DistortedNode |
... | ... | |
107 | 113 |
private final Static3D mNodeScale; |
108 | 114 |
private final Static4D mQuat; |
109 | 115 |
private final int[] mNumLayers; |
110 |
private final float mRealSize;
|
|
116 |
private final float mSize; |
|
111 | 117 |
private final DistortedEffects mEffects; |
112 | 118 |
private final VertexEffectRotate mRotateEffect; |
113 | 119 |
private final Dynamic1D mRotationAngle; |
... | ... | |
126 | 132 |
private int[] mTmpQuats; |
127 | 133 |
private int mNumTexRows, mNumTexCols; |
128 | 134 |
private int mRotRowBitmap; |
129 |
private int mRotAxis; |
|
135 |
private int mCurrentRotAxis;
|
|
130 | 136 |
private MeshBase mMesh; |
131 | 137 |
private final TwistyObjectScrambler mScrambler; |
138 |
private Movement mMovement; |
|
139 |
private boolean[][] mLayerRotatable; |
|
140 |
private int[][][] mEnabled; |
|
132 | 141 |
|
133 | 142 |
//////////////////// SOLVED1 //////////////////////// |
134 | 143 |
|
... | ... | |
138 | 147 |
|
139 | 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
140 | 149 |
|
141 |
TwistyObject(int[] numLayers, float realSize, Static4D quat, Static3D move, DistortedTexture nodeTexture,
|
|
150 |
TwistyObject(int[] numLayers, float size, Static4D quat, Static3D move, DistortedTexture nodeTexture,
|
|
142 | 151 |
MeshSquare nodeMesh, DistortedEffects nodeEffects, Resources res, int surfaceW, int surfaceH) |
143 | 152 |
{ |
144 | 153 |
super(nodeTexture,nodeEffects,nodeMesh); |
... | ... | |
149 | 158 |
resizeFBO(mNodeW,mNodeH); |
150 | 159 |
|
151 | 160 |
mNumLayers = numLayers; |
152 |
mRealSize = realSize;
|
|
161 |
mSize = size;
|
|
153 | 162 |
mOrigPos = getCubitPositions(mNumLayers); |
154 | 163 |
mAxis = getRotationAxis(); |
155 | 164 |
mInitScreenRatio = getScreenRatio(); |
... | ... | |
907 | 916 |
double nearestAngleInRadians = angle*Math.PI/180; |
908 | 917 |
float sinA =-(float)Math.sin(nearestAngleInRadians*0.5); |
909 | 918 |
float cosA = (float)Math.cos(nearestAngleInRadians*0.5); |
910 |
float axisX = mAxis[mRotAxis].get0(); |
|
911 |
float axisY = mAxis[mRotAxis].get1(); |
|
912 |
float axisZ = mAxis[mRotAxis].get2(); |
|
919 |
float axisX = mAxis[mCurrentRotAxis].get0();
|
|
920 |
float axisY = mAxis[mCurrentRotAxis].get1();
|
|
921 |
float axisZ = mAxis[mCurrentRotAxis].get2();
|
|
913 | 922 |
Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA); |
914 | 923 |
|
915 | 924 |
mRotationAngle.removeAll(); |
916 | 925 |
mRotationAngleStatic.set0(0); |
917 | 926 |
|
918 | 927 |
for(int i=0; i<NUM_CUBITS; i++) |
919 |
if( belongsToRotation(i,mRotAxis,mRotRowBitmap) )
|
|
928 |
if( belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap) )
|
|
920 | 929 |
{ |
921 | 930 |
int index = CUBITS[i].removeRotationNow(quat); |
922 | 931 |
mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),index); |
... | ... | |
954 | 963 |
{ |
955 | 964 |
if( wasRotateApplied() ) |
956 | 965 |
{ |
957 |
mRotAxis = axis;
|
|
966 |
mCurrentRotAxis = axis;
|
|
958 | 967 |
mRotRowBitmap= computeBitmapFromRow( rowBitmap,axis ); |
959 | 968 |
|
960 | 969 |
mRotationAngleStatic.set0(0.0f); |
... | ... | |
994 | 1003 |
return; |
995 | 1004 |
} |
996 | 1005 |
|
997 |
mRotAxis = axis;
|
|
1006 |
mCurrentRotAxis = axis;
|
|
998 | 1007 |
mRotRowBitmap= computeBitmapFromRow( (1<<row),axis ); |
999 | 1008 |
mRotationAngleStatic.set0(0.0f); |
1000 | 1009 |
mRotationAxis.set( mAxis[axis] ); |
... | ... | |
1144 | 1153 |
{ |
1145 | 1154 |
mObjectScreenRatio = sc; |
1146 | 1155 |
int nodeMinSize = Math.min(mNodeW,mNodeH); |
1147 |
float scale = mObjectScreenRatio*mInitScreenRatio*nodeMinSize/mRealSize;
|
|
1156 |
float scale = mObjectScreenRatio*mInitScreenRatio*nodeMinSize/mSize; |
|
1148 | 1157 |
mObjectScale.set(scale,scale,scale); |
1149 | 1158 |
} |
1150 | 1159 |
|
... | ... | |
1255 | 1264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1256 | 1265 |
|
1257 | 1266 |
public Static4D getRotationQuat() |
1258 |
{ |
|
1259 |
return mQuat; |
|
1260 |
} |
|
1267 |
{ |
|
1268 |
return mQuat; |
|
1269 |
} |
|
1270 |
|
|
1271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1272 |
|
|
1273 |
public float getSize() |
|
1274 |
{ |
|
1275 |
return mSize; |
|
1276 |
} |
|
1261 | 1277 |
|
1262 | 1278 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1263 | 1279 |
|
... | ... | |
1326 | 1342 |
return intGetObjectType(mNumLayers); |
1327 | 1343 |
} |
1328 | 1344 |
|
1345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1346 |
|
|
1347 |
public Movement getMovement() |
|
1348 |
{ |
|
1349 |
if( mMovement==null ) |
|
1350 |
{ |
|
1351 |
int[] numLayers = getNumLayers(); |
|
1352 |
if( mCuts==null ) getCuts(numLayers); |
|
1353 |
if( mLayerRotatable==null ) mLayerRotatable = getLayerRotatable(numLayers); |
|
1354 |
if( mEnabled==null ) mEnabled = getEnabled(); |
|
1355 |
|
|
1356 |
int movementType = getMovementType(); |
|
1357 |
int movementSplit= getMovementSplit(); |
|
1358 |
|
|
1359 |
switch(movementType) |
|
1360 |
{ |
|
1361 |
case MOVEMENT_TETRAHEDRON : mMovement = new Movement4(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled); |
|
1362 |
break; |
|
1363 |
case MOVEMENT_HEXAHEDRON : mMovement = new Movement6(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled); |
|
1364 |
break; |
|
1365 |
case MOVEMENT_OCTAHEDRON : mMovement = new Movement8(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled); |
|
1366 |
break; |
|
1367 |
case MOVEMENT_DODECAHEDRON: mMovement = new Movement12(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled); |
|
1368 |
break; |
|
1369 |
case MOVEMENT_SHAPECHANGE : float[] dist3D = getDist3D(numLayers); |
|
1370 |
mMovement = new MovementC(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled,dist3D); |
|
1371 |
break; |
|
1372 |
} |
|
1373 |
} |
|
1374 |
return mMovement; |
|
1375 |
} |
|
1376 |
|
|
1329 | 1377 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1330 | 1378 |
|
1331 | 1379 |
protected abstract int getFOV(); |
... | ... | |
1341 | 1389 |
protected abstract Static4D getQuat(int cubit, int[] numLayers); |
1342 | 1390 |
protected abstract ObjectShape getObjectShape(int cubit, int[] numLayers); |
1343 | 1391 |
protected abstract int[] getSolvedQuats(int cubit, int[] numLayers); |
1344 |
protected abstract int getSolvedFunctionIndex(); |
|
1345 | 1392 |
protected abstract ScrambleState[] getScrambleStates(); |
1346 | 1393 |
protected abstract int getNumStickerTypes(int[] numLayers); |
1347 | 1394 |
protected abstract ObjectSticker retSticker(int face); |
1348 | 1395 |
protected abstract int getFaceColor(int cubit, int cubitface, int[] numLayers); |
1349 | 1396 |
protected abstract int getResource(int[] numLayers); |
1350 | 1397 |
protected abstract ObjectType intGetObjectType(int[] numLayers); |
1351 |
protected abstract Movement getMovement(); |
|
1398 |
|
|
1399 |
// for JSON only |
|
1400 |
public abstract int getSolvedFunctionIndex(); |
|
1401 |
public abstract int getMovementType(); |
|
1402 |
public abstract int getMovementSplit(); |
|
1403 |
public abstract boolean[][] getLayerRotatable(int[] numLayers); |
|
1404 |
public abstract int[][][] getEnabled(); |
|
1405 |
public abstract float[] getDist3D(int[] numLayers); |
|
1352 | 1406 |
|
1353 | 1407 |
public abstract Static3D[] getRotationAxis(); |
1354 | 1408 |
public abstract int[] getBasicAngle(); |
1355 | 1409 |
public abstract int getNumFaces(); |
1356 | 1410 |
public abstract int getObjectName(int[] numLayers); |
1357 | 1411 |
public abstract int getInventor(int[] numLayers); |
1412 |
public abstract int getYearOfInvention(int[] numLayers); |
|
1358 | 1413 |
public abstract int getComplexity(int[] numLayers); |
1359 | 1414 |
} |
Also available in: Unified diff
Reorg for writing the JSON