Revision a3b2e132
Added by Leszek Koltunski 11 months ago
src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import java.util.ArrayList; |
13 | 13 |
|
14 |
import static org.distorted.objectlib.main.TwistyObject.SQ2; |
|
15 |
import static org.distorted.objectlib.main.TwistyObject.SQ3; |
|
14 | 16 |
import static org.distorted.objectlib.main.TwistyObject.SQ6; |
15 | 17 |
import static org.distorted.objectlib.scrambling.ScrambleStateLocallyBandaged.MAX_SUPPORTED_SIZE; |
16 | 18 |
|
19 |
import org.distorted.library.helpers.QuatHelper; |
|
17 | 20 |
import org.distorted.objectlib.bandaged.BandagedObjectPyraminx; |
18 | 21 |
|
19 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
22 | 25 |
{ |
23 | 26 |
public static final int SIZE = computeNum(); |
24 | 27 |
|
28 |
private static final float[][] mRotAxisPyraminx = |
|
29 |
{ |
|
30 |
{ 0, -SQ3/3, -SQ6/3}, |
|
31 |
{ 0, -SQ3/3, SQ6/3}, |
|
32 |
{ SQ6/3, SQ3/3, 0}, |
|
33 |
{-SQ6/3, SQ3/3, 0}, |
|
34 |
}; |
|
35 |
|
|
36 |
private static final float[][] mQuatsPyraminx = |
|
37 |
{ |
|
38 |
{ 0, -0.5f, -SQ2/2, 0.5f }, |
|
39 |
{ 0, -0.5f, SQ2/2, 0.5f }, |
|
40 |
{ SQ2/2, 0.5f, 0, 0.5f }, |
|
41 |
{-SQ2/2, 0.5f, 0, 0.5f }, |
|
42 |
}; |
|
43 |
|
|
25 | 44 |
private long[] mSignature; |
26 | 45 |
private int[] mLayer; |
27 | 46 |
private int[][][][] mCycles; |
28 | 47 |
private float[][] mCubitTouch; |
48 |
private int[][] mTouchRows; |
|
29 | 49 |
private int mNumCubitTouches; |
30 | 50 |
private int[] mNumLeftCyclesPerLayer; |
31 | 51 |
private int[] mNumCentCyclesPerLayer; |
32 | 52 |
private int[] mNumInneCyclesPerLayer; |
33 | 53 |
private String mName=null; |
54 |
private float[] mTmp; |
|
34 | 55 |
|
35 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
36 | 57 |
// a cube of size N has 12*(N-1)^2 possible places two adjacent cubies can be 'glued'; therefore |
... | ... | |
69 | 90 |
mLayer = sig.mLayer; |
70 | 91 |
mCycles = sig.mCycles; |
71 | 92 |
mCubitTouch = sig.mCubitTouch; |
93 |
mTouchRows = sig.mTouchRows; |
|
72 | 94 |
mName = sig.mName; |
73 | 95 |
|
74 | 96 |
mNumCubitTouches = sig.mNumCubitTouches; |
... | ... | |
102 | 124 |
int z=shortName.charAt(2)-'0'; |
103 | 125 |
mLayer=new int[]{x, y, z}; |
104 | 126 |
prepareCubitTouch(); |
127 |
prepareTouchRows(); |
|
105 | 128 |
prepareAllCycles(); |
106 | 129 |
} |
107 | 130 |
else |
108 | 131 |
{ |
132 |
mTmp = new float[4]; |
|
109 | 133 |
int x=shortName.charAt(1)-'0'; |
110 | 134 |
mLayer=new int[]{x, x, x, x}; |
111 | 135 |
prepareCubitTouchPyraminx(); |
136 |
prepareTouchRowsPyraminx(); |
|
112 | 137 |
prepareAllCyclesPyraminx(); |
113 | 138 |
} |
114 | 139 |
} |
... | ... | |
123 | 148 |
mLayer = new int[] {size,size,size}; |
124 | 149 |
|
125 | 150 |
prepareCubitTouch(); |
151 |
prepareTouchRows(); |
|
126 | 152 |
prepareAllCycles(); |
127 | 153 |
} |
128 | 154 |
|
... | ... | |
145 | 171 |
mSignature = new long[SIZE]; |
146 | 172 |
|
147 | 173 |
prepareCubitTouch(); |
174 |
prepareTouchRows(); |
|
148 | 175 |
prepareAllCycles(); |
149 | 176 |
|
150 | 177 |
for(float[] pos : position) |
... | ... | |
282 | 309 |
} |
283 | 310 |
|
284 | 311 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
285 |
// TODO |
|
286 | 312 |
|
287 | 313 |
public boolean isUnblockedFromLeft(int axis, int layer) |
288 | 314 |
{ |
289 | 315 |
if(layer>0) |
290 | 316 |
for(int index=0; index<mNumCubitTouches; index++) |
291 |
if( getBit(index)!=0 ) |
|
292 |
{ |
|
293 |
float[] touch = getCubitTouchOfIndex(index); |
|
294 |
if( belongsLeft(touch,axis,layer) ) return false; |
|
295 |
} |
|
317 |
if( getBit(index)!=0 && mTouchRows[index][axis]==layer ) return false; |
|
296 | 318 |
|
297 | 319 |
return true; |
298 | 320 |
} |
... | ... | |
320 | 342 |
return ret; |
321 | 343 |
} |
322 | 344 |
|
323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
324 |
|
|
325 |
private boolean belongsLeft(float[] point, int axis, int layer) |
|
326 |
{ |
|
327 |
return 2*point[axis]+mLayer[axis] == 2*layer; |
|
328 |
} |
|
329 |
|
|
330 | 345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
331 | 346 |
|
332 | 347 |
private void cycle2(int[] cyc) |
... | ... | |
474 | 489 |
} |
475 | 490 |
} |
476 | 491 |
|
492 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
493 |
|
|
494 |
private void prepareTouchRows() |
|
495 |
{ |
|
496 |
mTouchRows = new int[mNumCubitTouches][3]; |
|
497 |
|
|
498 |
for(int i=0; i<mNumCubitTouches; i++) |
|
499 |
{ |
|
500 |
float[] touch = mCubitTouch[i]; |
|
501 |
|
|
502 |
for(int a=0; a<3; a++) |
|
503 |
{ |
|
504 |
int l = (int)(2*touch[a] + mLayer[a] + 0.01f); |
|
505 |
mTouchRows[i][a] = ( (l%2)==0 ) ? l/2 : -1; |
|
506 |
} |
|
507 |
} |
|
508 |
} |
|
509 |
|
|
477 | 510 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
478 | 511 |
|
479 | 512 |
private void prepareAllCycles() |
... | ... | |
669 | 702 |
for(int i=0; i<mNumCubitTouches; i++) mCubitTouch[i] = mTouch.remove(0); |
670 | 703 |
} |
671 | 704 |
|
705 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
706 |
|
|
707 |
private void prepareTouchRowsPyraminx() |
|
708 |
{ |
|
709 |
mTouchRows = new int[mNumCubitTouches][4]; |
|
710 |
|
|
711 |
for(int i=0; i<mNumCubitTouches; i++) |
|
712 |
{ |
|
713 |
float[] touch = mCubitTouch[i]; |
|
714 |
|
|
715 |
for(int a=0; a<4; a++) |
|
716 |
{ |
|
717 |
float[] ax = mRotAxisPyraminx[a]; |
|
718 |
float d = touch[0]*ax[0] + touch[1]*ax[1] + touch[2]*ax[2]; |
|
719 |
int l = (int)(4*d + mLayer[a] + 0.01f); |
|
720 |
mTouchRows[i][a] = ( (l%4)==0 ) ? l/4 : -1; |
|
721 |
} |
|
722 |
} |
|
723 |
} |
|
724 |
|
|
672 | 725 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
673 | 726 |
|
674 | 727 |
private void prepareAllCyclesPyraminx() |
... | ... | |
761 | 814 |
private int rotateIndex3(int axis, int index) |
762 | 815 |
{ |
763 | 816 |
float[] touch = getCubitTouchOfIndex(index); |
764 |
|
|
765 |
switch(axis) |
|
766 |
{ |
|
767 |
case 0: return getIndexOfCubitTouch(+touch[0],-touch[1],-touch[2]); |
|
768 |
case 1: return getIndexOfCubitTouch(-touch[0],+touch[1],-touch[2]); |
|
769 |
case 2: return getIndexOfCubitTouch(-touch[0],-touch[1],+touch[2]); |
|
770 |
} |
|
771 |
|
|
772 |
return -1; |
|
817 |
QuatHelper.rotateVectorByQuat(mTmp, touch[0], touch[1], touch[2], 1.0f, mQuatsPyraminx[axis]); |
|
818 |
return getIndexOfCubitTouch(mTmp[0],mTmp[1],mTmp[2]); |
|
773 | 819 |
} |
774 | 820 |
|
775 | 821 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
779 | 825 |
for(int i=0; i<mNumCubitTouches; i++) |
780 | 826 |
{ |
781 | 827 |
float[] touch = mCubitTouch[i]; |
782 |
if( touch[0]==x && touch[1]==y && touch[2]==z ) return i; |
|
828 |
|
|
829 |
float dx = touch[0] - x; |
|
830 |
float dy = touch[1] - y; |
|
831 |
float dz = touch[2] - z; |
|
832 |
|
|
833 |
if( dx*dx + dy*dy + dz*dz < 0.01f ) return i; |
|
783 | 834 |
} |
784 | 835 |
|
785 | 836 |
return -1; |
Also available in: Unified diff
progress with 'turnable' BandagedPyraminx Signature.