Revision 7c111294
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/main/TwistyObject.java | ||
---|---|---|
891 | 891 |
} |
892 | 892 |
|
893 | 893 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
894 |
// PUBLIC API
|
|
894 |
// INTERNAL API
|
|
895 | 895 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
896 | 896 |
|
897 |
public boolean isSolved()
|
|
897 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
|
|
898 | 898 |
{ |
899 |
if( mSolvedFunctionIndex==0 ) return isSolved0(); |
|
900 |
if( mSolvedFunctionIndex==1 ) return isSolved1(); |
|
901 |
if( mSolvedFunctionIndex==2 ) return isSolved2(); |
|
902 |
if( mSolvedFunctionIndex==3 ) return isSolved3(); |
|
903 |
|
|
904 |
return false; |
|
899 |
mScrambler.randomizeNewScramble(scramble,rnd,curr,total); |
|
905 | 900 |
} |
906 | 901 |
|
907 | 902 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
908 |
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size) |
|
909 | 903 |
|
910 |
public void createTexture()
|
|
904 |
public int getNodeSize()
|
|
911 | 905 |
{ |
912 |
Bitmap bitmap; |
|
906 |
return mNodeSize; |
|
907 |
} |
|
913 | 908 |
|
914 |
Paint paint = new Paint(); |
|
915 |
bitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888); |
|
916 |
Canvas canvas = new Canvas(bitmap); |
|
909 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
917 | 910 |
|
918 |
paint.setAntiAlias(true); |
|
919 |
paint.setTextAlign(Paint.Align.CENTER); |
|
920 |
paint.setStyle(Paint.Style.FILL); |
|
911 |
public void initializeObject(int[][] moves) |
|
912 |
{ |
|
913 |
solve(); |
|
914 |
setupPosition(moves); |
|
915 |
} |
|
921 | 916 |
|
922 |
paint.setColor(COLOR_BLACK); |
|
923 |
canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint); |
|
917 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
924 | 918 |
|
925 |
int face = 0; |
|
926 |
FactorySticker factory = FactorySticker.getInstance(); |
|
919 |
public synchronized void removeRotationNow() |
|
920 |
{ |
|
921 |
float angle = getAngle(); |
|
922 |
double nearestAngleInRadians = angle*Math.PI/180; |
|
923 |
float sinA =-(float)Math.sin(nearestAngleInRadians*0.5); |
|
924 |
float cosA = (float)Math.cos(nearestAngleInRadians*0.5); |
|
925 |
float axisX = mAxis[mRotAxis].get0(); |
|
926 |
float axisY = mAxis[mRotAxis].get1(); |
|
927 |
float axisZ = mAxis[mRotAxis].get2(); |
|
928 |
Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA); |
|
927 | 929 |
|
928 |
for(int row=0; row<mNumTexRows; row++) |
|
929 |
for(int col=0; col<mNumTexCols; col++) |
|
930 |
mRotationAngle.removeAll(); |
|
931 |
mRotationAngleStatic.set0(0); |
|
932 |
|
|
933 |
for(int i=0; i<NUM_CUBITS; i++) |
|
934 |
if( belongsToRotation(i,mRotAxis,mRotRowBitmap) ) |
|
930 | 935 |
{ |
931 |
if( face>=NUM_TEXTURES ) break; |
|
932 |
ObjectSticker sticker = retSticker(face); |
|
933 |
factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, row*TEXTURE_HEIGHT, getColor(face%NUM_FACE_COLORS), sticker); |
|
934 |
face++; |
|
936 |
int index = CUBITS[i].removeRotationNow(quat); |
|
937 |
mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),index); |
|
935 | 938 |
} |
936 |
|
|
937 |
if( !mTexture.setTexture(bitmap) ) |
|
938 |
{ |
|
939 |
int max = DistortedLibrary.getMaxTextureSize(); |
|
940 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
941 |
crashlytics.log("failed to set texture of size "+bitmap.getWidth()+"x"+bitmap.getHeight()+" max is "+max); |
|
942 |
} |
|
943 | 939 |
} |
944 | 940 |
|
945 | 941 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
946 | 942 |
|
947 |
public void setObjectRatio(float sizeChange)
|
|
943 |
public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
|
|
948 | 944 |
{ |
949 |
mObjectScreenRatio *= (1.0f+sizeChange)/2; |
|
950 |
|
|
951 |
if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE; |
|
952 |
if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE; |
|
945 |
if( wasRotateApplied() ) |
|
946 |
{ |
|
947 |
float angle = getAngle(); |
|
948 |
mRotationAngleStatic.set0(angle); |
|
949 |
mRotationAngleFinal.set0(nearestAngleInDegrees); |
|
950 |
mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f ); |
|
953 | 951 |
|
954 |
float scale = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize; |
|
955 |
mObjectScale.set(scale,scale,scale); |
|
956 |
} |
|
952 |
mRotationAngle.setDuration(POST_ROTATION_MILLISEC); |
|
953 |
mRotationAngle.resetToBeginning(); |
|
954 |
mRotationAngle.removeAll(); |
|
955 |
mRotationAngle.add(mRotationAngleStatic); |
|
956 |
mRotationAngle.add(mRotationAngleMiddle); |
|
957 |
mRotationAngle.add(mRotationAngleFinal); |
|
958 |
mRotateEffect.notifyWhenFinished(listener); |
|
957 | 959 |
|
958 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
960 |
return mRotateEffect.getID(); |
|
961 |
} |
|
959 | 962 |
|
960 |
public float getObjectRatio() |
|
961 |
{ |
|
962 |
return mObjectScreenRatio*mInitScreenRatio; |
|
963 |
return 0; |
|
963 | 964 |
} |
964 | 965 |
|
965 | 966 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
966 | 967 |
|
967 |
public int getCubitFaceColorIndex(int cubit, int face)
|
|
968 |
public synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
|
|
968 | 969 |
{ |
969 |
Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face); |
|
970 |
if( wasRotateApplied() ) |
|
971 |
{ |
|
972 |
mRotAxis = axis; |
|
973 |
mRotRowBitmap= computeBitmapFromRow( rowBitmap,axis ); |
|
970 | 974 |
|
971 |
int x = (int)(texMap.get0()/texMap.get2()); |
|
972 |
int y = (int)(texMap.get1()/texMap.get3()); |
|
975 |
mRotationAngleStatic.set0(0.0f); |
|
976 |
mRotationAxis.set( mAxis[axis] ); |
|
977 |
mRotationAngle.setDuration(durationMillis); |
|
978 |
mRotationAngle.resetToBeginning(); |
|
979 |
mRotationAngle.add(new Static1D(0)); |
|
980 |
mRotationAngle.add(new Static1D(angle)); |
|
981 |
mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1); |
|
982 |
mRotateEffect.notifyWhenFinished(listener); |
|
973 | 983 |
|
974 |
return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x; |
|
984 |
return mRotateEffect.getID(); |
|
985 |
} |
|
986 |
|
|
987 |
return 0; |
|
975 | 988 |
} |
976 | 989 |
|
977 | 990 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
978 | 991 |
|
979 |
public int getNumLayers()
|
|
992 |
public void setTextureMap(int cubit, int face, int newColor)
|
|
980 | 993 |
{ |
981 |
return mNumLayers; |
|
994 |
final float ratioW = 1.0f/mNumTexCols; |
|
995 |
final float ratioH = 1.0f/mNumTexRows; |
|
996 |
final Static4D[] maps = new Static4D[mNumCubitFaces]; |
|
997 |
int row = (mNumTexRows-1) - newColor/mNumTexCols; |
|
998 |
int col = newColor%mNumTexCols; |
|
999 |
|
|
1000 |
maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH); |
|
1001 |
mMesh.setTextureMap(maps,mNumCubitFaces*cubit); |
|
982 | 1002 |
} |
983 | 1003 |
|
984 | 1004 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
985 | 1005 |
|
986 |
public void continueRotation(float angleInDegrees)
|
|
1006 |
public void resetAllTextureMaps()
|
|
987 | 1007 |
{ |
988 |
mRotationAngleStatic.set0(angleInDegrees); |
|
989 |
} |
|
990 |
|
|
991 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1008 |
final float ratioW = 1.0f/mNumTexCols; |
|
1009 |
final float ratioH = 1.0f/mNumTexRows; |
|
1010 |
int color, row, col; |
|
992 | 1011 |
|
993 |
public Static4D getRotationQuat()
|
|
1012 |
for(int cubit=0; cubit<NUM_CUBITS; cubit++)
|
|
994 | 1013 |
{ |
995 |
return mQuat; |
|
996 |
} |
|
1014 |
final Static4D[] maps = new Static4D[mNumCubitFaces]; |
|
997 | 1015 |
|
998 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1016 |
for(int cubitface=0; cubitface<mNumCubitFaces; cubitface++) |
|
1017 |
{ |
|
1018 |
color = getFaceColor(cubit,cubitface,mNumLayers); |
|
1019 |
row = (mNumTexRows-1) - color/mNumTexCols; |
|
1020 |
col = color%mNumTexCols; |
|
1021 |
maps[cubitface] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH); |
|
1022 |
} |
|
999 | 1023 |
|
1000 |
public void recomputeScaleFactor(int scrWidth) |
|
1001 |
{ |
|
1002 |
mNodeScale.set(scrWidth,NODE_RATIO*scrWidth,scrWidth); |
|
1024 |
mMesh.setTextureMap(maps,mNumCubitFaces*cubit); |
|
1025 |
} |
|
1003 | 1026 |
} |
1004 | 1027 |
|
1005 | 1028 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1006 | 1029 |
|
1007 |
public void savePreferences(SharedPreferences.Editor editor)
|
|
1030 |
public void releaseResources()
|
|
1008 | 1031 |
{ |
1009 |
for(int i=0; i<NUM_CUBITS; i++) CUBITS[i].savePreferences(editor); |
|
1032 |
mTexture.markForDeletion(); |
|
1033 |
mMesh.markForDeletion(); |
|
1034 |
mEffects.markForDeletion(); |
|
1035 |
|
|
1036 |
for(int j=0; j<NUM_CUBITS; j++) |
|
1037 |
{ |
|
1038 |
CUBITS[j].releaseResources(); |
|
1039 |
} |
|
1010 | 1040 |
} |
1011 | 1041 |
|
1012 | 1042 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1043 | 1073 |
|
1044 | 1074 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1045 | 1075 |
|
1046 |
public void releaseResources() |
|
1047 |
{ |
|
1048 |
mTexture.markForDeletion(); |
|
1049 |
mMesh.markForDeletion(); |
|
1050 |
mEffects.markForDeletion(); |
|
1051 |
|
|
1052 |
for(int j=0; j<NUM_CUBITS; j++) |
|
1053 |
{ |
|
1054 |
CUBITS[j].releaseResources(); |
|
1055 |
} |
|
1056 |
} |
|
1057 |
|
|
1058 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1059 |
|
|
1060 |
public void apply(Effect effect, int position) |
|
1076 |
public void savePreferences(SharedPreferences.Editor editor) |
|
1061 | 1077 |
{ |
1062 |
mEffects.apply(effect, position);
|
|
1078 |
for(int i=0; i<NUM_CUBITS; i++) CUBITS[i].savePreferences(editor);
|
|
1063 | 1079 |
} |
1064 | 1080 |
|
1065 | 1081 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1066 | 1082 |
|
1067 |
public void remove(long effectID)
|
|
1083 |
public void recomputeScaleFactor(int scrWidth)
|
|
1068 | 1084 |
{ |
1069 |
mEffects.abortById(effectID);
|
|
1085 |
mNodeScale.set(scrWidth,NODE_RATIO*scrWidth,scrWidth);
|
|
1070 | 1086 |
} |
1071 | 1087 |
|
1072 | 1088 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1073 | 1089 |
|
1074 |
public synchronized void solve() |
|
1075 |
{ |
|
1076 |
for(int i=0; i<NUM_CUBITS; i++) |
|
1090 |
public Static4D getRotationQuat() |
|
1077 | 1091 |
{ |
1078 |
CUBITS[i].solve(); |
|
1079 |
mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0); |
|
1092 |
return mQuat; |
|
1080 | 1093 |
} |
1081 |
} |
|
1082 | 1094 |
|
1083 | 1095 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1096 |
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size) |
|
1084 | 1097 |
|
1085 |
public void resetAllTextureMaps()
|
|
1098 |
public void createTexture()
|
|
1086 | 1099 |
{ |
1087 |
final float ratioW = 1.0f/mNumTexCols; |
|
1088 |
final float ratioH = 1.0f/mNumTexRows; |
|
1089 |
int color, row, col; |
|
1100 |
Bitmap bitmap; |
|
1090 | 1101 |
|
1091 |
for(int cubit=0; cubit<NUM_CUBITS; cubit++)
|
|
1092 |
{
|
|
1093 |
final Static4D[] maps = new Static4D[mNumCubitFaces];
|
|
1102 |
Paint paint = new Paint();
|
|
1103 |
bitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
|
|
1104 |
Canvas canvas = new Canvas(bitmap);
|
|
1094 | 1105 |
|
1095 |
for(int cubitface=0; cubitface<mNumCubitFaces; cubitface++) |
|
1106 |
paint.setAntiAlias(true); |
|
1107 |
paint.setTextAlign(Paint.Align.CENTER); |
|
1108 |
paint.setStyle(Paint.Style.FILL); |
|
1109 |
|
|
1110 |
paint.setColor(COLOR_BLACK); |
|
1111 |
canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint); |
|
1112 |
|
|
1113 |
int face = 0; |
|
1114 |
FactorySticker factory = FactorySticker.getInstance(); |
|
1115 |
|
|
1116 |
for(int row=0; row<mNumTexRows; row++) |
|
1117 |
for(int col=0; col<mNumTexCols; col++) |
|
1096 | 1118 |
{ |
1097 |
color = getFaceColor(cubit,cubitface,mNumLayers);
|
|
1098 |
row = (mNumTexRows-1) - color/mNumTexCols;
|
|
1099 |
col = color%mNumTexCols;
|
|
1100 |
maps[cubitface] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
|
|
1119 |
if( face>=NUM_TEXTURES ) break;
|
|
1120 |
ObjectSticker sticker = retSticker(face);
|
|
1121 |
factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, row*TEXTURE_HEIGHT, getColor(face%NUM_FACE_COLORS), sticker);
|
|
1122 |
face++;
|
|
1101 | 1123 |
} |
1102 | 1124 |
|
1103 |
mMesh.setTextureMap(maps,mNumCubitFaces*cubit); |
|
1125 |
if( !mTexture.setTexture(bitmap) ) |
|
1126 |
{ |
|
1127 |
int max = DistortedLibrary.getMaxTextureSize(); |
|
1128 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
1129 |
crashlytics.log("failed to set texture of size "+bitmap.getWidth()+"x"+bitmap.getHeight()+" max is "+max); |
|
1104 | 1130 |
} |
1105 | 1131 |
} |
1106 | 1132 |
|
1133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1134 |
// PUBLIC API |
|
1107 | 1135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1108 | 1136 |
|
1109 |
public void setTextureMap(int cubit, int face, int newColor)
|
|
1137 |
public boolean isSolved()
|
|
1110 | 1138 |
{ |
1111 |
final float ratioW = 1.0f/mNumTexCols; |
|
1112 |
final float ratioH = 1.0f/mNumTexRows; |
|
1113 |
final Static4D[] maps = new Static4D[mNumCubitFaces]; |
|
1114 |
int row = (mNumTexRows-1) - newColor/mNumTexCols; |
|
1115 |
int col = newColor%mNumTexCols; |
|
1139 |
if( mSolvedFunctionIndex==0 ) return isSolved0(); |
|
1140 |
if( mSolvedFunctionIndex==1 ) return isSolved1(); |
|
1141 |
if( mSolvedFunctionIndex==2 ) return isSolved2(); |
|
1142 |
if( mSolvedFunctionIndex==3 ) return isSolved3(); |
|
1116 | 1143 |
|
1117 |
maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH); |
|
1118 |
mMesh.setTextureMap(maps,mNumCubitFaces*cubit); |
|
1144 |
return false; |
|
1119 | 1145 |
} |
1120 | 1146 |
|
1121 | 1147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1122 | 1148 |
|
1123 |
public synchronized void beginNewRotation(int axis, int row )
|
|
1149 |
public void setObjectRatio(float sizeChange)
|
|
1124 | 1150 |
{ |
1125 |
if( axis<0 || axis>=NUM_AXIS ) |
|
1126 |
{ |
|
1127 |
android.util.Log.e("object", "invalid rotation axis: "+axis); |
|
1128 |
return; |
|
1129 |
} |
|
1130 |
if( row<0 || row>=mNumLayers ) |
|
1131 |
{ |
|
1132 |
android.util.Log.e("object", "invalid rotation row: "+row); |
|
1133 |
return; |
|
1134 |
} |
|
1151 |
mObjectScreenRatio *= (1.0f+sizeChange)/2; |
|
1135 | 1152 |
|
1136 |
mRotAxis = axis; |
|
1137 |
mRotRowBitmap= computeBitmapFromRow( (1<<row),axis ); |
|
1138 |
mRotationAngleStatic.set0(0.0f); |
|
1139 |
mRotationAxis.set( mAxis[axis] ); |
|
1140 |
mRotationAngle.add(mRotationAngleStatic); |
|
1141 |
mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1); |
|
1153 |
if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE; |
|
1154 |
if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE; |
|
1155 |
|
|
1156 |
float scale = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize; |
|
1157 |
mObjectScale.set(scale,scale,scale); |
|
1142 | 1158 |
} |
1143 | 1159 |
|
1144 | 1160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1145 | 1161 |
|
1146 |
public synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
|
|
1162 |
public float getObjectRatio()
|
|
1147 | 1163 |
{ |
1148 |
if( wasRotateApplied() ) |
|
1149 |
{ |
|
1150 |
mRotAxis = axis; |
|
1151 |
mRotRowBitmap= computeBitmapFromRow( rowBitmap,axis ); |
|
1164 |
return mObjectScreenRatio*mInitScreenRatio; |
|
1165 |
} |
|
1152 | 1166 |
|
1153 |
mRotationAngleStatic.set0(0.0f); |
|
1154 |
mRotationAxis.set( mAxis[axis] ); |
|
1155 |
mRotationAngle.setDuration(durationMillis); |
|
1156 |
mRotationAngle.resetToBeginning(); |
|
1157 |
mRotationAngle.add(new Static1D(0)); |
|
1158 |
mRotationAngle.add(new Static1D(angle)); |
|
1159 |
mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1); |
|
1160 |
mRotateEffect.notifyWhenFinished(listener); |
|
1167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1161 | 1168 |
|
1162 |
return mRotateEffect.getID(); |
|
1163 |
} |
|
1169 |
public int getCubitFaceColorIndex(int cubit, int face) |
|
1170 |
{ |
|
1171 |
Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face); |
|
1164 | 1172 |
|
1165 |
return 0; |
|
1173 |
int x = (int)(texMap.get0()/texMap.get2()); |
|
1174 |
int y = (int)(texMap.get1()/texMap.get3()); |
|
1175 |
|
|
1176 |
return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x; |
|
1166 | 1177 |
} |
1167 | 1178 |
|
1168 | 1179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1169 | 1180 |
|
1170 |
public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
|
|
1181 |
public int getNumLayers()
|
|
1171 | 1182 |
{ |
1172 |
if( wasRotateApplied() ) |
|
1173 |
{ |
|
1174 |
float angle = getAngle(); |
|
1175 |
mRotationAngleStatic.set0(angle); |
|
1176 |
mRotationAngleFinal.set0(nearestAngleInDegrees); |
|
1177 |
mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f ); |
|
1183 |
return mNumLayers; |
|
1184 |
} |
|
1178 | 1185 |
|
1179 |
mRotationAngle.setDuration(POST_ROTATION_MILLISEC); |
|
1180 |
mRotationAngle.resetToBeginning(); |
|
1181 |
mRotationAngle.removeAll(); |
|
1182 |
mRotationAngle.add(mRotationAngleStatic); |
|
1183 |
mRotationAngle.add(mRotationAngleMiddle); |
|
1184 |
mRotationAngle.add(mRotationAngleFinal); |
|
1185 |
mRotateEffect.notifyWhenFinished(listener); |
|
1186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1186 | 1187 |
|
1187 |
return mRotateEffect.getID(); |
|
1188 |
} |
|
1188 |
public void continueRotation(float angleInDegrees) |
|
1189 |
{ |
|
1190 |
mRotationAngleStatic.set0(angleInDegrees); |
|
1191 |
} |
|
1189 | 1192 |
|
1190 |
return 0; |
|
1193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1194 |
|
|
1195 |
public void apply(Effect effect, int position) |
|
1196 |
{ |
|
1197 |
mEffects.apply(effect, position); |
|
1191 | 1198 |
} |
1192 | 1199 |
|
1193 | 1200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1194 | 1201 |
|
1195 |
public synchronized void removeRotationNow()
|
|
1202 |
public void remove(long effectID)
|
|
1196 | 1203 |
{ |
1197 |
float angle = getAngle(); |
|
1198 |
double nearestAngleInRadians = angle*Math.PI/180; |
|
1199 |
float sinA =-(float)Math.sin(nearestAngleInRadians*0.5); |
|
1200 |
float cosA = (float)Math.cos(nearestAngleInRadians*0.5); |
|
1201 |
float axisX = mAxis[mRotAxis].get0(); |
|
1202 |
float axisY = mAxis[mRotAxis].get1(); |
|
1203 |
float axisZ = mAxis[mRotAxis].get2(); |
|
1204 |
Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA); |
|
1204 |
mEffects.abortById(effectID); |
|
1205 |
} |
|
1205 | 1206 |
|
1206 |
mRotationAngle.removeAll(); |
|
1207 |
mRotationAngleStatic.set0(0); |
|
1207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1208 | 1208 |
|
1209 |
public synchronized void solve() |
|
1210 |
{ |
|
1209 | 1211 |
for(int i=0; i<NUM_CUBITS; i++) |
1210 |
if( belongsToRotation(i,mRotAxis,mRotRowBitmap) ) |
|
1211 |
{ |
|
1212 |
int index = CUBITS[i].removeRotationNow(quat); |
|
1213 |
mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),index); |
|
1214 |
} |
|
1212 |
{ |
|
1213 |
CUBITS[i].solve(); |
|
1214 |
mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0); |
|
1215 |
} |
|
1215 | 1216 |
} |
1216 | 1217 |
|
1217 | 1218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1218 | 1219 |
|
1219 |
public void initializeObject(int[][] moves)
|
|
1220 |
public synchronized void beginNewRotation(int axis, int row )
|
|
1220 | 1221 |
{ |
1221 |
solve(); |
|
1222 |
setupPosition(moves); |
|
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 ) |
|
1228 |
{ |
|
1229 |
android.util.Log.e("object", "invalid rotation row: "+row); |
|
1230 |
return; |
|
1231 |
} |
|
1232 |
|
|
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); |
|
1223 | 1239 |
} |
1224 | 1240 |
|
1225 | 1241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1270 | 1286 |
return mCameraDist; |
1271 | 1287 |
} |
1272 | 1288 |
|
1273 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1274 |
|
|
1275 |
public int getNodeSize() |
|
1276 |
{ |
|
1277 |
return mNodeSize; |
|
1278 |
} |
|
1279 |
|
|
1280 | 1289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1281 | 1290 |
|
1282 | 1291 |
public ObjectType getObjectType() |
... | ... | |
1284 | 1293 |
return intGetObjectType(mNumLayers); |
1285 | 1294 |
} |
1286 | 1295 |
|
1287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1288 |
|
|
1289 |
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total) |
|
1290 |
{ |
|
1291 |
mScrambler.randomizeNewScramble(scramble,rnd,curr,total); |
|
1292 |
} |
|
1293 |
|
|
1294 | 1296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1295 | 1297 |
|
1296 | 1298 |
protected abstract int getFOV(); |
... | ... | |
1314 | 1316 |
protected abstract int getFaceColor(int cubit, int cubitface, int numLayers); |
1315 | 1317 |
protected abstract int getResource(int mNumLayers); |
1316 | 1318 |
protected abstract ObjectType intGetObjectType(int numLayers); |
1319 |
protected abstract Movement getMovement(); |
|
1317 | 1320 |
|
1318 |
public abstract Movement getMovement(); |
|
1319 | 1321 |
public abstract Static3D[] getRotationAxis(); |
1320 | 1322 |
public abstract int[] getBasicAngle(); |
1321 | 1323 |
public abstract int getObjectName(int numLayers); |
Also available in: Unified diff
Move PreRender to objectlib.
This code is now shared betweeen the Rubik and Tutorial activities.