Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.objects;
11

    
12
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
14

    
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17

    
18
import org.distorted.objectlib.helpers.FactoryCubit;
19
import org.distorted.objectlib.helpers.ObjectFaceShape;
20
import org.distorted.objectlib.metadata.Metadata;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
24
import org.distorted.objectlib.metadata.ListObjects;
25
import org.distorted.objectlib.helpers.ObjectShape;
26
import org.distorted.objectlib.shape.ShapeHexahedron;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class TwistyRex extends ShapeHexahedron
31
{
32
  static final Static3D[] ROT_AXIS = new Static3D[]
33
         {
34
           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
         };
39

    
40
  public static final float REX_D = 0.2f;
41

    
42
  private int[][] mEdges;
43
  private int[][] mBasicAngle;
44
  private float[][] mCuts;
45
  private float[][] mPosition;
46
  private int[] mQuatIndex;
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  public TwistyRex(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
51
    {
52
    super(iconMode, meta.getNumLayers()[0], quat, move, scale, meta, asset);
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  @Override
68
  public void adjustStickerCoords()
69
    {
70
    mStickerCoords = new float[][][][]
71
          {
72
             { { { 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
          };
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
// single state; middle layer doesn't move.
80

    
81
  public int[][] getScrambleEdges()
82
    {
83
    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
    return mEdges;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  public float[][] getCuts(int[] numLayers)
93
    {
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
  public boolean[][] getLayerRotatable(int[] numLayers)
107
    {
108
    boolean[] tmp = new boolean[] {true,false,true};
109
    return new boolean[][] { tmp,tmp,tmp,tmp };
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public int getTouchControlType()
115
    {
116
    return TC_HEXAHEDRON;
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  public int getTouchControlSplit()
122
    {
123
    return TYPE_SPLIT_CORNER;
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public int[][][] getEnabled()
129
    {
130
    return new int[][][]
131
      {
132
          {{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
    return TouchControlHexahedron.D3D;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public Static3D[] getFaceAxis()
151
    {
152
    return TouchControlHexahedron.FACE_AXIS;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public float[][] getCubitPositions(int[] numLayers)
158
    {
159
    if( mPosition==null )
160
      {
161
      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
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  public Static4D getCubitQuats(int cubit, int[] numLayers)
221
    {
222
    if( mQuatIndex==null )
223
      {
224
      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
      }
231
    return mObjectQuats[mQuatIndex[cubit]];
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  private float[][] getVertices(int variant)
237
    {
238
    if( variant==0 )
239
      {
240
      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
      }
242
    else if( variant==1 )
243
      {
244
      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
      }
246
    else if( variant==2 )
247
      {
248
      float G = 3*REX_D;
249
      return new float[][] { { -G, 0, 0 },{ 0,-G, 0 },{ +G, 0, 0 },{ 0,+G,0 },{ 0, 0,-G} };
250
      }
251
    else
252
      {
253
      float E = 1.5f - 3*REX_D;
254
      float F = 1.5f;
255
      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
      }
283
    }
284

    
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286

    
287
  public ObjectFaceShape getObjectFaceShape(int variant)
288
    {
289
    if( variant==0 || variant==1 )
290
      {
291
      float height = isInIconMode() ? 0.001f : 0.02f;
292
      float G = (1-REX_D)*SQ2/2;
293
      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
      }
297
    else if( variant==2 )
298
      {
299
      float height = isInIconMode() ? 0.001f : 0.025f;
300
      float G = 3*REX_D;
301
      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
      }
305
    else
306
      {
307
      float h1 = isInIconMode() ? 0.001f : 0.03f;
308
      float h2 = isInIconMode() ? 0.001f : 0.01f;
309
      float E = 1.5f - 3*REX_D;
310
      float F = 1.5f;
311
      float G = (float)Math.sqrt(E*E+F*F);
312
      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
      float[][] centers= { {0.0f,-1.5f,-1.5f} };
336
      float[][] corners= { {0.06f,0.20f} };
337
      int[] indices    = { 0,-1,0,-1 };
338
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
339
      }
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
  public int getNumCubitVariants(int[] numLayers)
345
    {
346
    return 4;
347
    }
348

    
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350

    
351
  public int getCubitVariant(int cubit, int[] numLayers)
352
    {
353
    return cubit<12 ? 0 : (cubit<24 ? 1 : (cubit<30?2:3));
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
  public float getStickerRadius()
359
    {
360
    return 0.09f;
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  public float getStickerStroke()
366
    {
367
    return isInIconMode() ? 0.25f : 0.12f;
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public float[][][] getStickerAngles()
373
    {
374
    final float F = (float)(Math.PI/20);
375
    return new float[][][] { {{ F,-F/2,F }} , {{0,0,0,0}} , {{ -F,0,-F }} };
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379
// PUBLIC API
380

    
381
  public Static3D[] getRotationAxis()
382
    {
383
    return ROT_AXIS;
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

    
388
  public int[][] getBasicAngles()
389
    {
390
    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
    return mBasicAngle;
399
    }
400

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402

    
403
  public String getShortName()
404
    {
405
    return ListObjects.REX_3.name();
406
    }
407

    
408
///////////////////////////////////////////////////////////////////////////////////////////////////
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
                          {"vn","5nE9Q7QmOP4","Tutorial N.87 - Rex Cube","Duy Thích Rubik"},
421
                          {"tw","XZYHm28qiHE","八軸魔星 教學","不正常魔術方塊研究中心"},
422
                         };
423
    }
424
}
(47-47/59)