1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2023 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.TC_OCTAHEDRON;
|
13
|
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
|
14
|
|
15
|
import org.distorted.library.effect.EffectName;
|
16
|
import org.distorted.library.main.DistortedLibrary;
|
17
|
import org.distorted.library.type.Static3D;
|
18
|
import org.distorted.library.type.Static4D;
|
19
|
import org.distorted.objectlib.bandaged.FactoryBandagedOctahedron;
|
20
|
import org.distorted.objectlib.helpers.ObjectFaceShape;
|
21
|
import org.distorted.objectlib.helpers.ObjectShape;
|
22
|
import org.distorted.objectlib.metadata.Metadata;
|
23
|
import org.distorted.objectlib.signature.ObjectSignature;
|
24
|
import org.distorted.objectlib.helpers.ObjectVertexEffects;
|
25
|
import org.distorted.objectlib.main.InitAssets;
|
26
|
import org.distorted.objectlib.scrambling.ObjectScrambler;
|
27
|
import org.distorted.objectlib.shape.ShapeOctahedron;
|
28
|
import org.distorted.objectlib.signature.ObjectSignatureDiamond;
|
29
|
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
|
30
|
|
31
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
|
33
|
public class TwistyBandagedDiamond extends ShapeOctahedron
|
34
|
{
|
35
|
public static final String OBJECT_NAME_DIAMOND = "LOCAL_DIAMOND";
|
36
|
public static final char MARKER = 'd'; // keep lowercase
|
37
|
|
38
|
private static final Static3D[] ROT_AXIS = new Static3D[]
|
39
|
{
|
40
|
new Static3D( SQ6/3, SQ3/3, 0),
|
41
|
new Static3D(-SQ6/3, SQ3/3, 0),
|
42
|
new Static3D( 0,-SQ3/3,-SQ6/3),
|
43
|
new Static3D( 0,-SQ3/3, SQ6/3)
|
44
|
};
|
45
|
|
46
|
private static final Static4D QUAT = new Static4D(0,0,0,1);
|
47
|
|
48
|
private static final int OCT_1 = 0;
|
49
|
private static final int TET_1 = 1;
|
50
|
private static final int OTHER = 2;
|
51
|
|
52
|
private static final int NUM_TYPES = 2; // OCT_1 and TET_1
|
53
|
|
54
|
private int[] mCubitVariantMap;
|
55
|
private int[] mTypeVariantMap;
|
56
|
private ObjectShape[] mTmpShapes;
|
57
|
private int mNumVariants;
|
58
|
private float[][] mPosition;
|
59
|
private ObjectSignature mSignature;
|
60
|
private float[][] mCuts;
|
61
|
private int[][] mBasicAngle;
|
62
|
|
63
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
|
65
|
private float[][] getPositions()
|
66
|
{
|
67
|
if( mPosition==null ) mPosition = getMetadata().getPos();
|
68
|
return mPosition;
|
69
|
}
|
70
|
|
71
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72
|
|
73
|
private int getType(float[] pos)
|
74
|
{
|
75
|
if( pos.length>3 ) return OTHER;
|
76
|
boolean octa = FactoryBandagedOctahedron.isOctahedron(pos[1]);
|
77
|
return octa ? OCT_1 : TET_1;
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
private int getType(int variant)
|
83
|
{
|
84
|
for(int t=0; t<NUM_TYPES; t++)
|
85
|
if( mTypeVariantMap[t]==variant ) return t;
|
86
|
|
87
|
return -1;
|
88
|
}
|
89
|
|
90
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91
|
|
92
|
private void produceTmpShape(int variant)
|
93
|
{
|
94
|
float[][] positions = getPositions();
|
95
|
int cubit,numCubits = positions.length;
|
96
|
|
97
|
for(cubit=0; cubit<numCubits; cubit++)
|
98
|
{
|
99
|
if( mCubitVariantMap[cubit]==variant ) break;
|
100
|
}
|
101
|
|
102
|
if( cubit>=numCubits )
|
103
|
{
|
104
|
android.util.Log.e("D", "unknown variant: "+variant);
|
105
|
}
|
106
|
else
|
107
|
{
|
108
|
FactoryBandagedOctahedron factory = FactoryBandagedOctahedron.getInstance();
|
109
|
mTmpShapes[variant] = factory.createIrregularShape(variant,positions[cubit]);
|
110
|
}
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
private float[][] getVertices(int variant)
|
116
|
{
|
117
|
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
|
118
|
if( mTmpShapes[variant]==null ) produceTmpShape(variant);
|
119
|
return mTmpShapes[variant].getVertices();
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
// PUBLIC API
|
124
|
|
125
|
public TwistyBandagedDiamond(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
|
126
|
{
|
127
|
super(iconMode, meta.getNumLayers()[0], quat, move, scale, meta, asset);
|
128
|
}
|
129
|
|
130
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131
|
// Computing scramble states of many a bandaged objects takes way too long time and too much space.
|
132
|
// Return null here and turn to construction of scramble tables just-in-time (scrambleType=2)
|
133
|
|
134
|
public int[][] getScrambleEdges()
|
135
|
{
|
136
|
return null;
|
137
|
}
|
138
|
|
139
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140
|
|
141
|
@Override
|
142
|
public float[][] returnRotationFactor()
|
143
|
{
|
144
|
int numL = getNumLayers()[0];
|
145
|
float[] f = new float[numL];
|
146
|
for(int i=0; i<numL; i++) f[i] = 1.5f;
|
147
|
return new float[][] { f,f,f,f };
|
148
|
}
|
149
|
|
150
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151
|
|
152
|
@Override
|
153
|
public int[][] getScrambleAlgorithms()
|
154
|
{
|
155
|
return null;
|
156
|
}
|
157
|
|
158
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
159
|
|
160
|
@Override
|
161
|
public int getScrambleType()
|
162
|
{
|
163
|
return ObjectScrambler.SCRAMBLING_BANDAGED;
|
164
|
}
|
165
|
|
166
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167
|
|
168
|
public ObjectShape getObjectShape(int variant)
|
169
|
{
|
170
|
if( mTmpShapes==null ) mTmpShapes = new ObjectShape[mNumVariants];
|
171
|
if( mTmpShapes[variant]==null ) produceTmpShape(variant);
|
172
|
return mTmpShapes[variant];
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
public ObjectFaceShape getObjectFaceShape(int variant)
|
178
|
{
|
179
|
int type = getType(variant);
|
180
|
FactoryBandagedOctahedron factory = FactoryBandagedOctahedron.getInstance();
|
181
|
|
182
|
if( type>=0 )
|
183
|
{
|
184
|
int[] numLayers = getNumLayers();
|
185
|
boolean iconMode = isInIconMode();
|
186
|
float[][] bands = factory.getBands(iconMode,numLayers);
|
187
|
int numFaces = type==TET_1 ? 4:8;
|
188
|
int[] bandIndices= new int[numFaces];
|
189
|
for(int i=0; i<numFaces; i++) bandIndices[i] = 1;
|
190
|
return new ObjectFaceShape(bands,bandIndices,null);
|
191
|
}
|
192
|
|
193
|
return factory.createIrregularFaceShape(variant, isInIconMode() );
|
194
|
}
|
195
|
|
196
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197
|
|
198
|
public ObjectVertexEffects getVertexEffects(int variant)
|
199
|
{
|
200
|
int[] numLayers = getNumLayers();
|
201
|
int size = numLayers[0];
|
202
|
boolean round = (DistortedLibrary.fastCompilationTF() && size<=5 && !isInIconMode());
|
203
|
int type = getType(variant);
|
204
|
|
205
|
if( type>=0 )
|
206
|
{
|
207
|
float[][] vertices = getVertices(variant);
|
208
|
int numV = vertices.length;
|
209
|
float S = type==0 ? -0.06f : -0.08f;
|
210
|
|
211
|
String name = EffectName.DEFORM.name();
|
212
|
float[] reg = {0,0,0,0.15f};
|
213
|
|
214
|
float[][] variables = new float[numV][];
|
215
|
String[] names = new String[numV];
|
216
|
float[][] regions = new float[numV][];
|
217
|
boolean[] uses = new boolean[numV];
|
218
|
|
219
|
for(int i=0; i<numV; i++)
|
220
|
{
|
221
|
float[] v = vertices[i];
|
222
|
variables[i] = new float[] { 0, S*v[0], S*v[1], S*v[2], 1 };
|
223
|
names[i] = name;
|
224
|
regions[i] = reg;
|
225
|
uses[i] = round;
|
226
|
}
|
227
|
|
228
|
return new ObjectVertexEffects(names,variables,vertices,regions,uses);
|
229
|
}
|
230
|
|
231
|
FactoryBandagedOctahedron factory = FactoryBandagedOctahedron.getInstance();
|
232
|
return factory.createVertexEffects(variant,round);
|
233
|
}
|
234
|
|
235
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236
|
|
237
|
public Static4D getCubitQuats(int cubit, int[] numLayers)
|
238
|
{
|
239
|
float[] pos = mPosition[cubit];
|
240
|
return pos.length>3 ? QUAT : FactoryBandagedOctahedron.getInstance().getCubitQuat(pos[0],pos[1],pos[2]);
|
241
|
}
|
242
|
|
243
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
244
|
|
245
|
public int getNumCubitVariants(int[] numLayers)
|
246
|
{
|
247
|
if( mNumVariants==0 )
|
248
|
{
|
249
|
float[][] positions = getPositions();
|
250
|
boolean T1=false;
|
251
|
boolean O1=false;
|
252
|
|
253
|
int numCubits = positions.length;
|
254
|
mCubitVariantMap = new int[numCubits];
|
255
|
|
256
|
mTypeVariantMap = new int[NUM_TYPES];
|
257
|
for(int i=0; i<NUM_TYPES; i++) mTypeVariantMap[i] = -1;
|
258
|
|
259
|
for (int cubit=0; cubit<numCubits; cubit++)
|
260
|
{
|
261
|
int type = getType(positions[cubit]);
|
262
|
|
263
|
switch (type)
|
264
|
{
|
265
|
case TET_1: if (!T1) { T1 = true; mTypeVariantMap[TET_1]=mNumVariants++; }
|
266
|
mCubitVariantMap[cubit] = mTypeVariantMap[TET_1];
|
267
|
break;
|
268
|
case OCT_1: if (!O1) { O1 = true; mTypeVariantMap[OCT_1]=mNumVariants++; }
|
269
|
mCubitVariantMap[cubit] = mTypeVariantMap[OCT_1];
|
270
|
break;
|
271
|
default : mCubitVariantMap[cubit] = mNumVariants++;
|
272
|
}
|
273
|
}
|
274
|
|
275
|
FactoryBandagedOctahedron factory = FactoryBandagedOctahedron.getInstance();
|
276
|
factory.prepare(mNumVariants,numLayers);
|
277
|
}
|
278
|
|
279
|
return mNumVariants;
|
280
|
}
|
281
|
|
282
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
283
|
|
284
|
public float[][] getCubitPositions(int[] numLayers)
|
285
|
{
|
286
|
return getPositions();
|
287
|
}
|
288
|
|
289
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
290
|
|
291
|
public boolean[][] getLayerRotatable(int[] numLayers)
|
292
|
{
|
293
|
int numAxis = ROT_AXIS.length;
|
294
|
boolean[][] layerRotatable = new boolean[numAxis][];
|
295
|
|
296
|
for(int i=0; i<numAxis; i++)
|
297
|
{
|
298
|
layerRotatable[i] = new boolean[numLayers[i]];
|
299
|
for(int j=0; j<numLayers[i]; j++) layerRotatable[i][j] = true;
|
300
|
}
|
301
|
|
302
|
return layerRotatable;
|
303
|
}
|
304
|
|
305
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
306
|
|
307
|
public float[][] getCuts(int[] numLayers)
|
308
|
{
|
309
|
int numL = numLayers[0];
|
310
|
if( numL<2 ) return null;
|
311
|
|
312
|
if( mCuts==null )
|
313
|
{
|
314
|
mCuts = new float[4][numL-1];
|
315
|
float cut = (SQ6/6)*(2-numL);
|
316
|
|
317
|
for(int i=0; i<numL-1; i++)
|
318
|
{
|
319
|
mCuts[0][i] = cut;
|
320
|
mCuts[1][i] = cut;
|
321
|
mCuts[2][i] = cut;
|
322
|
mCuts[3][i] = cut;
|
323
|
cut += SQ6/3;
|
324
|
}
|
325
|
}
|
326
|
|
327
|
return mCuts;
|
328
|
}
|
329
|
|
330
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
331
|
|
332
|
public Static3D[] getFaceAxis()
|
333
|
{
|
334
|
return TouchControlOctahedron.FACE_AXIS;
|
335
|
}
|
336
|
|
337
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
338
|
|
339
|
public Static3D[] getRotationAxis()
|
340
|
{
|
341
|
return ROT_AXIS;
|
342
|
}
|
343
|
|
344
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
345
|
|
346
|
public int[][][] getEnabled()
|
347
|
{
|
348
|
return new int[][][]
|
349
|
{
|
350
|
{{1,2,3}},{{1,2,3}},{{0,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,3}},{{0,1,2}},{{0,1,2}}
|
351
|
};
|
352
|
}
|
353
|
|
354
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
355
|
|
356
|
public int getTouchControlType()
|
357
|
{
|
358
|
return TC_OCTAHEDRON;
|
359
|
}
|
360
|
|
361
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
362
|
|
363
|
public int getTouchControlSplit()
|
364
|
{
|
365
|
return TYPE_NOT_SPLIT;
|
366
|
}
|
367
|
|
368
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
369
|
|
370
|
public int getCubitVariant(int cubit, int[] numLayers)
|
371
|
{
|
372
|
return mCubitVariantMap[cubit];
|
373
|
}
|
374
|
|
375
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
376
|
|
377
|
public float[] getDist3D(int[] numLayers)
|
378
|
{
|
379
|
return TouchControlOctahedron.D3D;
|
380
|
}
|
381
|
|
382
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
383
|
|
384
|
public int[][] getBasicAngles()
|
385
|
{
|
386
|
if( mBasicAngle ==null )
|
387
|
{
|
388
|
int num = getNumLayers()[0];
|
389
|
int[] tmp = new int[num];
|
390
|
for(int i=0; i<num; i++) tmp[i] = 3;
|
391
|
mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
|
392
|
}
|
393
|
return mBasicAngle;
|
394
|
}
|
395
|
|
396
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
397
|
|
398
|
public float getStickerRadius()
|
399
|
{
|
400
|
return 0.08f;
|
401
|
}
|
402
|
|
403
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
404
|
|
405
|
public float getStickerStroke()
|
406
|
{
|
407
|
float stroke = 0.095f;
|
408
|
|
409
|
if( isInIconMode() )
|
410
|
{
|
411
|
int[] numLayers = getNumLayers();
|
412
|
|
413
|
switch(numLayers[0])
|
414
|
{
|
415
|
case 2: stroke*=1.4f; break;
|
416
|
case 3: stroke*=2.0f; break;
|
417
|
case 4: stroke*=2.1f; break;
|
418
|
default:stroke*=2.2f; break;
|
419
|
}
|
420
|
}
|
421
|
|
422
|
return stroke;
|
423
|
}
|
424
|
|
425
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
426
|
|
427
|
public float[][][] getStickerAngles()
|
428
|
{
|
429
|
return null;
|
430
|
}
|
431
|
|
432
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
433
|
|
434
|
public String getShortName()
|
435
|
{
|
436
|
if( mSignature==null ) mSignature = getSignature();
|
437
|
int[] numLayers = getNumLayers();
|
438
|
return MARKER+(numLayers[0]+"_"+mSignature.getString());
|
439
|
}
|
440
|
|
441
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
442
|
|
443
|
public ObjectSignature getSignature()
|
444
|
{
|
445
|
if( mSignature==null )
|
446
|
{
|
447
|
int[] numLayers = getNumLayers();
|
448
|
mSignature = new ObjectSignatureDiamond(numLayers[0],mPosition);
|
449
|
}
|
450
|
return mSignature;
|
451
|
}
|
452
|
|
453
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
454
|
|
455
|
public String getObjectName()
|
456
|
{
|
457
|
return OBJECT_NAME_DIAMOND;
|
458
|
}
|
459
|
|
460
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
461
|
|
462
|
public String getInventor()
|
463
|
{
|
464
|
return "??";
|
465
|
}
|
466
|
|
467
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
468
|
|
469
|
public int getYearOfInvention()
|
470
|
{
|
471
|
return 0;
|
472
|
}
|
473
|
|
474
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
475
|
|
476
|
public float getComplexity()
|
477
|
{
|
478
|
return 4;
|
479
|
}
|
480
|
|
481
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
482
|
|
483
|
public String[][] getTutorials()
|
484
|
{
|
485
|
return null;
|
486
|
}
|
487
|
}
|