Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyHelicopter.java @ 7ee89540

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 static org.distorted.objects.Movement.TYPE_SPLIT_EDGE;
23

    
24
import android.content.res.Resources;
25

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

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class TwistyHelicopter extends Twisty6
39
{
40
  // the six rotation axis of a Helicopter. Must be normalized.
41
  static final Static3D[] ROT_AXIS = new Static3D[]
42
         {
43
           new Static3D(     0, +SQ2/2, -SQ2/2),
44
           new Static3D(     0, -SQ2/2, -SQ2/2),
45
           new Static3D(+SQ2/2,      0, -SQ2/2),
46
           new Static3D(-SQ2/2,      0, -SQ2/2),
47
           new Static3D(+SQ2/2, -SQ2/2,      0),
48
           new Static3D(-SQ2/2, -SQ2/2,      0)
49
         };
50

    
51
  private static final int[][][] ENABLED = new int[][][]
52
      {
53
          {{2,5},{2,4},{3,4},{3,5}},
54
          {{2,4},{2,5},{3,5},{3,4}},
55
          {{0,5},{1,5},{1,4},{0,4}},
56
          {{0,4},{1,4},{1,5},{0,5}},
57
          {{1,3},{0,3},{0,2},{1,2}},
58
          {{0,3},{1,3},{1,2},{0,2}},
59
      };
60

    
61
  private ScrambleState[] mStates;
62
  private int[] mBasicAngle;
63
  private Static4D[] mQuats;
64
  private float[][] mCuts;
65
  private boolean[][] mLayerRotatable;
66
  private float[][] mCenters;
67
  private int[] mQuatIndices;
68
  private int[][] mFaceMap;
69
  private ObjectSticker[] mStickers;
70
  private Movement mMovement;
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  TwistyHelicopter(int size, Static4D quat, DistortedTexture texture,
75
                   MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
76
    {
77
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.HELI, res, scrWidth);
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
  ScrambleState[] getScrambleStates()
83
    {
84
    if( mStates==null )
85
      {
86
      mStates = new ScrambleState[]
87
        {
88
        new ScrambleState( new int[][] { {0,1,1,2,1,2},{0,1,3,2,1,4},{0,1,5,2,1,6},{0,1,7,2,1,8},{0,1,9,2,1,10},{0,1,11,2,1,12} } ),
89
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
90
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
91
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
92
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
93
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
94
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
95
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
96
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
97
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
98
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
99
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
100
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
101
        };
102
      }
103

    
104
    return mStates;
105
    }
106

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

    
109
  private void initializeQuats()
110
    {
111
    mQuats = new Static4D[]
112
         {
113
         new Static4D( 0.00f,  0.00f,  0.00f,  1.00f ),
114
         new Static4D( 1.00f,  0.00f,  0.00f,  0.00f ),
115
         new Static4D( 0.00f,  1.00f,  0.00f,  0.00f ),
116
         new Static4D( 0.00f,  0.00f,  1.00f,  0.00f ),
117

    
118
         new Static4D( SQ2/2,  SQ2/2,  0.00f,  0.00f ),
119
         new Static4D( SQ2/2, -SQ2/2,  0.00f,  0.00f ),
120
         new Static4D( SQ2/2,  0.00f,  SQ2/2,  0.00f ),
121
         new Static4D( SQ2/2,  0.00f, -SQ2/2,  0.00f ),
122
         new Static4D( SQ2/2,  0.00f,  0.00f,  SQ2/2 ),
123
         new Static4D( SQ2/2,  0.00f,  0.00f, -SQ2/2 ),
124
         new Static4D( 0.00f,  SQ2/2,  SQ2/2,  0.00f ),
125
         new Static4D( 0.00f,  SQ2/2, -SQ2/2,  0.00f ),
126
         new Static4D( 0.00f,  SQ2/2,  0.00f,  SQ2/2 ),
127
         new Static4D( 0.00f,  SQ2/2,  0.00f, -SQ2/2 ),
128
         new Static4D( 0.00f,  0.00f,  SQ2/2,  SQ2/2 ),
129
         new Static4D( 0.00f,  0.00f,  SQ2/2, -SQ2/2 ),
130

    
131
         new Static4D( 0.50f,  0.50f,  0.50f,  0.50f ),
132
         new Static4D( 0.50f,  0.50f,  0.50f, -0.50f ),
133
         new Static4D( 0.50f,  0.50f, -0.50f,  0.50f ),
134
         new Static4D( 0.50f,  0.50f, -0.50f, -0.50f ),
135
         new Static4D( 0.50f, -0.50f,  0.50f,  0.50f ),
136
         new Static4D( 0.50f, -0.50f,  0.50f, -0.50f ),
137
         new Static4D( 0.50f, -0.50f, -0.50f,  0.50f ),
138
         new Static4D( 0.50f, -0.50f, -0.50f, -0.50f )
139
         };
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  int[] getSolvedQuats(int cubit, int numLayers)
145
    {
146
    if( mQuats==null ) initializeQuats();
147
    int status = retCubitSolvedStatus(cubit,numLayers);
148
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  Static4D[] getQuats()
154
    {
155
    if( mQuats==null ) initializeQuats();
156
    return mQuats;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  int getSolvedFunctionIndex()
162
    {
163
    return 0;
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  int getNumStickerTypes(int numLayers)
169
    {
170
    return 1;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  float[][] getCuts(int size)
176
    {
177
    if( mCuts==null )
178
      {
179
      float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
180
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
181
      }
182

    
183
    return mCuts;
184
    }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
  private void getLayerRotatable(int numLayers)
189
    {
190
    if( mLayerRotatable==null )
191
      {
192
      int numAxis = ROT_AXIS.length;
193
      boolean[] tmp = new boolean[] {true,false,true};
194
      mLayerRotatable = new boolean[numAxis][];
195
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
196
      }
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  int getNumCubitFaces()
202
    {
203
    return 4;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  float[][] getCubitPositions(int size)
209
    {
210
    if( mCenters==null )
211
      {
212
      float DIST_CORNER = 1.50f;
213
      float DIST_CENTER = 1.50f;
214
      float XY_CENTER = DIST_CORNER/3;
215

    
216
      mCenters = new float[][]
217
         {
218
             {   DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
219
             {   DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
220
             {   DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
221
             {   DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
222
             {  -DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
223
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
224
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
225
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
226

    
227
             {   DIST_CENTER,     XY_CENTER,     XY_CENTER },
228
             {   DIST_CENTER,     XY_CENTER,    -XY_CENTER },
229
             {   DIST_CENTER,    -XY_CENTER,     XY_CENTER },
230
             {   DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
231

    
232
             {  -DIST_CENTER,     XY_CENTER,     XY_CENTER },
233
             {  -DIST_CENTER,     XY_CENTER,    -XY_CENTER },
234
             {  -DIST_CENTER,    -XY_CENTER,     XY_CENTER },
235
             {  -DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
236

    
237
             {   XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
238
             {   XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
239
             {  -XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
240
             {  -XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
241

    
242
             {   XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
243
             {   XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
244
             {  -XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
245
             {  -XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
246

    
247
             {   XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
248
             {   XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
249
             {  -XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
250
             {  -XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
251

    
252
             {   XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
253
             {   XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
254
             {  -XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
255
             {  -XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
256
         };
257
      }
258

    
259
    return mCenters;
260
    }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
  ObjectShape getObjectShape(int cubit, int numLayers)
265
    {
266
    int variant = getCubitVariant(cubit,numLayers);
267

    
268
    if( variant==0 )
269
      {
270
      double[][] vertices = new double[][]
271
          {
272
            {-1.50f, 0.00f, 0.00f},
273
            { 0.00f,-1.50f, 0.00f},
274
            { 0.00f, 0.00f,-1.50f},
275
            {-0.75f,-0.75f,-0.75f},
276
            { 0.00f, 0.00f, 0.00f}
277
          };
278

    
279
      int[][] vert_indices = new int[][]
280
          {
281
            {0,1,4},
282
            {2,0,4},
283
            {1,2,4},
284
            {3,1,0},
285
            {3,2,1},
286
            {3,0,2}
287
          };
288

    
289
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,5} };
290
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
291
      float[][] corners   = new float[][] { {0.08f,0.20f} };
292
      int[] cornerIndices = new int[] { 0,0,0,0,0 };
293
      float[][] centers   = new float[][] { {-0.75f, -0.75f, -0.75f} };
294
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
295
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
296
      }
297
    else
298
      {
299
      double[][] vertices = new double[][]
300
          {
301
            { 0.50f, 0.50f, 0.00f },
302
            {-1.00f, 0.50f, 0.00f },
303
            { 0.50f,-1.00f, 0.00f },
304
            {-0.25f,-0.25f,-0.75f },
305
          };
306

    
307
      int[][] vert_indices = new int[][]
308
          {
309
            { 0,1,2 },
310
            { 2,1,3 },
311
            { 0,1,3 },
312
            { 2,0,3 }
313
          };
314

    
315
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
316
      int[] bandIndices   = new int[] { 0,1,1,1 };
317
      float[][] corners   = new float[][] { {0.06f,0.20f} };
318
      int[] cornerIndices = new int[] { 0,0,0,-1 };
319
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.75f} };
320
      int[] centerIndices = new int[] { 0,0,0,-1 };
321
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
322
      }
323
    }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
  Static4D getQuat(int cubit, int numLayers)
328
    {
329
    if( mQuats==null ) initializeQuats();
330
    if( mQuatIndices==null ) mQuatIndices = new int[] { 0,13,14,1,12,2,3,7,20,6,13,17,7,23,18,12,22,10,8,16,11,21,19,9,3,15,14,0,5,2,1,4 };
331
    return mQuats[mQuatIndices[cubit]];
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

    
336
  int getNumCubitVariants(int numLayers)
337
    {
338
    return 2;
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

    
343
  int getCubitVariant(int cubit, int numLayers)
344
    {
345
    return cubit<8 ? 0:1;
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
  int getFaceColor(int cubit, int cubitface, int size)
351
    {
352
    if( mFaceMap==null )
353
      {
354
      mFaceMap = new int[][]
355
         {
356
           { 4,2,0, 6,6,6 },
357
           { 0,2,5, 6,6,6 },
358
           { 4,0,3, 6,6,6 },
359
           { 5,3,0, 6,6,6 },
360
           { 1,2,4, 6,6,6 },
361
           { 5,2,1, 6,6,6 },
362
           { 4,3,1, 6,6,6 },
363
           { 1,3,5, 6,6,6 },
364

    
365
           { 0 , 6,6,6,6,6 },
366
           { 0 , 6,6,6,6,6 },
367
           { 0 , 6,6,6,6,6 },
368
           { 0 , 6,6,6,6,6 },
369

    
370
           { 1 , 6,6,6,6,6 },
371
           { 1 , 6,6,6,6,6 },
372
           { 1 , 6,6,6,6,6 },
373
           { 1 , 6,6,6,6,6 },
374

    
375
           { 2 , 6,6,6,6,6 },
376
           { 2 , 6,6,6,6,6 },
377
           { 2 , 6,6,6,6,6 },
378
           { 2 , 6,6,6,6,6 },
379

    
380
           { 3 , 6,6,6,6,6 },
381
           { 3 , 6,6,6,6,6 },
382
           { 3 , 6,6,6,6,6 },
383
           { 3 , 6,6,6,6,6 },
384

    
385
           { 4 , 6,6,6,6,6 },
386
           { 4 , 6,6,6,6,6 },
387
           { 4 , 6,6,6,6,6 },
388
           { 4 , 6,6,6,6,6 },
389

    
390
           { 5 , 6,6,6,6,6 },
391
           { 5 , 6,6,6,6,6 },
392
           { 5 , 6,6,6,6,6 },
393
           { 5 , 6,6,6,6,6 },
394
         };
395
      }
396

    
397
    return mFaceMap[cubit][cubitface];
398
    }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

    
402
  ObjectSticker retSticker(int face)
403
    {
404
    if( mStickers==null )
405
      {
406
      float[][] STICKERS = new float[][] { { -0.5f, 0.25f, 0.25f, -0.5f, 0.25f, 0.25f } };
407
      float radius = 0.03f;
408
      float stroke = 0.05f;
409
      float[] radii = new float[] {radius,radius,radius};
410
      mStickers = new ObjectSticker[STICKERS.length];
411
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
412
      }
413

    
414
    return mStickers[face/NUM_FACE_COLORS];
415
    }
416

    
417
///////////////////////////////////////////////////////////////////////////////////////////////////
418
// PUBLIC API
419

    
420
  public Static3D[] getRotationAxis()
421
    {
422
    return ROT_AXIS;
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public Movement getMovement()
428
    {
429
    if( mMovement==null )
430
      {
431
      int numLayers = getNumLayers();
432
      if( mCuts==null ) getCuts(numLayers);
433
      getLayerRotatable(numLayers);
434
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_EDGE,ENABLED);
435
      }
436
    return mMovement;
437
    }
438

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

    
441
  public int[] getBasicAngle()
442
    {
443
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
444
    return mBasicAngle;
445
    }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

    
449
  public int getObjectName(int numLayers)
450
    {
451
    return R.string.heli3;
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

    
456
  public int getInventor(int numLayers)
457
    {
458
    return R.string.heli3_inventor;
459
    }
460

    
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

    
463
  public int getComplexity(int numLayers)
464
    {
465
    return 8;
466
    }
467
}
(22-22/38)