Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyRex.java @ cf93ea4e

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

    
18
import org.distorted.objectlib.helpers.FactoryCubit;
19
import org.distorted.objectlib.helpers.ObjectFaceShape;
20
import org.distorted.objectlib.helpers.ObjectSignature;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.main.InitData;
24
import org.distorted.objectlib.main.ObjectSignatures;
25
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
26
import org.distorted.objectlib.main.ObjectType;
27
import org.distorted.objectlib.helpers.ObjectShape;
28
import org.distorted.objectlib.shape.ShapeHexahedron;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

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

    
42
  public static final float REX_D = 0.2f;
43

    
44
  private int[][] mEdges;
45
  private int[][] mBasicAngle;
46
  private float[][] mCuts;
47
  private float[][] mPosition;
48
  private int[] mQuatIndex;
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  public TwistyRex(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
53
    {
54
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  @Override
60
  public void adjustStickerCoords()
61
    {
62
    mStickerCoords = new float[][]
63
          {
64
             { 0.35f, -0.35f, -0.1428f, 0.5f, -0.5f, 0.1428f },
65
             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
66
             { 0.00f, -0.200f, 0.525f, 0.105f, -0.525f, 0.105f }
67
          };
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
// single state; middle layer doesn't move.
72

    
73
  public int[][] getScrambleEdges()
74
    {
75
    if( mEdges==null )
76
      {
77
      mEdges = new int[][] { { 0,0,1,0, 4,0,5,0, 6,0,7,0, 10,0,11,0, 12,0,13,0, 16,0,17,0, 18,0,19,0, 22,0,23,0 } };
78
      }
79
    return mEdges;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  public float[][] getCuts(int[] numLayers)
85
    {
86
    if( mCuts==null )
87
      {
88
      float C = SQ3*0.45f; // bit less than 1/2 of the length of the main diagonal
89
      float[] cut = new float[] {-C,+C};
90
      mCuts = new float[][] { cut,cut,cut,cut };
91
      }
92

    
93
    return mCuts;
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  public boolean[][] getLayerRotatable(int[] numLayers)
99
    {
100
    boolean[] tmp = new boolean[] {true,false,true};
101
    return new boolean[][] { tmp,tmp,tmp,tmp };
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  public int getTouchControlType()
107
    {
108
    return TC_HEXAHEDRON;
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  public int getTouchControlSplit()
114
    {
115
    return TYPE_SPLIT_CORNER;
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  public int[][][] getEnabled()
121
    {
122
    return new int[][][]
123
      {
124
          {{0,1},{3,1},{2,3},{0,2}},
125
          {{2,3},{3,1},{0,1},{0,2}},
126
          {{1,2},{0,1},{0,3},{2,3}},
127
          {{1,2},{2,3},{0,3},{0,1}},
128
          {{0,3},{0,2},{1,2},{1,3}},
129
          {{1,2},{0,2},{0,3},{1,3}},
130
      };
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  public float[] getDist3D(int[] numLayers)
136
    {
137
    return TouchControlHexahedron.D3D;
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  public Static3D[] getFaceAxis()
143
    {
144
    return TouchControlHexahedron.FACE_AXIS;
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  public float[][] getCubitPositions(int[] numLayers)
150
    {
151
    if( mPosition==null )
152
      {
153
      final float DIST1= 1.50f;
154
      final float DIST2= (1+2*REX_D)/2;
155
      final float DIST3= 1.53f;
156

    
157
      mPosition = new float[][]
158
        {
159
          { +DIST2, -DIST2, +DIST3 },
160
          { -DIST2, +DIST2, +DIST3 },
161
          { +DIST2, +DIST2, -DIST3 },
162
          { -DIST2, -DIST2, -DIST3 },
163
          { +DIST2, +DIST3, -DIST2 },
164
          { -DIST2, +DIST3, +DIST2 },
165
          { +DIST2, -DIST3, +DIST2 },
166
          { -DIST2, -DIST3, -DIST2 },
167
          { +DIST3, +DIST2, -DIST2 },
168
          { +DIST3, -DIST2, +DIST2 },
169
          { -DIST3, +DIST2, +DIST2 },
170
          { -DIST3, -DIST2, -DIST2 },
171

    
172
          { +DIST2, +DIST2, +DIST3 },
173
          { -DIST2, -DIST2, +DIST3 },
174
          { +DIST2, -DIST2, -DIST3 },
175
          { -DIST2, +DIST2, -DIST3 },
176
          { -DIST2, +DIST3, -DIST2 },
177
          { +DIST2, +DIST3, +DIST2 },
178
          { -DIST2, -DIST3, +DIST2 },
179
          { +DIST2, -DIST3, -DIST2 },
180
          { +DIST3, +DIST2, +DIST2 },
181
          { +DIST3, -DIST2, -DIST2 },
182
          { -DIST3, +DIST2, -DIST2 },
183
          { -DIST3, -DIST2, +DIST2 },
184

    
185
          { +0.00f, +0.00f, +DIST3 },
186
          { +0.00f, +0.00f, -DIST3 },
187
          { +0.00f, +DIST3, +0.00f },
188
          { +0.00f, -DIST3, +0.00f },
189
          { +DIST3, +0.00f, +0.00f },
190
          { -DIST3, +0.00f, +0.00f },
191

    
192
          { +0.00f, +DIST1, +DIST1 },
193
          { +DIST1, +0.00f, +DIST1 },
194
          { +0.00f, -DIST1, +DIST1 },
195
          { -DIST1, +0.00f, +DIST1 },
196
          { +DIST1, +DIST1, +0.00f },
197
          { +DIST1, -DIST1, +0.00f },
198
          { -DIST1, -DIST1, +0.00f },
199
          { -DIST1, +DIST1, +0.00f },
200
          { +0.00f, +DIST1, -DIST1 },
201
          { +DIST1, +0.00f, -DIST1 },
202
          { +0.00f, -DIST1, -DIST1 },
203
          { -DIST1, +0.00f, -DIST1 },
204
        };
205
      }
206

    
207
    return mPosition;
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

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

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  private float[][] getVertices(int variant)
229
    {
230
    if( variant==0 )
231
      {
232
      return new float[][] { {-0.10f,+0.70f,0},{-0.70f,+0.10f,0},{+0.65f,-0.71f,0},{+0.71f,-0.65f,0},{0,0.05f,-0.2f} };
233
      }
234
    else if( variant==1 )
235
      {
236
      return new float[][] { {-0.10f,-0.70f,0},{-0.70f,-0.10f,0},{+0.65f,+0.71f,0},{+0.71f,+0.65f,0},{0,-0.05f,-0.2f} };
237
      }
238
    else if( variant==2 )
239
      {
240
      float G = 3*REX_D;
241
      return new float[][] { { -G, 0, 0 },{ 0,-G, 0 },{ +G, 0, 0 },{ 0,+G,0 },{ 0, 0,-G} };
242
      }
243
    else
244
      {
245
      float E = 1.5f - 3*REX_D;
246
      float F = 1.5f;
247
      return new float[][] { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
248
      }
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

    
253
  public ObjectShape getObjectShape(int variant)
254
    {
255
    if( variant==0 )
256
      {
257
      int[][] indices = { {0,1,2,3},{0,3,4},{3,2,4},{2,1,4},{1,0,4} };
258
      return new ObjectShape(getVertices(variant), indices);
259
      }
260
    else if( variant==1 )
261
      {
262
      int[][] indices = { {3,2,1,0},{4,3,0},{4,2,3},{4,1,2},{4,0,1} };
263
      return new ObjectShape(getVertices(variant), indices);
264
      }
265
    else if( variant==2 )
266
      {
267
      int[][] indices = { {0,1,2,3},{0,3,4},{3,2,4},{2,1,4},{1,0,4} };
268
      return new ObjectShape(getVertices(variant), indices);
269
      }
270
    else
271
      {
272
      int[][] indices = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
273
      return new ObjectShape(getVertices(variant), indices);
274
      }
275
    }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

    
279
  public ObjectFaceShape getObjectFaceShape(int variant)
280
    {
281
    if( variant==0 || variant==1 )
282
      {
283
      float height = isInIconMode() ? 0.001f : 0.02f;
284
      float G = (1-REX_D)*SQ2/2;
285
      int[] indices  = { 0,1,1,1,1 };
286
      float[][] bands= { { height,10,G/3,0.5f,5,1,1},{ 0.001f,45,0.1f,0.1f,2,0,0} };
287
      return new ObjectFaceShape(bands,indices,null);
288
      }
289
    else if( variant==2 )
290
      {
291
      float height = isInIconMode() ? 0.001f : 0.025f;
292
      float G = 3*REX_D;
293
      int[] indices  = { 0,1,1,1,1 };
294
      float[][] bands= { {height,10,G/2,0.5f,5,0,0},{0.001f,45,G/2,0.0f,2,0,0} };
295
      return new ObjectFaceShape(bands,indices,null);
296
      }
297
    else
298
      {
299
      float h1 = isInIconMode() ? 0.001f : 0.03f;
300
      float h2 = isInIconMode() ? 0.001f : 0.01f;
301
      float E = 1.5f - 3*REX_D;
302
      float F = 1.5f;
303
      float G = (float)Math.sqrt(E*E+F*F);
304
      int[] indices  = { 0,0,1,1 };
305
      float[][] bands= { {h1,12,F/3,0.8f,5,2,3},{h2,45,G/3,0.2f,5,2,3} };
306
      return new ObjectFaceShape(bands,indices,null);
307
      }
308
    }
309

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

    
312
  public ObjectVertexEffects getVertexEffects(int variant)
313
    {
314
    if( variant==0 || variant==1 )
315
      {
316
      float[][] centers= { {0.0f,0.0f,(REX_D-1)*SQ2/2} };
317
      float[][] corners= { {0.03f,0.30f} };
318
      int[] indices    = {-1,-1,0,0,-1};
319
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
320
      }
321
    else if( variant==2 )
322
      {
323
      return null;
324
      }
325
    else
326
      {
327
      float[][] centers= { {0.0f,-1.5f,-1.5f} };
328
      float[][] corners= { {0.06f,0.20f} };
329
      int[] indices    = { 0,-1,0,-1 };
330
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
331
      }
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

    
336
  public int getNumCubitVariants(int[] numLayers)
337
    {
338
    return 4;
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

    
343
  public int getCubitVariant(int cubit, int[] numLayers)
344
    {
345
    return cubit<12 ? 0 : (cubit<24 ? 1 : (cubit<30?2:3));
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
  public float getStickerRadius()
351
    {
352
    return 0.09f;
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  public float getStickerStroke()
358
    {
359
    return isInIconMode() ? 0.25f : 0.12f;
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
  public float[][] getStickerAngles()
365
    {
366
    final float F = (float)(Math.PI/20);
367
    return new float[][] { { F,-F/2,F },{0,0,0,0},{ -F,0,-F } };
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371
// PUBLIC API
372

    
373
  public Static3D[] getRotationAxis()
374
    {
375
    return ROT_AXIS;
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
  public int[][] getBasicAngles()
381
    {
382
    if( mBasicAngle==null )
383
      {
384
      int num = getNumLayers()[0];
385
      int[] tmp = new int[num];
386
      for(int i=0; i<num; i++) tmp[i] = 3;
387
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
388
      }
389

    
390
    return mBasicAngle;
391
    }
392

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

    
395
  public String getShortName()
396
    {
397
    return ObjectType.REX_3.name();
398
    }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

    
402
  public ObjectSignature getSignature()
403
    {
404
    return new ObjectSignature(ObjectSignatures.REX_3);
405
    }
406

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408

    
409
  public String getObjectName()
410
    {
411
    return "Rex Cube";
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415

    
416
  public String getInventor()
417
    {
418
    return "Andrew Cormier";
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

    
423
  public int getYearOfInvention()
424
    {
425
    return 2009;
426
    }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

    
430
  public int getComplexity()
431
    {
432
    return 3;
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  public String[][] getTutorials()
438
    {
439
    return new String[][]{
440
                          {"gb","noAQfWqlMbk","Rex Cube Tutorial","CrazyBadCuber"},
441
                          {"es","Q90x9rjLJzw","Resolver Cubo Rex","Cuby"},
442
                          {"ru","Dr9CLM6A3fU","Как собрать Рекс Куб","Алексей Ярыгин"},
443
                          {"fr","SvK1kf6c43c","Résolution du Rex Cube","Asthalis"},
444
                          {"de","AI4vtwpRkEQ","Rex Cube - Tutorial","GerCubing"},
445
                          {"pl","ffbFRnHglWY","Rex Cube TUTORIAL PL","MrUk"},
446
                          {"kr","B3ftZzHRQyU","렉스 큐브 해법","듀나메스 큐브 해법연구소"},
447
                          {"vn","5nE9Q7QmOP4","Tutorial N.87 - Rex Cube","Duy Thích Rubik"},
448
                         };
449
    }
450
}
(32-32/41)