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.objectlib.objects;
|
21
|
|
22
|
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
|
23
|
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
|
24
|
|
25
|
import java.io.InputStream;
|
26
|
|
27
|
import org.distorted.library.type.Static3D;
|
28
|
import org.distorted.library.type.Static4D;
|
29
|
|
30
|
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
31
|
import org.distorted.objectlib.main.ObjectControl;
|
32
|
import org.distorted.objectlib.main.ObjectType;
|
33
|
import org.distorted.objectlib.helpers.ObjectShape;
|
34
|
import org.distorted.objectlib.helpers.ScrambleState;
|
35
|
import org.distorted.objectlib.main.ShapeHexahedron;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
public class TwistyIvy extends ShapeHexahedron
|
40
|
{
|
41
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
42
|
{
|
43
|
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
|
44
|
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
|
45
|
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
|
46
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
47
|
};
|
48
|
|
49
|
public static final float IVY_D = 0.006f;
|
50
|
private static final int IVY_N = 8;
|
51
|
|
52
|
private ScrambleState[] mStates;
|
53
|
private int[] mBasicAngle;
|
54
|
private Static4D[] mQuats;
|
55
|
private float[][] mCuts;
|
56
|
private int[][] mFaceMap;
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
|
60
|
public TwistyIvy(int[] numL, int meshState, Static4D quat, Static3D move, float scale, InputStream stream)
|
61
|
{
|
62
|
super(numL, meshState, numL[0], quat, move, scale, stream);
|
63
|
}
|
64
|
|
65
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66
|
|
67
|
public ScrambleState[] getScrambleStates()
|
68
|
{
|
69
|
if( mStates==null )
|
70
|
{
|
71
|
int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
|
72
|
|
73
|
mStates = new ScrambleState[]
|
74
|
{
|
75
|
new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
|
76
|
};
|
77
|
}
|
78
|
|
79
|
return mStates;
|
80
|
}
|
81
|
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
|
84
|
private void initializeQuats()
|
85
|
{
|
86
|
mQuats = new Static4D[]
|
87
|
{
|
88
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
89
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
90
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
91
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
92
|
|
93
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ),
|
94
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
95
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f ),
|
96
|
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ),
|
97
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
98
|
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ),
|
99
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
100
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f )
|
101
|
};
|
102
|
}
|
103
|
|
104
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105
|
|
106
|
public int[] getSolvedQuats(int cubit, int[] numLayers)
|
107
|
{
|
108
|
if( mQuats==null ) initializeQuats();
|
109
|
int status = retCubitSolvedStatus(cubit,numLayers);
|
110
|
return status<0 ? null : buildSolvedQuats(TouchControlHexahedron.FACE_AXIS[status],mQuats);
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
public Static4D[] getQuats()
|
116
|
{
|
117
|
if( mQuats==null ) initializeQuats();
|
118
|
return mQuats;
|
119
|
}
|
120
|
|
121
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
122
|
|
123
|
public int getSolvedFunctionIndex()
|
124
|
{
|
125
|
return 0;
|
126
|
}
|
127
|
|
128
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129
|
|
130
|
public float[][] getCuts(int[] numLayers)
|
131
|
{
|
132
|
if( mCuts==null )
|
133
|
{
|
134
|
float[] cut = new float[] {0.0f};
|
135
|
mCuts = new float[][] { cut,cut,cut,cut };
|
136
|
}
|
137
|
|
138
|
return mCuts;
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
|
143
|
public boolean[][] getLayerRotatable(int[] numLayers)
|
144
|
{
|
145
|
int numAxis = ROT_AXIS.length;
|
146
|
boolean[][] layerRotatable = new boolean[numAxis][];
|
147
|
|
148
|
for(int i=0; i<numAxis; i++)
|
149
|
{
|
150
|
layerRotatable[i] = new boolean[numLayers[i]];
|
151
|
for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
|
152
|
}
|
153
|
|
154
|
return layerRotatable;
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
public int getTouchControlType()
|
160
|
{
|
161
|
return TC_HEXAHEDRON;
|
162
|
}
|
163
|
|
164
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165
|
|
166
|
public int getTouchControlSplit()
|
167
|
{
|
168
|
return TYPE_SPLIT_CORNER;
|
169
|
}
|
170
|
|
171
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
172
|
|
173
|
public int[][][] getEnabled()
|
174
|
{
|
175
|
return new int[][][]
|
176
|
{
|
177
|
{{0},{3},{3},{0}},
|
178
|
{{2},{1},{1},{2}},
|
179
|
{{2},{0},{0},{2}},
|
180
|
{{1},{3},{3},{1}},
|
181
|
{{0},{0},{1},{1}},
|
182
|
{{2},{2},{3},{3}},
|
183
|
};
|
184
|
}
|
185
|
|
186
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187
|
|
188
|
public float[] getDist3D(int[] numLayers)
|
189
|
{
|
190
|
return null;
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
public int getNumCubitFaces()
|
196
|
{
|
197
|
return 6;
|
198
|
}
|
199
|
|
200
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201
|
|
202
|
public float[][] getCubitPositions(int[] numLayers)
|
203
|
{
|
204
|
final float DIST_CORNER = numLayers[0]-1;
|
205
|
final float DIST_CENTER = numLayers[0]-1;
|
206
|
|
207
|
final float[][] CENTERS = new float[10][];
|
208
|
|
209
|
CENTERS[0] = new float[] { DIST_CORNER, DIST_CORNER, DIST_CORNER };
|
210
|
CENTERS[1] = new float[] {-DIST_CORNER, DIST_CORNER,-DIST_CORNER };
|
211
|
CENTERS[2] = new float[] {-DIST_CORNER,-DIST_CORNER, DIST_CORNER };
|
212
|
CENTERS[3] = new float[] { DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
|
213
|
CENTERS[4] = new float[] { DIST_CENTER, 0, 0 };
|
214
|
CENTERS[5] = new float[] {-DIST_CENTER, 0, 0 };
|
215
|
CENTERS[6] = new float[] { 0, DIST_CENTER, 0 };
|
216
|
CENTERS[7] = new float[] { 0,-DIST_CENTER, 0 };
|
217
|
CENTERS[8] = new float[] { 0, 0, DIST_CENTER };
|
218
|
CENTERS[9] = new float[] { 0, 0,-DIST_CENTER };
|
219
|
|
220
|
return CENTERS;
|
221
|
}
|
222
|
|
223
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
224
|
|
225
|
public ObjectShape getObjectShape(int variant)
|
226
|
{
|
227
|
if( variant==0 )
|
228
|
{
|
229
|
final float angle = (float)Math.PI/(2*IVY_N);
|
230
|
final float CORR = 1-2*IVY_D;
|
231
|
|
232
|
float[][] centers = new float[][] { {-1.0f,-1.0f,-1.0f} };
|
233
|
float[][] corners = new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
|
234
|
float[][] vertices = new float[3*(IVY_N+1)+4][3];
|
235
|
int[] cornerIndices= new int[3*(IVY_N+1)+4];
|
236
|
int[] centerIndices= new int[3*(IVY_N+1)+4];
|
237
|
int[][] vertIndices= new int[6][IVY_N+4];
|
238
|
int[] bandIndices = new int[] { 0,0,0,1,1,1 };
|
239
|
|
240
|
float[][] bands =
|
241
|
{
|
242
|
{+0.015f,20,0.2f,0.5f,7,1,2},
|
243
|
{-0.100f,20,0.2f,0.0f,2,1,2}
|
244
|
};
|
245
|
|
246
|
for(int i=0; i<3*(IVY_N+1); i++)
|
247
|
{
|
248
|
cornerIndices[i+4] = -1;
|
249
|
centerIndices[i+4] = -1;
|
250
|
}
|
251
|
|
252
|
cornerIndices[0] = 1;
|
253
|
cornerIndices[1] = 0;
|
254
|
cornerIndices[2] = 0;
|
255
|
cornerIndices[3] = 0;
|
256
|
|
257
|
centerIndices[0] = 0;
|
258
|
centerIndices[1] = 0;
|
259
|
centerIndices[2] = 0;
|
260
|
centerIndices[3] = 0;
|
261
|
|
262
|
vertices[0][0] = 0;
|
263
|
vertices[0][1] = 0;
|
264
|
vertices[0][2] = 0;
|
265
|
vertices[1][0] =-2;
|
266
|
vertices[1][1] = 0;
|
267
|
vertices[1][2] = 0;
|
268
|
vertices[2][0] = 0;
|
269
|
vertices[2][1] =-2;
|
270
|
vertices[2][2] = 0;
|
271
|
vertices[3][0] = 0;
|
272
|
vertices[3][1] = 0;
|
273
|
vertices[3][2] =-2;
|
274
|
|
275
|
vertIndices[0][0] = 2;
|
276
|
vertIndices[0][1] = 0;
|
277
|
vertIndices[0][2] = 1;
|
278
|
vertIndices[3][0] = 2;
|
279
|
vertIndices[3][1] = 0;
|
280
|
vertIndices[3][2] = 1;
|
281
|
|
282
|
vertIndices[1][0] = 3;
|
283
|
vertIndices[1][1] = 0;
|
284
|
vertIndices[1][2] = 2;
|
285
|
vertIndices[4][0] = 3;
|
286
|
vertIndices[4][1] = 0;
|
287
|
vertIndices[4][2] = 2;
|
288
|
|
289
|
vertIndices[2][0] = 1;
|
290
|
vertIndices[2][1] = 0;
|
291
|
vertIndices[2][2] = 3;
|
292
|
vertIndices[5][0] = 1;
|
293
|
vertIndices[5][1] = 0;
|
294
|
vertIndices[5][2] = 3;
|
295
|
|
296
|
int N1 = 4;
|
297
|
int N2 = N1 + IVY_N + 1;
|
298
|
int N3 = N2 + IVY_N + 1;
|
299
|
|
300
|
for(int i=0; i<=IVY_N; i++)
|
301
|
{
|
302
|
float cos1 = (float)Math.cos((IVY_N-i)*angle);
|
303
|
float sin1 = (float)Math.sin((IVY_N-i)*angle);
|
304
|
float cos2 = (float)Math.cos(( i)*angle);
|
305
|
float sin2 = (float)Math.sin(( i)*angle);
|
306
|
|
307
|
vertices[N1+i][0] = CORR*(2*cos1-1) - 1;
|
308
|
vertices[N1+i][1] = CORR*(2*sin1-1) - 1;
|
309
|
vertices[N1+i][2] = 0;
|
310
|
|
311
|
vertices[N2+i][0] = 0;
|
312
|
vertices[N2+i][1] = CORR*(2*sin2-1) - 1;
|
313
|
vertices[N2+i][2] = CORR*(2*cos2-1) - 1;
|
314
|
|
315
|
vertices[N3+i][0] = CORR*(2*cos2-1) - 1;
|
316
|
vertices[N3+i][1] = 0;
|
317
|
vertices[N3+i][2] = CORR*(2*sin2-1) - 1;
|
318
|
|
319
|
vertIndices[0][i+3] = N1 + i;
|
320
|
vertIndices[1][i+3] = N2 + i;
|
321
|
vertIndices[2][i+3] = N3 + i;
|
322
|
vertIndices[3][i+3] = N1 + i;
|
323
|
vertIndices[4][i+3] = N2 + i;
|
324
|
vertIndices[5][i+3] = N3 + i;
|
325
|
}
|
326
|
|
327
|
float C = 1-SQ2/2;
|
328
|
float[] convexCenter = new float[] {-C,-C,-C};
|
329
|
return new ObjectShape(vertices,vertIndices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), convexCenter, 3);
|
330
|
}
|
331
|
else
|
332
|
{
|
333
|
final float angle = (float)Math.PI/(2*IVY_N);
|
334
|
final float CORR = 1-2*IVY_D;
|
335
|
float[][] vertices = new float[2*IVY_N][3];
|
336
|
int[][] vert_indices = new int[2][2*IVY_N];
|
337
|
|
338
|
int[] bandIndices= new int[] { 0,1 };
|
339
|
int[] indexes = new int[2*IVY_N];
|
340
|
float[][] corners= new float[][] { {0.05f,0.20f} };
|
341
|
float[][] centers= new float[][] { {-0.0f,-0.0f,-1.0f} };
|
342
|
|
343
|
for(int i=0; i<IVY_N; i++)
|
344
|
{
|
345
|
float sin = (float)Math.sin(i*angle);
|
346
|
float cos = (float)Math.cos(i*angle);
|
347
|
|
348
|
vertices[i ][0] = CORR*(1-2*cos);
|
349
|
vertices[i ][1] = CORR*(1-2*sin);
|
350
|
vertices[i ][2] = 0;
|
351
|
vertices[i+IVY_N][0] = CORR*(2*cos-1);
|
352
|
vertices[i+IVY_N][1] = CORR*(2*sin-1);
|
353
|
vertices[i+IVY_N][2] = 0;
|
354
|
}
|
355
|
|
356
|
for(int i=0; i<2*IVY_N; i++)
|
357
|
{
|
358
|
vert_indices[0][i] = i;
|
359
|
vert_indices[1][i] = i;
|
360
|
}
|
361
|
|
362
|
for(int i=0; i<2*IVY_N; i++)
|
363
|
{
|
364
|
indexes[i] = -1;
|
365
|
}
|
366
|
indexes[0] = indexes[IVY_N] = 0;
|
367
|
|
368
|
float[][] bands =
|
369
|
{
|
370
|
{+0.03f,35,0.5f,0.5f,5,0,0},
|
371
|
{-0.10f,45,0.5f,0.0f,2,0,0}
|
372
|
};
|
373
|
|
374
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,indexes,centers,indexes,getNumCubitFaces(), null, 1);
|
375
|
}
|
376
|
}
|
377
|
|
378
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
379
|
|
380
|
public Static4D getQuat(int cubit, int[] numLayers)
|
381
|
{
|
382
|
if( mQuats==null ) initializeQuats();
|
383
|
|
384
|
switch(cubit)
|
385
|
{
|
386
|
case 0: return mQuats[0];
|
387
|
case 1: return mQuats[2];
|
388
|
case 2: return mQuats[3];
|
389
|
case 3: return mQuats[1];
|
390
|
|
391
|
case 4: return mQuats[8];
|
392
|
case 5: return mQuats[11];
|
393
|
case 6: return mQuats[10];
|
394
|
case 7: return mQuats[9];
|
395
|
case 8: return mQuats[0];
|
396
|
case 9: return mQuats[2];
|
397
|
}
|
398
|
|
399
|
return mQuats[0];
|
400
|
}
|
401
|
|
402
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
403
|
|
404
|
public int getNumCubitVariants(int[] numLayers)
|
405
|
{
|
406
|
return 2;
|
407
|
}
|
408
|
|
409
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
410
|
|
411
|
public int getCubitVariant(int cubit, int[] numLayers)
|
412
|
{
|
413
|
return cubit<4 ? 0:1;
|
414
|
}
|
415
|
|
416
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
417
|
|
418
|
public int getCubitFaceColor(int cubit, int face, int[] numLayers)
|
419
|
{
|
420
|
if( mFaceMap==null )
|
421
|
{
|
422
|
mFaceMap = new int[][]
|
423
|
{
|
424
|
{ 4, 0, 2, -1,-1,-1 },
|
425
|
{ 5, 1, 2, -1,-1,-1 },
|
426
|
{ 4, 1, 3, -1,-1,-1 },
|
427
|
{ 5, 0, 3, -1,-1,-1 },
|
428
|
|
429
|
{ 0, -1,-1,-1,-1,-1 },
|
430
|
{ 1, -1,-1,-1,-1,-1 },
|
431
|
{ 2, -1,-1,-1,-1,-1 },
|
432
|
{ 3, -1,-1,-1,-1,-1 },
|
433
|
{ 4, -1,-1,-1,-1,-1 },
|
434
|
{ 5, -1,-1,-1,-1,-1 },
|
435
|
};
|
436
|
}
|
437
|
|
438
|
return mFaceMap[cubit][face];
|
439
|
}
|
440
|
|
441
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
442
|
|
443
|
public int getVariantFaceColor(int variant, int face, int[] numLayers)
|
444
|
{
|
445
|
return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
|
446
|
}
|
447
|
|
448
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
449
|
|
450
|
public void adjustStickerCoords()
|
451
|
{
|
452
|
mStickerCoords = new float[][]
|
453
|
{
|
454
|
{ 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f },
|
455
|
{ -0.5f, 0.5f, 0.5f, -0.5f }
|
456
|
};
|
457
|
}
|
458
|
|
459
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
460
|
|
461
|
public float getStickerRadius()
|
462
|
{
|
463
|
return 0.19f;
|
464
|
}
|
465
|
|
466
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
467
|
|
468
|
public float getStickerStroke()
|
469
|
{
|
470
|
return ObjectControl.isInIconMode() ? 0.16f : 0.12f;
|
471
|
}
|
472
|
|
473
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
474
|
|
475
|
public float[][] getStickerAngles()
|
476
|
{
|
477
|
float D = (float)(Math.PI/4);
|
478
|
return new float[][] { { 0,0,D },{ D,D } };
|
479
|
}
|
480
|
|
481
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
482
|
// PUBLIC API
|
483
|
|
484
|
public Static3D[] getRotationAxis()
|
485
|
{
|
486
|
return ROT_AXIS;
|
487
|
}
|
488
|
|
489
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
490
|
|
491
|
public int[] getBasicAngle()
|
492
|
{
|
493
|
if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
|
494
|
return mBasicAngle;
|
495
|
}
|
496
|
|
497
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
498
|
|
499
|
public ObjectType intGetObjectType(int[] numLayers)
|
500
|
{
|
501
|
return ObjectType.IVY_2;
|
502
|
}
|
503
|
|
504
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
505
|
|
506
|
public String getObjectName()
|
507
|
{
|
508
|
return "Ivy Cube";
|
509
|
}
|
510
|
|
511
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
512
|
|
513
|
public String getInventor()
|
514
|
{
|
515
|
return "Eitan Cher";
|
516
|
}
|
517
|
|
518
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
519
|
|
520
|
public int getYearOfInvention()
|
521
|
{
|
522
|
return 2009;
|
523
|
}
|
524
|
|
525
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
526
|
|
527
|
public int getComplexity()
|
528
|
{
|
529
|
return 0;
|
530
|
}
|
531
|
}
|