Project

General

Profile

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

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

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_EDGE;
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.touchcontrol.TouchControlHexahedron;
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objectlib.main.ObjectType;
33
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.helpers.ObjectSticker;
35
import org.distorted.objectlib.helpers.ScrambleState;
36
import org.distorted.objectlib.main.ShapeHexahedron;
37

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

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

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

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

    
64
  public TwistyHelicopter(int[] numL, Static4D quat, Static3D move, float scale, InputStream stream)
65
    {
66
    super(numL, numL[0], quat, move, scale, stream);
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

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

    
93
    return mStates;
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  private void initializeQuats()
99
    {
100
    mQuats = new Static4D[]
101
         {
102
         new Static4D( 0.00f,  0.00f,  0.00f,  1.00f ),
103
         new Static4D( 1.00f,  0.00f,  0.00f,  0.00f ),
104
         new Static4D( 0.00f,  1.00f,  0.00f,  0.00f ),
105
         new Static4D( 0.00f,  0.00f,  1.00f,  0.00f ),
106

    
107
         new Static4D( SQ2/2,  SQ2/2,  0.00f,  0.00f ),
108
         new Static4D( SQ2/2, -SQ2/2,  0.00f,  0.00f ),
109
         new Static4D( SQ2/2,  0.00f,  SQ2/2,  0.00f ),
110
         new Static4D( SQ2/2,  0.00f, -SQ2/2,  0.00f ),
111
         new Static4D( SQ2/2,  0.00f,  0.00f,  SQ2/2 ),
112
         new Static4D( SQ2/2,  0.00f,  0.00f, -SQ2/2 ),
113
         new Static4D( 0.00f,  SQ2/2,  SQ2/2,  0.00f ),
114
         new Static4D( 0.00f,  SQ2/2, -SQ2/2,  0.00f ),
115
         new Static4D( 0.00f,  SQ2/2,  0.00f,  SQ2/2 ),
116
         new Static4D( 0.00f,  SQ2/2,  0.00f, -SQ2/2 ),
117
         new Static4D( 0.00f,  0.00f,  SQ2/2,  SQ2/2 ),
118
         new Static4D( 0.00f,  0.00f,  SQ2/2, -SQ2/2 ),
119

    
120
         new Static4D( 0.50f,  0.50f,  0.50f,  0.50f ),
121
         new Static4D( 0.50f,  0.50f,  0.50f, -0.50f ),
122
         new Static4D( 0.50f,  0.50f, -0.50f,  0.50f ),
123
         new Static4D( 0.50f,  0.50f, -0.50f, -0.50f ),
124
         new Static4D( 0.50f, -0.50f,  0.50f,  0.50f ),
125
         new Static4D( 0.50f, -0.50f,  0.50f, -0.50f ),
126
         new Static4D( 0.50f, -0.50f, -0.50f,  0.50f ),
127
         new Static4D( 0.50f, -0.50f, -0.50f, -0.50f )
128
         };
129
    }
130

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

    
133
  public int[] getSolvedQuats(int cubit, int[] numLayers)
134
    {
135
    if( mQuats==null ) initializeQuats();
136
    int status = retCubitSolvedStatus(cubit,numLayers);
137
    return status<0 ? null : buildSolvedQuats(TouchControlHexahedron.FACE_AXIS[status],mQuats);
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  public Static4D[] getQuats()
143
    {
144
    if( mQuats==null ) initializeQuats();
145
    return mQuats;
146
    }
147

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

    
150
  public int getSolvedFunctionIndex()
151
    {
152
    return 0;
153
    }
154

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

    
157
  public int getNumStickerTypes(int[] numLayers)
158
    {
159
    return 1;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  public float[][] getCuts(int[] numLayers)
165
    {
166
    if( mCuts==null )
167
      {
168
      float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
169
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
170
      }
171

    
172
    return mCuts;
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  public boolean[][] getLayerRotatable(int[] numLayers)
178
    {
179
    int numAxis = ROT_AXIS.length;
180
    boolean[] tmp = new boolean[] {true,false,true};
181
    boolean[][] layerRotatable = new boolean[numAxis][];
182
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
183

    
184
    return layerRotatable;
185
    }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

    
189
  public int getTouchControlType()
190
    {
191
    return TC_HEXAHEDRON;
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  public int getTouchControlSplit()
197
    {
198
    return TYPE_SPLIT_EDGE;
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

    
203
  public int[][][] getEnabled()
204
    {
205
    return new int[][][]
206
      {
207
          {{2,5},{2,4},{3,4},{3,5}},
208
          {{2,4},{2,5},{3,5},{3,4}},
209
          {{0,5},{1,5},{1,4},{0,4}},
210
          {{0,4},{1,4},{1,5},{0,5}},
211
          {{1,3},{0,3},{0,2},{1,2}},
212
          {{0,3},{1,3},{1,2},{0,2}},
213
      };
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  public float[] getDist3D(int[] numLayers)
219
    {
220
    return null;
221
    }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
  public int getNumCubitFaces()
226
    {
227
    return 6;
228
    }
229

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
  public float[][] getCubitPositions(int[] numLayers)
233
    {
234
    if( mCenters==null )
235
      {
236
      float DIST_CORNER = 1.50f;
237
      float DIST_CENTER = 1.50f;
238
      float XY_CENTER = DIST_CORNER/3;
239

    
240
      mCenters = new float[][]
241
         {
242
             {   DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
243
             {   DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
244
             {   DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
245
             {   DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
246
             {  -DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
247
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
248
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
249
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
250

    
251
             {   DIST_CENTER,     XY_CENTER,     XY_CENTER },
252
             {   DIST_CENTER,     XY_CENTER,    -XY_CENTER },
253
             {   DIST_CENTER,    -XY_CENTER,     XY_CENTER },
254
             {   DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
255

    
256
             {  -DIST_CENTER,     XY_CENTER,     XY_CENTER },
257
             {  -DIST_CENTER,     XY_CENTER,    -XY_CENTER },
258
             {  -DIST_CENTER,    -XY_CENTER,     XY_CENTER },
259
             {  -DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
260

    
261
             {   XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
262
             {   XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
263
             {  -XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
264
             {  -XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
265

    
266
             {   XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
267
             {   XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
268
             {  -XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
269
             {  -XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
270

    
271
             {   XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
272
             {   XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
273
             {  -XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
274
             {  -XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
275

    
276
             {   XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
277
             {   XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
278
             {  -XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
279
             {  -XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
280
         };
281
      }
282

    
283
    return mCenters;
284
    }
285

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

    
288
  public ObjectShape getObjectShape(int variant)
289
    {
290
    if( variant==0 )
291
      {
292
      float[][] vertices = new float[][]
293
          {
294
            {-1.50f, 0.00f, 0.00f},
295
            { 0.00f,-1.50f, 0.00f},
296
            { 0.00f, 0.00f,-1.50f},
297
            {-0.75f,-0.75f,-0.75f},
298
            { 0.00f, 0.00f, 0.00f}
299
          };
300

    
301
      int[][] vert_indices = new int[][]
302
          {
303
            {0,1,4},
304
            {2,0,4},
305
            {1,2,4},
306
            {3,1,0},
307
            {3,2,1},
308
            {3,0,2}
309
          };
310

    
311
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,5} };
312
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
313
      float[][] corners   = new float[][] { {0.08f,0.20f} };
314
      int[] cornerIndices = new int[] { 0,0,0,0,0 };
315
      float[][] centers   = new float[][] { {-0.75f, -0.75f, -0.75f} };
316
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
317
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
318
      }
319
    else
320
      {
321
      float[][] vertices = new float[][]
322
          {
323
            { 0.50f, 0.50f, 0.00f },
324
            {-1.00f, 0.50f, 0.00f },
325
            { 0.50f,-1.00f, 0.00f },
326
            {-0.25f,-0.25f,-0.75f },
327
          };
328

    
329
      int[][] vert_indices = new int[][]
330
          {
331
            { 0,1,2 },
332
            { 2,1,3 },
333
            { 0,1,3 },
334
            { 2,0,3 }
335
          };
336

    
337
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
338
      int[] bandIndices   = new int[] { 0,1,1,1 };
339
      float[][] corners   = new float[][] { {0.06f,0.20f} };
340
      int[] cornerIndices = new int[] { 0,0,0,-1 };
341
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.75f} };
342
      int[] centerIndices = new int[] { 0,0,0,-1 };
343
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
344
      }
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  public Static4D getQuat(int cubit, int[] numLayers)
350
    {
351
    if( mQuats==null ) initializeQuats();
352
    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 };
353
    return mQuats[mQuatIndices[cubit]];
354
    }
355

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

    
358
  public int getNumCubitVariants(int[] numLayers)
359
    {
360
    return 2;
361
    }
362

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

    
365
  public int getCubitVariant(int cubit, int[] numLayers)
366
    {
367
    return cubit<8 ? 0:1;
368
    }
369

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

    
372
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
373
    {
374
    return 0;
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
380
    {
381
    if( mFaceMap==null )
382
      {
383
      mFaceMap = new int[][]
384
         {
385
           { 4,2,0, -1,-1,-1 },
386
           { 0,2,5, -1,-1,-1 },
387
           { 4,0,3, -1,-1,-1 },
388
           { 5,3,0, -1,-1,-1 },
389
           { 1,2,4, -1,-1,-1 },
390
           { 5,2,1, -1,-1,-1 },
391
           { 4,3,1, -1,-1,-1 },
392
           { 1,3,5, -1,-1,-1 },
393

    
394
           { 0 , -1,-1,-1,-1,-1 },
395
           { 0 , -1,-1,-1,-1,-1 },
396
           { 0 , -1,-1,-1,-1,-1 },
397
           { 0 , -1,-1,-1,-1,-1 },
398

    
399
           { 1 , -1,-1,-1,-1,-1 },
400
           { 1 , -1,-1,-1,-1,-1 },
401
           { 1 , -1,-1,-1,-1,-1 },
402
           { 1 , -1,-1,-1,-1,-1 },
403

    
404
           { 2 , -1,-1,-1,-1,-1 },
405
           { 2 , -1,-1,-1,-1,-1 },
406
           { 2 , -1,-1,-1,-1,-1 },
407
           { 2 , -1,-1,-1,-1,-1 },
408

    
409
           { 3 , -1,-1,-1,-1,-1 },
410
           { 3 , -1,-1,-1,-1,-1 },
411
           { 3 , -1,-1,-1,-1,-1 },
412
           { 3 , -1,-1,-1,-1,-1 },
413

    
414
           { 4 , -1,-1,-1,-1,-1 },
415
           { 4 , -1,-1,-1,-1,-1 },
416
           { 4 , -1,-1,-1,-1,-1 },
417
           { 4 , -1,-1,-1,-1,-1 },
418

    
419
           { 5 , -1,-1,-1,-1,-1 },
420
           { 5 , -1,-1,-1,-1,-1 },
421
           { 5 , -1,-1,-1,-1,-1 },
422
           { 5 , -1,-1,-1,-1,-1 },
423
         };
424
      }
425

    
426
    return mFaceMap[cubit][face];
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

    
431
  public ObjectSticker retSticker(int sticker)
432
    {
433
    if( mStickers==null )
434
      {
435
      float[][] STICKERS = new float[][] { { -0.5f, 0.25f, 0.25f, -0.5f, 0.25f, 0.25f } };
436
      float radius = 0.03f;
437
      float stroke = 0.05f;
438
      float[] radii = new float[] {radius,radius,radius};
439

    
440
      if( ObjectControl.isInIconMode() )
441
        {
442
        stroke*=2.0f;
443
        }
444

    
445
      mStickers = new ObjectSticker[STICKERS.length];
446
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
447
      }
448

    
449
    return mStickers[sticker];
450
    }
451

    
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
// PUBLIC API
454

    
455
  public Static3D[] getRotationAxis()
456
    {
457
    return ROT_AXIS;
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
  public int[] getBasicAngle()
463
    {
464
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
465
    return mBasicAngle;
466
    }
467

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

    
470
  public ObjectType intGetObjectType(int[] numLayers)
471
    {
472
    return ObjectType.HELI_3;
473
    }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

    
477
  public String getObjectName()
478
    {
479
    return "Helicopter Cube";
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

    
484
  public String getInventor()
485
    {
486
    return "Adam G. Cowan";
487
    }
488

    
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490

    
491
  public int getYearOfInvention()
492
    {
493
    return 2006;
494
    }
495

    
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

    
498
  public int getComplexity()
499
    {
500
    return 8;
501
    }
502
}
(11-11/25)