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