Revision 7764a67a
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objects/FactoryCubit.java | ||
---|---|---|
672 | 672 |
|
673 | 673 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
674 | 674 |
|
675 |
MeshBase createFacesKilominxCorner()
|
|
675 |
MeshBase createFacesKilominxCenter()
|
|
676 | 676 |
{ |
677 | 677 |
MeshBase[] meshes = new MeshPolygon[6]; |
678 | 678 |
|
679 |
float X1= (SQ5+1)/8;
|
|
680 |
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
|
|
681 |
float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
|
|
679 |
float X1= 0.5f*SIN54;
|
|
680 |
float Y1= 0.5f*SIN_HALFD;
|
|
681 |
float Y2= Y1 - 0.5f*COS54;
|
|
682 | 682 |
float H = 0.5f* SIN54 /COS54 ; |
683 | 683 |
float X2= MINX_SC*H* SIN_HALFD; |
684 | 684 |
float Y3= MINX_SC*H/(2*COS_HALFD); |
... | ... | |
1354 | 1354 |
|
1355 | 1355 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1356 | 1356 |
|
1357 |
VertexEffect[] createVertexEffectsKilominxCorner()
|
|
1357 |
VertexEffect[] createVertexEffectsKilominxCenter(float width)
|
|
1358 | 1358 |
{ |
1359 | 1359 |
VertexEffect[] effect = new VertexEffect[10]; |
1360 | 1360 |
|
1361 |
float H = 0.5f*(SIN54 /COS54 );
|
|
1362 |
float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
|
|
1361 |
float H = 0.5f*(SIN54/COS54);
|
|
1362 |
float Y1= 0.5f*SIN_HALFD;
|
|
1363 | 1363 |
float Y2= H/(2*COS_HALFD); |
1364 |
float A = (float)(Math.acos(-SQ5/5)*180/Math.PI); // dihedral angle of a dedecahedron in degrees |
|
1365 |
float sin18 = SIN18; |
|
1366 | 1364 |
float cos18 = (float)(Math.sqrt(1- SIN18 * SIN18)); |
1367 | 1365 |
float LEN = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f); |
1368 | 1366 |
|
1369 | 1367 |
Static3D axisZ = new Static3D(0.0f , 0.0f , 1.0f); |
1370 | 1368 |
Static3D axisY = new Static3D(0.0f , 1.0f , 0.0f); |
1371 |
Static3D axisA = new Static3D(-sin18, cos18, 0.0f);
|
|
1369 |
Static3D axisA = new Static3D(-SIN18, cos18, 0.0f);
|
|
1372 | 1370 |
Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H* SIN_HALFD /(COS_HALFD*LEN)); |
1373 | 1371 |
|
1374 | 1372 |
Static3D move1 = new Static3D(0,-Y1,0); |
1375 | 1373 |
Static3D move2 = new Static3D(0,-Y2,0); |
1376 |
Static3D move3 = new Static3D(0.5f*cos18,0.5f*sin18,0);
|
|
1374 |
Static3D move3 = new Static3D(0.5f*cos18,0.5f*SIN18,0);
|
|
1377 | 1375 |
Static3D center= new Static3D(0.0f, 0.0f, 0.0f); |
1378 | 1376 |
|
1379 | 1377 |
Static1D angle1 = new Static1D(54); |
1380 |
Static1D angle2 = new Static1D(A/2+18);
|
|
1378 |
Static1D angle2 = new Static1D(DIHEDRAL1/2+18);
|
|
1381 | 1379 |
Static1D angle3 = new Static1D(90); |
1382 | 1380 |
Static1D angle4 = new Static1D(120); |
1383 | 1381 |
Static1D angle5 = new Static1D(240); |
1384 |
Static1D angle6 = new Static1D(90-A/2);
|
|
1382 |
Static1D angle6 = new Static1D(90-DIHEDRAL1/2);
|
|
1385 | 1383 |
|
1386 | 1384 |
effect[0] = new VertexEffectMove(move1); |
1387 | 1385 |
effect[1] = new VertexEffectScale(1/MINX_SC); |
... | ... | |
1934 | 1932 |
|
1935 | 1933 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1936 | 1934 |
|
1937 |
MeshBase createKilominxCornerMesh()
|
|
1935 |
MeshBase createKilominxCenterMesh(float width)
|
|
1938 | 1936 |
{ |
1939 |
MeshBase mesh = createFacesKilominxCorner();
|
|
1940 |
VertexEffect[] effects = createVertexEffectsKilominxCorner();
|
|
1937 |
MeshBase mesh = createFacesKilominxCenter();
|
|
1938 |
VertexEffect[] effects = createVertexEffectsKilominxCenter(width);
|
|
1941 | 1939 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
1942 | 1940 |
|
1943 | 1941 |
float A = (2*SQ3/3)* SIN54; |
... | ... | |
1961 | 1959 |
return mesh; |
1962 | 1960 |
} |
1963 | 1961 |
|
1962 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1963 |
// numLayers==3 --> index=0; numLayers=5 --> index=1 ... |
|
1964 |
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc |
|
1965 |
// TODO |
|
1966 |
|
|
1967 |
MeshBase createKilominxEdgeMesh(int numLayers, float width, float height) |
|
1968 |
{ |
|
1969 |
MeshBase mesh = createFacesMegaminxEdge(numLayers,width,height); |
|
1970 |
VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height); |
|
1971 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1972 |
|
|
1973 |
mesh.mergeEffComponents(); |
|
1974 |
|
|
1975 |
return mesh; |
|
1976 |
} |
|
1977 |
|
|
1964 | 1978 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1965 | 1979 |
|
1966 |
MeshBase createMegaminxCornerMesh(int numLayers)
|
|
1980 |
MeshBase createMinxCornerMesh(ObjectList object, int numLayers)
|
|
1967 | 1981 |
{ |
1968 | 1982 |
MeshBase mesh = createFacesMegaminxCorner(numLayers); |
1969 | 1983 |
VertexEffect[] effects = createVertexEffectsMegaminxCorner(numLayers); |
src/main/java/org/distorted/objects/TwistyKilominx.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
import static org.distorted.objects.FactoryCubit.COS18; |
37 | 37 |
import static org.distorted.objects.FactoryCubit.COS54; |
38 |
import static org.distorted.objects.FactoryCubit.SIN18; |
|
38 | 39 |
|
39 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 41 |
|
41 | 42 |
public class TwistyKilominx extends TwistyMinx |
42 | 43 |
{ |
43 |
private static MeshBase mMesh; |
|
44 |
private static MeshBase[] mCenterMeshes, mCornerMeshes; |
|
45 |
private static MeshBase[][] mEdgeMeshes; |
|
46 |
|
|
47 |
private static final int mNumCornerEdgeVariants; |
|
48 |
|
|
49 |
static |
|
50 |
{ |
|
51 |
int[] sizes = ObjectList.KILO.getSizes(); |
|
52 |
int variants = sizes.length; |
|
53 |
mNumCornerEdgeVariants = sizes[0]==3 ? variants-1 : variants; |
|
54 |
} |
|
44 | 55 |
|
45 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 57 |
|
... | ... | |
169 | 180 |
private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge) |
170 | 181 |
{ |
171 | 182 |
int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge; |
172 |
return (part+1)/2;
|
|
183 |
return part - 2*(part/4);
|
|
173 | 184 |
} |
174 | 185 |
|
175 | 186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
251 | 262 |
} |
252 | 263 |
|
253 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
254 |
// TODO |
|
255 | 265 |
|
256 |
private int getQuat(int cubit) |
|
266 |
private int getQuat(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
|
|
257 | 267 |
{ |
258 |
return ( cubit>=0 && cubit<20 ) ? QUAT_CORNER_INDICES[cubit] : 0; |
|
268 |
if( cubit < NUM_CORNERS*numCubitsPerCorner ) |
|
269 |
{ |
|
270 |
int corner = cubit/numCubitsPerCorner; |
|
271 |
return QUAT_CORNER_INDICES[corner]; |
|
272 |
} |
|
273 |
|
|
274 |
if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge ) |
|
275 |
{ |
|
276 |
int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge; |
|
277 |
return QUAT_EDGE_INDICES[edge]; |
|
278 |
} |
|
279 |
|
|
280 |
if( numCubitsPerCorner==0 ) |
|
281 |
{ |
|
282 |
return QUAT_CORNER_INDICES[cubit]; |
|
283 |
} |
|
284 |
else |
|
285 |
{ |
|
286 |
cubit -= (NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge); |
|
287 |
int numCubitsPerCenter = 5; |
|
288 |
int face = cubit/numCubitsPerCenter; |
|
289 |
int index= cubit%numCubitsPerCenter; |
|
290 |
int corner=mCenterMap[face][index]; |
|
291 |
|
|
292 |
return QUAT_CORNER_INDICES[corner]; |
|
293 |
} |
|
259 | 294 |
} |
260 | 295 |
|
261 | 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
262 |
// TODO |
|
263 | 297 |
|
264 | 298 |
MeshBase createCubitMesh(int cubit, int numLayers) |
265 | 299 |
{ |
266 |
if( mMesh==null ) mMesh = FactoryCubit.getInstance().createKilominxCornerMesh(); |
|
267 |
MeshBase mesh = mMesh.copy(true); |
|
300 |
int numCubitsPerCorner = numCubitsPerCorner(numLayers); |
|
301 |
int numCubitsPerEdge = numCubitsPerEdge(numLayers); |
|
302 |
int[] sizes = ObjectList.KILO.getSizes(); |
|
303 |
int variants = sizes.length; |
|
304 |
int highestSize = sizes[variants-1]; |
|
305 |
int lowestSize = sizes[0]; |
|
306 |
int indexCornerEdge = (numLayers-lowestSize)/2 - (lowestSize==3 ? 1:0); |
|
307 |
MeshBase mesh; |
|
308 |
|
|
309 |
if( mNumCornerEdgeVariants>0 ) |
|
310 |
{ |
|
311 |
if( mCornerMeshes==null ) mCornerMeshes = new MeshBase[mNumCornerEdgeVariants]; |
|
312 |
if( mEdgeMeshes ==null ) mEdgeMeshes = new MeshBase[mNumCornerEdgeVariants][(highestSize-3)/2]; |
|
313 |
} |
|
314 |
|
|
315 |
if( mCenterMeshes==null ) mCenterMeshes = new MeshBase[variants]; |
|
316 |
|
|
317 |
if( cubit < NUM_CORNERS*numCubitsPerCorner ) |
|
318 |
{ |
|
319 |
if( mCornerMeshes[indexCornerEdge]==null ) |
|
320 |
{ |
|
321 |
mCornerMeshes[indexCornerEdge] = FactoryCubit.getInstance().createMinxCornerMesh(ObjectList.KILO,numLayers); |
|
322 |
} |
|
323 |
mesh = mCornerMeshes[indexCornerEdge].copy(true); |
|
324 |
} |
|
325 |
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge ) |
|
326 |
{ |
|
327 |
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge); // left-top, right-top, left-second, right-second, left-third... |
|
328 |
|
|
329 |
if( mEdgeMeshes[indexCornerEdge][type]==null ) |
|
330 |
{ |
|
331 |
float tmp = (numLayers/3.0f)/(numLayers-1); |
|
332 |
float height= tmp*COS18; |
|
333 |
float width = tmp + type*height*SIN18/COS18; |
|
334 |
|
|
335 |
mEdgeMeshes[indexCornerEdge][type] = FactoryCubit.getInstance().createKilominxEdgeMesh(numLayers,width,height); |
|
336 |
} |
|
337 |
|
|
338 |
mesh = mEdgeMeshes[indexCornerEdge][type].copy(true); |
|
339 |
} |
|
340 |
else |
|
341 |
{ |
|
342 |
int indexCenter = (numLayers-3)/2; |
|
343 |
|
|
344 |
if( mCenterMeshes[indexCenter]==null ) |
|
345 |
{ |
|
346 |
float width = (1+0.5f*(numLayers-3)*SIN18)*(numLayers/3.0f)/(numLayers-1); |
|
347 |
mCenterMeshes[indexCenter] = FactoryCubit.getInstance().createKilominxCenterMesh(width); |
|
348 |
} |
|
349 |
|
|
350 |
mesh = mCenterMeshes[indexCenter].copy(true); |
|
351 |
} |
|
268 | 352 |
|
269 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) ); |
|
353 |
Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)]; |
|
354 |
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( q, new Static3D(0,0,0) ); |
|
270 | 355 |
mesh.apply(quat,0xffffffff,0); |
271 | 356 |
|
272 | 357 |
return mesh; |
src/main/java/org/distorted/objects/TwistyMegaminx.java | ||
---|---|---|
44 | 44 |
{ |
45 | 45 |
static final float MEGA_D = 0.04f; |
46 | 46 |
|
47 |
private static final int[] QUAT_EDGE_INDICES = |
|
48 |
{ |
|
49 |
56, 40, 43, 59, 0, 55, 10, 17, 25, 49, |
|
50 |
48, 57, 18, 7, 53, 32, 20, 11, 31, 38, |
|
51 |
37, 30, 8, 28, 36, 44, 1, 46, 12, 14 |
|
52 |
}; |
|
53 |
|
|
54 | 47 |
private static final int[] QUAT_CENTER_INDICES = |
55 | 48 |
{ |
56 | 49 |
16, 18, 22, 1, 20, 13, 14, 15, 0, 12, 2, 3 |
... | ... | |
161 | 154 |
Static4D pri = mCurrCornerV[index]; |
162 | 155 |
Static4D sec = mCurrCornerV[(index+2)%3]; |
163 | 156 |
|
164 |
int layers= (numLayers-5)/2;
|
|
157 |
int layers= (numLayers-3)/2;
|
|
165 | 158 |
int multP = (block % layers) + 1; |
166 | 159 |
int multS = (block / layers); |
167 | 160 |
|
... | ... | |
290 | 283 |
{ |
291 | 284 |
if( mCornerMeshes[index]==null ) |
292 | 285 |
{ |
293 |
mCornerMeshes[index] = FactoryCubit.getInstance().createMegaminxCornerMesh(numLayers);
|
|
286 |
mCornerMeshes[index] = FactoryCubit.getInstance().createMinxCornerMesh(ObjectList.MEGA,numLayers);
|
|
294 | 287 |
} |
295 | 288 |
mesh = mCornerMeshes[index].copy(true); |
296 | 289 |
} |
src/main/java/org/distorted/objects/TwistyMinx.java | ||
---|---|---|
194 | 194 |
{ 6, 2, 3 }, |
195 | 195 |
}; |
196 | 196 |
|
197 |
static final int[] QUAT_EDGE_INDICES = |
|
198 |
{ |
|
199 |
56, 40, 43, 59, 0, 55, 10, 17, 25, 49, |
|
200 |
48, 57, 18, 7, 53, 32, 20, 11, 31, 38, |
|
201 |
37, 30, 8, 28, 36, 44, 1, 46, 12, 14 |
|
202 |
}; |
|
203 |
|
|
204 |
|
|
197 | 205 |
static final int[] QUAT_CORNER_INDICES = |
198 | 206 |
{ |
199 | 207 |
0, 2, 3, 1, 40, 31, 41, 30, 39, 35, |
Also available in: Unified diff
Progress with any size Kilominx.