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
|
import static org.distorted.objectlib.main.TwistyObject.SQ3;
|
14
|
import static org.distorted.objectlib.main.TwistyObject.SQ6;
|
15
|
|
16
|
import org.distorted.library.main.DistortedScreen;
|
17
|
import org.distorted.library.mesh.MeshBase;
|
18
|
import org.distorted.library.type.Static3D;
|
19
|
import org.distorted.objectlib.main.InitData;
|
20
|
import org.distorted.objectlib.main.TwistyObject;
|
21
|
import org.distorted.objectlib.objects.TwistyBandagedPyraminx;
|
22
|
import org.distorted.objectlib.shape.ShapeTetrahedron;
|
23
|
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
|
24
|
|
25
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26
|
|
27
|
public class BandagedObjectPyraminx extends BandagedObject
|
28
|
{
|
29
|
private boolean isFaceInverted(int face)
|
30
|
{
|
31
|
return face>1;
|
32
|
}
|
33
|
|
34
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35
|
|
36
|
private void addTetrahedralLattice(int size, float[][] pos)
|
37
|
{
|
38
|
final float DX = 1.0f;
|
39
|
final float DY = SQ2/2;
|
40
|
final float DZ = 1.0f;
|
41
|
|
42
|
float startX = 0.0f;
|
43
|
float startY =-DY*(size-1)/2;
|
44
|
float startZ = DZ*(size-1)/2;
|
45
|
|
46
|
int index = 0;
|
47
|
|
48
|
for(int layer=0; layer<size; layer++)
|
49
|
{
|
50
|
float currX = startX;
|
51
|
float currY = startY;
|
52
|
|
53
|
for(int x=0; x<layer+1; x++)
|
54
|
{
|
55
|
float currZ = startZ;
|
56
|
|
57
|
for(int z=0; z<size-layer; z++)
|
58
|
{
|
59
|
pos[index] = new float[] {currX,currY,currZ};
|
60
|
index++;
|
61
|
currZ -= DZ;
|
62
|
}
|
63
|
|
64
|
currX += DX;
|
65
|
}
|
66
|
|
67
|
startX-=DX/2;
|
68
|
startY+=DY;
|
69
|
startZ-=DZ/2;
|
70
|
}
|
71
|
}
|
72
|
|
73
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74
|
|
75
|
float getDist2D()
|
76
|
{
|
77
|
return SQ3/6;
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
int[] getColors()
|
83
|
{
|
84
|
return ShapeTetrahedron.FACE_COLORS;
|
85
|
}
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
|
89
|
boolean isAdjacent(float dx, float dy, float dz)
|
90
|
{
|
91
|
return dx*dx + dy*dy + dz*dz < (SQ3/4)*1.01f;
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
float[][][] getPositions()
|
97
|
{
|
98
|
int num = mSize[0];
|
99
|
int numO= (num-1)*num*(num+1)/6;
|
100
|
int numT= (num+1)*num*(num+2)/6;
|
101
|
|
102
|
float[][] retO = new float[numO][];
|
103
|
float[][] retT = new float[numT][];
|
104
|
|
105
|
addTetrahedralLattice(num-1,retO);
|
106
|
addTetrahedralLattice(num ,retT);
|
107
|
|
108
|
return new float[][][] { retO,retT };
|
109
|
}
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
MeshBase createMesh(float[] pos, boolean round)
|
114
|
{
|
115
|
FactoryBandagedPyraminx factory = FactoryBandagedPyraminx.getInstance();
|
116
|
return factory.createMesh(pos,mSize,false,round);
|
117
|
}
|
118
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
// PUBLIC API
|
121
|
|
122
|
public BandagedObjectPyraminx(DistortedScreen screen)
|
123
|
{
|
124
|
super(screen,4);
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
public float getScreenRatio()
|
130
|
{
|
131
|
return 0.8f;
|
132
|
}
|
133
|
|
134
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135
|
|
136
|
public float[] getDist3D()
|
137
|
{
|
138
|
float d = SQ6/12;
|
139
|
return new float[] {d,d,d,d};
|
140
|
}
|
141
|
|
142
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143
|
|
144
|
public Static3D[] getFaceAxis()
|
145
|
{
|
146
|
return TouchControlTetrahedron.FACE_AXIS;
|
147
|
}
|
148
|
|
149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150
|
|
151
|
public boolean tryChangeObject(int x, int y, int z)
|
152
|
{
|
153
|
if( mSize[0]!=x )
|
154
|
{
|
155
|
mSize[0] = x;
|
156
|
mSize[1] = x;
|
157
|
mSize[2] = x;
|
158
|
mSize[3] = x;
|
159
|
|
160
|
mMax = x;
|
161
|
int numOcta = (x-1)*x*(x+1)/6;
|
162
|
int numTetra= x*(x+1)*(x+2)/6;
|
163
|
mNumCubits = numOcta + numTetra;
|
164
|
return true;
|
165
|
}
|
166
|
|
167
|
return false;
|
168
|
}
|
169
|
|
170
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171
|
|
172
|
public int computeProjectionAngle()
|
173
|
{
|
174
|
return 120;
|
175
|
}
|
176
|
|
177
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178
|
|
179
|
public boolean isInsideFace(int face, float[] p)
|
180
|
{
|
181
|
float y = (isFaceInverted(face) ? p[1] : -p[1]);
|
182
|
float x = p[0];
|
183
|
return (y >= -mDist2D) && (y <= mDist2D*(2-6*x)) && (y <= mDist2D*(2+6*x));
|
184
|
}
|
185
|
|
186
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187
|
|
188
|
public TwistyObject createObject(int mode, float size)
|
189
|
{
|
190
|
float[][] pos = getCubitPositions();
|
191
|
InitData data = new InitData( mSize,pos);
|
192
|
return new TwistyBandagedPyraminx( TwistyObject.MESH_NICE, mode, ShapeTetrahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
|
193
|
}
|
194
|
}
|