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
|
import android.graphics.Canvas;
|
24
|
import android.graphics.Paint;
|
25
|
|
26
|
import org.distorted.helpers.FactoryCubit;
|
27
|
import org.distorted.helpers.FactorySticker;
|
28
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
29
|
import org.distorted.library.main.DistortedEffects;
|
30
|
import org.distorted.library.main.DistortedTexture;
|
31
|
import org.distorted.library.mesh.MeshBase;
|
32
|
import org.distorted.library.mesh.MeshSquare;
|
33
|
import org.distorted.library.type.Static3D;
|
34
|
import org.distorted.library.type.Static4D;
|
35
|
import org.distorted.main.R;
|
36
|
|
37
|
import java.util.Random;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
class TwistySquare2 extends TwistySquare
|
42
|
{
|
43
|
private static final float Y = 0.75f + X/2;
|
44
|
private static final float Z = 0.75f - X/2;
|
45
|
|
46
|
private static final int[] QUAT_NUMBER = new int[]
|
47
|
{
|
48
|
0, 6,
|
49
|
0, 9, 6, 3, 18, 15, 12, 21,
|
50
|
0, 9, 6, 3, 0, 9, 6, 3,
|
51
|
15, 12, 21, 18, 15, 12, 21, 18
|
52
|
};
|
53
|
|
54
|
// centers of the 2 middles + 8 edges + 8 left corners + 8 right corners
|
55
|
private static final float[][] CENTERS = new float[][]
|
56
|
{
|
57
|
{ 1.5f, 0.0f, 0.0f },
|
58
|
{-1.5f, 0.0f, 0.0f },
|
59
|
|
60
|
{ 0.0f, 1.0f, 1.5f },
|
61
|
{ 1.5f, 1.0f, 0.0f },
|
62
|
{ 0.0f, 1.0f,-1.5f },
|
63
|
{-1.5f, 1.0f, 0.0f },
|
64
|
{ 0.0f,-1.0f, 1.5f },
|
65
|
{ 1.5f,-1.0f, 0.0f },
|
66
|
{ 0.0f,-1.0f,-1.5f },
|
67
|
{-1.5f,-1.0f, 0.0f },
|
68
|
|
69
|
{ Y, 1.0f, 1.5f },
|
70
|
{ 1.5f, 1.0f, -Y },
|
71
|
{ -Y, 1.0f,-1.5f },
|
72
|
{-1.5f, 1.0f, Y },
|
73
|
{ Y,-1.0f, 1.5f },
|
74
|
{ 1.5f,-1.0f, -Y },
|
75
|
{ -Y,-1.0f,-1.5f },
|
76
|
{-1.5f,-1.0f, Y },
|
77
|
|
78
|
{ 1.5f, 1.0f, Y },
|
79
|
{ Y, 1.0f,-1.5f },
|
80
|
{-1.5f, 1.0f, -Y },
|
81
|
{ -Y, 1.0f, 1.5f },
|
82
|
{ 1.5f,-1.0f, Y },
|
83
|
{ Y,-1.0f,-1.5f },
|
84
|
{-1.5f,-1.0f, -Y },
|
85
|
{ -Y,-1.0f, 1.5f },
|
86
|
};
|
87
|
|
88
|
private static final double[][] VERTICES_CORNER = new double[][]
|
89
|
{
|
90
|
{ X-1.5+Z, 0.5, 0.0 },
|
91
|
{ Z, 0.5, 0.0 },
|
92
|
{ -1.5+Z, 0.5, -1.5 },
|
93
|
{ X-1.5+Z,-0.5, 0.0 },
|
94
|
{ Z,-0.5, 0.0 },
|
95
|
{ -1.5+Z,-0.5, -1.5 }
|
96
|
};
|
97
|
|
98
|
private static final int[][] VERT_INDEXES_CORNER = new int[][]
|
99
|
{
|
100
|
{0,1,2}, // counterclockwise!
|
101
|
{5,4,3},
|
102
|
{3,4,1,0},
|
103
|
{4,5,2,1},
|
104
|
{5,3,0,2}
|
105
|
};
|
106
|
|
107
|
private static final float[][] STICKERS = new float[][]
|
108
|
{
|
109
|
{ -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
|
110
|
{ -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
|
111
|
{ -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
|
112
|
{ -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f }, // edge top
|
113
|
{ -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
|
114
|
{ -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f } // corner top
|
115
|
};
|
116
|
|
117
|
private static final int NUM_ST = STICKERS.length;
|
118
|
|
119
|
private static final int[][] mStickerType = new int[][]
|
120
|
{
|
121
|
{ NUM_ST,NUM_ST,0, 1, 2,NUM_ST },
|
122
|
{ 3,NUM_ST,4,NUM_ST,NUM_ST,NUM_ST },
|
123
|
{ 5,NUM_ST,2,NUM_ST,NUM_ST,NUM_ST },
|
124
|
{ NUM_ST, 5,2,NUM_ST,NUM_ST,NUM_ST }
|
125
|
};
|
126
|
|
127
|
// YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
|
128
|
private static final int[][] mStickerColor = new int[][]
|
129
|
{
|
130
|
{ 0, 0, 4, 0, 5, 0 }, // 0
|
131
|
{ 0, 0, 5, 1, 4, 0 },
|
132
|
|
133
|
{ 2, 0, 4, 0, 0, 0 }, // 2
|
134
|
{ 2, 0, 0, 0, 0, 0 },
|
135
|
{ 2, 0, 5, 0, 0, 0 },
|
136
|
{ 2, 0, 1, 0, 0, 0 },
|
137
|
{ 3, 0, 4, 0, 0, 0 },
|
138
|
{ 3, 0, 0, 0, 0, 0 },
|
139
|
{ 3, 0, 5, 0, 0, 0 },
|
140
|
{ 3, 0, 1, 0, 0, 0 },
|
141
|
|
142
|
{ 2, 0, 4, 0, 0, 0 }, // 10
|
143
|
{ 2, 0, 0, 0, 0, 0 },
|
144
|
{ 2, 0, 5, 0, 0, 0 },
|
145
|
{ 2, 0, 1, 0, 0, 0 },
|
146
|
|
147
|
{ 0, 3, 4, 0, 0, 0 },
|
148
|
{ 0, 3, 0, 0, 0, 0 },
|
149
|
{ 0, 3, 5, 0, 0, 0 },
|
150
|
{ 0, 3, 1, 0, 0, 0 },
|
151
|
|
152
|
{ 0, 2, 0, 0, 0, 0 }, // 18
|
153
|
{ 0, 2, 5, 0, 0, 0 },
|
154
|
{ 0, 2, 1, 0, 0, 0 },
|
155
|
{ 0, 2, 4, 0, 0, 0 },
|
156
|
{ 3, 0, 0, 0, 0, 0 },
|
157
|
{ 3, 0, 5, 0, 0, 0 },
|
158
|
{ 3, 0, 1, 0, 0, 0 },
|
159
|
{ 3, 0, 4, 0, 0, 0 },
|
160
|
};
|
161
|
|
162
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163
|
|
164
|
TwistySquare2(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
165
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
166
|
{
|
167
|
super(size, quat, texture, mesh, effects, moves, ObjectList.SQU2, res, scrWidth);
|
168
|
|
169
|
FactoryCubit factory = FactoryCubit.getInstance();
|
170
|
factory.printStickerCoords();
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
private Static4D getQuat(int cubit)
|
176
|
{
|
177
|
return QUATS[QUAT_NUMBER[cubit]];
|
178
|
}
|
179
|
|
180
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181
|
|
182
|
MeshBase createCornerCubitMesh()
|
183
|
{
|
184
|
if( mMeshes[3]==null )
|
185
|
{
|
186
|
float[][] bands= new float[][]
|
187
|
{
|
188
|
{0.030f,35,0.9f,1.0f, 5,2,1},
|
189
|
{0.001f,35,0.9f,1.0f, 5,2,1}
|
190
|
};
|
191
|
int[] bandIndexes = new int[] { 0,0,0,1,1 };
|
192
|
float[][] corners = new float[][] { {0.05f,0.13f} };
|
193
|
int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
|
194
|
float[][] centers = new float[][] { { 0.0f, 0.0f,-0.5f} };
|
195
|
int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
|
196
|
|
197
|
FactoryCubit factory = FactoryCubit.getInstance();
|
198
|
factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
|
199
|
mMeshes[3] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
|
200
|
bands, bandIndexes,
|
201
|
corners, cornerIndexes,
|
202
|
centers, centerIndexes,
|
203
|
getNumCubitFaces() );
|
204
|
}
|
205
|
return mMeshes[3].copy(true);
|
206
|
}
|
207
|
|
208
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
209
|
|
210
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
211
|
{
|
212
|
if( mMeshes==null )
|
213
|
{
|
214
|
FactoryCubit factory = FactoryCubit.getInstance();
|
215
|
factory.clear();
|
216
|
mMeshes = new MeshBase[4];
|
217
|
}
|
218
|
|
219
|
MeshBase mesh;
|
220
|
|
221
|
if( cubit< 2 ) mesh = createMiddleCubitMesh();
|
222
|
else if( cubit<10 ) mesh = createEdgeCubitMesh();
|
223
|
else mesh = createCornerCubitMesh();
|
224
|
|
225
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
|
226
|
mesh.apply(quat,0xffffffff,0);
|
227
|
|
228
|
return mesh;
|
229
|
}
|
230
|
|
231
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232
|
|
233
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
|
234
|
{
|
235
|
int COLORS = FACE_COLORS.length;
|
236
|
int stickerType = face/COLORS;
|
237
|
float R,S;
|
238
|
|
239
|
switch(stickerType)
|
240
|
{
|
241
|
case 0: R = 0.060f; S = 0.05f; break;
|
242
|
case 1: R = 0.040f; S = 0.04f; break;
|
243
|
case 2: R = 0.110f; S = 0.09f; break;
|
244
|
case 3: R = 0.030f; S = 0.05f; break;
|
245
|
case 4: R = 0.110f; S = 0.08f; break;
|
246
|
case 5: R = 0.025f; S = 0.06f; break;
|
247
|
default: R = 0.000f; S = 0.00f; break;
|
248
|
}
|
249
|
|
250
|
FactorySticker factory = FactorySticker.getInstance();
|
251
|
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[stickerType], S, FACE_COLORS[face%COLORS], R);
|
252
|
}
|
253
|
|
254
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
255
|
|
256
|
float[][] getCubitPositions(int numLayers)
|
257
|
{
|
258
|
return CENTERS;
|
259
|
}
|
260
|
|
261
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
262
|
|
263
|
int getNumStickerTypes(int numLayers)
|
264
|
{
|
265
|
return STICKERS.length;
|
266
|
}
|
267
|
|
268
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
269
|
|
270
|
int getFaceColor(int cubit, int cubitface, int numLayers)
|
271
|
{
|
272
|
int type;
|
273
|
|
274
|
if( cubit< 2 ) type = 0;
|
275
|
else if( cubit<10 ) type = 1;
|
276
|
else if( cubit>13 && cubit<22 ) type = 3;
|
277
|
else type = 2;
|
278
|
|
279
|
return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
|
280
|
}
|
281
|
|
282
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
283
|
// PUBLIC API
|
284
|
|
285
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
|
286
|
{
|
287
|
int layer, nextAngle;
|
288
|
|
289
|
if( num==0 ) mLastRot = rnd.nextInt(4);
|
290
|
|
291
|
switch(mLastRot)
|
292
|
{
|
293
|
case LAST_SL: layer = rnd.nextInt(2);
|
294
|
nextAngle = rnd.nextInt(12)-6;
|
295
|
|
296
|
if( nextAngle==0 )
|
297
|
{
|
298
|
layer = 1-layer;
|
299
|
nextAngle = (2*rnd.nextInt(2)-1)*(rnd.nextInt(5)+1);
|
300
|
}
|
301
|
|
302
|
scramble[num][0] = 0;
|
303
|
scramble[num][1] = 2*layer;
|
304
|
scramble[num][2] = nextAngle;
|
305
|
mLastRot = layer==0 ? LAST_LO : LAST_UP;
|
306
|
break;
|
307
|
case LAST_LO:
|
308
|
case LAST_UP: layer = mLastRot==LAST_LO ? 1:0;
|
309
|
nextAngle = rnd.nextInt(12)-6;
|
310
|
|
311
|
if( nextAngle!=0 )
|
312
|
{
|
313
|
scramble[num][0] = 0;
|
314
|
scramble[num][1] = 2*layer;
|
315
|
scramble[num][2] = nextAngle;
|
316
|
mLastRot = LAST_UL;
|
317
|
}
|
318
|
else
|
319
|
{
|
320
|
scramble[num][0] = 1;
|
321
|
scramble[num][1] = rnd.nextInt(2);
|
322
|
scramble[num][2] = 1;
|
323
|
mLastRot = LAST_SL;
|
324
|
}
|
325
|
break;
|
326
|
case LAST_UL: scramble[num][0] = 1;
|
327
|
scramble[num][1] = rnd.nextInt(2);
|
328
|
scramble[num][2] = 1;
|
329
|
mLastRot = LAST_SL;
|
330
|
break;
|
331
|
}
|
332
|
}
|
333
|
|
334
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
335
|
|
336
|
public int getObjectName(int numLayers)
|
337
|
{
|
338
|
return R.string.squa2;
|
339
|
}
|
340
|
|
341
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
342
|
|
343
|
public int getInventor(int numLayers)
|
344
|
{
|
345
|
return R.string.squa2_inventor;
|
346
|
}
|
347
|
|
348
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
349
|
|
350
|
public int getComplexity(int numLayers)
|
351
|
{
|
352
|
return 7;
|
353
|
}
|
354
|
}
|