Project

General

Profile

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

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

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.FactoryCubit;
21
import org.distorted.objectlib.helpers.ObjectFaceShape;
22
import org.distorted.objectlib.helpers.ObjectSignature;
23
import org.distorted.objectlib.helpers.ObjectVertexEffects;
24
import org.distorted.objectlib.main.InitData;
25
import org.distorted.objectlib.main.ObjectSignatures;
26
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
27
import org.distorted.objectlib.main.ObjectType;
28
import org.distorted.objectlib.helpers.ObjectShape;
29
import org.distorted.objectlib.shape.ShapeHexahedron;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class TwistyRex extends ShapeHexahedron
34
{
35
  static final Static3D[] ROT_AXIS = new Static3D[]
36
         {
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
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
41
         };
42

    
43
  public static final float REX_D = 0.2f;
44

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

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

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

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

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

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

    
74
  public int[][] getScrambleEdges()
75
    {
76
    if( mEdges==null )
77
      {
78
      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 } };
79
      }
80
    return mEdges;
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

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

    
94
    return mCuts;
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

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

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

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

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

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

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

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

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

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

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

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

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

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

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

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

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

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

    
208
    return mPosition;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

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

    
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

    
229
  private float[][] getVertices(int variant)
230
    {
231
    if( variant==0 )
232
      {
233
      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} };
234
      }
235
    else if( variant==1 )
236
      {
237
      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} };
238
      }
239
    else if( variant==2 )
240
      {
241
      float G = 3*REX_D;
242
      return new float[][] { { -G, 0, 0 },{ 0,-G, 0 },{ +G, 0, 0 },{ 0,+G,0 },{ 0, 0,-G} };
243
      }
244
    else
245
      {
246
      float E = 1.5f - 3*REX_D;
247
      float F = 1.5f;
248
      return new float[][] { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
249
      }
250
    }
251

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

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

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

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

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

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

    
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

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

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

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

    
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350

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

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

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

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

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

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372
// PUBLIC API
373

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

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

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

    
391
    return mBasicAngle;
392
    }
393

    
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395

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

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402

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

    
408
///////////////////////////////////////////////////////////////////////////////////////////////////
409

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

    
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

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

    
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

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

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

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

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

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