Revision a4af26c1
Added by Leszek Koltunski about 2 years ago
src/main/java/org/distorted/objectlib/main/TwistyObject.java | ||
---|---|---|
318 | 318 |
FactoryCubit factory = FactoryCubit.getInstance(); |
319 | 319 |
factory.clear(); |
320 | 320 |
|
321 |
displayCubitQuats(); |
|
322 |
|
|
321 | 323 |
mOrigQuat = new Static4D[mNumCubits]; |
322 | 324 |
for(int i=0; i<mNumCubits; i++) mOrigQuat[i] = getCubitQuats(i,mNumLayers); |
323 | 325 |
|
... | ... | |
516 | 518 |
return nonBlackIndex; |
517 | 519 |
} |
518 | 520 |
|
521 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
522 |
|
|
523 |
private boolean sticksOut(Static3D[] faceAxis, float[] dist, float x, float y, float z ) |
|
524 |
{ |
|
525 |
final float MAXERR = 0.05f; |
|
526 |
int numAxis = dist.length; |
|
527 |
float NUM = mNumLayers[0]; |
|
528 |
|
|
529 |
for(int i=0; i<numAxis; i++) |
|
530 |
{ |
|
531 |
Static3D ax = faceAxis[i]; |
|
532 |
float len = ax.get0()*x + ax.get1()*y + ax.get2()*z; |
|
533 |
if( len>NUM*dist[i]+MAXERR ) return true; |
|
534 |
} |
|
535 |
|
|
536 |
return false; |
|
537 |
} |
|
538 |
|
|
539 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
540 |
|
|
541 |
private boolean doesNotStickOut(int variant, float[] pos, float[] tmp, Static4D quat) |
|
542 |
{ |
|
543 |
ObjectShape shape = getObjectShape(variant); |
|
544 |
float[][] vertices = shape.getVertices(); |
|
545 |
Static3D[] axis = getFaceAxis(); |
|
546 |
float[] dist3D = getDist3D(mNumLayers); |
|
547 |
|
|
548 |
for( float[] vertex : vertices) |
|
549 |
{ |
|
550 |
float x = vertex[0]; |
|
551 |
float y = vertex[1]; |
|
552 |
float z = vertex[2]; |
|
553 |
|
|
554 |
QuatHelper.rotateVectorByQuat(tmp, x, y, z, 1, quat); |
|
555 |
|
|
556 |
float mx = tmp[0] + pos[0]; |
|
557 |
float my = tmp[1] + pos[1]; |
|
558 |
float mz = tmp[2] + pos[2]; |
|
559 |
|
|
560 |
if( sticksOut(axis, dist3D, mx,my,mz) ) return false; |
|
561 |
} |
|
562 |
|
|
563 |
return true; |
|
564 |
} |
|
565 |
|
|
519 | 566 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
520 | 567 |
|
521 | 568 |
protected void displayCubitQuats() |
522 | 569 |
{ |
523 | 570 |
StringBuilder builder = new StringBuilder(); |
524 | 571 |
float[] tmp = new float[4]; |
525 |
float MAXERR = 0.01f;
|
|
572 |
float ERR = 0.01f; |
|
526 | 573 |
|
527 | 574 |
for(int cubit=0; cubit<mNumCubits; cubit++) |
528 | 575 |
{ |
576 |
builder.append(cubit); |
|
577 |
builder.append(" : "); |
|
578 |
|
|
529 | 579 |
int refCubit,variant = getCubitVariant(cubit,mNumLayers); |
530 | 580 |
|
531 | 581 |
for(refCubit=0; refCubit<mNumCubits; refCubit++) |
... | ... | |
550 | 600 |
float dy = tmp[1]-curY; |
551 | 601 |
float dz = tmp[2]-curZ; |
552 | 602 |
|
553 |
if( dx>-MAXERR && dx<MAXERR && dy>-MAXERR && dy<MAXERR && dz>-MAXERR && dz<MAXERR )
|
|
603 |
if( dx>-ERR && dx<ERR && dy>-ERR && dy<ERR && dz>-ERR && dz<ERR )
|
|
554 | 604 |
{ |
555 |
builder.append(quat); |
|
556 |
builder.append(','); |
|
605 |
if( doesNotStickOut(variant,curpos,tmp,mObjectQuats[quat]) ) |
|
606 |
{ |
|
607 |
builder.append(quat); |
|
608 |
builder.append(','); |
|
609 |
} |
|
610 |
else |
|
611 |
{ |
|
612 |
android.util.Log.e("D", "cubit: "+cubit+" quat: "+quat+" : center correct, but shape sticks out"); |
|
613 |
} |
|
557 | 614 |
} |
558 | 615 |
} |
559 | 616 |
|
src/main/java/org/distorted/objectlib/objects/TwistyAxis.java | ||
---|---|---|
206 | 206 |
|
207 | 207 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
208 | 208 |
{ |
209 |
if( mQuatIndex==null ) mQuatIndex = new int[] {0,22,10,17,14,19, 0,22,10,17,14,19, 0,22,10, 0,22,10, 0,14, 0,14,10,19,17,22 }; |
|
209 |
if( mQuatIndex==null ) |
|
210 |
{ |
|
211 |
mQuatIndex = new int[] { 0,22,10,17,14,19, |
|
212 |
0,22,10,17,14,19, |
|
213 |
0,22,10, |
|
214 |
0,22,10, |
|
215 |
0,14, |
|
216 |
0,14,10,19,17,22 |
|
217 |
}; |
|
218 |
} |
|
210 | 219 |
return mObjectQuats[mQuatIndex[cubit]]; |
211 | 220 |
} |
212 | 221 |
|
src/main/java/org/distorted/objectlib/objects/TwistyCrystal.java | ||
---|---|---|
75 | 75 |
|
76 | 76 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
77 | 77 |
{ |
78 |
if( mQuatIndex==null ) mQuatIndex = new int[] { 17,12,13,20, 0, 4,25, 5,24,16,
|
|
78 |
if( mQuatIndex==null ) mQuatIndex = new int[] { 0,17,12,13,20, 4,25, 5,24,16,
|
|
79 | 79 |
9,21, 1,34, 8,11,30,43,26,14, |
80 | 80 |
15,45,33,28,10, 2,29, 6, 7, 3, |
81 | 81 |
|
... | ... | |
88 | 88 |
|
89 | 89 |
public ObjectShape getObjectShape(int variant) |
90 | 90 |
{ |
91 |
float[] blueCenter = mCenterCoords[0]; |
|
92 |
float[] greeCenter = mCenterCoords[1]; |
|
93 |
float[] pinkCenter = mCenterCoords[2]; |
|
94 |
|
|
91 | 95 |
if( variant==0 ) |
92 | 96 |
{ |
93 |
float B = mCenterCoords[0][2]-mCorners[0][2];
|
|
97 |
float B = greeCenter[2]-mCorners[0][2];
|
|
94 | 98 |
float C = A*mCorners[0][1]+(1.0f-A)*mCorners[2][1]; |
95 |
float D = mCenterCoords[0][0];
|
|
99 |
float D = greeCenter[0];
|
|
96 | 100 |
|
97 | 101 |
float[][] vertices = |
98 | 102 |
{ |
... | ... | |
133 | 137 |
{X1-X, Y1-Y, Z1-Z}, |
134 | 138 |
{X2-X, Y2-Y, Z2-Z}, |
135 | 139 |
{X3-X, Y3-Y, Z3-Z}, |
136 |
{ mCenterCoords[0][0]-X, mCenterCoords[0][1]-Y, mCenterCoords[0][2]-Z },
|
|
137 |
{ mCenterCoords[1][0]-X, mCenterCoords[1][1]-Y, mCenterCoords[1][2]-Z },
|
|
138 |
{ mCenterCoords[8][0]-X, mCenterCoords[8][1]-Y, mCenterCoords[8][2]-Z }
|
|
140 |
{ greeCenter[0]-X, greeCenter[1]-Y, greeCenter[2]-Z },
|
|
141 |
{ pinkCenter[0]-X, pinkCenter[1]-Y, pinkCenter[2]-Z },
|
|
142 |
{ blueCenter[0]-X, blueCenter[1]-Y, blueCenter[2]-Z }
|
|
139 | 143 |
}; |
140 | 144 |
int[][] indices = |
141 | 145 |
{ |
src/main/java/org/distorted/objectlib/objects/TwistyJing.java | ||
---|---|---|
170 | 170 |
|
171 | 171 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
172 | 172 |
{ |
173 |
if( mQuatIndex==null ) mQuatIndex = new int[] {0,10,5,8,0,5,8,6,7,9,0,10,7,3}; |
|
173 |
if( mQuatIndex==null ) mQuatIndex = new int[] {0,10,5,8, |
|
174 |
0,5,8,6,7,9, |
|
175 |
0,10,7,3}; |
|
174 | 176 |
return mObjectQuats[mQuatIndex[cubit]]; |
175 | 177 |
} |
176 | 178 |
|
src/main/java/org/distorted/objectlib/objects/TwistyMegaminx.java | ||
---|---|---|
50 | 50 |
|
51 | 51 |
private void initializeCenterIndices() |
52 | 52 |
{ |
53 |
mQuatCenterIndices = new int[] { 35, 55, 38, 48, 41, 42, 58, 57, 0, 46, 29, 59 };
|
|
53 |
mQuatCenterIndices = new int[] { 0, 35, 55, 38, 48, 41, 42, 58, 57, 46, 29, 59 };
|
|
54 | 54 |
} |
55 | 55 |
|
56 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/objects/TwistyMinx.java | ||
---|---|---|
104 | 104 |
{ |
105 | 105 |
mCenterMap = new int[][] |
106 | 106 |
{ |
107 |
{ 0, 12, 8, 10, 16}, |
|
107 | 108 |
{ 0, 12, 4, 14, 2}, |
108 | 109 |
{ 0, 2, 18, 6, 16}, |
109 | 110 |
{ 6, 18, 11, 19, 7}, |
... | ... | |
112 | 113 |
{ 1, 13, 5, 15, 3}, |
113 | 114 |
{ 1, 3, 19, 7, 17}, |
114 | 115 |
{10, 16, 6, 7, 17}, |
115 |
{ 0, 12, 8, 10, 16}, |
|
116 | 116 |
{ 8, 13, 5, 4, 12}, |
117 | 117 |
{ 1, 13, 8, 10, 17}, |
118 | 118 |
{ 2, 14, 9, 11, 18}, |
... | ... | |
129 | 129 |
{ |
130 | 130 |
mEdgeMap = new int[][] |
131 | 131 |
{ |
132 |
{ 0, 12, 0, 8}, //0
|
|
133 |
{ 12, 4, 0, 9},
|
|
134 |
{ 4, 14, 0, 4},
|
|
135 |
{ 14, 2, 0, 11},
|
|
136 |
{ 2, 0, 0, 1},
|
|
137 |
{ 14, 9, 11, 4}, //5
|
|
138 |
{ 9, 11, 11, 3},
|
|
139 |
{ 11, 18, 11, 2},
|
|
140 |
{ 18, 2, 11, 1},
|
|
141 |
{ 18, 6, 1, 2},
|
|
142 |
{ 6, 16, 1, 7}, //10
|
|
143 |
{ 16, 0, 1, 8},
|
|
144 |
{ 16, 10, 8, 7},
|
|
145 |
{ 10, 8, 8, 10},
|
|
146 |
{ 8, 12, 8, 9},
|
|
132 |
{ 2, 0, 1, 2}, //0
|
|
133 |
{ 0, 12, 1, 0},
|
|
134 |
{ 12, 4, 1, 9},
|
|
135 |
{ 4, 14, 1, 5},
|
|
136 |
{ 14, 2, 1, 11},
|
|
137 |
{ 14, 9, 11, 5}, //5
|
|
138 |
{ 9, 11, 11, 4},
|
|
139 |
{ 11, 18, 11, 3},
|
|
140 |
{ 18, 2, 11, 2},
|
|
141 |
{ 18, 6, 2, 3},
|
|
142 |
{ 6, 16, 2, 8}, //10
|
|
143 |
{ 16, 0, 2, 0},
|
|
144 |
{ 16, 10, 0, 8},
|
|
145 |
{ 10, 8, 0, 10},
|
|
146 |
{ 8, 12, 0, 9},
|
|
147 | 147 |
{ 8, 13, 9, 10}, //15 |
148 |
{ 13, 5, 9, 5},
|
|
149 |
{ 5, 4, 9, 4},
|
|
150 |
{ 5, 15, 4, 5},
|
|
151 |
{ 15, 9, 4, 3},
|
|
152 |
{ 11, 19, 2, 3}, //20
|
|
153 |
{ 19, 7, 2, 6},
|
|
154 |
{ 7, 6, 2, 7},
|
|
155 |
{ 7, 17, 7, 6},
|
|
156 |
{ 17, 10, 7, 10},
|
|
157 |
{ 17, 1, 10, 6}, //25
|
|
158 |
{ 1, 3, 5, 6},
|
|
159 |
{ 3, 19, 3, 6},
|
|
160 |
{ 1, 13, 10, 5},
|
|
161 |
{ 3, 15, 5, 3},
|
|
148 |
{ 13, 5, 9, 6},
|
|
149 |
{ 5, 4, 9, 5},
|
|
150 |
{ 5, 15, 5, 6},
|
|
151 |
{ 15, 9, 5, 4},
|
|
152 |
{ 11, 19, 3, 4}, //20
|
|
153 |
{ 19, 7, 3, 7},
|
|
154 |
{ 7, 6, 3, 8},
|
|
155 |
{ 7, 17, 8, 7},
|
|
156 |
{ 17, 10, 8, 10},
|
|
157 |
{ 17, 1, 10, 7}, //25
|
|
158 |
{ 1, 3, 6, 7},
|
|
159 |
{ 3, 19, 4, 7},
|
|
160 |
{ 1, 13, 10, 6},
|
|
161 |
{ 3, 15, 6, 4},
|
|
162 | 162 |
}; |
163 | 163 |
} |
164 | 164 |
|
... | ... | |
168 | 168 |
{ |
169 | 169 |
mQuatEdgeIndices = new int[] |
170 | 170 |
{ |
171 |
17, 18, 19, 20, 0, 56, 25, 5, 24, 16,
|
|
171 |
0, 17, 18, 19, 20, 56, 25, 5, 24, 16,
|
|
172 | 172 |
9, 44, 1, 34, 35, 27, 41, 50, 26, 54, |
173 | 173 |
15, 49, 39, 28, 10, 2, 48, 6, 46, 3 |
174 | 174 |
}; |
src/main/java/org/distorted/objectlib/objects/TwistyPentultimate.java | ||
---|---|---|
143 | 143 |
{ |
144 | 144 |
mQuatIndex = new int[] |
145 | 145 |
{ |
146 |
0, 29, 59, 48, 18, 53, 22, 49, 11, 54, |
|
147 |
10, 52, 17, 27, 19, 26, 9, 28, 23, 45, |
|
148 |
0, 59, 15, 6, 4, 3, 29, 10, 35, 8, 2, 5 |
|
146 |
0,29,59,48,18,53,22,49,11,54,10,52,17,27,19,26, 9,28,23,45, |
|
147 |
0, 4, 5, 6,26, 3, 2, 7,16,13, 1,19 |
|
149 | 148 |
}; |
150 | 149 |
} |
151 | 150 |
|
... | ... | |
259 | 258 |
}; |
260 | 259 |
int[][] indices = |
261 | 260 |
{ |
262 |
{4,3,2,1,0},
|
|
261 |
{0,1,2,3,4},
|
|
263 | 262 |
{0,5,1}, |
264 | 263 |
{1,5,2}, |
265 | 264 |
{2,5,3}, |
src/main/java/org/distorted/objectlib/objects/TwistyStarminx.java | ||
---|---|---|
94 | 94 |
{ |
95 | 95 |
mQuatIndex = new int[] |
96 | 96 |
{ |
97 |
17,12,13,20, 0, 4,25, 5,24,16,
|
|
97 |
0,17,12,13,20, 4,25, 5,24,16,
|
|
98 | 98 |
9,21, 1,34, 8,11,30,43,26,14, |
99 | 99 |
15,45,33,28,10, 2,29, 6, 7, 3, |
100 | 100 |
|
101 |
35,55,38,48,41,42,58,57, 0,46,29,59,
|
|
101 |
0,35,55,38,48,41,42,58,57,46,29,59,
|
|
102 | 102 |
|
103 | 103 |
0,36,44, 29, 2, 7, 59,20,24, 48,42,58, |
104 | 104 |
18,13,50, 53,41,43, 22,16,39, 49,33,38, |
src/main/java/org/distorted/objectlib/objects/TwistyUltimate.java | ||
---|---|---|
117 | 117 |
|
118 | 118 |
public Static4D getCubitQuats(int cubit, int[] numLayers) |
119 | 119 |
{ |
120 |
if( mQuatIndex==null ) mQuatIndex = new int[] { 0,2,5,6,0,8,2,1,0,5,8,9,1,6 }; |
|
120 |
if( mQuatIndex==null ) mQuatIndex = new int[] { 0,2,5,6, |
|
121 |
0,8,2,1, |
|
122 |
0,5,8,9,1,6 }; |
|
121 | 123 |
return mObjectQuats[mQuatIndex[cubit]]; |
122 | 124 |
} |
123 | 125 |
|
Also available in: Unified diff
Progress with cubit quaternions.