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 org.distorted.library.main.DistortedScreen;
|
13
|
import org.distorted.library.mesh.MeshBase;
|
14
|
import org.distorted.library.type.Static3D;
|
15
|
import org.distorted.objectlib.main.InitData;
|
16
|
import org.distorted.objectlib.main.TwistyObject;
|
17
|
import org.distorted.objectlib.objects.TwistyBandagedCuboid;
|
18
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
19
|
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
20
|
|
21
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
22
|
|
23
|
public class BandagedObjectCuboid extends BandagedObject
|
24
|
{
|
25
|
private float[][] getCuts(int[] numLayers)
|
26
|
{
|
27
|
float[][] ret = new float[3][];
|
28
|
|
29
|
for(int axis=0; axis<3; axis++)
|
30
|
{
|
31
|
int len = numLayers[axis];
|
32
|
float start = (2-len)*0.5f;
|
33
|
|
34
|
if( len>=2 )
|
35
|
{
|
36
|
ret[axis] = new float[len-1];
|
37
|
for(int i=0; i<len-1; i++) ret[axis][i] = start+i;
|
38
|
}
|
39
|
}
|
40
|
|
41
|
return ret;
|
42
|
}
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
float[][] getRotAxis()
|
47
|
{
|
48
|
return new float[][]
|
49
|
{
|
50
|
{1,0,0},
|
51
|
{0,1,0},
|
52
|
{0,0,1},
|
53
|
};
|
54
|
}
|
55
|
|
56
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57
|
|
58
|
float getDist2D()
|
59
|
{
|
60
|
return 0.5f;
|
61
|
}
|
62
|
|
63
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
|
65
|
int[] getColors()
|
66
|
{
|
67
|
return ShapeHexahedron.FACE_COLORS;
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
|
72
|
boolean isAdjacent(float x1, float y1, float z1, float x2, float y2, float z2 )
|
73
|
{
|
74
|
float dx = x1-x2;
|
75
|
float dy = y1-y2;
|
76
|
float dz = z1-z2;
|
77
|
|
78
|
return dx*dx + dy*dy + dz*dz <= 1;
|
79
|
}
|
80
|
|
81
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82
|
|
83
|
float[][][] getPositions()
|
84
|
{
|
85
|
FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
|
86
|
return factory.getPositions(mSize);
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
MeshBase createMesh(float[] pos, boolean round)
|
92
|
{
|
93
|
FactoryBandagedCuboid factory = FactoryBandagedCuboid.getInstance();
|
94
|
return factory.createMesh(pos,mSize,false,round);
|
95
|
}
|
96
|
|
97
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98
|
// PUBLIC API
|
99
|
|
100
|
public BandagedObjectCuboid(DistortedScreen screen, int minSize, int maxSize)
|
101
|
{
|
102
|
super(screen,minSize, maxSize);
|
103
|
}
|
104
|
|
105
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106
|
|
107
|
public float getScreenRatio()
|
108
|
{
|
109
|
return 0.5f;
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
|
114
|
public float[] getDist3D()
|
115
|
{
|
116
|
float max = mMax;
|
117
|
|
118
|
float x = 0.5f*(mSize[0]/max);
|
119
|
float y = 0.5f*(mSize[1]/max);
|
120
|
float z = 0.5f*(mSize[2]/max);
|
121
|
|
122
|
return new float[] {x,x,y,y,z,z};
|
123
|
}
|
124
|
|
125
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126
|
|
127
|
public Static3D[] getFaceAxis()
|
128
|
{
|
129
|
return TouchControlHexahedron.FACE_AXIS;
|
130
|
}
|
131
|
|
132
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133
|
|
134
|
public boolean isInsideFace(int face, float[] p)
|
135
|
{
|
136
|
float max = mMax;
|
137
|
|
138
|
switch(face/2)
|
139
|
{
|
140
|
case 0: p[0] *= (max/mSize[2]); p[1] *= (max/mSize[1]); break;
|
141
|
case 1: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[2]); break;
|
142
|
case 2: p[0] *= (max/mSize[0]); p[1] *= (max/mSize[1]); break;
|
143
|
}
|
144
|
|
145
|
return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D );
|
146
|
}
|
147
|
|
148
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149
|
|
150
|
public int computeProjectionAngle()
|
151
|
{
|
152
|
float quot1 = mSize[2]/ (float)mSize[0];
|
153
|
float quot2 = mSize[2]/ (float)mSize[1];
|
154
|
float quot3 = mSize[0]/ (float)mSize[2];
|
155
|
float quot4 = mSize[0]/ (float)mSize[1];
|
156
|
|
157
|
float quot5 = Math.max(quot1,quot2);
|
158
|
float quot6 = Math.max(quot3,quot4);
|
159
|
float quot7 = Math.max(quot5,quot6);
|
160
|
|
161
|
if( quot7<=1.0f ) return 120;
|
162
|
else if( quot7<=1.5f ) return 90;
|
163
|
else if( quot7<=2.0f ) return 60;
|
164
|
else return 30;
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
public boolean tryChangeObject(int x, int y, int z)
|
170
|
{
|
171
|
if( (mSize[0]!=x || mSize[1]!=y || mSize[2]!=z) &&
|
172
|
x>=mMinSize && x<=mMaxSize && y>= mMinSize &&
|
173
|
y<=mMaxSize && z>=mMinSize && z<=mMaxSize )
|
174
|
{
|
175
|
mSize[0] = x;
|
176
|
mSize[1] = y;
|
177
|
mSize[2] = z;
|
178
|
|
179
|
mMax = x>y ? Math.max(x,z) : Math.max(y,z);
|
180
|
mNumCubits = ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2);
|
181
|
mCuts = getCuts(mSize);
|
182
|
return true;
|
183
|
}
|
184
|
else if( mCuts==null )
|
185
|
{
|
186
|
mMax = 1;
|
187
|
mNumCubits = 1;
|
188
|
mCuts = getCuts(mSize);
|
189
|
}
|
190
|
return false;
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
public TwistyObject createObject(int mode, float size)
|
196
|
{
|
197
|
float[][] pos = getCubitPositions();
|
198
|
InitData data = new InitData( mSize,pos);
|
199
|
return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
|
200
|
}
|
201
|
}
|