Project

General

Profile

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

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

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 82eb152a Leszek Koltunski
import java.io.InputStream;
16 29b82486 Leszek Koltunski
17
import org.distorted.library.type.Static3D;
18
import org.distorted.library.type.Static4D;
19
20 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
21 3ee1d662 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
22 1d581993 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectSignature;
23 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectVertexEffects;
24 a8295031 Leszek Koltunski
import org.distorted.objectlib.main.InitData;
25 2dffaf22 Leszek Koltunski
import org.distorted.objectlib.main.ObjectSignatures;
26 c9c71c3f Leszek Koltunski
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
27 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
28 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
29 b31249d6 Leszek Koltunski
import org.distorted.objectlib.shape.ShapeHexahedron;
30 29b82486 Leszek Koltunski
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 386af988 Leszek Koltunski
public class TwistyRex extends ShapeHexahedron
34 29b82486 Leszek Koltunski
{
35
  static final Static3D[] ROT_AXIS = new Static3D[]
36
         {
37 84a17011 Leszek Koltunski
           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 29b82486 Leszek Koltunski
         };
42
43
  public static final float REX_D = 0.2f;
44
45 9ba7f3f6 Leszek Koltunski
  private int[][] mEdges;
46 beee90ab Leszek Koltunski
  private int[][] mBasicAngle;
47 29b82486 Leszek Koltunski
  private float[][] mCuts;
48 52f4db8a Leszek Koltunski
  private float[][] mPosition;
49
  private int[] mQuatIndex;
50 29b82486 Leszek Koltunski
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
53 a8295031 Leszek Koltunski
  public TwistyRex(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
54 29b82486 Leszek Koltunski
    {
55 a8295031 Leszek Koltunski
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
56 29b82486 Leszek Koltunski
    }
57
58 ed0988c0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
59
60
  @Override
61
  public void adjustStickerCoords()
62
    {
63
    mStickerCoords = new float[][]
64
          {
65 cc70f525 Leszek Koltunski
             { 0.35f, -0.35f, -0.1428f, 0.5f, -0.5f, 0.1428f },
66 ed0988c0 Leszek Koltunski
             { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
67 cc70f525 Leszek Koltunski
             { 0.00f, -0.200f, 0.525f, 0.105f, -0.525f, 0.105f }
68 ed0988c0 Leszek Koltunski
          };
69
    }
70
71 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
72 ea889ebf Leszek Koltunski
// single state; middle layer doesn't move.
73 29b82486 Leszek Koltunski
74 9ba7f3f6 Leszek Koltunski
  public int[][] getScrambleEdges()
75 29b82486 Leszek Koltunski
    {
76 ea889ebf Leszek Koltunski
    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 9ba7f3f6 Leszek Koltunski
    return mEdges;
81 29b82486 Leszek Koltunski
    }
82
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
85 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
86 29b82486 Leszek Koltunski
    {
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 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
100
    {
101
    boolean[] tmp = new boolean[] {true,false,true};
102 802fe251 Leszek Koltunski
    return new boolean[][] { tmp,tmp,tmp,tmp };
103 59c20632 Leszek Koltunski
    }
104
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
107 11fa413d Leszek Koltunski
  public int getTouchControlType()
108 59c20632 Leszek Koltunski
    {
109 c9c71c3f Leszek Koltunski
    return TC_HEXAHEDRON;
110 59c20632 Leszek Koltunski
    }
111
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
114 11fa413d Leszek Koltunski
  public int getTouchControlSplit()
115 59c20632 Leszek Koltunski
    {
116
    return TYPE_SPLIT_CORNER;
117
    }
118
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
121
  public int[][][] getEnabled()
122 29b82486 Leszek Koltunski
    {
123 59c20632 Leszek Koltunski
    return new int[][][]
124 29b82486 Leszek Koltunski
      {
125 59c20632 Leszek Koltunski
          {{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 4c9ca251 Leszek Koltunski
    return TouchControlHexahedron.D3D;
139
    }
140
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142
143
  public Static3D[] getFaceAxis()
144
    {
145
    return TouchControlHexahedron.FACE_AXIS;
146 29b82486 Leszek Koltunski
    }
147
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149
150 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
151 29b82486 Leszek Koltunski
    {
152 52f4db8a Leszek Koltunski
    if( mPosition==null )
153 802fe251 Leszek Koltunski
      {
154 52f4db8a Leszek Koltunski
      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 29b82486 Leszek Koltunski
    }
210
211 d0e6cf7f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
212
213
  public Static4D getCubitQuats(int cubit, int[] numLayers)
214
    {
215 52f4db8a Leszek Koltunski
    if( mQuatIndex==null )
216 d0e6cf7f Leszek Koltunski
      {
217 52f4db8a Leszek Koltunski
      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 d0e6cf7f Leszek Koltunski
      }
224 52f4db8a Leszek Koltunski
    return mObjectQuats[mQuatIndex[cubit]];
225 d0e6cf7f Leszek Koltunski
    }
226
227 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
228
229 84a17011 Leszek Koltunski
  private float[][] getVertices(int variant)
230 29b82486 Leszek Koltunski
    {
231
    if( variant==0 )
232
      {
233 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} };
234 29b82486 Leszek Koltunski
      }
235
    else if( variant==1 )
236 52f4db8a Leszek Koltunski
      {
237 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} };
238 52f4db8a Leszek Koltunski
      }
239
    else if( variant==2 )
240 29b82486 Leszek Koltunski
      {
241
      float G = 3*REX_D;
242 84a17011 Leszek Koltunski
      return new float[][] { { -G, 0, 0 },{ 0,-G, 0 },{ +G, 0, 0 },{ 0,+G,0 },{ 0, 0,-G} };
243 29b82486 Leszek Koltunski
      }
244
    else
245
      {
246
      float E = 1.5f - 3*REX_D;
247
      float F = 1.5f;
248 84a17011 Leszek Koltunski
      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 3ee1d662 Leszek Koltunski
      }
276
    }
277
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279
280
  public ObjectFaceShape getObjectFaceShape(int variant)
281
    {
282 52f4db8a Leszek Koltunski
    if( variant==0 || variant==1 )
283 3ee1d662 Leszek Koltunski
      {
284 3bf19410 Leszek Koltunski
      float height = isInIconMode() ? 0.001f : 0.02f;
285 3ee1d662 Leszek Koltunski
      float G = (1-REX_D)*SQ2/2;
286 84a17011 Leszek Koltunski
      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 3ee1d662 Leszek Koltunski
      }
290 52f4db8a Leszek Koltunski
    else if( variant==2 )
291 3ee1d662 Leszek Koltunski
      {
292 3bf19410 Leszek Koltunski
      float height = isInIconMode() ? 0.001f : 0.025f;
293 3ee1d662 Leszek Koltunski
      float G = 3*REX_D;
294 84a17011 Leszek Koltunski
      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 3ee1d662 Leszek Koltunski
      }
298
    else
299
      {
300 3bf19410 Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.03f;
301
      float h2 = isInIconMode() ? 0.001f : 0.01f;
302 3ee1d662 Leszek Koltunski
      float E = 1.5f - 3*REX_D;
303
      float F = 1.5f;
304
      float G = (float)Math.sqrt(E*E+F*F);
305 84a17011 Leszek Koltunski
      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 3ee1d662 Leszek Koltunski
      float[][] centers= { {0.0f,-1.5f,-1.5f} };
329
      float[][] corners= { {0.06f,0.20f} };
330
      int[] indices    = { 0,-1,0,-1 };
331 84a17011 Leszek Koltunski
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
332 29b82486 Leszek Koltunski
      }
333
    }
334
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336
337 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
338 29b82486 Leszek Koltunski
    {
339 52f4db8a Leszek Koltunski
    return 4;
340 29b82486 Leszek Koltunski
    }
341
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
344 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
345 29b82486 Leszek Koltunski
    {
346 52f4db8a Leszek Koltunski
    return cubit<12 ? 0 : (cubit<24 ? 1 : (cubit<30?2:3));
347 29b82486 Leszek Koltunski
    }
348
349 00f4980d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
350 29b82486 Leszek Koltunski
351 d53fb890 Leszek Koltunski
  public float getStickerRadius()
352 00f4980d Leszek Koltunski
    {
353
    return 0.09f;
354
    }
355
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357
358 d53fb890 Leszek Koltunski
  public float getStickerStroke()
359 00f4980d Leszek Koltunski
    {
360 3bf19410 Leszek Koltunski
    return isInIconMode() ? 0.25f : 0.12f;
361 00f4980d Leszek Koltunski
    }
362
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364 8592461c Leszek Koltunski
365 d53fb890 Leszek Koltunski
  public float[][] getStickerAngles()
366 00f4980d Leszek Koltunski
    {
367
    final float F = (float)(Math.PI/20);
368 cc70f525 Leszek Koltunski
    return new float[][] { { F,-F/2,F },{0,0,0,0},{ -F,0,-F } };
369 00f4980d Leszek Koltunski
    }
370
371 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
372
// PUBLIC API
373
374
  public Static3D[] getRotationAxis()
375
    {
376
    return ROT_AXIS;
377
    }
378
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380
381 beee90ab Leszek Koltunski
  public int[][] getBasicAngles()
382 29b82486 Leszek Koltunski
    {
383 beee90ab Leszek Koltunski
    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 29b82486 Leszek Koltunski
    return mBasicAngle;
392
    }
393
394 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
395
396 5f54927b Leszek Koltunski
  public String getShortName()
397 61aa85e4 Leszek Koltunski
    {
398 5f54927b Leszek Koltunski
    return ObjectType.REX_3.name();
399
    }
400
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402
403 1d581993 Leszek Koltunski
  public ObjectSignature getSignature()
404 5f54927b Leszek Koltunski
    {
405 2dffaf22 Leszek Koltunski
    return new ObjectSignature(ObjectSignatures.REX_3);
406 61aa85e4 Leszek Koltunski
    }
407
408 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
409
410 e26eb4e7 Leszek Koltunski
  public String getObjectName()
411 29b82486 Leszek Koltunski
    {
412 e26eb4e7 Leszek Koltunski
    return "Rex Cube";
413 29b82486 Leszek Koltunski
    }
414
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416
417 e26eb4e7 Leszek Koltunski
  public String getInventor()
418 29b82486 Leszek Koltunski
    {
419 e26eb4e7 Leszek Koltunski
    return "Andrew Cormier";
420 29b82486 Leszek Koltunski
    }
421
422 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
423
424 e26eb4e7 Leszek Koltunski
  public int getYearOfInvention()
425 59c20632 Leszek Koltunski
    {
426
    return 2009;
427
    }
428
429 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
430
431 e26eb4e7 Leszek Koltunski
  public int getComplexity()
432 29b82486 Leszek Koltunski
    {
433
    return 3;
434
    }
435 052e0362 Leszek Koltunski
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 a399e91b Leszek Koltunski
                          {"vn","5nE9Q7QmOP4","Tutorial N.87 - Rex Cube","Duy Thích Rubik"},
449 052e0362 Leszek Koltunski
                         };
450
    }
451 29b82486 Leszek Koltunski
}