1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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.objects;
|
11
|
|
12
|
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
|
13
|
|
14
|
import org.distorted.library.type.Static3D;
|
15
|
import org.distorted.library.type.Static4D;
|
16
|
import org.distorted.objectlib.helpers.ObjectShape;
|
17
|
import org.distorted.objectlib.metadata.Metadata;
|
18
|
import org.distorted.objectlib.signature.ObjectSignature;
|
19
|
import org.distorted.objectlib.main.InitAssets;
|
20
|
import org.distorted.objectlib.shape.ShapeHexahedron;
|
21
|
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
22
|
|
23
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24
|
|
25
|
public abstract class TwistyBandagedAbstract extends ShapeHexahedron
|
26
|
{
|
27
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
28
|
{
|
29
|
new Static3D(1,0,0),
|
30
|
new Static3D(0,1,0),
|
31
|
new Static3D(0,0,1)
|
32
|
};
|
33
|
|
34
|
private int[][] mBasicAngle;
|
35
|
private float[][] mCuts;
|
36
|
private int[][] mSolvedQuatsAbstract;
|
37
|
|
38
|
protected ObjectShape[] mTmpShapes;
|
39
|
protected int mNumVariants;
|
40
|
protected float[][] mPosition;
|
41
|
protected ObjectSignature mSignature;
|
42
|
|
43
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44
|
|
45
|
public TwistyBandagedAbstract(int iconMode, float size, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
|
46
|
{
|
47
|
super(iconMode, size, quat, move, scale, meta, asset);
|
48
|
}
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
|
52
|
boolean isAShapeshifter(int[] numLayers)
|
53
|
{
|
54
|
int x = numLayers[0];
|
55
|
int y = numLayers[1];
|
56
|
int z = numLayers[2];
|
57
|
|
58
|
return ( (((x-y)%2)==0 && x!=y) || (((x-z)%2)==0 && x!=z) || (((y-z)%2)==0 && y!=z) );
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
@Override
|
64
|
public int getInternalColor()
|
65
|
{
|
66
|
int[] numL = getNumLayers();
|
67
|
return isAShapeshifter(numL) ? 0xff333333 : 0xff000000;
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
// return 0 if cubit is 'external' (it has at least two walls which belong to two different faces
|
72
|
// of the cuboid, faces which do not both rotate along the same axis! So: it is an edge, a corner,
|
73
|
// or a bandaged cubit which 'comes out' in two different, non-opposite, faces.
|
74
|
// Otherwise, if the cubit only comes out in one face or in two faces which are opposite to each other,
|
75
|
// return the index of the first of the three quats which rotate stuff in this face (so right or left
|
76
|
// return 1 because quats 1,2,3 are the ones rotating along the X axis)
|
77
|
|
78
|
private int cubitIsExternal(float[] pos, float dx, float dy, float dz)
|
79
|
{
|
80
|
int len = pos.length/3;
|
81
|
int x=0, y=0, z=0;
|
82
|
|
83
|
for(int i=0; i<len; i++)
|
84
|
{
|
85
|
float cx = pos[3*i ];
|
86
|
float cy = pos[3*i+1];
|
87
|
float cz = pos[3*i+2];
|
88
|
|
89
|
if( cx>dx || cx<-dx ) x=1;
|
90
|
if( cy>dy || cy<-dy ) y=1;
|
91
|
if( cz>dz || cz<-dz ) z=1;
|
92
|
}
|
93
|
|
94
|
if( x+y+z>=2 ) return 0;
|
95
|
|
96
|
if( x==1 ) return 1;
|
97
|
if( y==1 ) return 4;
|
98
|
if( z==1 ) return 7;
|
99
|
|
100
|
android.util.Log.e("D", "ERROR: unsupported: internal cubit! ");
|
101
|
return 0;
|
102
|
}
|
103
|
|
104
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105
|
|
106
|
float[][] getPositions()
|
107
|
{
|
108
|
if( mPosition==null ) mPosition = getMetadata().getPos();
|
109
|
return mPosition;
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
|
114
|
public float[][] getCuts(int[] numLayers)
|
115
|
{
|
116
|
if( mCuts==null )
|
117
|
{
|
118
|
mCuts = new float[3][];
|
119
|
|
120
|
for(int axis=0; axis<3; axis++)
|
121
|
{
|
122
|
int len = numLayers[axis];
|
123
|
float start = (2-len)*0.5f;
|
124
|
|
125
|
if( len>=2 )
|
126
|
{
|
127
|
mCuts[axis] = new float[len-1];
|
128
|
for(int i=0; i<len-1; i++) mCuts[axis][i] = start+i;
|
129
|
}
|
130
|
}
|
131
|
}
|
132
|
|
133
|
return mCuts;
|
134
|
}
|
135
|
|
136
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
137
|
|
138
|
public boolean[][] getLayerRotatable(int[] numLayers)
|
139
|
{
|
140
|
int numAxis = ROT_AXIS.length;
|
141
|
boolean[][] layerRotatable = new boolean[numAxis][];
|
142
|
|
143
|
for(int i=0; i<numAxis; i++)
|
144
|
{
|
145
|
layerRotatable[i] = new boolean[numLayers[i]];
|
146
|
for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
|
147
|
}
|
148
|
|
149
|
if( isAShapeshifter(numLayers) && (numLayers[0]==1 || numLayers[1]==1 || numLayers[2]==1) )
|
150
|
{
|
151
|
for(int i=0; i<numAxis; i++)
|
152
|
{
|
153
|
if( (numLayers[i]%2)==1 )
|
154
|
{
|
155
|
int mid = (numLayers[i]-1)/2;
|
156
|
layerRotatable[i][mid] = false;
|
157
|
}
|
158
|
}
|
159
|
}
|
160
|
|
161
|
return layerRotatable;
|
162
|
}
|
163
|
|
164
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165
|
|
166
|
public int getTouchControlSplit()
|
167
|
{
|
168
|
return TYPE_NOT_SPLIT;
|
169
|
}
|
170
|
|
171
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
172
|
|
173
|
public int[][][] getEnabled()
|
174
|
{
|
175
|
return new int[][][] { {{1,2}},{{1,2}},{{0,2}},{{0,2}},{{0,1}},{{0,1}} };
|
176
|
}
|
177
|
|
178
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
179
|
|
180
|
public Static3D[] getFaceAxis()
|
181
|
{
|
182
|
return TouchControlHexahedron.FACE_AXIS;
|
183
|
}
|
184
|
|
185
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186
|
|
187
|
public float[][][] getStickerAngles()
|
188
|
{
|
189
|
return null;
|
190
|
}
|
191
|
|
192
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
193
|
|
194
|
public float[][] getCubitPositions(int[] numLayers)
|
195
|
{
|
196
|
return getPositions();
|
197
|
}
|
198
|
|
199
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200
|
|
201
|
public Static3D[] getRotationAxis()
|
202
|
{
|
203
|
return ROT_AXIS;
|
204
|
}
|
205
|
|
206
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
207
|
// switch off shape-shifting cuboids here - problems with scrambling.
|
208
|
|
209
|
private int basicAngle(int d1, int d2)
|
210
|
{
|
211
|
return d1==d2 ? 4 : 2;
|
212
|
}
|
213
|
|
214
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
215
|
|
216
|
public int[][] getBasicAngles()
|
217
|
{
|
218
|
if( mBasicAngle==null )
|
219
|
{
|
220
|
int[] num = getNumLayers();
|
221
|
int numX = num[0];
|
222
|
int numY = num[1];
|
223
|
int numZ = num[2];
|
224
|
|
225
|
int x = basicAngle(numY,numZ);
|
226
|
int y = basicAngle(numX,numZ);
|
227
|
int z = basicAngle(numX,numY);
|
228
|
|
229
|
int[] tmpX = new int[numX];
|
230
|
for(int i=0; i<numX; i++) tmpX[i] = x;
|
231
|
int[] tmpY = new int[numY];
|
232
|
for(int i=0; i<numY; i++) tmpY[i] = y;
|
233
|
int[] tmpZ = new int[numZ];
|
234
|
for(int i=0; i<numZ; i++) tmpZ[i] = z;
|
235
|
|
236
|
mBasicAngle = new int[][] { tmpX,tmpY,tmpZ };
|
237
|
}
|
238
|
|
239
|
return mBasicAngle;
|
240
|
}
|
241
|
}
|