Revision a31d25de
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/dialog/RubikDialogPatternView.java | ||
|---|---|---|
| 153 | 153 |
state.setPattern(act, mTab, category, ii); |
| 154 | 154 |
int[] sizes = RubikObjectList.CUBE.getSizes(); |
| 155 | 155 |
RubikPattern pattern = RubikPattern.getInstance(); |
| 156 |
String moves = pattern.getMoves(mTab, category, ii);
|
|
| 156 |
int[][] moves = pattern.getMoves(mTab, category, ii);
|
|
| 157 | 157 |
act.changeObject(RubikObjectList.CUBE,sizes[mTab],moves); |
| 158 | 158 |
mDialog.rememberCategories(); |
| 159 | 159 |
mDialog.dismiss(); |
| src/main/java/org/distorted/magic/RubikActivity.java | ||
|---|---|---|
| 193 | 193 |
|
| 194 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 195 | 195 |
|
| 196 |
public void changeObject(RubikObjectList object, int size, String moves)
|
|
| 196 |
public void changeObject(RubikObjectList object, int size, int[][] moves)
|
|
| 197 | 197 |
{
|
| 198 | 198 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
| 199 | 199 |
RubikPostRender post = view.getPostRender(); |
| src/main/java/org/distorted/magic/RubikPostRender.java | ||
|---|---|---|
| 54 | 54 |
private long mNewRecord; |
| 55 | 55 |
private int mScreenWidth, mScreenHeight; |
| 56 | 56 |
private SharedPreferences mPreferences; |
| 57 |
private String mNextMoves;
|
|
| 57 |
private int[][] mNextMoves;
|
|
| 58 | 58 |
private RubikObject mOldObject, mNewObject; |
| 59 | 59 |
private int mScrambleObjectNum; |
| 60 | 60 |
private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle; |
| ... | ... | |
| 92 | 92 |
|
| 93 | 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 94 | 94 |
|
| 95 |
private void createObjectNow(RubikObjectList object, int size, String moves)
|
|
| 95 |
private void createObjectNow(RubikObjectList object, int size, int[][] moves)
|
|
| 96 | 96 |
{
|
| 97 | 97 |
boolean firstTime = (mNewObject==null); |
| 98 | 98 |
|
| ... | ... | |
| 161 | 161 |
} |
| 162 | 162 |
} |
| 163 | 163 |
|
| 164 |
android.util.Log.e("post", "1 canDrag true");
|
|
| 165 |
|
|
| 166 | 164 |
mCanDrag = true; |
| 167 | 165 |
mCanRotate = false; |
| 168 | 166 |
mCanUI = false; |
| ... | ... | |
| 312 | 310 |
|
| 313 | 311 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 314 | 312 |
|
| 315 |
void changeObject(RubikObjectList object, int size, String moves)
|
|
| 313 |
void changeObject(RubikObjectList object, int size, int[][] moves)
|
|
| 316 | 314 |
{
|
| 317 | 315 |
if( size>0 ) |
| 318 | 316 |
{
|
| src/main/java/org/distorted/object/RubikCube.java | ||
|---|---|---|
| 78 | 78 |
|
| 79 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 80 | 80 |
|
| 81 |
RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, String moves)
|
|
| 81 |
RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, int[][] moves)
|
|
| 82 | 82 |
{
|
| 83 | 83 |
super(size, 60, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.CUBE); |
| 84 | 84 |
} |
| src/main/java/org/distorted/object/RubikObject.java | ||
|---|---|---|
| 75 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 76 | 76 |
|
| 77 | 77 |
RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, |
| 78 |
MeshRectangles nodeMesh, DistortedEffects nodeEffects, String moves, RubikObjectList list)
|
|
| 78 |
MeshRectangles nodeMesh, DistortedEffects nodeEffects, int[][] moves, RubikObjectList list)
|
|
| 79 | 79 |
{
|
| 80 | 80 |
super(nodeTexture,nodeEffects,nodeMesh); |
| 81 | 81 |
|
| ... | ... | |
| 221 | 221 |
} |
| 222 | 222 |
|
| 223 | 223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 224 |
// TODO |
|
| 224 |
// note the minus in front of the sin() - we rotate counterclockwise |
|
| 225 |
// when looking towards the direction where the axis increases in values. |
|
| 225 | 226 |
|
| 226 |
private void setupPosition(String moves)
|
|
| 227 |
private Static4D makeQuaternion(int axisIndex, int angleInDegrees)
|
|
| 227 | 228 |
{
|
| 228 |
android.util.Log.e("object", "initializing: "+moves);
|
|
| 229 |
/* |
|
| 230 |
int index,tmp, a1,a2,a3, rv, rc, ra; |
|
| 231 |
|
|
| 232 |
numRotations=0; |
|
| 233 |
initializeVertices(mSize); |
|
| 234 |
|
|
| 235 |
int len=moves.length()/4; |
|
| 236 |
|
|
| 237 |
for(int i=0; i<len; i++) |
|
| 238 |
{
|
|
| 239 |
a1=moves.charAt(4*i+1)-'0'; |
|
| 240 |
a2=moves.charAt(4*i+2)-'0'; |
|
| 241 |
a3=moves.charAt(4*i+3)-'0'; |
|
| 242 |
|
|
| 243 |
rv = (10*a1+a2)/32; |
|
| 244 |
rc = (10*a1+a2)%32; |
|
| 245 |
ra = 2-a3; |
|
| 246 |
|
|
| 247 |
rotVector = rv; |
|
| 248 |
|
|
| 249 |
tmp=rc; |
|
| 250 |
index=0; |
|
| 251 |
|
|
| 252 |
while( tmp!=0 ) |
|
| 253 |
{
|
|
| 254 |
if( (tmp&0x1)==1 ) |
|
| 255 |
{
|
|
| 256 |
rotAngle[index] = ra*90; |
|
| 257 |
RubikWorld.setIdentity(rotMat[index]); |
|
| 258 |
|
|
| 259 |
switch(rotVector) |
|
| 260 |
{
|
|
| 261 |
case VECTX: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 1f,0f,0f); break; |
|
| 262 |
case VECTY: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 0f,1f,0f); break; |
|
| 263 |
case VECTZ: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 0f,0f,1f); break; |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
transposeTiles(index); |
|
| 267 |
rotAngle[index]=0; |
|
| 268 |
} |
|
| 269 |
|
|
| 270 |
tmp/=2; |
|
| 271 |
index++; |
|
| 272 |
} |
|
| 273 |
} |
|
| 274 |
*/ |
|
| 229 |
Static3D axis = ROTATION_AXIS[axisIndex]; |
|
| 230 |
|
|
| 231 |
while( angleInDegrees<0 ) angleInDegrees += 360; |
|
| 232 |
angleInDegrees %= 360; |
|
| 233 |
|
|
| 234 |
float cosA = (float)Math.cos(Math.PI*angleInDegrees/360); |
|
| 235 |
float sinA =-(float)Math.sqrt(1-cosA*cosA); |
|
| 236 |
|
|
| 237 |
return new Static4D(axis.get0()*sinA, axis.get1()*sinA, axis.get2()*sinA, cosA); |
|
| 238 |
} |
|
| 239 |
|
|
| 240 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 241 |
|
|
| 242 |
private void setupPosition(int[][] moves) |
|
| 243 |
{
|
|
| 244 |
if( moves!=null ) |
|
| 245 |
{
|
|
| 246 |
Static4D quat; |
|
| 247 |
int axis, rowBitmap, angle; |
|
| 248 |
int corr = (360/getBasicAngle()); |
|
| 249 |
|
|
| 250 |
for(int[] move: moves) |
|
| 251 |
{
|
|
| 252 |
axis = move[0]; |
|
| 253 |
rowBitmap= move[1]; |
|
| 254 |
angle = move[2]*corr; |
|
| 255 |
quat = makeQuaternion(axis,angle); |
|
| 256 |
|
|
| 257 |
for(int j=0; j<NUM_CUBITS; j++) |
|
| 258 |
if( belongsToRotation(j,axis,rowBitmap) ) |
|
| 259 |
{
|
|
| 260 |
mCubits[j].removeRotationNow(quat); |
|
| 261 |
} |
|
| 262 |
} |
|
| 263 |
} |
|
| 275 | 264 |
} |
| 276 | 265 |
|
| 277 | 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 523 | 512 |
|
| 524 | 513 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 525 | 514 |
|
| 526 |
public void initializeObject(String moves)
|
|
| 515 |
public void initializeObject(int[][] moves)
|
|
| 527 | 516 |
{
|
| 528 | 517 |
solve(); |
| 529 | 518 |
setupPosition(moves); |
| src/main/java/org/distorted/object/RubikObjectList.java | ||
|---|---|---|
| 245 | 245 |
|
| 246 | 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 247 | 247 |
|
| 248 |
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc, String moves)
|
|
| 248 |
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc, int[][] moves)
|
|
| 249 | 249 |
{
|
| 250 | 250 |
DistortedTexture texture = new DistortedTexture(); |
| 251 | 251 |
DistortedEffects effects = new DistortedEffects(); |
| src/main/java/org/distorted/object/RubikPyraminx.java | ||
|---|---|---|
| 83 | 83 |
|
| 84 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 85 | 85 |
|
| 86 |
RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, String moves)
|
|
| 86 |
RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, int[][] moves)
|
|
| 87 | 87 |
{
|
| 88 | 88 |
super(size, 30, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.PYRA); |
| 89 | 89 |
} |
| src/main/java/org/distorted/patterns/RubikPattern.java | ||
|---|---|---|
| 138 | 138 |
|
| 139 | 139 |
///////////////////////////////////////////////////////////// |
| 140 | 140 |
|
| 141 |
String getMoves(int pattern)
|
|
| 141 |
int[][] getMoves(int pattern)
|
|
| 142 | 142 |
{
|
| 143 | 143 |
if( pattern>=0 && pattern<numPatterns ) |
| 144 | 144 |
{
|
| ... | ... | |
| 146 | 146 |
if( p!=null ) return p.getMoves(); |
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 |
return "";
|
|
| 149 |
return null;
|
|
| 150 | 150 |
} |
| 151 | 151 |
} |
| 152 | 152 |
|
| ... | ... | |
| 155 | 155 |
private static class Pattern implements RubikPostRender.ActionFinishedListener |
| 156 | 156 |
{
|
| 157 | 157 |
private String name; |
| 158 |
private String moves;
|
|
| 158 |
private int[][] moves;
|
|
| 159 | 159 |
private int curMove; |
| 160 | 160 |
private int numMove; |
| 161 | 161 |
|
| ... | ... | |
| 167 | 167 |
Pattern(String n, String m) |
| 168 | 168 |
{
|
| 169 | 169 |
name=n; |
| 170 |
moves=m; |
|
| 171 |
numMove = moves.length()/4; |
|
| 170 |
moves= movesParser(m); |
|
| 172 | 171 |
curMove=numMove; |
| 173 |
|
|
| 174 | 172 |
mCanRotate = true; |
| 175 | 173 |
} |
| 176 | 174 |
|
| 175 |
///////////////////////////////////////////////////////////// |
|
| 176 |
|
|
| 177 |
private int[][] movesParser(String moves) |
|
| 178 |
{
|
|
| 179 |
numMove = moves.length()/4; |
|
| 180 |
|
|
| 181 |
int digit0, digit1, digit2; |
|
| 182 |
int[][] result = new int[numMove][3]; |
|
| 183 |
|
|
| 184 |
for(int i=0; i<numMove; i++) |
|
| 185 |
{
|
|
| 186 |
digit0 = moves.charAt(4*i+1)-'0'; |
|
| 187 |
digit1 = moves.charAt(4*i+2)-'0'; |
|
| 188 |
digit2 = moves.charAt(4*i+3)-'0'; |
|
| 189 |
|
|
| 190 |
result[i][0] = (10*digit0+digit1)/32; |
|
| 191 |
result[i][1] = (10*digit0+digit1)%32; |
|
| 192 |
result[i][2] = 2-digit2; |
|
| 193 |
} |
|
| 194 |
|
|
| 195 |
return result; |
|
| 196 |
} |
|
| 197 |
|
|
| 177 | 198 |
///////////////////////////////////////////////////////////// |
| 178 | 199 |
|
| 179 | 200 |
String getName() |
| ... | ... | |
| 205 | 226 |
if( curMove>numMove ) |
| 206 | 227 |
{
|
| 207 | 228 |
curMove= 0; |
| 208 |
object.initializeObject(moves.substring(0,4*curMove));
|
|
| 229 |
object.initializeObject(null);
|
|
| 209 | 230 |
} |
| 210 | 231 |
else |
| 211 | 232 |
{
|
| ... | ... | |
| 214 | 235 |
mCanRotate = false; |
| 215 | 236 |
mObject = object; |
| 216 | 237 |
|
| 217 |
String move = moves.substring(4*curMove-4,4*curMove); |
|
| 218 |
int a1=move.charAt(1)-'0'; |
|
| 219 |
int a2=move.charAt(2)-'0'; |
|
| 220 |
int a3=move.charAt(3)-'0'; |
|
| 221 |
|
|
| 222 |
int axis = (10*a1+a2)/32; |
|
| 223 |
int rowBitmap = (10*a1+a2)%32; |
|
| 224 |
int angle = (2-a3)*(360/object.getBasicAngle()); |
|
| 225 |
int numRot = Math.abs(2-a3); |
|
| 238 |
int axis =moves[curMove-1][0]; |
|
| 239 |
int rowBitmap=moves[curMove-1][1]; |
|
| 240 |
int bareAngle=moves[curMove-1][2]; |
|
| 241 |
int angle = bareAngle*(360/object.getBasicAngle()); |
|
| 242 |
int numRot = Math.abs(bareAngle); |
|
| 226 | 243 |
|
| 227 | 244 |
post.addRotation(this, axis, rowBitmap, angle, numRot*DURATION_MILLIS); |
| 228 | 245 |
} |
| ... | ... | |
| 245 | 262 |
if( curMove<0 ) |
| 246 | 263 |
{
|
| 247 | 264 |
curMove=numMove; |
| 248 |
object.initializeObject(moves.substring(0,4*curMove));
|
|
| 265 |
object.initializeObject(moves); |
|
| 249 | 266 |
} |
| 250 | 267 |
else |
| 251 | 268 |
{
|
| ... | ... | |
| 254 | 271 |
mCanRotate = false; |
| 255 | 272 |
mObject = object; |
| 256 | 273 |
|
| 257 |
String move = moves.substring(4*curMove,4*curMove+4); |
|
| 258 |
int a1=move.charAt(1)-'0'; |
|
| 259 |
int a2=move.charAt(2)-'0'; |
|
| 260 |
int a3=move.charAt(3)-'0'; |
|
| 261 |
|
|
| 262 |
int axis = (10*a1+a2)/32; |
|
| 263 |
int rowBitmap = (10*a1+a2)%32; |
|
| 264 |
int angle = (2-a3)*(360/object.getBasicAngle()); |
|
| 265 |
int numRot = Math.abs(2-a3); |
|
| 274 |
int axis =moves[curMove][0]; |
|
| 275 |
int rowBitmap=moves[curMove][1]; |
|
| 276 |
int bareAngle=moves[curMove][2]; |
|
| 277 |
int angle = bareAngle*(360/object.getBasicAngle()); |
|
| 278 |
int numRot = Math.abs(bareAngle); |
|
| 266 | 279 |
|
| 267 | 280 |
post.addRotation(this, axis, rowBitmap, -angle, numRot*DURATION_MILLIS); |
| 268 | 281 |
} |
| ... | ... | |
| 276 | 289 |
|
| 277 | 290 |
///////////////////////////////////////////////////////////// |
| 278 | 291 |
|
| 279 |
String getMoves()
|
|
| 292 |
int[][] getMoves()
|
|
| 280 | 293 |
{
|
| 281 |
return moves.substring(0,4*curMove);
|
|
| 294 |
return moves; |
|
| 282 | 295 |
} |
| 283 | 296 |
|
| 284 | 297 |
///////////////////////////////////////////////////////////// |
| ... | ... | |
| 461 | 474 |
|
| 462 | 475 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 463 | 476 |
|
| 464 |
public String getMoves(int size, int cat, int pat)
|
|
| 477 |
public int[][] getMoves(int size, int cat, int pat)
|
|
| 465 | 478 |
{
|
| 466 | 479 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
| 467 | 480 |
{
|
| ... | ... | |
| 469 | 482 |
if( c!=null ) return c.getMoves(pat); |
| 470 | 483 |
} |
| 471 | 484 |
|
| 472 |
return "";
|
|
| 485 |
return null;
|
|
| 473 | 486 |
} |
| 474 | 487 |
} |
Also available in: Unified diff
Major progress with Prretty Patterns.
Two things remain:
1) looks like sometimes making/backing Moves in a Pattern gets stuck. ( Pattern.mCanRotate! )
2) we need to add RubikPatternList!