Revision 880beeea
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/main/TwistyObject.java | ||
---|---|---|
890 | 890 |
} |
891 | 891 |
} |
892 | 892 |
|
893 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
894 |
// INTERNAL API |
|
895 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
896 |
|
|
897 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total) |
|
898 |
{ |
|
899 |
mScrambler.randomizeNewScramble(scramble,rnd,curr,total); |
|
900 |
} |
|
901 |
|
|
902 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
903 |
|
|
904 |
public int getNodeSize() |
|
905 |
{ |
|
906 |
return mNodeSize; |
|
907 |
} |
|
908 |
|
|
909 | 893 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
910 | 894 |
|
911 |
public void initializeObject(int[][] moves)
|
|
895 |
void initializeObject(int[][] moves) |
|
912 | 896 |
{ |
913 | 897 |
solve(); |
914 | 898 |
setupPosition(moves); |
... | ... | |
916 | 900 |
|
917 | 901 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
918 | 902 |
|
919 |
public synchronized void removeRotationNow()
|
|
903 |
synchronized void removeRotationNow() |
|
920 | 904 |
{ |
921 | 905 |
float angle = getAngle(); |
922 | 906 |
double nearestAngleInRadians = angle*Math.PI/180; |
... | ... | |
940 | 924 |
|
941 | 925 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
942 | 926 |
|
943 |
public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
|
|
927 |
long finishRotationNow(EffectListener listener, int nearestAngleInDegrees) |
|
944 | 928 |
{ |
945 | 929 |
if( wasRotateApplied() ) |
946 | 930 |
{ |
... | ... | |
965 | 949 |
|
966 | 950 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
967 | 951 |
|
968 |
public synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
|
|
952 |
synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener ) |
|
969 | 953 |
{ |
970 | 954 |
if( wasRotateApplied() ) |
971 | 955 |
{ |
... | ... | |
989 | 973 |
|
990 | 974 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
991 | 975 |
|
992 |
public void setTextureMap(int cubit, int face, int newColor) |
|
976 |
void continueRotation(float angleInDegrees) |
|
977 |
{ |
|
978 |
mRotationAngleStatic.set0(angleInDegrees); |
|
979 |
} |
|
980 |
|
|
981 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
982 |
|
|
983 |
synchronized void beginNewRotation(int axis, int row ) |
|
984 |
{ |
|
985 |
if( axis<0 || axis>=NUM_AXIS ) |
|
986 |
{ |
|
987 |
android.util.Log.e("object", "invalid rotation axis: "+axis); |
|
988 |
return; |
|
989 |
} |
|
990 |
if( row<0 || row>=mNumLayers ) |
|
991 |
{ |
|
992 |
android.util.Log.e("object", "invalid rotation row: "+row); |
|
993 |
return; |
|
994 |
} |
|
995 |
|
|
996 |
mRotAxis = axis; |
|
997 |
mRotRowBitmap= computeBitmapFromRow( (1<<row),axis ); |
|
998 |
mRotationAngleStatic.set0(0.0f); |
|
999 |
mRotationAxis.set( mAxis[axis] ); |
|
1000 |
mRotationAngle.add(mRotationAngleStatic); |
|
1001 |
mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1); |
|
1002 |
} |
|
1003 |
|
|
1004 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1005 |
|
|
1006 |
void setTextureMap(int cubit, int face, int newColor) |
|
993 | 1007 |
{ |
994 | 1008 |
final float ratioW = 1.0f/mNumTexCols; |
995 | 1009 |
final float ratioH = 1.0f/mNumTexRows; |
... | ... | |
1003 | 1017 |
|
1004 | 1018 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1005 | 1019 |
|
1006 |
public void resetAllTextureMaps()
|
|
1020 |
void resetAllTextureMaps() |
|
1007 | 1021 |
{ |
1008 | 1022 |
final float ratioW = 1.0f/mNumTexCols; |
1009 | 1023 |
final float ratioH = 1.0f/mNumTexRows; |
... | ... | |
1027 | 1041 |
|
1028 | 1042 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1029 | 1043 |
|
1030 |
public void releaseResources()
|
|
1044 |
void releaseResources() |
|
1031 | 1045 |
{ |
1032 | 1046 |
mTexture.markForDeletion(); |
1033 | 1047 |
mMesh.markForDeletion(); |
... | ... | |
1041 | 1055 |
|
1042 | 1056 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1043 | 1057 |
|
1044 |
public synchronized void restorePreferences(SharedPreferences preferences)
|
|
1058 |
synchronized void restorePreferences(SharedPreferences preferences) |
|
1045 | 1059 |
{ |
1046 | 1060 |
boolean error = false; |
1047 | 1061 |
|
... | ... | |
1073 | 1087 |
|
1074 | 1088 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1075 | 1089 |
|
1076 |
public void savePreferences(SharedPreferences.Editor editor)
|
|
1090 |
void savePreferences(SharedPreferences.Editor editor) |
|
1077 | 1091 |
{ |
1078 | 1092 |
for(int i=0; i<NUM_CUBITS; i++) CUBITS[i].savePreferences(editor); |
1079 | 1093 |
} |
1080 | 1094 |
|
1081 | 1095 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1082 | 1096 |
|
1083 |
public void recomputeScaleFactor(int scrWidth)
|
|
1097 |
void recomputeScaleFactor(int scrWidth) |
|
1084 | 1098 |
{ |
1085 | 1099 |
mNodeScale.set(scrWidth,NODE_RATIO*scrWidth,scrWidth); |
1086 | 1100 |
} |
1087 | 1101 |
|
1088 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1089 |
|
|
1090 |
public Static4D getRotationQuat() |
|
1091 |
{ |
|
1092 |
return mQuat; |
|
1093 |
} |
|
1094 |
|
|
1095 | 1102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1096 | 1103 |
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size) |
1097 | 1104 |
|
1098 |
public void createTexture()
|
|
1105 |
void createTexture() |
|
1099 | 1106 |
{ |
1100 | 1107 |
Bitmap bitmap; |
1101 | 1108 |
|
... | ... | |
1130 | 1137 |
} |
1131 | 1138 |
} |
1132 | 1139 |
|
1133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1134 |
// PUBLIC API |
|
1135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1136 |
|
|
1137 |
public boolean isSolved() |
|
1138 |
{ |
|
1139 |
if( mSolvedFunctionIndex==0 ) return isSolved0(); |
|
1140 |
if( mSolvedFunctionIndex==1 ) return isSolved1(); |
|
1141 |
if( mSolvedFunctionIndex==2 ) return isSolved2(); |
|
1142 |
if( mSolvedFunctionIndex==3 ) return isSolved3(); |
|
1143 |
|
|
1144 |
return false; |
|
1145 |
} |
|
1146 |
|
|
1147 | 1140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1148 | 1141 |
|
1149 |
public void setObjectRatio(float sizeChange)
|
|
1142 |
void setObjectRatio(float sizeChange) |
|
1150 | 1143 |
{ |
1151 | 1144 |
mObjectScreenRatio *= (1.0f+sizeChange)/2; |
1152 | 1145 |
|
... | ... | |
1159 | 1152 |
|
1160 | 1153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1161 | 1154 |
|
1162 |
public float getObjectRatio()
|
|
1155 |
float getObjectRatio() |
|
1163 | 1156 |
{ |
1164 | 1157 |
return mObjectScreenRatio*mInitScreenRatio; |
1165 | 1158 |
} |
1166 | 1159 |
|
1167 | 1160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1168 | 1161 |
|
1169 |
public int getCubitFaceColorIndex(int cubit, int face)
|
|
1162 |
boolean isSolved()
|
|
1170 | 1163 |
{ |
1171 |
Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face);
|
|
1172 |
|
|
1173 |
int x = (int)(texMap.get0()/texMap.get2());
|
|
1174 |
int y = (int)(texMap.get1()/texMap.get3());
|
|
1164 |
if( mSolvedFunctionIndex==0 ) return isSolved0();
|
|
1165 |
if( mSolvedFunctionIndex==1 ) return isSolved1(); |
|
1166 |
if( mSolvedFunctionIndex==2 ) return isSolved2();
|
|
1167 |
if( mSolvedFunctionIndex==3 ) return isSolved3();
|
|
1175 | 1168 |
|
1176 |
return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
|
|
1169 |
return false;
|
|
1177 | 1170 |
} |
1178 | 1171 |
|
1179 | 1172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1180 | 1173 |
|
1181 |
public int getNumLayers()
|
|
1174 |
int getCubit(float[] point3D)
|
|
1182 | 1175 |
{ |
1183 |
return mNumLayers; |
|
1176 |
float dist, minDist = Float.MAX_VALUE; |
|
1177 |
int currentBest=-1; |
|
1178 |
float multiplier = returnMultiplier(); |
|
1179 |
|
|
1180 |
point3D[0] *= multiplier; |
|
1181 |
point3D[1] *= multiplier; |
|
1182 |
point3D[2] *= multiplier; |
|
1183 |
|
|
1184 |
for(int i=0; i<NUM_CUBITS; i++) |
|
1185 |
{ |
|
1186 |
dist = CUBITS[i].getDistSquared(point3D); |
|
1187 |
if( dist<minDist ) |
|
1188 |
{ |
|
1189 |
minDist = dist; |
|
1190 |
currentBest = i; |
|
1191 |
} |
|
1192 |
} |
|
1193 |
|
|
1194 |
return currentBest; |
|
1184 | 1195 |
} |
1185 | 1196 |
|
1186 | 1197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1187 | 1198 |
|
1188 |
public void continueRotation(float angleInDegrees)
|
|
1199 |
int computeNearestAngle(int axis, float angle, float speed)
|
|
1189 | 1200 |
{ |
1190 |
mRotationAngleStatic.set0(angleInDegrees); |
|
1201 |
int[] basicArray = getBasicAngle(); |
|
1202 |
int basicAngle = basicArray[axis>=basicArray.length ? 0 : axis]; |
|
1203 |
int nearestAngle = 360/basicAngle; |
|
1204 |
|
|
1205 |
int tmp = (int)((angle+nearestAngle/2)/nearestAngle); |
|
1206 |
if( angle< -(nearestAngle*0.5) ) tmp-=1; |
|
1207 |
|
|
1208 |
if( tmp!=0 ) return nearestAngle*tmp; |
|
1209 |
|
|
1210 |
return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0; |
|
1191 | 1211 |
} |
1192 | 1212 |
|
1193 | 1213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1194 | 1214 |
|
1195 |
public void apply(Effect effect, int position)
|
|
1215 |
float getCameraDist()
|
|
1196 | 1216 |
{ |
1197 |
mEffects.apply(effect, position);
|
|
1217 |
return mCameraDist;
|
|
1198 | 1218 |
} |
1199 | 1219 |
|
1220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1221 |
// INTERNAL API - those are called from 'effects' package |
|
1200 | 1222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1201 | 1223 |
|
1202 |
public void remove(long effectID)
|
|
1224 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
|
|
1203 | 1225 |
{ |
1204 |
mEffects.abortById(effectID);
|
|
1226 |
mScrambler.randomizeNewScramble(scramble,rnd,curr,total);
|
|
1205 | 1227 |
} |
1206 | 1228 |
|
1207 | 1229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1208 | 1230 |
|
1209 |
public synchronized void solve()
|
|
1231 |
public int getNodeSize()
|
|
1210 | 1232 |
{ |
1211 |
for(int i=0; i<NUM_CUBITS; i++) |
|
1212 |
{ |
|
1213 |
CUBITS[i].solve(); |
|
1214 |
mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0); |
|
1215 |
} |
|
1233 |
return mNodeSize; |
|
1216 | 1234 |
} |
1217 | 1235 |
|
1218 | 1236 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1219 | 1237 |
|
1220 |
public synchronized void beginNewRotation(int axis, int row ) |
|
1221 |
{ |
|
1222 |
if( axis<0 || axis>=NUM_AXIS ) |
|
1223 |
{ |
|
1224 |
android.util.Log.e("object", "invalid rotation axis: "+axis); |
|
1225 |
return; |
|
1226 |
} |
|
1227 |
if( row<0 || row>=mNumLayers ) |
|
1238 |
public Static4D getRotationQuat() |
|
1228 | 1239 |
{ |
1229 |
android.util.Log.e("object", "invalid rotation row: "+row); |
|
1230 |
return; |
|
1240 |
return mQuat; |
|
1231 | 1241 |
} |
1232 | 1242 |
|
1233 |
mRotAxis = axis; |
|
1234 |
mRotRowBitmap= computeBitmapFromRow( (1<<row),axis ); |
|
1235 |
mRotationAngleStatic.set0(0.0f); |
|
1236 |
mRotationAxis.set( mAxis[axis] ); |
|
1237 |
mRotationAngle.add(mRotationAngleStatic); |
|
1238 |
mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1); |
|
1239 |
} |
|
1240 |
|
|
1243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1244 |
// PUBLIC API |
|
1241 | 1245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1242 | 1246 |
|
1243 |
public int getCubit(float[] point3D)
|
|
1247 |
public int getCubitFaceColorIndex(int cubit, int face)
|
|
1244 | 1248 |
{ |
1245 |
float dist, minDist = Float.MAX_VALUE; |
|
1246 |
int currentBest=-1; |
|
1247 |
float multiplier = returnMultiplier(); |
|
1248 |
|
|
1249 |
point3D[0] *= multiplier; |
|
1250 |
point3D[1] *= multiplier; |
|
1251 |
point3D[2] *= multiplier; |
|
1249 |
Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face); |
|
1252 | 1250 |
|
1253 |
for(int i=0; i<NUM_CUBITS; i++) |
|
1254 |
{ |
|
1255 |
dist = CUBITS[i].getDistSquared(point3D); |
|
1256 |
if( dist<minDist ) |
|
1257 |
{ |
|
1258 |
minDist = dist; |
|
1259 |
currentBest = i; |
|
1260 |
} |
|
1261 |
} |
|
1251 |
int x = (int)(texMap.get0()/texMap.get2()); |
|
1252 |
int y = (int)(texMap.get1()/texMap.get3()); |
|
1262 | 1253 |
|
1263 |
return currentBest;
|
|
1254 |
return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
|
|
1264 | 1255 |
} |
1265 | 1256 |
|
1266 | 1257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1267 | 1258 |
|
1268 |
public int computeNearestAngle(int axis, float angle, float speed)
|
|
1259 |
public int getNumLayers()
|
|
1269 | 1260 |
{ |
1270 |
int[] basicArray = getBasicAngle(); |
|
1271 |
int basicAngle = basicArray[axis>=basicArray.length ? 0 : axis]; |
|
1272 |
int nearestAngle = 360/basicAngle; |
|
1261 |
return mNumLayers; |
|
1262 |
} |
|
1273 | 1263 |
|
1274 |
int tmp = (int)((angle+nearestAngle/2)/nearestAngle); |
|
1275 |
if( angle< -(nearestAngle*0.5) ) tmp-=1; |
|
1264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1276 | 1265 |
|
1277 |
if( tmp!=0 ) return nearestAngle*tmp; |
|
1266 |
public void apply(Effect effect, int position) |
|
1267 |
{ |
|
1268 |
mEffects.apply(effect, position); |
|
1269 |
} |
|
1278 | 1270 |
|
1279 |
return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0; |
|
1271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1272 |
|
|
1273 |
public void remove(long effectID) |
|
1274 |
{ |
|
1275 |
mEffects.abortById(effectID); |
|
1280 | 1276 |
} |
1281 | 1277 |
|
1282 | 1278 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1283 | 1279 |
|
1284 |
public float getCameraDist()
|
|
1280 |
public synchronized void solve()
|
|
1285 | 1281 |
{ |
1286 |
return mCameraDist; |
|
1282 |
for(int i=0; i<NUM_CUBITS; i++) |
|
1283 |
{ |
|
1284 |
CUBITS[i].solve(); |
|
1285 |
mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0); |
|
1286 |
} |
|
1287 | 1287 |
} |
1288 | 1288 |
|
1289 | 1289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Move ObjectControl, the next big chunk of code, to objectlib.