1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2023 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.objectlib.bandaged;
|
11
|
|
12
|
import static org.distorted.objectlib.main.TwistyObject.SQ2;
|
13
|
|
14
|
import org.distorted.library.type.Static3D;
|
15
|
import org.distorted.library.type.Static4D;
|
16
|
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
|
17
|
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
public class FactoryBandagedPyraminx extends FactoryBandaged
|
21
|
{
|
22
|
private static FactoryBandagedPyraminx mThis;
|
23
|
private float[][][] mVertices;
|
24
|
private int[][][] mIndices;
|
25
|
|
26
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27
|
|
28
|
private FactoryBandagedPyraminx()
|
29
|
{
|
30
|
|
31
|
}
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public static FactoryBandagedPyraminx getInstance()
|
36
|
{
|
37
|
if( mThis==null ) mThis = new FactoryBandagedPyraminx();
|
38
|
return mThis;
|
39
|
}
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
private static void addTetrahedralLattice(int size, float[][] pos)
|
44
|
{
|
45
|
final float DX = 1.0f;
|
46
|
final float DY = SQ2/2;
|
47
|
final float DZ = 1.0f;
|
48
|
|
49
|
float startX = 0.0f;
|
50
|
float startY =-DY*(size-1)/2;
|
51
|
float startZ = DZ*(size-1)/2;
|
52
|
|
53
|
int index = 0;
|
54
|
|
55
|
for(int layer=0; layer<size; layer++)
|
56
|
{
|
57
|
float currX = startX;
|
58
|
float currY = startY;
|
59
|
|
60
|
for(int x=0; x<layer+1; x++)
|
61
|
{
|
62
|
float currZ = startZ;
|
63
|
|
64
|
for(int z=0; z<size-layer; z++)
|
65
|
{
|
66
|
if( x==0 || x==layer || z==0 || z==size-layer-1 )
|
67
|
{
|
68
|
pos[index]=new float[]{currX, currY, currZ};
|
69
|
index++;
|
70
|
}
|
71
|
currZ -= DZ;
|
72
|
}
|
73
|
|
74
|
currX += DX;
|
75
|
}
|
76
|
|
77
|
startX -= DX/2;
|
78
|
startY += DY;
|
79
|
startZ -= DZ/2;
|
80
|
}
|
81
|
}
|
82
|
|
83
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84
|
|
85
|
public static int numEntriesInFullLattice(int size)
|
86
|
{
|
87
|
return size*(size+1)*(size+2)/6;
|
88
|
}
|
89
|
|
90
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91
|
|
92
|
public static int numEntriesInEmptyLattice(int size)
|
93
|
{
|
94
|
int full = numEntriesInFullLattice(size);
|
95
|
if( size>=5 ) full -= numEntriesInFullLattice(size-4);
|
96
|
|
97
|
return full;
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
public static float[][][] createPositions(int size)
|
103
|
{
|
104
|
int numO= numEntriesInEmptyLattice(size-1);
|
105
|
int numT= numEntriesInEmptyLattice(size);
|
106
|
|
107
|
float[][] retO = new float[numO][];
|
108
|
float[][] retT = new float[numT][];
|
109
|
|
110
|
addTetrahedralLattice(size-1,retO);
|
111
|
addTetrahedralLattice(size ,retT);
|
112
|
|
113
|
return new float[][][] { retO,retT };
|
114
|
}
|
115
|
|
116
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117
|
|
118
|
public float[][] getVertices(int[] numLayers, int variant)
|
119
|
{
|
120
|
if( mVertices==null ) mVertices = new float[2][][];
|
121
|
|
122
|
if( variant==0 )
|
123
|
{
|
124
|
if( mVertices[0]==null )
|
125
|
mVertices[0] = new float[][] { { 0.5f,0.0f,0.5f},{ 0.5f,0.0f,-0.5f},{-0.5f,0.0f,-0.5f},{-0.5f,0.0f,0.5f},{ 0.0f,SQ2/2,0.0f},{ 0.0f,-SQ2/2,0.0f} };
|
126
|
|
127
|
return mVertices[0];
|
128
|
}
|
129
|
else
|
130
|
{
|
131
|
if( mVertices[1]==null )
|
132
|
mVertices[1] = new float[][] { {-0.5f, SQ2/4, 0.0f},{ 0.5f, SQ2/4, 0.0f},{ 0.0f,-SQ2/4, 0.5f},{ 0.0f,-SQ2/4,-0.5f} };
|
133
|
|
134
|
return mVertices[1];
|
135
|
}
|
136
|
}
|
137
|
|
138
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139
|
|
140
|
public int[][] getIndices(int[] numLayers, int variant)
|
141
|
{
|
142
|
if( mIndices==null ) mIndices = new int[2][][];
|
143
|
|
144
|
if( variant==0 )
|
145
|
{
|
146
|
if( mIndices[0]==null )
|
147
|
mIndices[0] = new int[][] { {3,0,4},{0,1,4},{1,2,4},{2,3,4},{5,0,3},{5,1,0},{5,2,1},{5,3,2} };
|
148
|
|
149
|
return mIndices[0];
|
150
|
}
|
151
|
else
|
152
|
{
|
153
|
if( mIndices[1]==null )
|
154
|
mIndices[1] = new int[][] { {2,1,0},{3,0,1},{3,2,0},{2,3,1} };
|
155
|
|
156
|
return mIndices[1];
|
157
|
}
|
158
|
}
|
159
|
|
160
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161
|
// see BandagedObjectPyraminx.addTetrahedralLattice()
|
162
|
// from there, 'y' is always of the form -DY*(size-1)/2 + K*DY, where DY = SQ2/2, K integer
|
163
|
// and 'size' is mNumLayers[0]-1 in case of Octahedrons and mNumLayers[0] in case of Tetrahedrons.
|
164
|
// From the above, the below quickly follows. +20*size to avoid negative values.
|
165
|
|
166
|
public static boolean isOctahedron(int size, float y)
|
167
|
{
|
168
|
int num = (int)(2*SQ2*y + 20*size + 0.1f);
|
169
|
return (num-size)%2 == 0;
|
170
|
}
|
171
|
|
172
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173
|
|
174
|
public int getNumVariants(int[] numLayers)
|
175
|
{
|
176
|
return 2;
|
177
|
}
|
178
|
|
179
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180
|
|
181
|
public int getElementVariant(int[] numLayers, float x, float y, float z)
|
182
|
{
|
183
|
return isOctahedron(numLayers[0],y) ? 0 : 1;
|
184
|
}
|
185
|
|
186
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187
|
|
188
|
public Static4D getElementQuat(int[] numLayers, int cubitIndex)
|
189
|
{
|
190
|
return QUAT;
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
public float[][][] getPositions(int[] numLayers)
|
196
|
{
|
197
|
return createPositions(numLayers[0]);
|
198
|
}
|
199
|
|
200
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201
|
|
202
|
public Static3D[] getNormals()
|
203
|
{
|
204
|
return TouchControlTetrahedron.FACE_AXIS;
|
205
|
}
|
206
|
|
207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208
|
// normalized 'edges' of the tetrahedron.
|
209
|
|
210
|
public float[][] getDiameterAxis()
|
211
|
{
|
212
|
return new float[][]
|
213
|
{
|
214
|
{ 1, 0, 0},
|
215
|
{ 0, 0, 1},
|
216
|
{ 0.5f,SQ2/2, 0.5f},
|
217
|
{ 0.5f,SQ2/2,-0.5f},
|
218
|
{-0.5f,SQ2/2, 0.5f},
|
219
|
{-0.5f,SQ2/2,-0.5f},
|
220
|
};
|
221
|
}
|
222
|
|
223
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
224
|
|
225
|
public float sizeCorrection(int[] numLayers)
|
226
|
{
|
227
|
return 1.0f;
|
228
|
}
|
229
|
|
230
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
231
|
|
232
|
public int diameterMap(float diameter)
|
233
|
{
|
234
|
if( diameter>=5.49f ) return 11;
|
235
|
if( diameter>1.1f && diameter<1.9f ) return 3;
|
236
|
return (int)(2*diameter+0.01f);
|
237
|
}
|
238
|
|
239
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
240
|
|
241
|
public float[] getDist3D(int[] numLayers)
|
242
|
{
|
243
|
final float d = TouchControlTetrahedron.DIST3D*numLayers[0];
|
244
|
return new float[] {d,d,d,d};
|
245
|
}
|
246
|
|
247
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
248
|
|
249
|
public float[][] getBands(boolean iconMode, int[] numLayers)
|
250
|
{
|
251
|
float height= iconMode ? 0.001f : 0.055f;
|
252
|
int[] angle = {1,56,50,43,39,35,32,30,28,26,25};
|
253
|
float R = 0.3f;
|
254
|
float S = 0.5f;
|
255
|
int extraI = 0;
|
256
|
int extraV = 0;
|
257
|
int numVertA= numLayers[0]>=5 ? 4 : 5;
|
258
|
int numVertI= numLayers[0]>=5 ? 2 : 3;
|
259
|
|
260
|
return new float[][] { { 0.001f ,angle[ 0],R,S,numVertI,extraV,extraI},
|
261
|
{height ,angle[ 1],R,S,numVertA,extraV,extraI},
|
262
|
{height ,angle[ 1],R,S,numVertA,extraV,extraI},
|
263
|
{height/ 1.5f,angle[ 2],R,S,numVertA,extraV,extraI},
|
264
|
{height/ 2.0f,angle[ 3],R,S,numVertA,extraV,extraI},
|
265
|
{height/ 2.5f,angle[ 4],R,S,numVertA,extraV,extraI},
|
266
|
{height/ 3.0f,angle[ 5],R,S,numVertA,extraV,extraI},
|
267
|
{height/ 3.5f,angle[ 6],R,S,numVertA,extraV,extraI},
|
268
|
{height/ 4.0f,angle[ 7],R,S,numVertA,extraV,extraI},
|
269
|
{height/ 4.5f,angle[ 8],R,S,numVertA,extraV,extraI},
|
270
|
{height/ 5.0f,angle[ 9],R,S,numVertA,extraV,extraI},
|
271
|
{height/ 5.5f,angle[10],R,S,numVertA,extraV,extraI}
|
272
|
};
|
273
|
}
|
274
|
}
|