Project

General

Profile

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

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

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