Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyHelicopter.java @ e26eb4e7

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.main.Movement.MOVEMENT_HEXAHEDRON;
23
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_EDGE;
24

    
25
import android.content.res.Resources;
26

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

    
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.main.Movement6;
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.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37
import org.distorted.objectlib.main.Twisty6;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

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

    
54
  private ScrambleState[] mStates;
55
  private int[] mBasicAngle;
56
  private Static4D[] mQuats;
57
  private float[][] mCuts;
58
  private float[][] mCenters;
59
  private int[] mQuatIndices;
60
  private int[][] mFaceMap;
61
  private ObjectSticker[] mStickers;
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  public TwistyHelicopter(int[] numL, Static4D quat, Static3D move,Resources res)
66
    {
67
    super(numL, numL[0], quat, move, res);
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  public ScrambleState[] getScrambleStates()
73
    {
74
    if( mStates==null )
75
      {
76
      mStates = new ScrambleState[]
77
        {
78
        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} } ),
79
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
80
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
81
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
82
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
83
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
84
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
85
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
86
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
87
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
88
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
89
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
90
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
91
        };
92
      }
93

    
94
    return mStates;
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
  protected int getResource(int[] numLayers)
100
    {
101
    return R.raw.heli_3;
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  private void initializeQuats()
107
    {
108
    mQuats = new Static4D[]
109
         {
110
         new Static4D( 0.00f,  0.00f,  0.00f,  1.00f ),
111
         new Static4D( 1.00f,  0.00f,  0.00f,  0.00f ),
112
         new Static4D( 0.00f,  1.00f,  0.00f,  0.00f ),
113
         new Static4D( 0.00f,  0.00f,  1.00f,  0.00f ),
114

    
115
         new Static4D( SQ2/2,  SQ2/2,  0.00f,  0.00f ),
116
         new Static4D( SQ2/2, -SQ2/2,  0.00f,  0.00f ),
117
         new Static4D( SQ2/2,  0.00f,  SQ2/2,  0.00f ),
118
         new Static4D( SQ2/2,  0.00f, -SQ2/2,  0.00f ),
119
         new Static4D( SQ2/2,  0.00f,  0.00f,  SQ2/2 ),
120
         new Static4D( SQ2/2,  0.00f,  0.00f, -SQ2/2 ),
121
         new Static4D( 0.00f,  SQ2/2,  SQ2/2,  0.00f ),
122
         new Static4D( 0.00f,  SQ2/2, -SQ2/2,  0.00f ),
123
         new Static4D( 0.00f,  SQ2/2,  0.00f,  SQ2/2 ),
124
         new Static4D( 0.00f,  SQ2/2,  0.00f, -SQ2/2 ),
125
         new Static4D( 0.00f,  0.00f,  SQ2/2,  SQ2/2 ),
126
         new Static4D( 0.00f,  0.00f,  SQ2/2, -SQ2/2 ),
127

    
128
         new Static4D( 0.50f,  0.50f,  0.50f,  0.50f ),
129
         new Static4D( 0.50f,  0.50f,  0.50f, -0.50f ),
130
         new Static4D( 0.50f,  0.50f, -0.50f,  0.50f ),
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
         };
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

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

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

    
150
  public Static4D[] getQuats()
151
    {
152
    if( mQuats==null ) initializeQuats();
153
    return mQuats;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  public int getSolvedFunctionIndex()
159
    {
160
    return 0;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  public int getNumStickerTypes(int[] numLayers)
166
    {
167
    return 1;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  public float[][] getCuts(int[] numLayers)
173
    {
174
    if( mCuts==null )
175
      {
176
      float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
177
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
178
      }
179

    
180
    return mCuts;
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  public boolean[][] getLayerRotatable(int[] numLayers)
186
    {
187
    int numAxis = ROT_AXIS.length;
188
    boolean[] tmp = new boolean[] {true,false,true};
189
    boolean[][] layerRotatable = new boolean[numAxis][];
190
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
191

    
192
    return layerRotatable;
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  public int getMovementType()
198
    {
199
    return MOVEMENT_HEXAHEDRON;
200
    }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

    
204
  public int getMovementSplit()
205
    {
206
    return TYPE_SPLIT_EDGE;
207
    }
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210

    
211
  public int[][][] getEnabled()
212
    {
213
    return new int[][][]
214
      {
215
          {{2,5},{2,4},{3,4},{3,5}},
216
          {{2,4},{2,5},{3,5},{3,4}},
217
          {{0,5},{1,5},{1,4},{0,4}},
218
          {{0,4},{1,4},{1,5},{0,5}},
219
          {{1,3},{0,3},{0,2},{1,2}},
220
          {{0,3},{1,3},{1,2},{0,2}},
221
      };
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public float[] getDist3D(int[] numLayers)
227
    {
228
    return null;
229
    }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

    
233
  public int getNumCubitFaces()
234
    {
235
    return 6;
236
    }
237

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

    
240
  public float[][] getCubitPositions(int[] numLayers)
241
    {
242
    if( mCenters==null )
243
      {
244
      float DIST_CORNER = 1.50f;
245
      float DIST_CENTER = 1.50f;
246
      float XY_CENTER = DIST_CORNER/3;
247

    
248
      mCenters = new float[][]
249
         {
250
             {   DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
251
             {   DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
252
             {   DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
253
             {   DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
254
             {  -DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
255
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
256
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
257
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
258

    
259
             {   DIST_CENTER,     XY_CENTER,     XY_CENTER },
260
             {   DIST_CENTER,     XY_CENTER,    -XY_CENTER },
261
             {   DIST_CENTER,    -XY_CENTER,     XY_CENTER },
262
             {   DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
263

    
264
             {  -DIST_CENTER,     XY_CENTER,     XY_CENTER },
265
             {  -DIST_CENTER,     XY_CENTER,    -XY_CENTER },
266
             {  -DIST_CENTER,    -XY_CENTER,     XY_CENTER },
267
             {  -DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
268

    
269
             {   XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
270
             {   XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
271
             {  -XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
272
             {  -XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
273

    
274
             {   XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
275
             {   XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
276
             {  -XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
277
             {  -XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
278

    
279
             {   XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
280
             {   XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
281
             {  -XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
282
             {  -XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
283

    
284
             {   XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
285
             {   XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
286
             {  -XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
287
             {  -XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
288
         };
289
      }
290

    
291
    return mCenters;
292
    }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
  public ObjectShape getObjectShape(int variant)
297
    {
298
    if( variant==0 )
299
      {
300
      double[][] vertices = new double[][]
301
          {
302
            {-1.50f, 0.00f, 0.00f},
303
            { 0.00f,-1.50f, 0.00f},
304
            { 0.00f, 0.00f,-1.50f},
305
            {-0.75f,-0.75f,-0.75f},
306
            { 0.00f, 0.00f, 0.00f}
307
          };
308

    
309
      int[][] vert_indices = new int[][]
310
          {
311
            {0,1,4},
312
            {2,0,4},
313
            {1,2,4},
314
            {3,1,0},
315
            {3,2,1},
316
            {3,0,2}
317
          };
318

    
319
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,5} };
320
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
321
      float[][] corners   = new float[][] { {0.08f,0.20f} };
322
      int[] cornerIndices = new int[] { 0,0,0,0,0 };
323
      float[][] centers   = new float[][] { {-0.75f, -0.75f, -0.75f} };
324
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
325
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
326
      }
327
    else
328
      {
329
      double[][] vertices = new double[][]
330
          {
331
            { 0.50f, 0.50f, 0.00f },
332
            {-1.00f, 0.50f, 0.00f },
333
            { 0.50f,-1.00f, 0.00f },
334
            {-0.25f,-0.25f,-0.75f },
335
          };
336

    
337
      int[][] vert_indices = new int[][]
338
          {
339
            { 0,1,2 },
340
            { 2,1,3 },
341
            { 0,1,3 },
342
            { 2,0,3 }
343
          };
344

    
345
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
346
      int[] bandIndices   = new int[] { 0,1,1,1 };
347
      float[][] corners   = new float[][] { {0.06f,0.20f} };
348
      int[] cornerIndices = new int[] { 0,0,0,-1 };
349
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.75f} };
350
      int[] centerIndices = new int[] { 0,0,0,-1 };
351
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
352
      }
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  public Static4D getQuat(int cubit, int[] numLayers)
358
    {
359
    if( mQuats==null ) initializeQuats();
360
    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 };
361
    return mQuats[mQuatIndices[cubit]];
362
    }
363

    
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365

    
366
  public int getNumCubitVariants(int[] numLayers)
367
    {
368
    return 2;
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
  public int getCubitVariant(int cubit, int[] numLayers)
374
    {
375
    return cubit<8 ? 0:1;
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
381
    {
382
    return 0;
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
388
    {
389
    if( mFaceMap==null )
390
      {
391
      mFaceMap = new int[][]
392
         {
393
           { 4,2,0, -1,-1,-1 },
394
           { 0,2,5, -1,-1,-1 },
395
           { 4,0,3, -1,-1,-1 },
396
           { 5,3,0, -1,-1,-1 },
397
           { 1,2,4, -1,-1,-1 },
398
           { 5,2,1, -1,-1,-1 },
399
           { 4,3,1, -1,-1,-1 },
400
           { 1,3,5, -1,-1,-1 },
401

    
402
           { 0 , -1,-1,-1,-1,-1 },
403
           { 0 , -1,-1,-1,-1,-1 },
404
           { 0 , -1,-1,-1,-1,-1 },
405
           { 0 , -1,-1,-1,-1,-1 },
406

    
407
           { 1 , -1,-1,-1,-1,-1 },
408
           { 1 , -1,-1,-1,-1,-1 },
409
           { 1 , -1,-1,-1,-1,-1 },
410
           { 1 , -1,-1,-1,-1,-1 },
411

    
412
           { 2 , -1,-1,-1,-1,-1 },
413
           { 2 , -1,-1,-1,-1,-1 },
414
           { 2 , -1,-1,-1,-1,-1 },
415
           { 2 , -1,-1,-1,-1,-1 },
416

    
417
           { 3 , -1,-1,-1,-1,-1 },
418
           { 3 , -1,-1,-1,-1,-1 },
419
           { 3 , -1,-1,-1,-1,-1 },
420
           { 3 , -1,-1,-1,-1,-1 },
421

    
422
           { 4 , -1,-1,-1,-1,-1 },
423
           { 4 , -1,-1,-1,-1,-1 },
424
           { 4 , -1,-1,-1,-1,-1 },
425
           { 4 , -1,-1,-1,-1,-1 },
426

    
427
           { 5 , -1,-1,-1,-1,-1 },
428
           { 5 , -1,-1,-1,-1,-1 },
429
           { 5 , -1,-1,-1,-1,-1 },
430
           { 5 , -1,-1,-1,-1,-1 },
431
         };
432
      }
433

    
434
    return mFaceMap[cubit][face];
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  public ObjectSticker retSticker(int sticker)
440
    {
441
    if( mStickers==null )
442
      {
443
      float[][] STICKERS = new float[][] { { -0.5f, 0.25f, 0.25f, -0.5f, 0.25f, 0.25f } };
444
      float radius = 0.03f;
445
      float stroke = 0.05f;
446
      float[] radii = new float[] {radius,radius,radius};
447

    
448
      if( ObjectControl.isInIconMode() )
449
        {
450
        stroke*=2.0f;
451
        }
452

    
453
      mStickers = new ObjectSticker[STICKERS.length];
454
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
455
      }
456

    
457
    return mStickers[sticker];
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461
// PUBLIC API
462

    
463
  public Static3D[] getRotationAxis()
464
    {
465
    return ROT_AXIS;
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  public int[] getBasicAngle()
471
    {
472
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
473
    return mBasicAngle;
474
    }
475

    
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

    
478
  public ObjectType intGetObjectType(int[] numLayers)
479
    {
480
    return ObjectType.HELI_3;
481
    }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
  public String getObjectName()
486
    {
487
    return "Helicopter Cube";
488
    }
489

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491

    
492
  public String getInventor()
493
    {
494
    return "Adam G. Cowan";
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  public int getYearOfInvention()
500
    {
501
    return 2006;
502
    }
503

    
504
///////////////////////////////////////////////////////////////////////////////////////////////////
505

    
506
  public int getComplexity()
507
    {
508
    return 8;
509
    }
510
}
(11-11/25)