Project

General

Profile

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

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

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.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 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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

    
92
    return mStates;
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

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

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

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

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

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

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

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

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

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

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

    
156
  public float[][] getCuts(int[] numLayers)
157
    {
158
    if( mCuts==null )
159
      {
160
      float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
161
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
162
      }
163

    
164
    return mCuts;
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  public boolean[][] getLayerRotatable(int[] numLayers)
170
    {
171
    int numAxis = ROT_AXIS.length;
172
    boolean[] tmp = new boolean[] {true,false,true};
173
    boolean[][] layerRotatable = new boolean[numAxis][];
174
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
175

    
176
    return layerRotatable;
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
  public int getTouchControlType()
182
    {
183
    return TC_HEXAHEDRON;
184
    }
185

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

    
188
  public int getTouchControlSplit()
189
    {
190
    return TYPE_SPLIT_EDGE;
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
  public int[][][] getEnabled()
196
    {
197
    return new int[][][]
198
      {
199
          {{2,5},{2,4},{3,4},{3,5}},
200
          {{2,4},{2,5},{3,5},{3,4}},
201
          {{0,5},{1,5},{1,4},{0,4}},
202
          {{0,4},{1,4},{1,5},{0,5}},
203
          {{1,3},{0,3},{0,2},{1,2}},
204
          {{0,3},{1,3},{1,2},{0,2}},
205
      };
206
    }
207

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

    
210
  public float[] getDist3D(int[] numLayers)
211
    {
212
    return null;
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
  public int getNumCubitFaces()
218
    {
219
    return 6;
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  public float[][] getCubitPositions(int[] numLayers)
225
    {
226
    if( mCenters==null )
227
      {
228
      float DIST_CORNER = 1.50f;
229
      float DIST_CENTER = 1.50f;
230
      float XY_CENTER = DIST_CORNER/3;
231

    
232
      mCenters = new float[][]
233
         {
234
             {   DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
235
             {   DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
236
             {   DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
237
             {   DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
238
             {  -DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
239
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
240
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
241
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
242

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

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

    
253
             {   XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
254
             {   XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
255
             {  -XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
256
             {  -XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
257

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

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

    
268
             {   XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
269
             {   XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
270
             {  -XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
271
             {  -XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
272
         };
273
      }
274

    
275
    return mCenters;
276
    }
277

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

    
280
  public ObjectShape getObjectShape(int variant)
281
    {
282
    if( variant==0 )
283
      {
284
      float[][] vertices = new float[][]
285
        { {-1.50f, 0.00f, 0.00f},{ 0.00f,-1.50f, 0.00f},{ 0.00f, 0.00f,-1.50f},{-0.75f,-0.75f,-0.75f},{ 0.00f, 0.00f, 0.00f} };
286

    
287
      int[][] vert_indices = new int[][]
288
          { {0,1,4},{2,0,4},{1,2,4},{3,1,0},{3,2,1},{3,0,2} };
289

    
290
      return new ObjectShape(vertices,vert_indices,getNumCubitFaces(),3);
291
      }
292
    else
293
      {
294
      float[][] vertices = new float[][]
295
        { { 0.50f, 0.50f, 0.00f }, {-1.00f, 0.50f, 0.00f }, { 0.50f,-1.00f, 0.00f }, {-0.25f,-0.25f,-0.75f } };
296

    
297
      int[][] vert_indices = new int[][]
298
        { { 0,1,2 },{ 2,1,3 },{ 0,1,3 },{ 2,0,3 } };
299

    
300
      return new ObjectShape(vertices,vert_indices,getNumCubitFaces(),1);
301
      }
302
    }
303

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

    
306
  public ObjectFaceShape getObjectFaceShape(int variant)
307
    {
308
    if( variant==0 )
309
      {
310
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,5} };
311
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
312
      float[][] corners   = new float[][] { {0.08f,0.20f} };
313
      int[] cornerIndices = new int[] { 0,0,0,0,0 };
314
      float[][] centers   = new float[][] { {-0.75f, -0.75f, -0.75f} };
315
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
316
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
317
      }
318
    else
319
      {
320
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
321
      int[] bandIndices   = new int[] { 0,1,1,1 };
322
      float[][] corners   = new float[][] { {0.06f,0.20f} };
323
      int[] cornerIndices = new int[] { 0,0,0,-1 };
324
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.75f} };
325
      int[] centerIndices = new int[] { 0,0,0,-1 };
326
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
327
      }
328
    }
329

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

    
332
  public Static4D getQuat(int cubit, int[] numLayers)
333
    {
334
    if( mQuats==null ) initializeQuats();
335
    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 };
336
    return mQuats[mQuatIndices[cubit]];
337
    }
338

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

    
341
  public int getNumCubitVariants(int[] numLayers)
342
    {
343
    return 2;
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

    
348
  public int getCubitVariant(int cubit, int[] numLayers)
349
    {
350
    return cubit<8 ? 0:1;
351
    }
352

    
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354

    
355
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
356
    {
357
    if( mFaceMap==null )
358
      {
359
      mFaceMap = new int[][]
360
         {
361
           { 4,2,0, -1,-1,-1 },
362
           { 0,2,5, -1,-1,-1 },
363
           { 4,0,3, -1,-1,-1 },
364
           { 5,3,0, -1,-1,-1 },
365
           { 1,2,4, -1,-1,-1 },
366
           { 5,2,1, -1,-1,-1 },
367
           { 4,3,1, -1,-1,-1 },
368
           { 1,3,5, -1,-1,-1 },
369

    
370
           { 0 , -1,-1,-1,-1,-1 },
371
           { 0 , -1,-1,-1,-1,-1 },
372
           { 0 , -1,-1,-1,-1,-1 },
373
           { 0 , -1,-1,-1,-1,-1 },
374

    
375
           { 1 , -1,-1,-1,-1,-1 },
376
           { 1 , -1,-1,-1,-1,-1 },
377
           { 1 , -1,-1,-1,-1,-1 },
378
           { 1 , -1,-1,-1,-1,-1 },
379

    
380
           { 2 , -1,-1,-1,-1,-1 },
381
           { 2 , -1,-1,-1,-1,-1 },
382
           { 2 , -1,-1,-1,-1,-1 },
383
           { 2 , -1,-1,-1,-1,-1 },
384

    
385
           { 3 , -1,-1,-1,-1,-1 },
386
           { 3 , -1,-1,-1,-1,-1 },
387
           { 3 , -1,-1,-1,-1,-1 },
388
           { 3 , -1,-1,-1,-1,-1 },
389

    
390
           { 4 , -1,-1,-1,-1,-1 },
391
           { 4 , -1,-1,-1,-1,-1 },
392
           { 4 , -1,-1,-1,-1,-1 },
393
           { 4 , -1,-1,-1,-1,-1 },
394

    
395
           { 5 , -1,-1,-1,-1,-1 },
396
           { 5 , -1,-1,-1,-1,-1 },
397
           { 5 , -1,-1,-1,-1,-1 },
398
           { 5 , -1,-1,-1,-1,-1 },
399
         };
400
      }
401

    
402
    return mFaceMap[cubit][face];
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  public float getStickerRadius()
408
    {
409
    return 0.08f;
410
    }
411

    
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

    
414
  public float getStickerStroke()
415
    {
416
    return ObjectControl.isInIconMode() ? 0.20f : 0.10f;
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  public float[][] getStickerAngles()
422
    {
423
    return null;
424
    }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
// PUBLIC API
428

    
429
  public Static3D[] getRotationAxis()
430
    {
431
    return ROT_AXIS;
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public int[] getBasicAngle()
437
    {
438
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
439
    return mBasicAngle;
440
    }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
  public ObjectType intGetObjectType(int[] numLayers)
445
    {
446
    return ObjectType.HELI_3;
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public String getObjectName()
452
    {
453
    return "Helicopter Cube";
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

    
458
  public String getInventor()
459
    {
460
    return "Adam G. Cowan";
461
    }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

    
465
  public int getYearOfInvention()
466
    {
467
    return 2006;
468
    }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

    
472
  public int getComplexity()
473
    {
474
    return 3;
475
    }
476
}
(11-11/26)