1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 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.ObjectShape;
|
25
|
import org.distorted.helpers.ObjectSticker;
|
26
|
import org.distorted.helpers.ScrambleState;
|
27
|
import org.distorted.library.main.DistortedEffects;
|
28
|
import org.distorted.library.main.DistortedTexture;
|
29
|
import org.distorted.library.mesh.MeshSquare;
|
30
|
import org.distorted.library.type.Static3D;
|
31
|
import org.distorted.library.type.Static4D;
|
32
|
import org.distorted.main.R;
|
33
|
|
34
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35
|
|
36
|
public class TwistyHelicopter extends Twisty6
|
37
|
{
|
38
|
// the six rotation axis of a Helicopter. Must be normalized.
|
39
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
40
|
{
|
41
|
new Static3D( 0, +SQ2/2, -SQ2/2),
|
42
|
new Static3D( 0, -SQ2/2, -SQ2/2),
|
43
|
new Static3D(+SQ2/2, 0, -SQ2/2),
|
44
|
new Static3D(-SQ2/2, 0, -SQ2/2),
|
45
|
new Static3D(+SQ2/2, -SQ2/2, 0),
|
46
|
new Static3D(-SQ2/2, -SQ2/2, 0)
|
47
|
};
|
48
|
|
49
|
private ScrambleState[] mStates;
|
50
|
private int[] mBasicAngle;
|
51
|
private Static4D[] mQuats;
|
52
|
private float[][] mCuts;
|
53
|
private boolean[][] mLayerRotatable;
|
54
|
private float[][] mCenters;
|
55
|
private int[] mQuatIndices;
|
56
|
private int[][] mFaceMap;
|
57
|
private ObjectSticker[] mStickers;
|
58
|
private Movement mMovement;
|
59
|
|
60
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61
|
|
62
|
TwistyHelicopter(int size, Static4D quat, DistortedTexture texture,
|
63
|
MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
64
|
{
|
65
|
super(size, size, quat, texture, mesh, effects, moves, ObjectList.HELI, res, scrWidth);
|
66
|
}
|
67
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
|
70
|
ScrambleState[] getScrambleStates()
|
71
|
{
|
72
|
if( mStates==null )
|
73
|
{
|
74
|
mStates = new ScrambleState[]
|
75
|
{
|
76
|
new ScrambleState( new int[][] { {0,1,1,2,1,2},{0,1,3,2,1,4},{0,1,5,2,1,6},{0,1,7,2,1,8},{0,1,9,2,1,10},{0,1,11,2,1,12} } ),
|
77
|
new ScrambleState( new int[][] { { },{ },{0,1,5 },{0,1,7 },{ 2,1,10},{ 2,1,12} } ),
|
78
|
new ScrambleState( new int[][] { { },{ },{ 2,1,6},{ 2,1,8},{0,1,9 },{0,1,11 } } ),
|
79
|
new ScrambleState( new int[][] { { },{ },{0,1,5 },{0,1,7 },{0,1,9 },{0,1,11 } } ),
|
80
|
new ScrambleState( new int[][] { { },{ },{ 2,1,6},{ 2,1,8},{ 2,1,10},{ 2,1,12} } ),
|
81
|
new ScrambleState( new int[][] { {0,1,1 },{0,1,3 },{ },{ },{0,1,9 },{ 2,1,12} } ),
|
82
|
new ScrambleState( new int[][] { { 2,1,2},{ 2,1,4},{ },{ },{ 2,1,10},{0,1,11 } } ),
|
83
|
new ScrambleState( new int[][] { {0,1,1 },{0,1,3 },{ },{ },{ 2,1,10},{0,1,11 } } ),
|
84
|
new ScrambleState( new int[][] { { 2,1,2},{ 2,1,4},{ },{ },{0,1,9 },{ 2,1,12} } ),
|
85
|
new ScrambleState( new int[][] { { 2,1,2},{0,1,3 },{0,1,5 },{ 2,1,8},{ },{ } } ),
|
86
|
new ScrambleState( new int[][] { {0,1,1 },{ 2,1,4},{ 2,1,6},{0,1,7 },{ },{ } } ),
|
87
|
new ScrambleState( new int[][] { { 2,1,2},{0,1,3 },{ 2,1,6},{0,1,7 },{ },{ } } ),
|
88
|
new ScrambleState( new int[][] { {0,1,1 },{ 2,1,4},{0,1,5 },{ 2,1,8},{ },{ } } ),
|
89
|
};
|
90
|
}
|
91
|
|
92
|
return mStates;
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
|
97
|
private void initializeQuats()
|
98
|
{
|
99
|
mQuats = new Static4D[]
|
100
|
{
|
101
|
new Static4D( 0.00f, 0.00f, 0.00f, 1.00f ),
|
102
|
new Static4D( 1.00f, 0.00f, 0.00f, 0.00f ),
|
103
|
new Static4D( 0.00f, 1.00f, 0.00f, 0.00f ),
|
104
|
new Static4D( 0.00f, 0.00f, 1.00f, 0.00f ),
|
105
|
|
106
|
new Static4D( SQ2/2, SQ2/2, 0.00f, 0.00f ),
|
107
|
new Static4D( SQ2/2, -SQ2/2, 0.00f, 0.00f ),
|
108
|
new Static4D( SQ2/2, 0.00f, SQ2/2, 0.00f ),
|
109
|
new Static4D( SQ2/2, 0.00f, -SQ2/2, 0.00f ),
|
110
|
new Static4D( SQ2/2, 0.00f, 0.00f, SQ2/2 ),
|
111
|
new Static4D( SQ2/2, 0.00f, 0.00f, -SQ2/2 ),
|
112
|
new Static4D( 0.00f, SQ2/2, SQ2/2, 0.00f ),
|
113
|
new Static4D( 0.00f, SQ2/2, -SQ2/2, 0.00f ),
|
114
|
new Static4D( 0.00f, SQ2/2, 0.00f, SQ2/2 ),
|
115
|
new Static4D( 0.00f, SQ2/2, 0.00f, -SQ2/2 ),
|
116
|
new Static4D( 0.00f, 0.00f, SQ2/2, SQ2/2 ),
|
117
|
new Static4D( 0.00f, 0.00f, SQ2/2, -SQ2/2 ),
|
118
|
|
119
|
new Static4D( 0.50f, 0.50f, 0.50f, 0.50f ),
|
120
|
new Static4D( 0.50f, 0.50f, 0.50f, -0.50f ),
|
121
|
new Static4D( 0.50f, 0.50f, -0.50f, 0.50f ),
|
122
|
new Static4D( 0.50f, 0.50f, -0.50f, -0.50f ),
|
123
|
new Static4D( 0.50f, -0.50f, 0.50f, 0.50f ),
|
124
|
new Static4D( 0.50f, -0.50f, 0.50f, -0.50f ),
|
125
|
new Static4D( 0.50f, -0.50f, -0.50f, 0.50f ),
|
126
|
new Static4D( 0.50f, -0.50f, -0.50f, -0.50f )
|
127
|
};
|
128
|
}
|
129
|
|
130
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131
|
|
132
|
int[] getSolvedQuats(int cubit, int numLayers)
|
133
|
{
|
134
|
if( mQuats==null ) initializeQuats();
|
135
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
136
|
return status<0 ? null : buildSolvedQuats(MovementHelicopter.FACE_AXIS[status],mQuats);
|
137
|
}
|
138
|
|
139
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140
|
|
141
|
Static4D[] getQuats()
|
142
|
{
|
143
|
if( mQuats==null ) initializeQuats();
|
144
|
return mQuats;
|
145
|
}
|
146
|
|
147
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148
|
|
149
|
int getSolvedFunctionIndex()
|
150
|
{
|
151
|
return 0;
|
152
|
}
|
153
|
|
154
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155
|
|
156
|
int getNumStickerTypes(int numLayers)
|
157
|
{
|
158
|
return 1;
|
159
|
}
|
160
|
|
161
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162
|
|
163
|
float[][] getCuts(int size)
|
164
|
{
|
165
|
if( mCuts==null )
|
166
|
{
|
167
|
float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
|
168
|
mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
|
169
|
}
|
170
|
|
171
|
return mCuts;
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
private void getLayerRotatable(int numLayers)
|
177
|
{
|
178
|
if( mLayerRotatable==null )
|
179
|
{
|
180
|
int numAxis = ROT_AXIS.length;
|
181
|
boolean[] tmp = new boolean[] {true,false,true};
|
182
|
mLayerRotatable = new boolean[numAxis][];
|
183
|
for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
|
184
|
}
|
185
|
}
|
186
|
|
187
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
188
|
|
189
|
int getNumCubitFaces()
|
190
|
{
|
191
|
return 4;
|
192
|
}
|
193
|
|
194
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195
|
|
196
|
float[][] getCubitPositions(int size)
|
197
|
{
|
198
|
if( mCenters==null )
|
199
|
{
|
200
|
float DIST_CORNER = 1.50f;
|
201
|
float DIST_CENTER = 1.50f;
|
202
|
float XY_CENTER = DIST_CORNER/3;
|
203
|
|
204
|
mCenters = new float[][]
|
205
|
{
|
206
|
{ DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
207
|
{ DIST_CORNER, DIST_CORNER, -DIST_CORNER },
|
208
|
{ DIST_CORNER, -DIST_CORNER, DIST_CORNER },
|
209
|
{ DIST_CORNER, -DIST_CORNER, -DIST_CORNER },
|
210
|
{ -DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
211
|
{ -DIST_CORNER, DIST_CORNER, -DIST_CORNER },
|
212
|
{ -DIST_CORNER, -DIST_CORNER, DIST_CORNER },
|
213
|
{ -DIST_CORNER, -DIST_CORNER, -DIST_CORNER },
|
214
|
|
215
|
{ DIST_CENTER, XY_CENTER, XY_CENTER },
|
216
|
{ DIST_CENTER, XY_CENTER, -XY_CENTER },
|
217
|
{ DIST_CENTER, -XY_CENTER, XY_CENTER },
|
218
|
{ DIST_CENTER, -XY_CENTER, -XY_CENTER },
|
219
|
|
220
|
{ -DIST_CENTER, XY_CENTER, XY_CENTER },
|
221
|
{ -DIST_CENTER, XY_CENTER, -XY_CENTER },
|
222
|
{ -DIST_CENTER, -XY_CENTER, XY_CENTER },
|
223
|
{ -DIST_CENTER, -XY_CENTER, -XY_CENTER },
|
224
|
|
225
|
{ XY_CENTER , DIST_CENTER, XY_CENTER },
|
226
|
{ XY_CENTER , DIST_CENTER, -XY_CENTER },
|
227
|
{ -XY_CENTER , DIST_CENTER, XY_CENTER },
|
228
|
{ -XY_CENTER , DIST_CENTER, -XY_CENTER },
|
229
|
|
230
|
{ XY_CENTER , -DIST_CENTER, XY_CENTER },
|
231
|
{ XY_CENTER , -DIST_CENTER, -XY_CENTER },
|
232
|
{ -XY_CENTER , -DIST_CENTER, XY_CENTER },
|
233
|
{ -XY_CENTER , -DIST_CENTER, -XY_CENTER },
|
234
|
|
235
|
{ XY_CENTER , XY_CENTER, DIST_CENTER },
|
236
|
{ XY_CENTER , -XY_CENTER, DIST_CENTER },
|
237
|
{ -XY_CENTER , XY_CENTER, DIST_CENTER },
|
238
|
{ -XY_CENTER , -XY_CENTER, DIST_CENTER },
|
239
|
|
240
|
{ XY_CENTER , XY_CENTER, -DIST_CENTER },
|
241
|
{ XY_CENTER , -XY_CENTER, -DIST_CENTER },
|
242
|
{ -XY_CENTER , XY_CENTER, -DIST_CENTER },
|
243
|
{ -XY_CENTER , -XY_CENTER, -DIST_CENTER },
|
244
|
};
|
245
|
}
|
246
|
|
247
|
return mCenters;
|
248
|
}
|
249
|
|
250
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
251
|
|
252
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
253
|
{
|
254
|
int variant = getCubitVariant(cubit,numLayers);
|
255
|
|
256
|
if( variant==0 )
|
257
|
{
|
258
|
double[][] vertices = new double[][]
|
259
|
{
|
260
|
{-1.50f, 0.00f, 0.00f},
|
261
|
{ 0.00f,-1.50f, 0.00f},
|
262
|
{ 0.00f, 0.00f,-1.50f},
|
263
|
{-0.75f,-0.75f,-0.75f},
|
264
|
{ 0.00f, 0.00f, 0.00f}
|
265
|
};
|
266
|
|
267
|
int[][] vert_indices = new int[][]
|
268
|
{
|
269
|
{0,1,4},
|
270
|
{2,0,4},
|
271
|
{1,2,4},
|
272
|
{3,1,0},
|
273
|
{3,2,1},
|
274
|
{3,0,2}
|
275
|
};
|
276
|
|
277
|
float[][] bands = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,5} };
|
278
|
int[] bandIndices = new int[] { 0,0,0,1,1,1 };
|
279
|
float[][] corners = new float[][] { {0.08f,0.20f} };
|
280
|
int[] cornerIndices = new int[] { 0,0,0,0,0 };
|
281
|
float[][] centers = new float[][] { {-0.75f, -0.75f, -0.75f} };
|
282
|
int[] centerIndices = new int[] { 0,0,0,-1,0 };
|
283
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
284
|
}
|
285
|
else
|
286
|
{
|
287
|
double[][] vertices = new double[][]
|
288
|
{
|
289
|
{ 0.50f, 0.50f, 0.00f },
|
290
|
{-1.00f, 0.50f, 0.00f },
|
291
|
{ 0.50f,-1.00f, 0.00f },
|
292
|
{-0.25f,-0.25f,-0.75f },
|
293
|
};
|
294
|
|
295
|
int[][] vert_indices = new int[][]
|
296
|
{
|
297
|
{ 0,1,2 },
|
298
|
{ 2,1,3 },
|
299
|
{ 0,1,3 },
|
300
|
{ 2,0,3 }
|
301
|
};
|
302
|
|
303
|
float[][] bands = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
|
304
|
int[] bandIndices = new int[] { 0,1,1,1 };
|
305
|
float[][] corners = new float[][] { {0.06f,0.20f} };
|
306
|
int[] cornerIndices = new int[] { 0,0,0,-1 };
|
307
|
float[][] centers = new float[][] { {-0.25f, -0.25f, -0.75f} };
|
308
|
int[] centerIndices = new int[] { 0,0,0,-1 };
|
309
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
310
|
}
|
311
|
}
|
312
|
|
313
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
314
|
|
315
|
Static4D getQuat(int cubit, int numLayers)
|
316
|
{
|
317
|
if( mQuats==null ) initializeQuats();
|
318
|
if( mQuatIndices==null ) mQuatIndices = new int[] { 0,13,14,1,12,2,3,7,20,6,13,17,7,23,18,12,22,10,8,16,11,21,19,9,3,15,14,0,5,2,1,4 };
|
319
|
return mQuats[mQuatIndices[cubit]];
|
320
|
}
|
321
|
|
322
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
323
|
|
324
|
int getNumCubitVariants(int numLayers)
|
325
|
{
|
326
|
return 2;
|
327
|
}
|
328
|
|
329
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
330
|
|
331
|
int getCubitVariant(int cubit, int numLayers)
|
332
|
{
|
333
|
return cubit<8 ? 0:1;
|
334
|
}
|
335
|
|
336
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
337
|
|
338
|
int getFaceColor(int cubit, int cubitface, int size)
|
339
|
{
|
340
|
if( mFaceMap==null )
|
341
|
{
|
342
|
mFaceMap = new int[][]
|
343
|
{
|
344
|
{ 4,2,0, 6,6,6 },
|
345
|
{ 0,2,5, 6,6,6 },
|
346
|
{ 4,0,3, 6,6,6 },
|
347
|
{ 5,3,0, 6,6,6 },
|
348
|
{ 1,2,4, 6,6,6 },
|
349
|
{ 5,2,1, 6,6,6 },
|
350
|
{ 4,3,1, 6,6,6 },
|
351
|
{ 1,3,5, 6,6,6 },
|
352
|
|
353
|
{ 0 , 6,6,6,6,6 },
|
354
|
{ 0 , 6,6,6,6,6 },
|
355
|
{ 0 , 6,6,6,6,6 },
|
356
|
{ 0 , 6,6,6,6,6 },
|
357
|
|
358
|
{ 1 , 6,6,6,6,6 },
|
359
|
{ 1 , 6,6,6,6,6 },
|
360
|
{ 1 , 6,6,6,6,6 },
|
361
|
{ 1 , 6,6,6,6,6 },
|
362
|
|
363
|
{ 2 , 6,6,6,6,6 },
|
364
|
{ 2 , 6,6,6,6,6 },
|
365
|
{ 2 , 6,6,6,6,6 },
|
366
|
{ 2 , 6,6,6,6,6 },
|
367
|
|
368
|
{ 3 , 6,6,6,6,6 },
|
369
|
{ 3 , 6,6,6,6,6 },
|
370
|
{ 3 , 6,6,6,6,6 },
|
371
|
{ 3 , 6,6,6,6,6 },
|
372
|
|
373
|
{ 4 , 6,6,6,6,6 },
|
374
|
{ 4 , 6,6,6,6,6 },
|
375
|
{ 4 , 6,6,6,6,6 },
|
376
|
{ 4 , 6,6,6,6,6 },
|
377
|
|
378
|
{ 5 , 6,6,6,6,6 },
|
379
|
{ 5 , 6,6,6,6,6 },
|
380
|
{ 5 , 6,6,6,6,6 },
|
381
|
{ 5 , 6,6,6,6,6 },
|
382
|
};
|
383
|
}
|
384
|
|
385
|
return mFaceMap[cubit][cubitface];
|
386
|
}
|
387
|
|
388
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
389
|
|
390
|
ObjectSticker retSticker(int face)
|
391
|
{
|
392
|
if( mStickers==null )
|
393
|
{
|
394
|
float[][] STICKERS = new float[][] { { -0.5f, 0.25f, 0.25f, -0.5f, 0.25f, 0.25f } };
|
395
|
float radius = 0.03f;
|
396
|
float stroke = 0.05f;
|
397
|
float[] radii = new float[] {radius,radius,radius};
|
398
|
mStickers = new ObjectSticker[STICKERS.length];
|
399
|
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
|
400
|
}
|
401
|
|
402
|
return mStickers[face/NUM_FACE_COLORS];
|
403
|
}
|
404
|
|
405
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
406
|
// PUBLIC API
|
407
|
|
408
|
public Static3D[] getRotationAxis()
|
409
|
{
|
410
|
return ROT_AXIS;
|
411
|
}
|
412
|
|
413
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
414
|
|
415
|
public Movement getMovement()
|
416
|
{
|
417
|
if( mMovement==null )
|
418
|
{
|
419
|
int numLayers = getNumLayers();
|
420
|
if( mCuts==null ) getCuts(numLayers);
|
421
|
getLayerRotatable(numLayers);
|
422
|
|
423
|
mMovement = new MovementHelicopter(mCuts,mLayerRotatable,numLayers);
|
424
|
}
|
425
|
return mMovement;
|
426
|
}
|
427
|
|
428
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
429
|
|
430
|
public int[] getBasicAngle()
|
431
|
{
|
432
|
if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
|
433
|
return mBasicAngle;
|
434
|
}
|
435
|
|
436
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
437
|
|
438
|
public int getObjectName(int numLayers)
|
439
|
{
|
440
|
return R.string.heli3;
|
441
|
}
|
442
|
|
443
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
444
|
|
445
|
public int getInventor(int numLayers)
|
446
|
{
|
447
|
return R.string.heli3_inventor;
|
448
|
}
|
449
|
|
450
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
451
|
|
452
|
public int getComplexity(int numLayers)
|
453
|
{
|
454
|
return 8;
|
455
|
}
|
456
|
}
|