Project

General

Profile

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

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

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