Project

General

Profile

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

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

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 6133be67 Leszek Koltunski
// 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 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.objectlib.objects;
11
12 c9c71c3f Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
14 29b82486 Leszek Koltunski
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17
18 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
19 3ee1d662 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
20 1d581993 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectSignature;
21 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22 cf93ea4e Leszek Koltunski
import org.distorted.objectlib.main.InitAssets;
23 a8295031 Leszek Koltunski
import org.distorted.objectlib.main.InitData;
24 2dffaf22 Leszek Koltunski
import org.distorted.objectlib.main.ObjectSignatures;
25 c9c71c3f Leszek Koltunski
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
26 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
27 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
28 b31249d6 Leszek Koltunski
import org.distorted.objectlib.shape.ShapeHexahedron;
29 29b82486 Leszek Koltunski
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31
32 386af988 Leszek Koltunski
public class TwistyRex extends ShapeHexahedron
33 29b82486 Leszek Koltunski
{
34
  static final Static3D[] ROT_AXIS = new Static3D[]
35
         {
36 84a17011 Leszek Koltunski
           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 29b82486 Leszek Koltunski
         };
41
42
  public static final float REX_D = 0.2f;
43
44 9ba7f3f6 Leszek Koltunski
  private int[][] mEdges;
45 beee90ab Leszek Koltunski
  private int[][] mBasicAngle;
46 29b82486 Leszek Koltunski
  private float[][] mCuts;
47 52f4db8a Leszek Koltunski
  private float[][] mPosition;
48
  private int[] mQuatIndex;
49 29b82486 Leszek Koltunski
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
52 cf93ea4e Leszek Koltunski
  public TwistyRex(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
53 29b82486 Leszek Koltunski
    {
54 cf93ea4e Leszek Koltunski
    super(meshState, iconMode, data.getNumLayers()[0], quat, move, scale, data, asset);
55 29b82486 Leszek Koltunski
    }
56
57 a70b1e96 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59
  @Override
60
  public float[][] returnRotationFactor()
61
    {
62
    float C = 1.5f;
63
    float[] f = new float[] { C,C,C };
64
    return new float[][] { f,f,f,f };
65
    }
66
67 ed0988c0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69
  @Override
70
  public void adjustStickerCoords()
71
    {
72
    mStickerCoords = new float[][]
73
          {
74 cc70f525 Leszek Koltunski
             { 0.35f, -0.35f, -0.1428f, 0.5f, -0.5f, 0.1428f },
75 ed0988c0 Leszek Koltunski
             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
76 cc70f525 Leszek Koltunski
             { 0.00f, -0.200f, 0.525f, 0.105f, -0.525f, 0.105f }
77 ed0988c0 Leszek Koltunski
          };
78
    }
79
80 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
81 ea889ebf Leszek Koltunski
// single state; middle layer doesn't move.
82 29b82486 Leszek Koltunski
83 9ba7f3f6 Leszek Koltunski
  public int[][] getScrambleEdges()
84 29b82486 Leszek Koltunski
    {
85 ea889ebf Leszek Koltunski
    if( mEdges==null )
86
      {
87
      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 } };
88
      }
89 9ba7f3f6 Leszek Koltunski
    return mEdges;
90 29b82486 Leszek Koltunski
    }
91
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
94 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
95 29b82486 Leszek Koltunski
    {
96
    if( mCuts==null )
97
      {
98
      float C = SQ3*0.45f; // bit less than 1/2 of the length of the main diagonal
99
      float[] cut = new float[] {-C,+C};
100
      mCuts = new float[][] { cut,cut,cut,cut };
101
      }
102
103
    return mCuts;
104
    }
105
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
108 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
109
    {
110
    boolean[] tmp = new boolean[] {true,false,true};
111 802fe251 Leszek Koltunski
    return new boolean[][] { tmp,tmp,tmp,tmp };
112 59c20632 Leszek Koltunski
    }
113
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115
116 11fa413d Leszek Koltunski
  public int getTouchControlType()
117 59c20632 Leszek Koltunski
    {
118 c9c71c3f Leszek Koltunski
    return TC_HEXAHEDRON;
119 59c20632 Leszek Koltunski
    }
120
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
123 11fa413d Leszek Koltunski
  public int getTouchControlSplit()
124 59c20632 Leszek Koltunski
    {
125
    return TYPE_SPLIT_CORNER;
126
    }
127
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
130
  public int[][][] getEnabled()
131 29b82486 Leszek Koltunski
    {
132 59c20632 Leszek Koltunski
    return new int[][][]
133 29b82486 Leszek Koltunski
      {
134 59c20632 Leszek Koltunski
          {{0,1},{3,1},{2,3},{0,2}},
135
          {{2,3},{3,1},{0,1},{0,2}},
136
          {{1,2},{0,1},{0,3},{2,3}},
137
          {{1,2},{2,3},{0,3},{0,1}},
138
          {{0,3},{0,2},{1,2},{1,3}},
139
          {{1,2},{0,2},{0,3},{1,3}},
140
      };
141
    }
142
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
145
  public float[] getDist3D(int[] numLayers)
146
    {
147 4c9ca251 Leszek Koltunski
    return TouchControlHexahedron.D3D;
148
    }
149
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
152
  public Static3D[] getFaceAxis()
153
    {
154
    return TouchControlHexahedron.FACE_AXIS;
155 29b82486 Leszek Koltunski
    }
156
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
159 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
160 29b82486 Leszek Koltunski
    {
161 52f4db8a Leszek Koltunski
    if( mPosition==null )
162 802fe251 Leszek Koltunski
      {
163 52f4db8a Leszek Koltunski
      final float DIST1= 1.50f;
164
      final float DIST2= (1+2*REX_D)/2;
165
      final float DIST3= 1.53f;
166
167
      mPosition = new float[][]
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
          { +DIST2, +DIST2, +DIST3 },
183
          { -DIST2, -DIST2, +DIST3 },
184
          { +DIST2, -DIST2, -DIST3 },
185
          { -DIST2, +DIST2, -DIST3 },
186
          { -DIST2, +DIST3, -DIST2 },
187
          { +DIST2, +DIST3, +DIST2 },
188
          { -DIST2, -DIST3, +DIST2 },
189
          { +DIST2, -DIST3, -DIST2 },
190
          { +DIST3, +DIST2, +DIST2 },
191
          { +DIST3, -DIST2, -DIST2 },
192
          { -DIST3, +DIST2, -DIST2 },
193
          { -DIST3, -DIST2, +DIST2 },
194
195
          { +0.00f, +0.00f, +DIST3 },
196
          { +0.00f, +0.00f, -DIST3 },
197
          { +0.00f, +DIST3, +0.00f },
198
          { +0.00f, -DIST3, +0.00f },
199
          { +DIST3, +0.00f, +0.00f },
200
          { -DIST3, +0.00f, +0.00f },
201
202
          { +0.00f, +DIST1, +DIST1 },
203
          { +DIST1, +0.00f, +DIST1 },
204
          { +0.00f, -DIST1, +DIST1 },
205
          { -DIST1, +0.00f, +DIST1 },
206
          { +DIST1, +DIST1, +0.00f },
207
          { +DIST1, -DIST1, +0.00f },
208
          { -DIST1, -DIST1, +0.00f },
209
          { -DIST1, +DIST1, +0.00f },
210
          { +0.00f, +DIST1, -DIST1 },
211
          { +DIST1, +0.00f, -DIST1 },
212
          { +0.00f, -DIST1, -DIST1 },
213
          { -DIST1, +0.00f, -DIST1 },
214
        };
215
      }
216
217
    return mPosition;
218 29b82486 Leszek Koltunski
    }
219
220 d0e6cf7f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
221
222
  public Static4D getCubitQuats(int cubit, int[] numLayers)
223
    {
224 52f4db8a Leszek Koltunski
    if( mQuatIndex==null )
225 d0e6cf7f Leszek Koltunski
      {
226 52f4db8a Leszek Koltunski
      mQuatIndex = new int[] {
227
                              0,10, 9,11, 7, 1, 6, 4, 2, 5, 3, 8,
228
                              0,10, 9,11, 7, 1, 6, 4, 2, 5, 3, 8,
229
                              0, 9, 1, 4, 2, 3,
230
                              0, 2,10, 8, 1, 4, 6, 7,11, 5, 9, 3
231
                             };
232 d0e6cf7f Leszek Koltunski
      }
233 52f4db8a Leszek Koltunski
    return mObjectQuats[mQuatIndex[cubit]];
234 d0e6cf7f Leszek Koltunski
    }
235
236 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
237
238 84a17011 Leszek Koltunski
  private float[][] getVertices(int variant)
239 29b82486 Leszek Koltunski
    {
240
    if( variant==0 )
241
      {
242 84a17011 Leszek Koltunski
      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} };
243 29b82486 Leszek Koltunski
      }
244
    else if( variant==1 )
245 52f4db8a Leszek Koltunski
      {
246 84a17011 Leszek Koltunski
      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} };
247 52f4db8a Leszek Koltunski
      }
248
    else if( variant==2 )
249 29b82486 Leszek Koltunski
      {
250
      float G = 3*REX_D;
251 84a17011 Leszek Koltunski
      return new float[][] { { -G, 0, 0 },{ 0,-G, 0 },{ +G, 0, 0 },{ 0,+G,0 },{ 0, 0,-G} };
252 29b82486 Leszek Koltunski
      }
253
    else
254
      {
255
      float E = 1.5f - 3*REX_D;
256
      float F = 1.5f;
257 84a17011 Leszek Koltunski
      return new float[][] { { -F, 0, 0 },{  0,-E, 0 },{ +F, 0, 0 },{  0, 0,-E } };
258
      }
259
    }
260
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262
263
  public ObjectShape getObjectShape(int variant)
264
    {
265
    if( variant==0 )
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 if( variant==1 )
271
      {
272
      int[][] indices = { {3,2,1,0},{4,3,0},{4,2,3},{4,1,2},{4,0,1} };
273
      return new ObjectShape(getVertices(variant), indices);
274
      }
275
    else if( variant==2 )
276
      {
277
      int[][] indices = { {0,1,2,3},{0,3,4},{3,2,4},{2,1,4},{1,0,4} };
278
      return new ObjectShape(getVertices(variant), indices);
279
      }
280
    else
281
      {
282
      int[][] indices = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
283
      return new ObjectShape(getVertices(variant), indices);
284 3ee1d662 Leszek Koltunski
      }
285
    }
286
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288
289
  public ObjectFaceShape getObjectFaceShape(int variant)
290
    {
291 52f4db8a Leszek Koltunski
    if( variant==0 || variant==1 )
292 3ee1d662 Leszek Koltunski
      {
293 3bf19410 Leszek Koltunski
      float height = isInIconMode() ? 0.001f : 0.02f;
294 3ee1d662 Leszek Koltunski
      float G = (1-REX_D)*SQ2/2;
295 84a17011 Leszek Koltunski
      int[] indices  = { 0,1,1,1,1 };
296
      float[][] bands= { { height,10,G/3,0.5f,5,1,1},{ 0.001f,45,0.1f,0.1f,2,0,0} };
297
      return new ObjectFaceShape(bands,indices,null);
298 3ee1d662 Leszek Koltunski
      }
299 52f4db8a Leszek Koltunski
    else if( variant==2 )
300 3ee1d662 Leszek Koltunski
      {
301 3bf19410 Leszek Koltunski
      float height = isInIconMode() ? 0.001f : 0.025f;
302 3ee1d662 Leszek Koltunski
      float G = 3*REX_D;
303 84a17011 Leszek Koltunski
      int[] indices  = { 0,1,1,1,1 };
304
      float[][] bands= { {height,10,G/2,0.5f,5,0,0},{0.001f,45,G/2,0.0f,2,0,0} };
305
      return new ObjectFaceShape(bands,indices,null);
306 3ee1d662 Leszek Koltunski
      }
307
    else
308
      {
309 3bf19410 Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.03f;
310
      float h2 = isInIconMode() ? 0.001f : 0.01f;
311 3ee1d662 Leszek Koltunski
      float E = 1.5f - 3*REX_D;
312
      float F = 1.5f;
313
      float G = (float)Math.sqrt(E*E+F*F);
314 84a17011 Leszek Koltunski
      int[] indices  = { 0,0,1,1 };
315
      float[][] bands= { {h1,12,F/3,0.8f,5,2,3},{h2,45,G/3,0.2f,5,2,3} };
316
      return new ObjectFaceShape(bands,indices,null);
317
      }
318
    }
319
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321
322
  public ObjectVertexEffects getVertexEffects(int variant)
323
    {
324
    if( variant==0 || variant==1 )
325
      {
326
      float[][] centers= { {0.0f,0.0f,(REX_D-1)*SQ2/2} };
327
      float[][] corners= { {0.03f,0.30f} };
328
      int[] indices    = {-1,-1,0,0,-1};
329
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
330
      }
331
    else if( variant==2 )
332
      {
333
      return null;
334
      }
335
    else
336
      {
337 3ee1d662 Leszek Koltunski
      float[][] centers= { {0.0f,-1.5f,-1.5f} };
338
      float[][] corners= { {0.06f,0.20f} };
339
      int[] indices    = { 0,-1,0,-1 };
340 84a17011 Leszek Koltunski
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
341 29b82486 Leszek Koltunski
      }
342
    }
343
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345
346 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
347 29b82486 Leszek Koltunski
    {
348 52f4db8a Leszek Koltunski
    return 4;
349 29b82486 Leszek Koltunski
    }
350
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352
353 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
354 29b82486 Leszek Koltunski
    {
355 52f4db8a Leszek Koltunski
    return cubit<12 ? 0 : (cubit<24 ? 1 : (cubit<30?2:3));
356 29b82486 Leszek Koltunski
    }
357
358 00f4980d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
359 29b82486 Leszek Koltunski
360 d53fb890 Leszek Koltunski
  public float getStickerRadius()
361 00f4980d Leszek Koltunski
    {
362
    return 0.09f;
363
    }
364
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366
367 d53fb890 Leszek Koltunski
  public float getStickerStroke()
368 00f4980d Leszek Koltunski
    {
369 3bf19410 Leszek Koltunski
    return isInIconMode() ? 0.25f : 0.12f;
370 00f4980d Leszek Koltunski
    }
371
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373 8592461c Leszek Koltunski
374 d53fb890 Leszek Koltunski
  public float[][] getStickerAngles()
375 00f4980d Leszek Koltunski
    {
376
    final float F = (float)(Math.PI/20);
377 cc70f525 Leszek Koltunski
    return new float[][] { { F,-F/2,F },{0,0,0,0},{ -F,0,-F } };
378 00f4980d Leszek Koltunski
    }
379
380 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
381
// PUBLIC API
382
383
  public Static3D[] getRotationAxis()
384
    {
385
    return ROT_AXIS;
386
    }
387
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
390 beee90ab Leszek Koltunski
  public int[][] getBasicAngles()
391 29b82486 Leszek Koltunski
    {
392 beee90ab Leszek Koltunski
    if( mBasicAngle==null )
393
      {
394
      int num = getNumLayers()[0];
395
      int[] tmp = new int[num];
396
      for(int i=0; i<num; i++) tmp[i] = 3;
397
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
398
      }
399
400 29b82486 Leszek Koltunski
    return mBasicAngle;
401
    }
402
403 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
404
405 5f54927b Leszek Koltunski
  public String getShortName()
406 61aa85e4 Leszek Koltunski
    {
407 5f54927b Leszek Koltunski
    return ObjectType.REX_3.name();
408
    }
409
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411
412 1d581993 Leszek Koltunski
  public ObjectSignature getSignature()
413 5f54927b Leszek Koltunski
    {
414 2dffaf22 Leszek Koltunski
    return new ObjectSignature(ObjectSignatures.REX_3);
415 61aa85e4 Leszek Koltunski
    }
416
417 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
418
419 e26eb4e7 Leszek Koltunski
  public String getObjectName()
420 29b82486 Leszek Koltunski
    {
421 e26eb4e7 Leszek Koltunski
    return "Rex Cube";
422 29b82486 Leszek Koltunski
    }
423
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425
426 e26eb4e7 Leszek Koltunski
  public String getInventor()
427 29b82486 Leszek Koltunski
    {
428 e26eb4e7 Leszek Koltunski
    return "Andrew Cormier";
429 29b82486 Leszek Koltunski
    }
430
431 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
432
433 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
434 59c20632 Leszek Koltunski
    {
435
    return 2009;
436
    }
437
438 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
439
440 e26eb4e7 Leszek Koltunski
  public int getComplexity()
441 29b82486 Leszek Koltunski
    {
442
    return 3;
443
    }
444 052e0362 Leszek Koltunski
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446
447
  public String[][] getTutorials()
448
    {
449
    return new String[][]{
450
                          {"gb","noAQfWqlMbk","Rex Cube Tutorial","CrazyBadCuber"},
451
                          {"es","Q90x9rjLJzw","Resolver Cubo Rex","Cuby"},
452
                          {"ru","Dr9CLM6A3fU","Как собрать Рекс Куб","Алексей Ярыгин"},
453
                          {"fr","SvK1kf6c43c","Résolution du Rex Cube","Asthalis"},
454
                          {"de","AI4vtwpRkEQ","Rex Cube - Tutorial","GerCubing"},
455
                          {"pl","ffbFRnHglWY","Rex Cube TUTORIAL PL","MrUk"},
456
                          {"kr","B3ftZzHRQyU","렉스 큐브 해법","듀나메스 큐브 해법연구소"},
457 a399e91b Leszek Koltunski
                          {"vn","5nE9Q7QmOP4","Tutorial N.87 - Rex Cube","Duy Thích Rubik"},
458 052e0362 Leszek Koltunski
                         };
459
    }
460 29b82486 Leszek Koltunski
}