Project

General

Profile

Download (15.4 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyRedi.java @ efa81f0c

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.objects;
21

    
22
import android.content.res.Resources;
23

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleState;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32
import org.distorted.main.R;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class TwistyRedi extends Twisty6
37
{
38
  static final Static3D[] ROT_AXIS = new Static3D[]
39
         {
40
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
41
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
42
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
43
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
44
         };
45

    
46
  private ScrambleState[] mStates;
47
  private int[] mBasicAngle;
48
  private Static4D[] mQuats;
49
  private float[][] mCenters;
50
  private int[][] mFaceMap;
51
  private ObjectSticker[] mStickers;
52
  private Movement mMovement;
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  TwistyRedi(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
57
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
58
    {
59
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.REDI, res, scrWidth);
60
    }
61

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

    
64
  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
  private void initializeQuats()
88
    {
89
    mQuats = new Static4D[]
90
         {
91
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
92
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
93
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
94
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
95

    
96
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
97
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
98
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
99
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
100
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
101
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
102
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
103
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
104
         };
105
    }
106

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

    
109
  int[] getSolvedQuats(int cubit, int numLayers)
110
    {
111
    if( mQuats==null ) initializeQuats();
112
    int status = retCubitSolvedStatus(cubit,numLayers);
113
    return status<0 ? null : buildSolvedQuats(MovementCornerTwisting.FACE_AXIS[status],mQuats);
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  Static4D[] getQuats()
119
    {
120
    if( mQuats==null ) initializeQuats();
121
    return mQuats;
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  int getSolvedFunctionIndex()
127
    {
128
    return 0;
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  int getNumStickerTypes(int numLayers)
134
    {
135
    return 2;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  float[][] getCuts(int size)
141
    {
142
    float C = +SQ3/3 +0.05f;
143
    float[] cut = new float[] {-C,+C};
144
    return new float[][] { cut,cut,cut,cut };
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  int getNumCubitFaces()
150
    {
151
    return 9;
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  float[][] getCubitPositions(int size)
157
    {
158
    if( mCenters==null )
159
      {
160
      final float DIST_CORNER = 1.0f;
161
      final float DIST_EDGE   = 1.5f;
162

    
163
      mCenters = new float[][]
164
         {
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
             {-DIST_CORNER, DIST_CORNER, DIST_CORNER },
170
             {-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
171
             {-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
172
             {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
173

    
174
             {      0.0f, DIST_EDGE, DIST_EDGE },
175
             { DIST_EDGE,      0.0f, DIST_EDGE },
176
             {      0.0f,-DIST_EDGE, DIST_EDGE },
177
             {-DIST_EDGE,      0.0f, DIST_EDGE },
178
             { DIST_EDGE, DIST_EDGE,      0.0f },
179
             { DIST_EDGE,-DIST_EDGE,      0.0f },
180
             {-DIST_EDGE,-DIST_EDGE,      0.0f },
181
             {-DIST_EDGE, DIST_EDGE,      0.0f },
182
             {      0.0f, DIST_EDGE,-DIST_EDGE },
183
             { DIST_EDGE,      0.0f,-DIST_EDGE },
184
             {      0.0f,-DIST_EDGE,-DIST_EDGE },
185
             {-DIST_EDGE,      0.0f,-DIST_EDGE }
186
         };
187
      }
188

    
189
    return mCenters;
190
    }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

    
194
  ObjectShape getObjectShape(int cubit, int numLayers)
195
    {
196
    int variant = getCubitVariant(cubit,numLayers);
197

    
198
    if( variant==0 )
199
      {
200
      double[][] vertices = new double[][]
201
          {
202
             { 0.0f, 0.0f, 0.0f },
203
             {-0.5f, 0.5f, 0.5f },
204
             {-0.5f,-0.5f, 0.5f },
205
             { 0.5f, 0.5f, 0.5f },
206
             { 0.5f,-0.5f, 0.5f },
207
             { 0.5f, 0.5f,-0.5f },
208
             { 0.5f,-0.5f,-0.5f },
209
             {-0.5f, 0.5f,-0.5f },
210
          };
211

    
212
      int[][] vert_indices = new int[][]
213
          {
214
             { 2,4,3,1 },
215
             { 1,3,5,7 },
216
             { 4,6,5,3 },
217

    
218
             { 2,4,0 },
219
             { 5,7,0 },
220
             { 4,6,0 },
221
             { 7,1,0 },
222
             { 1,2,0 },
223
             { 6,5,0 }
224
          };
225

    
226
      float[][] bands     = new float[][] { {0.06f,35,0.5f,0.7f,5,2,2}, {0.01f,35,0.2f,0.4f,5,2,2} };
227
      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
228
      float[][] corners   = new float[][] { {0.06f,0.12f} };
229
      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
230
      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
231
      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
232
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
233
      }
234
    else
235
      {
236
      double[][] vertices = new double[][]
237
          {
238
             {-0.5f, 0.0f, 0.0f},
239
             { 0.5f, 0.0f, 0.0f},
240
             {-0.5f,-1.0f, 0.0f},
241
             { 0.5f,-1.0f, 0.0f},
242
             { 0.0f,-1.5f, 0.0f},
243
             {-0.5f, 0.0f,-1.0f},
244
             { 0.5f, 0.0f,-1.0f},
245
             { 0.0f, 0.0f,-1.5f},
246
          };
247

    
248
      int[][] vert_indices = new int[][]
249
          {
250
             { 0,2,4,3,1 },
251
             { 0,1,6,7,5 },
252
             { 1,3,6 },
253
             { 0,2,5 },
254
             { 4,7,6,3 },
255
             { 4,7,5,2 }
256
          };
257

    
258
      float[][] bands     = new float[][] { {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} };
259
      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
260
      float[][] corners   = new float[][] { {0.06f,0.20f} };
261
      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
262
      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
263
      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
264
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
265
      }
266
    }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269

    
270
  Static4D getQuat(int cubit, int numLayers)
271
    {
272
    if( mQuats==null ) initializeQuats();
273

    
274
    switch(cubit)
275
      {
276
      case  0: return mQuats[0];                         //  unit quat
277
      case  1: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along X
278
      case  2: return new Static4D(-SQ2/2,0,0,SQ2/2);    // -90 along X
279
      case  3: return mQuats[1];                         // 180 along X
280
      case  4: return new Static4D(0, SQ2/2,0,SQ2/2);    //  90 along Y
281
      case  5: return mQuats[2];                         // 180 along Y
282
      case  6: return mQuats[3];                         // 180 along Z
283
      case  7: return new Static4D(SQ2/2,0,-SQ2/2,0);    // 180 along (SQ2/2,0,-SQ2/2)
284

    
285
      case  8: return mQuats[0];
286
      case  9: return mQuats[5];
287
      case 10: return mQuats[3];
288
      case 11: return mQuats[11];
289
      case 12: return mQuats[4];
290
      case 13: return mQuats[7];
291
      case 14: return mQuats[9];
292
      case 15: return mQuats[10];
293
      case 16: return mQuats[2];
294
      case 17: return mQuats[8];
295
      case 18: return mQuats[1];
296
      case 19: return mQuats[6];
297
      }
298

    
299
    return null;
300
    }
301

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

    
304
  int getNumCubitVariants(int numLayers)
305
    {
306
    return 2;
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
  int getCubitVariant(int cubit, int numLayers)
312
    {
313
    return cubit<8 ? 0:1;
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  int getFaceColor(int cubit, int cubitface, int size)
319
    {
320
    if( mFaceMap==null )
321
      {
322
      // Colors of the faces of cubits.
323
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4  ORANGE 5
324
      // YELLOW 6 WHITE 7 BLUE 8 GREEN 9 RED 10 ORANGE 11
325
      mFaceMap = new int[][]
326
         {
327
           {  4, 2, 0 },
328
           {  2, 5, 0 },
329
           {  3, 4, 0 },
330
           {  5, 3, 0 },
331
           {  1, 2, 4 },
332
           {  5, 2, 1 },
333
           {  4, 3, 1 },
334
           {  1, 3, 5 },
335

    
336
           { 10, 8,12 },
337
           {  6,10,12 },
338
           { 10, 9,12 },
339
           {  7,10,12 },
340
           {  8, 6,12 },
341
           {  9, 6,12 },
342
           {  9, 7,12 },
343
           {  8, 7,12 },
344
           { 11, 8,12 },
345
           {  6,11,12 },
346
           { 11, 9,12 },
347
           {  7,11,12 },
348
         };
349
      }
350

    
351
    return cubitface<3 ? mFaceMap[cubit][cubitface] : NUM_TEXTURES;
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  ObjectSticker retSticker(int face)
357
    {
358
    if( mStickers==null )
359
      {
360
      float[][] STICKERS = new float[][]
361
          {
362
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
363
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
364
          };
365

    
366
      final float R0 = 0.09f;
367
      final float R1 = 0.06f;
368
      final float[][] radii = { {R0,R0,R0,R0},{R1,R1,R1,R1,R1} };
369
      final float[] strokes = { 0.09f,0.06f };
370

    
371
      mStickers = new ObjectSticker[STICKERS.length];
372

    
373
      for(int s=0; s<STICKERS.length; s++)
374
        {
375
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
376
        }
377
      }
378

    
379
    return mStickers[face/NUM_FACE_COLORS];
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383
// PUBLIC API
384

    
385
  public Static3D[] getRotationAxis()
386
    {
387
    return ROT_AXIS;
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
  public Movement getMovement()
393
    {
394
    if( mMovement==null ) mMovement = new MovementCornerTwisting();
395
    return mMovement;
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  public int[] getBasicAngle()
401
    {
402
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
403
    return mBasicAngle;
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  public int getObjectName(int numLayers)
409
    {
410
    return R.string.redi2;
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
  public int getInventor(int numLayers)
416
    {
417
    return R.string.redi2_inventor;
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public int getComplexity(int numLayers)
423
    {
424
    return 4;
425
    }
426
}
(42-42/48)