Project

General

Profile

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

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

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 java.io.InputStream;
16

    
17
import org.distorted.library.type.Static3D;
18
import org.distorted.library.type.Static4D;
19

    
20
import org.distorted.objectlib.helpers.ObjectFaceShape;
21
import org.distorted.objectlib.helpers.ObjectSignature;
22
import org.distorted.objectlib.main.InitData;
23
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
24
import org.distorted.objectlib.main.ObjectType;
25
import org.distorted.objectlib.helpers.ObjectShape;
26
import org.distorted.objectlib.scrambling.ScrambleState;
27
import org.distorted.objectlib.main.ShapeHexahedron;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class TwistyRex extends ShapeHexahedron
32
{
33
  static final Static3D[] ROT_AXIS = new Static3D[]
34
         {
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
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
39
         };
40

    
41
  public static final float REX_D = 0.2f;
42

    
43
  private ScrambleState[] mStates;
44
  private int[][] mBasicAngle;
45
  private float[][] mCuts;
46
  private float[][] mPosition;
47
  private int[] mQuatIndex;
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

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

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

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

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  public ScrambleState[] getScrambleStates()
72
    {
73
    if( mStates==null )
74
      {
75
      int[] tmp = {0,-1,0, 0,1,0, 2,-1,0, 2,1,0 };
76

    
77
      mStates = new ScrambleState[]
78
        {
79
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
80
        };
81
      }
82

    
83
    return mStates;
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

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

    
97
    return mCuts;
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
  public boolean[][] getLayerRotatable(int[] numLayers)
103
    {
104
    boolean[] tmp = new boolean[] {true,false,true};
105
    return new boolean[][] { tmp,tmp,tmp,tmp };
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
  public int getTouchControlType()
111
    {
112
    return TC_HEXAHEDRON;
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
  public int getTouchControlSplit()
118
    {
119
    return TYPE_SPLIT_CORNER;
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  public int[][][] getEnabled()
125
    {
126
    return new int[][][]
127
      {
128
          {{0,1},{3,1},{2,3},{0,2}},
129
          {{2,3},{3,1},{0,1},{0,2}},
130
          {{1,2},{0,1},{0,3},{2,3}},
131
          {{1,2},{2,3},{0,3},{0,1}},
132
          {{0,3},{0,2},{1,2},{1,3}},
133
          {{1,2},{0,2},{0,3},{1,3}},
134
      };
135
    }
136

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

    
139
  public float[] getDist3D(int[] numLayers)
140
    {
141
    return TouchControlHexahedron.D3D;
142
    }
143

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

    
146
  public Static3D[] getFaceAxis()
147
    {
148
    return TouchControlHexahedron.FACE_AXIS;
149
    }
150

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

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

    
161
      mPosition = new float[][]
162
        {
163
          { +DIST2, -DIST2, +DIST3 },
164
          { -DIST2, +DIST2, +DIST3 },
165
          { +DIST2, +DIST2, -DIST3 },
166
          { -DIST2, -DIST2, -DIST3 },
167
          { +DIST2, +DIST3, -DIST2 },
168
          { -DIST2, +DIST3, +DIST2 },
169
          { +DIST2, -DIST3, +DIST2 },
170
          { -DIST2, -DIST3, -DIST2 },
171
          { +DIST3, +DIST2, -DIST2 },
172
          { +DIST3, -DIST2, +DIST2 },
173
          { -DIST3, +DIST2, +DIST2 },
174
          { -DIST3, -DIST2, -DIST2 },
175

    
176
          { +DIST2, +DIST2, +DIST3 },
177
          { -DIST2, -DIST2, +DIST3 },
178
          { +DIST2, -DIST2, -DIST3 },
179
          { -DIST2, +DIST2, -DIST3 },
180
          { -DIST2, +DIST3, -DIST2 },
181
          { +DIST2, +DIST3, +DIST2 },
182
          { -DIST2, -DIST3, +DIST2 },
183
          { +DIST2, -DIST3, -DIST2 },
184
          { +DIST3, +DIST2, +DIST2 },
185
          { +DIST3, -DIST2, -DIST2 },
186
          { -DIST3, +DIST2, -DIST2 },
187
          { -DIST3, -DIST2, +DIST2 },
188

    
189
          { +0.00f, +0.00f, +DIST3 },
190
          { +0.00f, +0.00f, -DIST3 },
191
          { +0.00f, +DIST3, +0.00f },
192
          { +0.00f, -DIST3, +0.00f },
193
          { +DIST3, +0.00f, +0.00f },
194
          { -DIST3, +0.00f, +0.00f },
195

    
196
          { +0.00f, +DIST1, +DIST1 },
197
          { +DIST1, +0.00f, +DIST1 },
198
          { +0.00f, -DIST1, +DIST1 },
199
          { -DIST1, +0.00f, +DIST1 },
200
          { +DIST1, +DIST1, +0.00f },
201
          { +DIST1, -DIST1, +0.00f },
202
          { -DIST1, -DIST1, +0.00f },
203
          { -DIST1, +DIST1, +0.00f },
204
          { +0.00f, +DIST1, -DIST1 },
205
          { +DIST1, +0.00f, -DIST1 },
206
          { +0.00f, -DIST1, -DIST1 },
207
          { -DIST1, +0.00f, -DIST1 },
208
        };
209
      }
210

    
211
    return mPosition;
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

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

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
  public ObjectShape getObjectShape(int variant)
233
    {
234
    if( variant==0 )
235
      {
236
      float[][] vertices= { {-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
      int[][] indices   = { {0,1,2,3},{0,3,4},{3,2,4},{2,1,4},{1,0,4} };
238
      return new ObjectShape(vertices, indices);
239
      }
240
    else if( variant==1 )
241
      {
242
      float[][] vertices= { {-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} };
243
      int[][] indices   = { {3,2,1,0},{4,3,0},{4,2,3},{4,1,2},{4,0,1} };
244
      return new ObjectShape(vertices, indices);
245
      }
246
    else if( variant==2 )
247
      {
248
      float G = 3*REX_D;
249
      float[][] vertices= { { -G, 0, 0 },{ 0,-G, 0 },{ +G, 0, 0 },{ 0,+G,0 },{ 0, 0,-G} };
250
      int[][] indices   = { {0,1,2,3},{0,3,4},{3,2,4},{2,1,4},{1,0,4} };
251
      return new ObjectShape(vertices, indices);
252
      }
253
    else
254
      {
255
      float E = 1.5f - 3*REX_D;
256
      float F = 1.5f;
257
      float[][] vertices= { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
258
      int[][] indices   = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
259
      return new ObjectShape(vertices, indices);
260
      }
261
    }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
  public ObjectFaceShape getObjectFaceShape(int variant)
266
    {
267
    if( variant==0 || variant==1 )
268
      {
269
      float height = isInIconMode() ? 0.001f : 0.02f;
270
      float G = (1-REX_D)*SQ2/2;
271
      float[][] centers= { {0.0f,0.0f,-G} };
272
      float[][] corners= { {0.03f,0.30f} };
273
      int[] indices    = {-1,-1,0,0,-1};
274
      int[] bandIndices= { 0,1,1,1,1 };
275
      float[][] bands  = { { height,10,G/3,0.5f,5,1,1},{ 0.001f,45,0.1f,0.1f,2,0,0} };
276
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
277
      }
278
    else if( variant==2 )
279
      {
280
      float height = isInIconMode() ? 0.001f : 0.025f;
281
      float G = 3*REX_D;
282
      int[] indices    = {-1,-1,-1,-1,-1};
283
      int[] bandIndices= { 0,1,1,1,1 };
284
      float[][] bands  = { {height,10,G/2,0.5f,5,0,0},{0.001f,45,G/2,0.0f,2,0,0} };
285
      return new ObjectFaceShape(bands,bandIndices,null,indices,null,indices,null);
286
      }
287
    else
288
      {
289
      float h1 = isInIconMode() ? 0.001f : 0.03f;
290
      float h2 = isInIconMode() ? 0.001f : 0.01f;
291
      float E = 1.5f - 3*REX_D;
292
      float F = 1.5f;
293
      float G = (float)Math.sqrt(E*E+F*F);
294
      float[][] centers= { {0.0f,-1.5f,-1.5f} };
295
      float[][] corners= { {0.06f,0.20f} };
296
      int[] indices    = { 0,-1,0,-1 };
297
      int[] bandIndices= { 0,0,1,1 };
298
      float[][] bands  = { {h1,12,F/3,0.8f,5,2,3},{h2,45,G/3,0.2f,5,2,3} };
299
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
300
      }
301
    }
302

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

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

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

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

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

    
319
  public float getStickerRadius()
320
    {
321
    return 0.09f;
322
    }
323

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

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

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
  public float[][] getStickerAngles()
334
    {
335
    final float F = (float)(Math.PI/20);
336
    return new float[][] { { F,-F/2,F },{0,0,0,0},{ -F,0,-F } };
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 num = getNumLayers()[0];
354
      int[] tmp = new int[num];
355
      for(int i=0; i<num; i++) tmp[i] = 3;
356
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
357
      }
358

    
359
    return mBasicAngle;
360
    }
361

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

    
364
  public String getShortName()
365
    {
366
    return ObjectType.REX_3.name();
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

    
371
  public ObjectSignature getSignature()
372
    {
373
    return new ObjectSignature(ObjectType.REX_3);
374
    }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
  public String getObjectName()
379
    {
380
    return "Rex Cube";
381
    }
382

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

    
385
  public String getInventor()
386
    {
387
    return "Andrew Cormier";
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
  public int getYearOfInvention()
393
    {
394
    return 2009;
395
    }
396

    
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398

    
399
  public int getComplexity()
400
    {
401
    return 3;
402
    }
403

    
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

    
406
  public String[][] getTutorials()
407
    {
408
    return new String[][]{
409
                          {"gb","noAQfWqlMbk","Rex Cube Tutorial","CrazyBadCuber"},
410
                          {"es","Q90x9rjLJzw","Resolver Cubo Rex","Cuby"},
411
                          {"ru","Dr9CLM6A3fU","Как собрать Рекс Куб","Алексей Ярыгин"},
412
                          {"fr","SvK1kf6c43c","Résolution du Rex Cube","Asthalis"},
413
                          {"de","AI4vtwpRkEQ","Rex Cube - Tutorial","GerCubing"},
414
                          {"pl","ffbFRnHglWY","Rex Cube TUTORIAL PL","MrUk"},
415
                          {"kr","B3ftZzHRQyU","렉스 큐브 해법","듀나메스 큐브 해법연구소"},
416
                          {"vn","5nE9Q7QmOP4","Tutorial N.87 - Rex Cube","Duy Thích Rubik"},
417
                         };
418
    }
419
}
(27-27/36)