1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.objects;
|
21
|
|
22
|
import android.content.res.Resources;
|
23
|
|
24
|
import org.distorted.helpers.FactoryCubit;
|
25
|
import org.distorted.library.main.DistortedEffects;
|
26
|
import org.distorted.library.main.DistortedTexture;
|
27
|
import org.distorted.library.mesh.MeshBase;
|
28
|
import org.distorted.library.mesh.MeshSquare;
|
29
|
import org.distorted.library.type.Static3D;
|
30
|
import org.distorted.library.type.Static4D;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
abstract class TwistySquare extends TwistyObject
|
35
|
{
|
36
|
static final int LAST_SL = 0; // automatic rotations: last rot was a 'slash' i.e. along ROT_AXIS[1]
|
37
|
static final int LAST_UP = 1; // last rot was along ROT_AXIS[0], upper layer and forelast was a slash
|
38
|
static final int LAST_LO = 2; // last rot was along ROT_AXIS[0], lower layer and forelast was a slash
|
39
|
static final int LAST_UL = 3; // two last rots were along ROT_AXIS[0] (so the next must be a slash)
|
40
|
|
41
|
static final float COS15 = (SQ6+SQ2)/4;
|
42
|
static final float SIN15 = (SQ6-SQ2)/4;
|
43
|
static final float X = 3*(2-SQ3)/2;
|
44
|
|
45
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
46
|
{
|
47
|
new Static3D(0,1,0),
|
48
|
new Static3D(COS15,0,SIN15)
|
49
|
};
|
50
|
|
51
|
static final int[] BASIC_ANGLE = new int[] { 12,2 };
|
52
|
|
53
|
static final int[] FACE_COLORS = new int[]
|
54
|
{
|
55
|
COLOR_YELLOW, COLOR_WHITE,
|
56
|
COLOR_BLUE , COLOR_GREEN,
|
57
|
COLOR_RED , COLOR_ORANGE
|
58
|
};
|
59
|
|
60
|
static final Static4D[] QUATS = new Static4D[]
|
61
|
{
|
62
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
63
|
new Static4D( 0.0f, SIN15, 0.0f, COS15 ),
|
64
|
new Static4D( 0.0f, 0.5f, 0.0f, SQ3/2 ),
|
65
|
new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2 ),
|
66
|
new Static4D( 0.0f, SQ3/2, 0.0f, 0.5f ),
|
67
|
new Static4D( 0.0f, COS15, 0.0f, SIN15 ),
|
68
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
69
|
new Static4D( 0.0f, COS15, 0.0f,-SIN15 ),
|
70
|
new Static4D( 0.0f, SQ3/2, 0.0f, -0.5f ),
|
71
|
new Static4D( 0.0f, SQ2/2, 0.0f,-SQ2/2 ),
|
72
|
new Static4D( 0.0f, 0.5f, 0.0f,-SQ3/2 ),
|
73
|
new Static4D( 0.0f, SIN15, 0.0f,-COS15 ),
|
74
|
|
75
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
76
|
new Static4D( COS15, 0.0f, SIN15, 0.0f ),
|
77
|
new Static4D( SQ3/2, 0.0f, 0.5f, 0.0f ),
|
78
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f ),
|
79
|
new Static4D( 0.5f, 0.0f, SQ3/2, 0.0f ),
|
80
|
new Static4D( SIN15, 0.0f, COS15, 0.0f ),
|
81
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
82
|
new Static4D(-SIN15, 0.0f, COS15, 0.0f ),
|
83
|
new Static4D( -0.5f, 0.0f, SQ3/2, 0.0f ),
|
84
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f ),
|
85
|
new Static4D(-SQ3/2, 0.0f, 0.5f, 0.0f ),
|
86
|
new Static4D(-COS15, 0.0f, SIN15, 0.0f )
|
87
|
};
|
88
|
|
89
|
static final double[][] VERTICES_MIDDLE = new double[][]
|
90
|
{
|
91
|
{ -1.5-X, 0.5, 1.5 },
|
92
|
{ 0.0, 0.5, 1.5 },
|
93
|
{ 0.0, 0.5,-1.5 },
|
94
|
{ -1.5+X, 0.5,-1.5 },
|
95
|
{ -1.5-X,-0.5, 1.5 },
|
96
|
{ 0.0,-0.5, 1.5 },
|
97
|
{ 0.0,-0.5,-1.5 },
|
98
|
{ -1.5+X,-0.5,-1.5 }
|
99
|
};
|
100
|
|
101
|
static final int[][] VERT_INDEXES_MIDDLE = new int[][]
|
102
|
{
|
103
|
{0,1,2,3}, // counterclockwise!
|
104
|
{4,5,6,7},
|
105
|
{4,5,1,0},
|
106
|
{5,6,2,1},
|
107
|
{6,7,3,2},
|
108
|
{7,4,0,3}
|
109
|
};
|
110
|
|
111
|
static final double[][] VERTICES_EDGE = new double[][]
|
112
|
{
|
113
|
{ -X, 0.5, 0.0 },
|
114
|
{ +X, 0.5, 0.0 },
|
115
|
{0.0, 0.5,-1.5 },
|
116
|
{ -X,-0.5, 0.0 },
|
117
|
{ +X,-0.5, 0.0 },
|
118
|
{0.0,-0.5,-1.5 },
|
119
|
};
|
120
|
|
121
|
static final int[][] VERT_INDEXES_EDGE = new int[][]
|
122
|
{
|
123
|
{0,1,2}, // counterclockwise!
|
124
|
{3,4,5},
|
125
|
{3,4,1,0},
|
126
|
{4,5,2,1},
|
127
|
{5,3,0,2}
|
128
|
};
|
129
|
|
130
|
// QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
|
131
|
static final int[][] QUAT_MULT = new int[][]
|
132
|
{
|
133
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
|
134
|
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
|
135
|
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
|
136
|
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
|
137
|
{ 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
|
138
|
{ 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
|
139
|
{ 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
|
140
|
{ 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
|
141
|
{ 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
|
142
|
{ 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
|
143
|
{ 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
|
144
|
{ 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
|
145
|
{ 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,},
|
146
|
{ 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,},
|
147
|
{ 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3,},
|
148
|
{ 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4,},
|
149
|
{ 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5,},
|
150
|
{ 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6,},
|
151
|
{ 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7,},
|
152
|
{ 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8,},
|
153
|
{ 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9,},
|
154
|
{ 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10,},
|
155
|
{ 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11,},
|
156
|
{ 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,}
|
157
|
};
|
158
|
|
159
|
int mLastRot;
|
160
|
|
161
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162
|
|
163
|
TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
164
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
165
|
{
|
166
|
super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
167
|
}
|
168
|
|
169
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
170
|
|
171
|
MeshBase createMiddleCubitMesh()
|
172
|
{
|
173
|
if( mMeshes[0]==null )
|
174
|
{
|
175
|
float[][] bands= new float[][]
|
176
|
{
|
177
|
{0.040f,35,0.8f,1.0f,5,2,1},
|
178
|
{0.020f,35,0.8f,1.0f,5,2,1},
|
179
|
{0.001f,35,0.8f,1.0f,5,2,1}
|
180
|
};
|
181
|
int[] bandIndexes = new int[] { 2,2,1,1,0,2 };
|
182
|
float[][] corners = new float[][] { {0.03f,0.05f} };
|
183
|
int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
184
|
float[][] centers = new float[][] { { -0.75f, 0.0f, 0.0f} };
|
185
|
int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
186
|
|
187
|
FactoryCubit factory = FactoryCubit.getInstance();
|
188
|
factory.createNewFaceTransform(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE);
|
189
|
mMeshes[0] = factory.createRoundedSolid(VERTICES_MIDDLE, VERT_INDEXES_MIDDLE,
|
190
|
bands, bandIndexes,
|
191
|
corners, cornerIndexes,
|
192
|
centers, centerIndexes,
|
193
|
getNumCubitFaces(), null );
|
194
|
}
|
195
|
|
196
|
return mMeshes[0].copy(true);
|
197
|
}
|
198
|
|
199
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200
|
|
201
|
MeshBase createEdgeCubitMesh()
|
202
|
{
|
203
|
if( mMeshes[1]==null )
|
204
|
{
|
205
|
float[][] bands= new float[][]
|
206
|
{
|
207
|
{0.038f,35,0.5f,0.9f, 5,2,1},
|
208
|
{0.001f,35,0.5f,0.9f, 5,2,1}
|
209
|
};
|
210
|
int[] bandIndexes = new int[] { 0,1,0,1,1 };
|
211
|
float[][] corners = new float[][] { {0.04f,0.15f} };
|
212
|
int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
|
213
|
float[][] centers = new float[][] { { 0.0f, 0.0f,-0.5f} };
|
214
|
int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
|
215
|
|
216
|
FactoryCubit factory = FactoryCubit.getInstance();
|
217
|
factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
|
218
|
mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
|
219
|
bands, bandIndexes,
|
220
|
corners, cornerIndexes,
|
221
|
centers, centerIndexes,
|
222
|
getNumCubitFaces(), null );
|
223
|
}
|
224
|
return mMeshes[1].copy(true);
|
225
|
}
|
226
|
|
227
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
228
|
|
229
|
Static4D[] getQuats()
|
230
|
{
|
231
|
return QUATS;
|
232
|
}
|
233
|
|
234
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
235
|
|
236
|
boolean shouldResetTextureMaps()
|
237
|
{
|
238
|
return false;
|
239
|
}
|
240
|
|
241
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
242
|
|
243
|
int getNumFaces()
|
244
|
{
|
245
|
return FACE_COLORS.length;
|
246
|
}
|
247
|
|
248
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249
|
|
250
|
int getNumCubitFaces()
|
251
|
{
|
252
|
return 6;
|
253
|
}
|
254
|
|
255
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256
|
|
257
|
float getScreenRatio()
|
258
|
{
|
259
|
return 0.5f;
|
260
|
}
|
261
|
|
262
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
263
|
|
264
|
float returnMultiplier()
|
265
|
{
|
266
|
return 1.0f;
|
267
|
}
|
268
|
|
269
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
270
|
|
271
|
float[][] getCuts(int numLayers)
|
272
|
{
|
273
|
return new float[][] { {-0.5f,+0.5f}, {0.0f} };
|
274
|
}
|
275
|
|
276
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
277
|
|
278
|
int getColor(int face)
|
279
|
{
|
280
|
return FACE_COLORS[face];
|
281
|
}
|
282
|
|
283
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
284
|
// PUBLIC API
|
285
|
|
286
|
public Static3D[] getRotationAxis()
|
287
|
{
|
288
|
return ROT_AXIS;
|
289
|
}
|
290
|
|
291
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
292
|
|
293
|
public int[] getBasicAngle()
|
294
|
{
|
295
|
return BASIC_ANGLE;
|
296
|
}
|
297
|
}
|