Revision 45f63f17
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/helpers/ObjectShape.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2021 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.helpers; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public class ObjectShape |
|
25 |
{ |
|
26 |
private final double[][] mVertices; |
|
27 |
private final int[][] mVertIndices; |
|
28 |
private final float[][] mBands; |
|
29 |
private final int[][] mBandIndices; |
|
30 |
private final float[][] mCorners; |
|
31 |
private final int[][] mCornerIndices; |
|
32 |
private final float[][] mCenters; |
|
33 |
private final int[][] mCenterIndices; |
|
34 |
private final int mNumComponents; |
|
35 |
private final float[] mConvexityCenter; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
public ObjectShape(double[][] vertices, int[][] vertIndices, float[][] bands, int[][] bandIndices, |
|
40 |
float[][] corners, int[][] cornIndices, float[][] centers, int[][] centIndices, |
|
41 |
int numComponents, float[] convexityCenter) |
|
42 |
{ |
|
43 |
mVertices = vertices; |
|
44 |
mVertIndices = vertIndices; |
|
45 |
mBands = bands; |
|
46 |
mBandIndices = bandIndices; |
|
47 |
mCorners = corners; |
|
48 |
mCornerIndices = cornIndices; |
|
49 |
mCenters = centers; |
|
50 |
mCenterIndices = centIndices; |
|
51 |
mNumComponents = numComponents; |
|
52 |
mConvexityCenter = convexityCenter; |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
public double[][] getVertices() |
|
58 |
{ |
|
59 |
return mVertices; |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
public int[][] getVertIndices() |
|
65 |
{ |
|
66 |
return mVertIndices; |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
public float[][] getBands() |
|
72 |
{ |
|
73 |
return mBands; |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
public int[][] getBandIndices() |
|
79 |
{ |
|
80 |
return mBandIndices; |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
public float[][] getCorners() |
|
86 |
{ |
|
87 |
return mCorners; |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
public int[][] getCornerIndices() |
|
93 |
{ |
|
94 |
return mCornerIndices; |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public float[][] getCenters() |
|
100 |
{ |
|
101 |
return mCenters; |
|
102 |
} |
|
103 |
|
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
public int[][] getCenterIndices() |
|
107 |
{ |
|
108 |
return mCenterIndices; |
|
109 |
} |
|
110 |
|
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 |
|
|
113 |
public int getNumComponents() |
|
114 |
{ |
|
115 |
return mNumComponents; |
|
116 |
} |
|
117 |
|
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
|
120 |
public float[] getConvexityCenter() |
|
121 |
{ |
|
122 |
return mConvexityCenter; |
|
123 |
} |
|
124 |
} |
src/main/java/org/distorted/objects/TwistyMegaminx.java | ||
---|---|---|
44 | 44 |
16, 18, 22, 1, 20, 13, 14, 15, 0, 12, 2, 3 |
45 | 45 |
}; |
46 | 46 |
|
47 |
private static MeshBase[] mCenterMeshes, mCornerMeshes; |
|
48 |
private static MeshBase[][] mEdgeMeshes; |
|
47 |
private static MeshBase[][] mMeshes; |
|
49 | 48 |
|
50 | 49 |
private static final float[][] STICKERS = new float[][] |
51 | 50 |
{ |
... | ... | |
415 | 414 |
int index = (numLayers-3)/2; |
416 | 415 |
int[] sizes = ObjectList.MEGA.getSizes(); |
417 | 416 |
int variants = sizes.length; |
417 |
int numShapes = 2+(sizes[variants-1]-1)/2; |
|
418 | 418 |
MeshBase mesh; |
419 | 419 |
|
420 |
if( mCornerMeshes==null ) mCornerMeshes = new MeshBase[variants]; |
|
421 |
if( mEdgeMeshes ==null ) mEdgeMeshes = new MeshBase[variants][(sizes[variants-1]-1)/2]; |
|
422 |
if( mCenterMeshes==null ) mCenterMeshes = new MeshBase[variants]; |
|
420 |
if( mMeshes==null ) mMeshes = new MeshBase[variants][numShapes]; |
|
423 | 421 |
|
424 | 422 |
if( cubit < NUM_CORNERS*numCubitsPerCorner ) |
425 | 423 |
{ |
426 |
if( mCornerMeshes[index]==null )
|
|
424 |
if( mMeshes[index][0]==null )
|
|
427 | 425 |
{ |
428 | 426 |
float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1)); |
429 |
mCornerMeshes[index] = createCornerMesh(numLayers, width);
|
|
427 |
mMeshes[index][0] = createCornerMesh(numLayers, width);
|
|
430 | 428 |
} |
431 |
mesh = mCornerMeshes[index].copy(true);
|
|
429 |
mesh = mMeshes[index][0].copy(true);
|
|
432 | 430 |
} |
433 | 431 |
else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge ) |
434 | 432 |
{ |
435 | 433 |
int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge); |
436 | 434 |
|
437 |
if( mEdgeMeshes[index][type]==null )
|
|
435 |
if( mMeshes[index][1+type]==null )
|
|
438 | 436 |
{ |
439 | 437 |
float height= (numLayers/3.0f)*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f); |
440 | 438 |
float width = (numLayers/3.0f)*2*MEGA_D + 2*type*height*SIN18/COS18; |
441 | 439 |
|
442 |
mEdgeMeshes[index][type] = createEdgeMesh(numLayers,width,height);
|
|
440 |
mMeshes[index][1+type] = createEdgeMesh(numLayers,width,height);
|
|
443 | 441 |
} |
444 |
|
|
445 |
mesh = mEdgeMeshes[index][type].copy(true); |
|
442 |
mesh = mMeshes[index][1+type].copy(true); |
|
446 | 443 |
} |
447 | 444 |
else |
448 | 445 |
{ |
449 |
if( mCenterMeshes[index]==null )
|
|
446 |
if( mMeshes[index][numShapes-1]==null )
|
|
450 | 447 |
{ |
451 | 448 |
float width = 2 * (numLayers/3.0f) * (MEGA_D+(0.5f-MEGA_D)*SIN18); |
452 |
mCenterMeshes[index] = createCenterMesh(numLayers,width);
|
|
449 |
mMeshes[index][numShapes-1] = createCenterMesh(numLayers,width);
|
|
453 | 450 |
} |
454 | 451 |
|
455 |
mesh = mCenterMeshes[index].copy(true);
|
|
452 |
mesh = mMeshes[index][numShapes-1].copy(true);
|
|
456 | 453 |
} |
457 | 454 |
|
458 | 455 |
Static4D q = QUATS[getQuat(cubit,numCubitsPerCorner,numCubitsPerEdge)]; |
Also available in: Unified diff
Introduce ObjectShape - a class encapsulating a shape of a Cubit.
Make the Megaminx cubit creation a bit more standard.