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.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.library.type.Static4D;
|
16
|
import org.distorted.objectlib.helpers.FactoryBandagedCubit;
|
17
|
import org.distorted.objectlib.main.InitData;
|
18
|
import org.distorted.objectlib.main.TwistyObject;
|
19
|
import org.distorted.objectlib.objects.TwistyBandagedCuboid;
|
20
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
21
|
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
22
|
|
23
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24
|
|
25
|
public class BandagedObjectCuboid extends BandagedObject
|
26
|
{
|
27
|
private final float[] mPos;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
BandagedObjectCuboid(DistortedScreen screen)
|
32
|
{
|
33
|
super(screen);
|
34
|
mPos = new float[3];
|
35
|
}
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
boolean isAdjacent(float[] pos1, float[] pos2)
|
40
|
{
|
41
|
int len1 = pos1.length/3;
|
42
|
int len2 = pos2.length/3;
|
43
|
|
44
|
for(int i=0; i<len1; i++)
|
45
|
for(int j=0; j<len2; j++)
|
46
|
{
|
47
|
float d0 = pos1[3*i ] - pos2[3*j ];
|
48
|
float d1 = pos1[3*i+1] - pos2[3*j+1];
|
49
|
float d2 = pos1[3*i+2] - pos2[3*j+2];
|
50
|
|
51
|
if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true;
|
52
|
}
|
53
|
|
54
|
return false;
|
55
|
}
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
TwistyObject createObject(int mode, float size)
|
60
|
{
|
61
|
float[][] pos = getCubitPositions();
|
62
|
InitData data = new InitData( mSize,pos);
|
63
|
return new TwistyBandagedCuboid( TwistyObject.MESH_NICE, mode, ShapeHexahedron.DEFAULT_ROT, new Static3D(0,0,0), size, data, null );
|
64
|
}
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
boolean tryChangeObject(int x, int y, int z)
|
69
|
{
|
70
|
if( mSize[0]!=x || mSize[1]!=y || mSize[2]!=z )
|
71
|
{
|
72
|
mSize[0] = x;
|
73
|
mSize[1] = y;
|
74
|
mSize[2] = z;
|
75
|
mMax = x>y ? Math.max(x,z) : Math.max(y,z);
|
76
|
mNumCubits = ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2);
|
77
|
return true;
|
78
|
}
|
79
|
|
80
|
return false;
|
81
|
}
|
82
|
|
83
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84
|
|
85
|
int computeProjectionAngle()
|
86
|
{
|
87
|
float quot1 = mSize[2]/ (float)mSize[0];
|
88
|
float quot2 = mSize[2]/ (float)mSize[1];
|
89
|
float quot3 = mSize[0]/ (float)mSize[2];
|
90
|
float quot4 = mSize[0]/ (float)mSize[1];
|
91
|
|
92
|
float quot5 = Math.max(quot1,quot2);
|
93
|
float quot6 = Math.max(quot3,quot4);
|
94
|
float quot7 = Math.max(quot5,quot6);
|
95
|
|
96
|
if( quot7<=1.0f ) return 120;
|
97
|
else if( quot7<=1.5f ) return 90;
|
98
|
else if( quot7<=2.0f ) return 60;
|
99
|
else return 30;
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
|
104
|
float[] getDist3D()
|
105
|
{
|
106
|
float max = mMax;
|
107
|
|
108
|
float x = 0.5f*(mSize[0]/max);
|
109
|
float y = 0.5f*(mSize[1]/max);
|
110
|
float z = 0.5f*(mSize[2]/max);
|
111
|
|
112
|
return new float[] {x,x,y,y,z,z};
|
113
|
}
|
114
|
|
115
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116
|
|
117
|
float getDist2D()
|
118
|
{
|
119
|
return 0.5f;
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
MeshBase createMesh(float[] pos, boolean round)
|
125
|
{
|
126
|
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance();
|
127
|
int[] size = getSize();
|
128
|
return factory.createMesh(pos,size[0],size[1],size[2],false,round);
|
129
|
}
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
|
133
|
int[] getColors()
|
134
|
{
|
135
|
return ShapeHexahedron.FACE_COLORS;
|
136
|
}
|
137
|
|
138
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139
|
|
140
|
void createCubits(Static4D quatT, Static4D quatA, Static3D scale)
|
141
|
{
|
142
|
mCubits = new BandagedCubit[mNumCubits];
|
143
|
int c=0;
|
144
|
int sx = mSize[0];
|
145
|
int sy = mSize[1];
|
146
|
int sz = mSize[2];
|
147
|
|
148
|
float begX = 0.5f*(1-sx);
|
149
|
float begY = 0.5f*(1-sy);
|
150
|
float begZ = 0.5f*(1-sz);
|
151
|
|
152
|
for(int x=0; x<sx; x++)
|
153
|
for(int y=0; y<sy; y++)
|
154
|
for(int z=0; z<sz; z++)
|
155
|
if( x==0 || x==sx-1 || y==0 || y==sy-1 || z==0 || z==sz-1 )
|
156
|
{
|
157
|
float[] pos = new float[] { begX+x,begY+y,begZ+z };
|
158
|
mCubits[c] = new BandagedCubit(this,pos,quatT,quatA,scale,false);
|
159
|
c++;
|
160
|
}
|
161
|
}
|
162
|
|
163
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164
|
|
165
|
Static3D[] getFaceAxis()
|
166
|
{
|
167
|
return TouchControlHexahedron.FACE_AXIS;
|
168
|
}
|
169
|
|
170
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171
|
|
172
|
void stretchPoint(int face, float[] output)
|
173
|
{
|
174
|
float max = getMaxSize();
|
175
|
|
176
|
switch(face/2)
|
177
|
{
|
178
|
case 0: output[0] *= (max/mSize[2]); output[1] *= (max/mSize[1]); break;
|
179
|
case 1: output[0] *= (max/mSize[0]); output[1] *= (max/mSize[2]); break;
|
180
|
case 2: output[0] *= (max/mSize[0]); output[1] *= (max/mSize[1]); break;
|
181
|
}
|
182
|
}
|
183
|
|
184
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185
|
|
186
|
int whichCubitTouched(int face, float pointX, float pointY)
|
187
|
{
|
188
|
float x = mSize[0];
|
189
|
float y = mSize[1];
|
190
|
float z = mSize[2];
|
191
|
|
192
|
switch(face)
|
193
|
{
|
194
|
case 0: mPos[0] = (x-1)/2;
|
195
|
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2;
|
196
|
mPos[2] = (int)(-z*pointX-z/2)+(z-1)/2;
|
197
|
break;
|
198
|
case 1: mPos[0] =-(x-1)/2;
|
199
|
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2;
|
200
|
mPos[2] = (int)( z*pointX+z/2)-(z-1)/2;
|
201
|
break;
|
202
|
case 2: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2;
|
203
|
mPos[1] = (y-1)/2;
|
204
|
mPos[2] = (int)(-z*pointY-z/2)+(z-1)/2;
|
205
|
break;
|
206
|
case 3: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2;
|
207
|
mPos[1] =-(y-1)/2;
|
208
|
mPos[2] = (int)( z*pointY+z/2)-(z-1)/2;
|
209
|
break;
|
210
|
case 4: mPos[0] = (int)( x*pointX+x/2)-(x-1)/2;
|
211
|
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2;
|
212
|
mPos[2] = (z-1)/2;
|
213
|
break;
|
214
|
case 5: mPos[0] = (int)(-x*pointX-x/2)+(x-1)/2;
|
215
|
mPos[1] = (int)( y*pointY+y/2)-(y-1)/2;
|
216
|
mPos[2] =-(z-1)/2;
|
217
|
break;
|
218
|
}
|
219
|
|
220
|
for(int c=0; c<mNumCubits; c++)
|
221
|
if( mCubits[c].isAttached() )
|
222
|
{
|
223
|
float[] pos = mCubits[c].getPosition();
|
224
|
int len = pos.length/3;
|
225
|
|
226
|
for(int p=0; p<len; p++)
|
227
|
if( pos[3*p]==mPos[0] && pos[3*p+1]==mPos[1] && pos[3*p+2]==mPos[2] ) return c;
|
228
|
}
|
229
|
|
230
|
android.util.Log.e("D", "whichCubitTouched: IMPOSSIBLE!!");
|
231
|
return -1;
|
232
|
}
|
233
|
|
234
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
235
|
|
236
|
boolean isInsideFace(int face, float[] p)
|
237
|
{
|
238
|
return ( p[0]<=mDist2D && p[0]>=-mDist2D && p[1]<=mDist2D && p[1]>=-mDist2D );
|
239
|
}
|
240
|
}
|