Project

General

Profile

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

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

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