Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyRedi.java @ 1b7ece90

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
24

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.helpers.ObjectFaceShape;
31
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
32
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ScrambleState;
36
import org.distorted.objectlib.main.ShapeHexahedron;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TwistyRedi extends ShapeHexahedron
41
{
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
  private ScrambleState[] mStates;
51
  private int[] mBasicAngle;
52
  private float[][] mCuts;
53
  private float[][] mCenters;
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  public TwistyRedi(int[] numL, int meshState, Static4D quat, Static3D move, float scale, InputStream stream)
58
    {
59
    super(numL, meshState, numL[0], quat, move, scale, stream);
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  public ScrambleState[] getScrambleStates()
65
    {
66
    if( mStates==null )
67
      {
68
      mStates = new ScrambleState[]
69
        {
70
        new ScrambleState( new int[][] { {0,1,1,0,-1,1, 2,1,2,2,-1,2},{0,1,3,0,-1,3, 2,1,4,2,-1,4},{0,1,5,0,-1,5, 2,1,6,2,-1,6},{0,1,7,0,-1,7, 2,1,8,2,-1,8} } ),
71
        new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
72
        new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
73
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
74
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
75
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
76
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
77
        new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
78
        new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
79
        };
80
      }
81

    
82
    return mStates;
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  public float[][] getCuts(int[] numLayers)
88
    {
89
    if( mCuts==null )
90
      {
91
      float C = +SQ3/3 +0.05f;
92
      float[] cut = new float[] {-C,+C};
93
      mCuts = new float[][] { cut,cut,cut,cut };
94
      }
95

    
96
    return mCuts;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  public boolean[][] getLayerRotatable(int[] numLayers)
102
    {
103
    boolean[] tmp = new boolean[] {true,false,true};
104
    return new boolean[][] { tmp,tmp,tmp,tmp };
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  public int getTouchControlType()
110
    {
111
    return TC_HEXAHEDRON;
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  public int getTouchControlSplit()
117
    {
118
    return TYPE_SPLIT_CORNER;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  public int[][][] getEnabled()
124
    {
125
    return new int[][][]
126
      {
127
          {{0,1},{3,1},{2,3},{0,2}},
128
          {{2,3},{3,1},{0,1},{0,2}},
129
          {{1,2},{0,1},{0,3},{2,3}},
130
          {{1,2},{2,3},{0,3},{0,1}},
131
          {{0,3},{0,2},{1,2},{1,3}},
132
          {{1,2},{0,2},{0,3},{1,3}},
133
      };
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public float[] getDist3D(int[] numLayers)
139
    {
140
    return TouchControlHexahedron.D3D;
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  public Static3D[] getFaceAxis()
146
    {
147
    return TouchControlHexahedron.FACE_AXIS;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  public float[][] getCubitPositions(int[] numLayers)
153
    {
154
    if( mCenters==null )
155
      {
156
      final float DIST_CORNER = 1.0f;
157
      final float DIST_EDGE   = 1.5f;
158

    
159
      mCenters = new float[][]
160
         {
161
             { DIST_CORNER, DIST_CORNER, DIST_CORNER },
162
             { DIST_CORNER, DIST_CORNER,-DIST_CORNER },
163
             { DIST_CORNER,-DIST_CORNER, DIST_CORNER },
164
             { DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
165
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
166
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
167
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
168
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
169

    
170
             {      0.0f, DIST_EDGE, DIST_EDGE },
171
             { DIST_EDGE,      0.0f, DIST_EDGE },
172
             {      0.0f,-DIST_EDGE, DIST_EDGE },
173
             {-DIST_EDGE,      0.0f, DIST_EDGE },
174
             { DIST_EDGE, DIST_EDGE,      0.0f },
175
             { DIST_EDGE,-DIST_EDGE,      0.0f },
176
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
177
             {-DIST_EDGE, DIST_EDGE,      0.0f },
178
             {      0.0f, DIST_EDGE,-DIST_EDGE },
179
             { DIST_EDGE,      0.0f,-DIST_EDGE },
180
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
181
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
182
         };
183
      }
184

    
185
    return mCenters;
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
  public Static4D getCubitQuats(int cubit, int[] numLayers)
191
    {
192
    switch(cubit)
193
      {
194
      case  0: return mObjectQuats[0];                   //  unit quat
195
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
196
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
197
      case  3: return mObjectQuats[9];                   // 180 along X
198
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
199
      case  5: return mObjectQuats[11];                  // 180 along Y
200
      case  6: return mObjectQuats[10];                  // 180 along Z
201
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
202

    
203
      case  8: return mObjectQuats[0];
204
      case  9: return mObjectQuats[2];
205
      case 10: return mObjectQuats[10];
206
      case 11: return mObjectQuats[8];
207
      case 12: return mObjectQuats[1];
208
      case 13: return mObjectQuats[4];
209
      case 14: return mObjectQuats[6];
210
      case 15: return mObjectQuats[7];
211
      case 16: return mObjectQuats[11];
212
      case 17: return mObjectQuats[5];
213
      case 18: return mObjectQuats[9];
214
      case 19: return mObjectQuats[3];
215
      }
216

    
217
    return null;
218
    }
219

    
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

    
222
  public ObjectShape getObjectShape(int variant)
223
    {
224
    if( variant==0 )
225
      {
226
      float[][] vertices =
227
          {
228
             { 0.0f, 0.0f, 0.0f },
229
             {-0.5f, 0.5f, 0.5f },
230
             {-0.5f,-0.5f, 0.5f },
231
             { 0.5f, 0.5f, 0.5f },
232
             { 0.5f,-0.5f, 0.5f },
233
             { 0.5f, 0.5f,-0.5f },
234
             { 0.5f,-0.5f,-0.5f },
235
             {-0.5f, 0.5f,-0.5f },
236
          };
237

    
238
      int[][] indices =
239
          {
240
             { 2,4,3,1 },
241
             { 1,3,5,7 },
242
             { 4,6,5,3 },
243

    
244
             { 2,4,0 },
245
             { 5,7,0 },
246
             { 4,6,0 },
247
             { 7,1,0 },
248
             { 1,2,0 },
249
             { 6,5,0 }
250
          };
251

    
252
      return new ObjectShape(vertices, indices);
253
      }
254
    else
255
      {
256
      float[][] vertices =
257
          {
258
             {-0.5f, 0.0f, 0.0f},
259
             { 0.5f, 0.0f, 0.0f},
260
             {-0.5f,-1.0f, 0.0f},
261
             { 0.5f,-1.0f, 0.0f},
262
             { 0.0f,-1.5f, 0.0f},
263
             {-0.5f, 0.0f,-1.0f},
264
             { 0.5f, 0.0f,-1.0f},
265
             { 0.0f, 0.0f,-1.5f},
266
          };
267

    
268
      int[][] indices =
269
          {
270
             { 0,2,4,3,1 },
271
             { 0,1,6,7,5 },
272
             { 1,3,6 },
273
             { 0,2,5 },
274
             { 4,7,6,3 },
275
             { 4,7,5,2 }
276
          };
277

    
278
      return new ObjectShape(vertices, indices);
279
      }
280
    }
281

    
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

    
284
  public ObjectFaceShape getObjectFaceShape(int variant)
285
    {
286
    if( variant==0 )
287
      {
288
      float[][] bands     = { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
289
      int[] bandIndices   = { 0,0,0,1,1,1,1,1,1 };
290
      float[][] corners   = { {0.06f,0.12f} };
291
      int[] cornerIndices = { -1,0,-1,0,0,0,-1,-1 };
292
      float[][] centers   = { { 0.0f, 0.0f, 0.0f} };
293
      int[] centerIndices = { -1,0,-1,0,0,0,-1,-1 };
294
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
295
      }
296
    else
297
      {
298
      float[][] bands     = { {0.038f,35,0.250f,0.7f,7,2,2}, {0.020f,35,0.125f,0.2f,3,1,2}, {0.020f,35,0.125f,0.2f,3,1,1} };
299
      int[] bandIndices   = { 0,0,1,1,2,2 };
300
      float[][] corners   = { {0.06f,0.20f} };
301
      int[] cornerIndices = { 0,0,-1,-1,-1,-1,-1,-1 };
302
      float[][] centers   = { { 0.0f,-0.75f,-0.75f} };
303
      int[] centerIndices = { 0,0,-1,-1,-1,-1,-1,-1 };
304
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
305
      }
306
    }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

    
310
  public int getNumCubitVariants(int[] numLayers)
311
    {
312
    return 2;
313
    }
314

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

    
317
  public int getCubitVariant(int cubit, int[] numLayers)
318
    {
319
    return cubit<8 ? 0:1;
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  public float getStickerRadius()
325
    {
326
    return 0.09f;
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  public float getStickerStroke()
332
    {
333
    return ObjectControl.isInIconMode() ? 0.20f : 0.09f;
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  public float[][] getStickerAngles()
339
    {
340
    return null;
341
    }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344
// PUBLIC API
345

    
346
  public Static3D[] getRotationAxis()
347
    {
348
    return ROT_AXIS;
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  public int[] getBasicAngles()
354
    {
355
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
356
    return mBasicAngle;
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

    
361
  public ObjectType intGetObjectType(int[] numLayers)
362
    {
363
    return ObjectType.REDI_3;
364
    }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
  public String getObjectName()
369
    {
370
    return "Redi Cube";
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
  public String getInventor()
376
    {
377
    return "Oskar van Deventer";
378
    }
379

    
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381

    
382
  public int getYearOfInvention()
383
    {
384
    return 2009;
385
    }
386

    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

    
389
  public int getComplexity()
390
    {
391
    return 1;
392
    }
393
}
(19-19/26)