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