Revision fb377dae
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
466 | 466 |
|
467 | 467 |
mCurrentAxis = (int)res.get0(); |
468 | 468 |
float offset = res.get1(); |
469 |
mCurrentRow = (int)(object.returnMultiplier()*offset); |
|
469 |
mCurrentRow = object.computeRowFromOffset(offset); |
|
470 |
|
|
470 | 471 |
computeCurrentAxis( object.getRotationAxis()[mCurrentAxis] ); |
471 | 472 |
mRotationFactor = object.returnRotationFactor(offset); |
472 | 473 |
|
src/main/java/org/distorted/objects/RubikCube.java | ||
---|---|---|
307 | 307 |
return mMeshes[index].copy(true); |
308 | 308 |
} |
309 | 309 |
|
310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
311 |
|
|
312 |
float returnMultiplier() |
|
313 |
{ |
|
314 |
return getSize(); |
|
315 |
} |
|
316 |
|
|
310 | 317 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
311 | 318 |
// PUBLIC API |
312 | 319 |
|
... | ... | |
324 | 331 |
|
325 | 332 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
326 | 333 |
|
327 |
public float returnMultiplier()
|
|
334 |
public int computeRowFromOffset(float offset)
|
|
328 | 335 |
{ |
329 |
return getSize();
|
|
336 |
return (int)(getSize()*offset);
|
|
330 | 337 |
} |
331 | 338 |
|
332 | 339 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/RubikDino.java | ||
---|---|---|
331 | 331 |
canvas.drawArc( ARC3_W-RADIUS+left, ARC2_H-RADIUS, ARC3_W+RADIUS+left, ARC2_H+RADIUS, 345, 90, false, paint); |
332 | 332 |
} |
333 | 333 |
|
334 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
335 |
|
|
336 |
float returnMultiplier() |
|
337 |
{ |
|
338 |
return 2.0f; |
|
339 |
} |
|
340 |
|
|
334 | 341 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
335 | 342 |
// PUBLIC API |
336 | 343 |
|
... | ... | |
348 | 355 |
|
349 | 356 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
350 | 357 |
|
351 |
public float returnMultiplier()
|
|
358 |
public int computeRowFromOffset(float offset)
|
|
352 | 359 |
{ |
353 |
// TODO |
|
354 |
|
|
355 |
return 0; |
|
360 |
return offset<0.5f ? 0:2; |
|
356 | 361 |
} |
357 | 362 |
|
358 | 363 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/RubikMovement.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
public abstract class RubikMovement |
29 | 29 |
{ |
30 |
private int mLastTouchedAxis; |
|
30 |
private int mLastTouchedFace, mNumFaceAxis;
|
|
31 | 31 |
private float[] mPoint, mCamera, mTouch; |
32 | 32 |
private float[] mPoint2D, mMove2D; |
33 | 33 |
private float[][][] mCastAxis; |
34 |
private int mNumRotAxis, mNumFaceAxis;
|
|
34 |
private int[] mEnabledRotAxis;
|
|
35 | 35 |
private float mDistanceCenterFace3D, mDistanceCenterFace2D; |
36 | 36 |
private Static3D[] mFaceAxis; |
37 | 37 |
|
38 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 39 |
|
40 | 40 |
abstract boolean isInsideFace(float[] point); |
41 |
abstract void computeEnabledAxis(int face, float[] touchPoint, int[] enabledAxis); |
|
41 | 42 |
|
42 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
43 | 44 |
|
... | ... | |
50 | 51 |
mPoint2D = new float[2]; |
51 | 52 |
mMove2D = new float[2]; |
52 | 53 |
|
53 |
mNumRotAxis = rotAxis.length; |
|
54 | 54 |
mFaceAxis = faceAxis; |
55 | 55 |
mNumFaceAxis= mFaceAxis.length; |
56 | 56 |
|
57 |
mEnabledRotAxis = new int[rotAxis.length+1]; |
|
58 |
|
|
57 | 59 |
mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces |
58 | 60 |
mDistanceCenterFace2D = distance2D; // distance from the center of a face to its edge |
59 | 61 |
|
60 | 62 |
// mCastAxis[1][2]{0,1} are the 2D coords of the 2nd axis cast onto the face defined by the |
61 | 63 |
// 1st pair (axis,lr) |
62 |
mCastAxis = new float[mNumFaceAxis][mNumRotAxis][2];
|
|
64 |
mCastAxis = new float[mNumFaceAxis][rotAxis.length][2];
|
|
63 | 65 |
|
64 |
for( int casted=0; casted<mNumRotAxis; casted++)
|
|
66 |
for( int casted=0; casted<rotAxis.length; casted++)
|
|
65 | 67 |
{ |
66 | 68 |
Static3D a = rotAxis[casted]; |
67 | 69 |
mPoint[0]= a.get0(); |
... | ... | |
88 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
89 | 91 |
// find the casted axis with which our move2D vector forms an angle closest to 90 deg. |
90 | 92 |
|
91 |
private int computeRotationIndex(int faceAxis, float[] move2D) |
|
93 |
private int computeRotationIndex(int faceAxis, float[] move2D, int[] enabled)
|
|
92 | 94 |
{ |
93 | 95 |
float cosAngle, minCosAngle = Float.MAX_VALUE; |
94 |
int minIndex=-1; |
|
96 |
int minIndex=-1, index;
|
|
95 | 97 |
float m0 = move2D[0]; |
96 | 98 |
float m1 = move2D[1]; |
97 | 99 |
float len = (float)Math.sqrt(m0*m0 + m1*m1); |
98 |
float x,y; |
|
99 | 100 |
|
100 | 101 |
if( len!=0.0f ) |
101 | 102 |
{ |
... | ... | |
108 | 109 |
m1 = 0.0f; // |
109 | 110 |
} |
110 | 111 |
|
111 |
for(int rotAxis=0; rotAxis<mNumRotAxis; rotAxis++) |
|
112 |
int numAxis = enabled[0]; |
|
113 |
|
|
114 |
for(int axis=1; axis<=numAxis; axis++) |
|
112 | 115 |
{ |
113 |
x = mCastAxis[faceAxis][rotAxis][0]; |
|
114 |
y = mCastAxis[faceAxis][rotAxis][1]; |
|
116 |
index = enabled[axis]; |
|
117 |
cosAngle = m0*mCastAxis[faceAxis][index][0] + m1*mCastAxis[faceAxis][index][1]; |
|
118 |
if( cosAngle<0 ) cosAngle = -cosAngle; |
|
115 | 119 |
|
116 |
if( x*x + y*y > 0.01f )
|
|
120 |
if( cosAngle<minCosAngle )
|
|
117 | 121 |
{ |
118 |
cosAngle = m0*x + m1*y; |
|
119 |
if( cosAngle<0 ) cosAngle = -cosAngle; |
|
120 |
|
|
121 |
if( cosAngle<minCosAngle ) |
|
122 |
{ |
|
123 |
minCosAngle=cosAngle; |
|
124 |
minIndex = rotAxis; |
|
125 |
} |
|
122 |
minCosAngle=cosAngle; |
|
123 |
minIndex = index; |
|
126 | 124 |
} |
127 | 125 |
} |
128 | 126 |
|
... | ... | |
242 | 240 |
mCamera[1] = rotatedCamera.get1()/objectRatio; |
243 | 241 |
mCamera[2] = rotatedCamera.get2()/objectRatio; |
244 | 242 |
|
245 |
for( mLastTouchedAxis=0; mLastTouchedAxis<mNumFaceAxis; mLastTouchedAxis++)
|
|
243 |
for( mLastTouchedFace=0; mLastTouchedFace<mNumFaceAxis; mLastTouchedFace++)
|
|
246 | 244 |
{ |
247 |
if( faceIsVisible(mFaceAxis[mLastTouchedAxis]) )
|
|
245 |
if( faceIsVisible(mFaceAxis[mLastTouchedFace]) )
|
|
248 | 246 |
{ |
249 |
castTouchPointOntoFace(mFaceAxis[mLastTouchedAxis], mTouch);
|
|
250 |
convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedAxis], mPoint2D);
|
|
247 |
castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch);
|
|
248 |
convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mPoint2D);
|
|
251 | 249 |
if( isInsideFace(mPoint2D) ) return true; |
252 | 250 |
} |
253 | 251 |
} |
... | ... | |
265 | 263 |
mPoint[1] = rotatedTouchPoint.get1()/objectRatio; |
266 | 264 |
mPoint[2] = rotatedTouchPoint.get2()/objectRatio; |
267 | 265 |
|
268 |
castTouchPointOntoFace(mFaceAxis[mLastTouchedAxis], mTouch);
|
|
269 |
convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedAxis], mMove2D);
|
|
266 |
castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch);
|
|
267 |
convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mMove2D);
|
|
270 | 268 |
|
271 | 269 |
mMove2D[0] -= mPoint2D[0]; |
272 | 270 |
mMove2D[1] -= mPoint2D[1]; |
273 | 271 |
|
274 |
int rotIndex = computeRotationIndex(mLastTouchedAxis, mMove2D); |
|
275 |
float offset = computeOffset(mPoint2D, mCastAxis[mLastTouchedAxis][rotIndex]); |
|
272 |
computeEnabledAxis(mLastTouchedFace, mPoint2D, mEnabledRotAxis); |
|
273 |
int rotIndex = computeRotationIndex(mLastTouchedFace, mMove2D, mEnabledRotAxis); |
|
274 |
float offset = computeOffset(mPoint2D, mCastAxis[mLastTouchedFace][rotIndex]); |
|
276 | 275 |
|
277 | 276 |
return new Static2D(rotIndex,offset); |
278 | 277 |
} |
... | ... | |
281 | 280 |
|
282 | 281 |
public int getTouchedFace() |
283 | 282 |
{ |
284 |
return mLastTouchedAxis;
|
|
283 |
return mLastTouchedFace;
|
|
285 | 284 |
} |
286 | 285 |
|
287 | 286 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/RubikMovementCube.java | ||
---|---|---|
34 | 34 |
{ |
35 | 35 |
return ( p[0]<=0.5f && p[0]>=-0.5f && p[1]<=0.5f && p[1]>=-0.5f ); |
36 | 36 |
} |
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
41 |
{ |
|
42 |
enabled[0] = 2; |
|
43 |
|
|
44 |
switch(face) |
|
45 |
{ |
|
46 |
case 0: |
|
47 |
case 1: enabled[1]=1; enabled[2]=2; break; |
|
48 |
case 2: |
|
49 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
50 |
case 4: |
|
51 |
case 5: enabled[1]=0; enabled[2]=1; break; |
|
52 |
} |
|
53 |
} |
|
37 | 54 |
} |
src/main/java/org/distorted/objects/RubikMovementDino.java | ||
---|---|---|
28 | 28 |
super(RubikDino.ROT_AXIS, RubikDino.FACE_AXIS, 0.5f, 0.5f); |
29 | 29 |
} |
30 | 30 |
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
// _____________ |
|
33 |
// | \ 0 / | |
|
34 |
// | \ / | |
|
35 |
// | 3 | | 1 | |
|
36 |
// | / \ | |
|
37 |
// | / 2 \ | |
|
38 |
// ------------- |
|
39 |
|
|
40 |
private int getQuarter(float[] touchPoint) |
|
41 |
{ |
|
42 |
boolean p0 = touchPoint[1] >= touchPoint[0]; |
|
43 |
boolean p1 = touchPoint[1] >=-touchPoint[0]; |
|
44 |
|
|
45 |
if( p0 ) return p1 ? 0:3; |
|
46 |
else return p1 ? 1:2; |
|
47 |
} |
|
48 |
|
|
31 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 50 |
|
33 | 51 |
boolean isInsideFace(float[] p) |
34 | 52 |
{ |
35 | 53 |
return ( p[0]<=0.5f && p[0]>=-0.5f && p[1]<=0.5f && p[1]>=-0.5f ); |
36 | 54 |
} |
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
59 |
{ |
|
60 |
enabled[0] = 2; |
|
61 |
|
|
62 |
int quarter = getQuarter(touchPoint); |
|
63 |
|
|
64 |
switch(face) |
|
65 |
{ |
|
66 |
case 0: switch(quarter) |
|
67 |
{ |
|
68 |
case 0: enabled[1]=0; enabled[2]=1; break; |
|
69 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
70 |
case 2: enabled[1]=2; enabled[2]=3; break; |
|
71 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
72 |
} |
|
73 |
break; |
|
74 |
case 1: switch(quarter) |
|
75 |
{ |
|
76 |
case 0: enabled[1]=2; enabled[2]=3; break; |
|
77 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
78 |
case 2: enabled[1]=0; enabled[2]=1; break; |
|
79 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
80 |
} |
|
81 |
break; |
|
82 |
case 2: switch(quarter) |
|
83 |
{ |
|
84 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
85 |
case 1: enabled[1]=0; enabled[2]=1; break; |
|
86 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
87 |
case 3: enabled[1]=2; enabled[2]=3; break; |
|
88 |
} |
|
89 |
break; |
|
90 |
case 3: switch(quarter) |
|
91 |
{ |
|
92 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
93 |
case 1: enabled[1]=2; enabled[2]=3; break; |
|
94 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
95 |
case 3: enabled[1]=0; enabled[2]=1; break; |
|
96 |
} |
|
97 |
break; |
|
98 |
case 4: switch(quarter) |
|
99 |
{ |
|
100 |
case 0: enabled[1]=0; enabled[2]=3; break; |
|
101 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
102 |
case 2: enabled[1]=1; enabled[2]=2; break; |
|
103 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
104 |
} |
|
105 |
break; |
|
106 |
case 5: switch(quarter) |
|
107 |
{ |
|
108 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
109 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
110 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
111 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
112 |
} |
|
113 |
break; |
|
114 |
} |
|
115 |
} |
|
37 | 116 |
} |
src/main/java/org/distorted/objects/RubikMovementPyraminx.java | ||
---|---|---|
43 | 43 |
|
44 | 44 |
return a1 && a2 && a3; |
45 | 45 |
} |
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
50 |
{ |
|
51 |
enabled[0] = 3; |
|
52 |
|
|
53 |
switch(face) |
|
54 |
{ |
|
55 |
case 0: enabled[1]=1; enabled[2]=2; enabled[3]=3; break; |
|
56 |
case 1: enabled[1]=0; enabled[2]=2; enabled[3]=3; break; |
|
57 |
case 2: enabled[1]=0; enabled[2]=1; enabled[3]=3; break; |
|
58 |
case 3: enabled[1]=0; enabled[2]=1; enabled[3]=2; break; |
|
59 |
} |
|
60 |
} |
|
46 | 61 |
} |
src/main/java/org/distorted/objects/RubikObject.java | ||
---|---|---|
63 | 63 |
private static final Static3D CENTER = new Static3D(0,0,0); |
64 | 64 |
static final int INTERIOR_COLOR = 0xff000000; |
65 | 65 |
private static final int POST_ROTATION_MILLISEC = 500; |
66 |
private static final int TEXTURE_HEIGHT = 128;
|
|
66 |
private static final int TEXTURE_HEIGHT = 256;
|
|
67 | 67 |
|
68 | 68 |
final Static3D[] ROTATION_AXIS; |
69 | 69 |
final Static4D[] QUATS; |
... | ... | |
695 | 695 |
abstract MeshBase createCubitMesh(int cubit); |
696 | 696 |
abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side); |
697 | 697 |
abstract int getFaceColor(int cubit, int cubitface, int size); |
698 |
abstract float returnMultiplier(); |
|
698 | 699 |
public abstract Static3D[] getRotationAxis(); |
699 | 700 |
public abstract int getBasicAngle(); |
700 |
public abstract float returnMultiplier();
|
|
701 |
public abstract int computeRowFromOffset(float offset);
|
|
701 | 702 |
public abstract float returnRotationFactor(float offset); |
702 | 703 |
public abstract String retObjectString(); |
703 | 704 |
public abstract float[] getRowChances(); |
src/main/java/org/distorted/objects/RubikPyraminx.java | ||
---|---|---|
391 | 391 |
canvas.drawArc( ARC3_W-RADIUS+left, ARC2_H-RADIUS, ARC3_W+RADIUS+left, ARC2_H+RADIUS, 345, 90, false, paint); |
392 | 392 |
} |
393 | 393 |
|
394 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
395 |
// I don't quite understand it, but 0.82 works better than the theoretically correct SQ3/2 ( 0.866 ) |
|
396 |
|
|
397 |
float returnMultiplier() |
|
398 |
{ |
|
399 |
return getSize()/0.82f;//(SQ3/2); |
|
400 |
} |
|
401 |
|
|
394 | 402 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
395 | 403 |
// PUBLIC API |
396 | 404 |
|
... | ... | |
407 | 415 |
} |
408 | 416 |
|
409 | 417 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
410 |
// I don't quite understand it, but 0.82 works better than the theoretically correct SQ3/2 ( 0.866 )
|
|
418 |
// 0.82?? see returnMultiplier()
|
|
411 | 419 |
|
412 |
public float returnMultiplier()
|
|
420 |
public int computeRowFromOffset(float offset)
|
|
413 | 421 |
{ |
414 |
return getSize()/0.82f;//(SQ3/2);
|
|
422 |
return (int)(getSize()*offset/0.82f);
|
|
415 | 423 |
} |
416 | 424 |
|
417 | 425 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/scores/RubikScoresDownloader.java | ||
---|---|---|
373 | 373 |
String timlist = scores.getUnsubmittedTimelist(); |
374 | 374 |
String country = scores.getCountry(); |
375 | 375 |
long epoch = System.currentTimeMillis(); |
376 |
String salt = "cubold";
|
|
376 |
String salt = "cuboid";
|
|
377 | 377 |
|
378 | 378 |
String url1="https://distorted.org/magic/cgi-bin/submit.cgi"; |
379 | 379 |
String url2 = "n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion+"d"; |
380 | 380 |
url2 += "&o="+objlist+"&l="+lvllist+"&t="+timlist+"&c="+country+"&f="+epoch; |
381 | 381 |
url2 += "&oo="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_LEVEL+"&lo="+MAX_PLACES; |
382 |
url2 += "&h="+computeHash( url2+"d", salt.getBytes() );
|
|
382 |
url2 += "&h="+computeHash( url2, salt.getBytes() ); |
|
383 | 383 |
|
384 | 384 |
return url1 + "?" + url2; |
385 | 385 |
} |
Also available in: Unified diff
Major progress with Dino; rotations (almost?) work now.