Project

General

Profile

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

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

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.scrambling.ScrambleEdgeGenerator;
25
import org.distorted.objectlib.main.InitData;
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

    
73
  public int[][] getScrambleEdges()
74
    {
75
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
76
    return mEdges;
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

    
90
    return mCuts;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  public boolean[][] getLayerRotatable(int[] numLayers)
96
    {
97
    boolean[] tmp = new boolean[] {true,false,true};
98
    return new boolean[][] { tmp,tmp,tmp,tmp };
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  public int getTouchControlType()
104
    {
105
    return TC_HEXAHEDRON;
106
    }
107

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

    
110
  public int getTouchControlSplit()
111
    {
112
    return TYPE_SPLIT_CORNER;
113
    }
114

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

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

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
  public float[] getDist3D(int[] numLayers)
133
    {
134
    return TouchControlHexahedron.D3D;
135
    }
136

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

    
139
  public Static3D[] getFaceAxis()
140
    {
141
    return TouchControlHexahedron.FACE_AXIS;
142
    }
143

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

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

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

    
169
          { +DIST2, +DIST2, +DIST3 },
170
          { -DIST2, -DIST2, +DIST3 },
171
          { +DIST2, -DIST2, -DIST3 },
172
          { -DIST2, +DIST2, -DIST3 },
173
          { -DIST2, +DIST3, -DIST2 },
174
          { +DIST2, +DIST3, +DIST2 },
175
          { -DIST2, -DIST3, +DIST2 },
176
          { +DIST2, -DIST3, -DIST2 },
177
          { +DIST3, +DIST2, +DIST2 },
178
          { +DIST3, -DIST2, -DIST2 },
179
          { -DIST3, +DIST2, -DIST2 },
180
          { -DIST3, -DIST2, +DIST2 },
181

    
182
          { +0.00f, +0.00f, +DIST3 },
183
          { +0.00f, +0.00f, -DIST3 },
184
          { +0.00f, +DIST3, +0.00f },
185
          { +0.00f, -DIST3, +0.00f },
186
          { +DIST3, +0.00f, +0.00f },
187
          { -DIST3, +0.00f, +0.00f },
188

    
189
          { +0.00f, +DIST1, +DIST1 },
190
          { +DIST1, +0.00f, +DIST1 },
191
          { +0.00f, -DIST1, +DIST1 },
192
          { -DIST1, +0.00f, +DIST1 },
193
          { +DIST1, +DIST1, +0.00f },
194
          { +DIST1, -DIST1, +0.00f },
195
          { -DIST1, -DIST1, +0.00f },
196
          { -DIST1, +DIST1, +0.00f },
197
          { +0.00f, +DIST1, -DIST1 },
198
          { +DIST1, +0.00f, -DIST1 },
199
          { +0.00f, -DIST1, -DIST1 },
200
          { -DIST1, +0.00f, -DIST1 },
201
        };
202
      }
203

    
204
    return mPosition;
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

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

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

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

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

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

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

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

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

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

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

    
333
  public int getNumCubitVariants(int[] numLayers)
334
    {
335
    return 4;
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

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

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

    
347
  public float getStickerRadius()
348
    {
349
    return 0.09f;
350
    }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
  public float getStickerStroke()
355
    {
356
    return isInIconMode() ? 0.25f : 0.12f;
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

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

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
// PUBLIC API
369

    
370
  public Static3D[] getRotationAxis()
371
    {
372
    return ROT_AXIS;
373
    }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

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

    
387
    return mBasicAngle;
388
    }
389

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

    
392
  public String getShortName()
393
    {
394
    return ObjectType.REX_3.name();
395
    }
396

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

    
399
  public ObjectSignature getSignature()
400
    {
401
    return new ObjectSignature(ObjectType.REX_3);
402
    }
403

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

    
406
  public String getObjectName()
407
    {
408
    return "Rex Cube";
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  public String getInventor()
414
    {
415
    return "Andrew Cormier";
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  public int getYearOfInvention()
421
    {
422
    return 2009;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public int getComplexity()
428
    {
429
    return 3;
430
    }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433

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