Project

General

Profile

Download (14.7 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyLattice.java @ 3a0990b1

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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_HEXAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
14

    
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17
import org.distorted.objectlib.helpers.FactoryCubit;
18
import org.distorted.objectlib.helpers.ObjectFaceShape;
19
import org.distorted.objectlib.helpers.ObjectShape;
20
import org.distorted.objectlib.helpers.ObjectVertexEffects;
21
import org.distorted.objectlib.main.InitAssets;
22
import org.distorted.objectlib.metadata.ListObjects;
23
import org.distorted.objectlib.metadata.Metadata;
24
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
25
import org.distorted.objectlib.shape.ShapeHexahedron;
26
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class TwistyLattice extends ShapeHexahedron
31
{
32
  public static final Static3D[] ROT_AXIS = new Static3D[]
33
         {
34
           new Static3D( SQ3/3, SQ3/3, SQ3/3),
35
           new Static3D( SQ3/3, SQ3/3,-SQ3/3),
36
           new Static3D( SQ3/3,-SQ3/3, SQ3/3),
37
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
38
         };
39

    
40
  private int[][] mEdges;
41
  private int[][] mBasicAngle;
42
  private float[][] mCuts;
43
  private float[][] mPositions;
44
  private int[] mQuatIndex;
45
  private boolean[][] mRotatable;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public TwistyLattice(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
50
    {
51
    super(iconMode, meta.getNumLayers()[0], quat, move, scale, meta, asset);
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  @Override
57
  public float[][] returnRotationFactor()
58
    {
59
    int numL = getNumLayers()[0];
60
    float[] f = new float[numL];
61
    for(int i=0; i<numL; i++) f[i] = 1.7f;
62
    return new float[][] { f,f,f,f };
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  public int[][] getScrambleEdges()
68
    {
69
    if( mEdges==null )
70
      {
71
      mEdges = new int[][]
72
        {
73
         { 0,16,1,16,2,8,3,8,  4,1,5,1,6,9,7,9,  8,15,9,15,10,7,11,7,  12,2,13,2,14,10,15,10,  16,14,17,14,18,6,19,6,  20,3,21,3,22,11,23,11,  24,13,25,13,26,5,27,5,  28,4,29,4,30,12,31,12 },  // 0
74

    
75
         {                                                             12,2,13,2,14,10,15,10,                          20,3,21,3,22,11,23,11,  24,13,25,13,26,5,27,5,                        },  // 1
76
         {                     4,1,5,1,6,9,7,9,                                                16,14,17,14,18,6,19,6,                                                  28,4,29,4,30,12,31,12 },  // 2
77
         {                     4,1,5,1,6,9,7,9,  8,15,9,15,10,7,11,7,                                                                                                  28,4,29,4,30,12,31,12 },  // 3
78
         { 0,16,1,16,2,8,3,8,                                          12,2,13,2,14,10,15,10,                          20,3,21,3,22,11,23,11,                                                },  // 4
79
         {                     4,1,5,1,6,9,7,9,  8,15,9,15,10,7,11,7,                          16,14,17,14,18,6,19,6,                                                                        },  // 5
80
         { 0,16,1,16,2,8,3,8,                                          12,2,13,2,14,10,15,10,                                                  24,13,25,13,26,5,27,5,                        },  // 6
81
         { 0,16,1,16,2,8,3,8,                                                                                          20,3,21,3,22,11,23,11,  24,13,25,13,26,5,27,5,                        },  // 7
82
         {                                       8,15,9,15,10,7,11,7,                          16,14,17,14,18,6,19,6,                                                  28,4,29,4,30,12,31,12 },  // 8
83

    
84
         {                                                             12,2,13,2,                                      20,3,21,3,                          26,5,27,5,                        },  // 9
85
         {                     4,1,5,1,                                                                    18,6,19,6,                                                  28,4,29,4,            },  // 10
86
         {                     4,1,5,1,                    10,7,11,7,                                                                                                  28,4,29,4,            },  // 11
87
         {           2,8,3,8,                                          12,2,13,2,                                      20,3,21,3,                                                            },  // 12
88
         {                     4,1,5,1,                    10,7,11,7,                                      18,6,19,6,                                                                        },  // 13
89
         {           2,8,3,8,                                          12,2,13,2,                                                                          26,5,27,5,                        },  // 14
90
         {           2,8,3,8,                                                                                          20,3,21,3,                          26,5,27,5,                        },  // 15
91
         {                                                 10,7,11,7,                                      18,6,19,6,                                                  28,4,29,4,            },  // 16
92
        };
93
      }
94

    
95
    return mEdges;
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  @Override
101
  public int[][] getScrambleAlgorithms()
102
    {
103
    if( mRotatable==null ) createRotatable();
104
    return ScrambleEdgeGenerator.getScramblingAlgorithms(mBasicAngle, mRotatable);
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  public float[][] getCuts(int[] numLayers)
110
    {
111
    if( mCuts==null )
112
      {
113
      float C = 5*SQ3/6;
114
      float[] c = {-2*C,-C,C,2*C};
115
      mCuts = new float[][] {c,c,c,c};
116
      }
117

    
118
    return mCuts;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  private void createRotatable()
124
    {
125
    boolean[] tmp = new boolean[] {true,true,false,true,true};
126
    mRotatable = new boolean[][] { tmp,tmp,tmp,tmp };
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public boolean[][] getLayerRotatable(int[] numLayers)
132
    {
133
    if( mRotatable==null ) createRotatable();
134
    return mRotatable;
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  public int getTouchControlType()
140
    {
141
    return TC_HEXAHEDRON;
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  public int getTouchControlSplit()
147
    {
148
    return TYPE_SPLIT_CORNER;
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  public int[][][] getEnabled()
154
    {
155
    return new int[][][]
156
      {
157
          {{0,1},{3,1},{2,3},{0,2}},
158
          {{2,3},{3,1},{0,1},{0,2}},
159
          {{1,2},{0,1},{0,3},{2,3}},
160
          {{1,2},{2,3},{0,3},{0,1}},
161
          {{0,3},{0,2},{1,2},{1,3}},
162
          {{1,2},{0,2},{0,3},{1,3}},
163
      };
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  public float[] getDist3D(int[] numLayers)
169
    {
170
    return TouchControlHexahedron.D3D;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  public Static3D[] getFaceAxis()
176
    {
177
    return TouchControlHexahedron.FACE_AXIS;
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

    
182
  public float[][] getCubitPositions(int[] numLayers)
183
    {
184
    if( mPositions==null )
185
      {
186
      final float C = 1.25f;
187

    
188
      mPositions = new float[][]
189
        {
190
          { 0, C, 2*C},  { C, 0, 2*C}, { 0,-C, 2*C}, {-C, 0, 2*C},
191
          { 0, C,-2*C},  { C, 0,-2*C}, { 0,-C,-2*C}, {-C, 0,-2*C},
192
          { 0, 2*C, C},  { C, 2*C, 0}, { 0, 2*C,-C}, {-C, 2*C, 0},
193
          { 0,-2*C, C},  { C,-2*C, 0}, { 0,-2*C,-C}, {-C,-2*C, 0},
194
          { 2*C, 0, C},  { 2*C, C, 0}, { 2*C, 0,-C}, { 2*C,-C, 0},
195
          {-2*C, 0, C},  {-2*C, C, 0}, {-2*C, 0,-C}, {-2*C,-C, 0},
196

    
197
          { C, 2*C, 2*C }, {-C, 2*C, 2*C },
198
          { 2*C, C, 2*C }, { 2*C,-C, 2*C },
199
          { C,-2*C, 2*C }, {-C,-2*C, 2*C },
200
          {-2*C, C, 2*C }, {-2*C,-C, 2*C },
201
          { 2*C, 2*C, C }, { 2*C, 2*C,-C },
202
          { 2*C,-2*C, C }, { 2*C,-2*C,-C },
203
          {-2*C,-2*C, C }, {-2*C,-2*C,-C },
204
          {-2*C, 2*C, C }, {-2*C, 2*C,-C },
205
          { C, 2*C,-2*C }, {-C, 2*C,-2*C },
206
          { 2*C, C,-2*C }, { 2*C,-C,-2*C },
207
          { C,-2*C,-2*C }, {-C,-2*C,-2*C },
208
          {-2*C, C,-2*C }, {-2*C,-C,-2*C },
209
        };
210
      }
211

    
212
    return mPositions;
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
  public Static4D getCubitQuats(int cubit, int[] numLayers)
218
    {
219
    if( mQuatIndex==null )
220
      {
221
      mQuatIndex = new int[]
222
         {
223
            0,0,0,0,9,9,9,9,1,1,1,1,4,4,4,4,2,2,2,2,3,3,3,3,
224
            0,0,2,2,10,10,8,8, 1,1,4,4,6,6,7,7, 11,11,5,5,9,9,3,3,
225
         };
226
      }
227

    
228
    return mObjectQuats[mQuatIndex[cubit]];
229
    }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

    
233
  private float[][] getVertices(int variant)
234
    {
235
    final float C = 1.25f;
236
    if( variant==0 ) return new float[][] { {-C,0,0},{0,-C,0},{C,0,0},{0,C,0},{0,0,-C} };
237
    else             return new float[][] { {-C,0,0},{C,0,0},{0,-C,0},{0,0,-C} };
238
    }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

    
242
  public ObjectShape getObjectShape(int variant)
243
    {
244
    if( variant==0 )
245
      {
246
      int[][] indices = { {0,1,2,3},{4,1,0},{4,2,1},{4,3,2},{4,0,3} };
247
      return new ObjectShape(getVertices(variant), indices);
248
      }
249
    else
250
      {
251
      int[][] indices = { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
252
      return new ObjectShape(getVertices(variant), indices);
253
      }
254
    }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

    
258
  public ObjectFaceShape getObjectFaceShape(int variant)
259
    {
260
    if( variant==0 )
261
      {
262
      int N = 4;
263
      int E = 1;
264
      float height = isInIconMode() ? 0.001f : 0.04f;
265
      float[][] bands = { {height,35,SQ2/8,0.9f,N,E,E}, {0.001f,35,1,0.0f,3,0,0} };
266
      int[] indices   = { 0,1,1,1,1 };
267
      return new ObjectFaceShape(bands,indices,null);
268
      }
269
    else
270
      {
271
      int N = 5;
272
      int E = 2;
273
      float h1 = isInIconMode() ? 0.001f : 0.035f;
274
      float h2 = isInIconMode() ? 0.001f : 0.020f;
275
      float[][] bands = { {h1,30,0.16f,0.8f,N,2,E}, {h2,45,0.16f,0.2f,3,1,2} };
276
      int[] indices   = { 0,0,1,1 };
277
      return new ObjectFaceShape(bands,indices,null);
278
      }
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
  public ObjectVertexEffects getVertexEffects(int variant)
284
    {
285
    if( variant==0 )
286
      {
287
      final float C = 1.25f;
288
      float[][] corners   = { {0.03f,0.15f} };
289
      int[] cornerIndices = { 0,0,0,0,0 };
290
      float[][] centers   = { {-C,0,-C},{0,-C,-C},{C,0,-C},{0,C,-C} };
291
      int[] centerIndices = { 0,1,2,3,-1 };
292
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,cornerIndices,centers,centerIndices);
293
      }
294
    else
295
      {
296
      float[][] corners   = { {0.07f,0.20f}, {0.02f,0.30f} };
297
      int[] cornerIndices = { 0,0,1,1 };
298
      float[][] centers   = { {0.0f, -0.5f, -0.5f} };
299
      int[] centerIndices = { 0,0,0,0 };
300
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,cornerIndices,centers,centerIndices);
301
      }
302
    }
303

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

    
306
  public int getNumCubitVariants(int[] numLayers)
307
    {
308
    return 2;
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

    
313
  public int getCubitVariant(int cubit, int[] numLayers)
314
    {
315
    return cubit<24 ? 0:1;
316
    }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

    
320
  public float getStickerRadius()
321
    {
322
    return 0.12f;
323
    }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
  public float getStickerStroke()
328
    {
329
    return isInIconMode() ? 0.27f : 0.12f;
330
    }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
  public float[][][] getStickerAngles()
335
    {
336
    return null;
337
    }
338

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340
// PUBLIC API
341

    
342
  public Static3D[] getRotationAxis()
343
    {
344
    return ROT_AXIS;
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  public int[][] getBasicAngles()
350
    {
351
    if( mBasicAngle ==null )
352
      {
353
      int[] tmp = {3,3,3,3,3};
354
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
355
      }
356

    
357
    return mBasicAngle;
358
    }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
  public String getShortName()
363
    {
364
    return ListObjects.LATT_5.name();
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

    
369
  public String[][] getTutorials()
370
    {
371
    return new String[][]
372
      {
373
         {"gb","fzrjXO0MUgE","How to solve Lattice Cube","martywolfman"},
374
         {"fr","7Tfp3opCCsQ","Résolution du Lattice Cube","asthalis"},
375
         {"pl","EPKHJ5C2yQY","Lattice Cube Tutorial PL","MrUK"},
376
         {"tw","V4zuvJBPdr8","格子方塊 教學","不正常魔術方塊研究中心"},
377
      };
378
    }
379
}
(28-28/59)