Project

General

Profile

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

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

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 float[][] getCubitPositions(int[] numLayers)
218
    {
219
    if( mCenters==null )
220
      {
221
      float DIST_CORNER = 1.50f;
222
      float DIST_CENTER = 1.50f;
223
      float XY_CENTER = DIST_CORNER/3;
224

    
225
      mCenters = new float[][]
226
         {
227
             {   DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
228
             {   DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
229
             {   DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
230
             {   DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
231
             {  -DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
232
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
233
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
234
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
235

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

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

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

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

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

    
261
             {   XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
262
             {   XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
263
             {  -XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
264
             {  -XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
265
         };
266
      }
267

    
268
    return mCenters;
269
    }
270

    
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272

    
273
  public ObjectShape getObjectShape(int variant)
274
    {
275
    if( variant==0 )
276
      {
277
      float[][] vertices =
278
        { {-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} };
279
      int[][] indices = { {0,1,4},{2,0,4},{1,2,4},{3,1,0},{3,2,1},{3,0,2} };
280
      return new ObjectShape(vertices, indices, 3);
281
      }
282
    else
283
      {
284
      float[][] vertices =
285
        { { 0.50f, 0.50f, 0.00f }, {-1.00f, 0.50f, 0.00f }, { 0.50f,-1.00f, 0.00f }, {-0.25f,-0.25f,-0.75f } };
286
      int[][] indices = { { 0,1,2 },{ 2,1,3 },{ 0,1,3 },{ 2,0,3 } };
287
      return new ObjectShape(vertices, indices, 1);
288
      }
289
    }
290

    
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

    
293
  public ObjectFaceShape getObjectFaceShape(int variant)
294
    {
295
    if( variant==0 )
296
      {
297
      float[][] bands     = { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,5} };
298
      int[] bandIndices   = { 0,0,0,1,1,1 };
299
      float[][] corners   = { {0.08f,0.20f} };
300
      int[] cornerIndices = { 0,0,0,0,0 };
301
      float[][] centers   = { {-0.75f, -0.75f, -0.75f} };
302
      int[] centerIndices = { 0,0,0,-1,0 };
303
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
304
      }
305
    else
306
      {
307
      float[][] bands     = { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
308
      int[] bandIndices   = { 0,1,1,1 };
309
      float[][] corners   = { {0.06f,0.20f} };
310
      int[] cornerIndices = { 0,0,0,-1 };
311
      float[][] centers   = { {-0.25f, -0.25f, -0.75f} };
312
      int[] centerIndices = { 0,0,0,-1 };
313
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
314
      }
315
    }
316

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

    
319
  public Static4D getQuat(int cubit, int[] numLayers)
320
    {
321
    if( mQuats==null ) initializeQuats();
322
    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 };
323
    return mQuats[mQuatIndices[cubit]];
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
  public int getNumCubitVariants(int[] numLayers)
329
    {
330
    return 2;
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
  public int getCubitVariant(int cubit, int[] numLayers)
336
    {
337
    return cubit<8 ? 0:1;
338
    }
339

    
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341

    
342
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
343
    {
344
    if( mFaceMap==null )
345
      {
346
      mFaceMap = new int[][]
347
         {
348
           { 4,2,0, -1,-1,-1 },
349
           { 0,2,5, -1,-1,-1 },
350
           { 4,0,3, -1,-1,-1 },
351
           { 5,3,0, -1,-1,-1 },
352
           { 1,2,4, -1,-1,-1 },
353
           { 5,2,1, -1,-1,-1 },
354
           { 4,3,1, -1,-1,-1 },
355
           { 1,3,5, -1,-1,-1 },
356

    
357
           { 0 , -1,-1,-1,-1,-1 },
358
           { 0 , -1,-1,-1,-1,-1 },
359
           { 0 , -1,-1,-1,-1,-1 },
360
           { 0 , -1,-1,-1,-1,-1 },
361

    
362
           { 1 , -1,-1,-1,-1,-1 },
363
           { 1 , -1,-1,-1,-1,-1 },
364
           { 1 , -1,-1,-1,-1,-1 },
365
           { 1 , -1,-1,-1,-1,-1 },
366

    
367
           { 2 , -1,-1,-1,-1,-1 },
368
           { 2 , -1,-1,-1,-1,-1 },
369
           { 2 , -1,-1,-1,-1,-1 },
370
           { 2 , -1,-1,-1,-1,-1 },
371

    
372
           { 3 , -1,-1,-1,-1,-1 },
373
           { 3 , -1,-1,-1,-1,-1 },
374
           { 3 , -1,-1,-1,-1,-1 },
375
           { 3 , -1,-1,-1,-1,-1 },
376

    
377
           { 4 , -1,-1,-1,-1,-1 },
378
           { 4 , -1,-1,-1,-1,-1 },
379
           { 4 , -1,-1,-1,-1,-1 },
380
           { 4 , -1,-1,-1,-1,-1 },
381

    
382
           { 5 , -1,-1,-1,-1,-1 },
383
           { 5 , -1,-1,-1,-1,-1 },
384
           { 5 , -1,-1,-1,-1,-1 },
385
           { 5 , -1,-1,-1,-1,-1 },
386
         };
387
      }
388

    
389
    return mFaceMap[cubit][face];
390
    }
391

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

    
394
  public float getStickerRadius()
395
    {
396
    return 0.08f;
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  public float getStickerStroke()
402
    {
403
    return ObjectControl.isInIconMode() ? 0.20f : 0.10f;
404
    }
405

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

    
408
  public float[][] getStickerAngles()
409
    {
410
    return null;
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414
// PUBLIC API
415

    
416
  public Static3D[] getRotationAxis()
417
    {
418
    return ROT_AXIS;
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

    
423
  public int[] getBasicAngle()
424
    {
425
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
426
    return mBasicAngle;
427
    }
428

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

    
431
  public ObjectType intGetObjectType(int[] numLayers)
432
    {
433
    return ObjectType.HELI_3;
434
    }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

    
438
  public String getObjectName()
439
    {
440
    return "Helicopter Cube";
441
    }
442

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

    
445
  public String getInventor()
446
    {
447
    return "Adam G. Cowan";
448
    }
449

    
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451

    
452
  public int getYearOfInvention()
453
    {
454
    return 2006;
455
    }
456

    
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

    
459
  public int getComplexity()
460
    {
461
    return 3;
462
    }
463
}
(11-11/26)