Project

General

Profile

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

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

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.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32

    
33
import org.distorted.objectlib.R;
34
import org.distorted.objectlib.main.Movement6;
35
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.objectlib.main.ObjectType;
37
import org.distorted.objectlib.helpers.ObjectShape;
38
import org.distorted.objectlib.helpers.ObjectSticker;
39
import org.distorted.objectlib.helpers.ScrambleState;
40
import org.distorted.objectlib.main.Twisty6;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

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

    
57
  private ScrambleState[] mStates;
58
  private int[] mBasicAngle;
59
  private Static4D[] mQuats;
60
  private float[][] mCuts;
61
  private float[][] mCenters;
62
  private int[] mQuatIndices;
63
  private int[][] mFaceMap;
64
  private ObjectSticker[] mStickers;
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  public TwistyHelicopter(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
69
                          MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
70
    {
71
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

    
98
    return mStates;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  protected int getResource(int[] numLayers)
104
    {
105
    return R.raw.heli;
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

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

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

    
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
         new Static4D( 0.50f, -0.50f, -0.50f, -0.50f )
140
         };
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

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

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

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

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

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

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

    
169
  public int getNumStickerTypes(int[] numLayers)
170
    {
171
    return 1;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

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

    
184
    return mCuts;
185
    }
186

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

    
189
  public boolean[][] getLayerRotatable(int[] numLayers)
190
    {
191
    int numAxis = ROT_AXIS.length;
192
    boolean[] tmp = new boolean[] {true,false,true};
193
    boolean[][] layerRotatable = new boolean[numAxis][];
194
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
195

    
196
    return layerRotatable;
197
    }
198

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

    
201
  public int getMovementType()
202
    {
203
    return MOVEMENT_HEXAHEDRON;
204
    }
205

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

    
208
  public int getMovementSplit()
209
    {
210
    return TYPE_SPLIT_EDGE;
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  public int[][][] getEnabled()
216
    {
217
    return new int[][][]
218
      {
219
          {{2,5},{2,4},{3,4},{3,5}},
220
          {{2,4},{2,5},{3,5},{3,4}},
221
          {{0,5},{1,5},{1,4},{0,4}},
222
          {{0,4},{1,4},{1,5},{0,5}},
223
          {{1,3},{0,3},{0,2},{1,2}},
224
          {{0,3},{1,3},{1,2},{0,2}},
225
      };
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
  public float[] getDist3D(int[] numLayers)
231
    {
232
    return null;
233
    }
234

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

    
237
  protected int getNumCubitFaces()
238
    {
239
    return 6;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  public float[][] getCubitPositions(int[] numLayers)
245
    {
246
    if( mCenters==null )
247
      {
248
      float DIST_CORNER = 1.50f;
249
      float DIST_CENTER = 1.50f;
250
      float XY_CENTER = DIST_CORNER/3;
251

    
252
      mCenters = new float[][]
253
         {
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
             {  -DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
259
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
260
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
261
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
262

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

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

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

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

    
283
             {   XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
284
             {   XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
285
             {  -XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
286
             {  -XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
287

    
288
             {   XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
289
             {   XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
290
             {  -XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
291
             {  -XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
292
         };
293
      }
294

    
295
    return mCenters;
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

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

    
313
      int[][] vert_indices = new int[][]
314
          {
315
            {0,1,4},
316
            {2,0,4},
317
            {1,2,4},
318
            {3,1,0},
319
            {3,2,1},
320
            {3,0,2}
321
          };
322

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

    
341
      int[][] vert_indices = new int[][]
342
          {
343
            { 0,1,2 },
344
            { 2,1,3 },
345
            { 0,1,3 },
346
            { 2,0,3 }
347
          };
348

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

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

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

    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369

    
370
  public int getNumCubitVariants(int[] numLayers)
371
    {
372
    return 2;
373
    }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

    
377
  public int getCubitVariant(int cubit, int[] numLayers)
378
    {
379
    return cubit<8 ? 0:1;
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
385
    {
386
    if( mFaceMap==null )
387
      {
388
      mFaceMap = new int[][]
389
         {
390
           { 4,2,0, 6,6,6 },
391
           { 0,2,5, 6,6,6 },
392
           { 4,0,3, 6,6,6 },
393
           { 5,3,0, 6,6,6 },
394
           { 1,2,4, 6,6,6 },
395
           { 5,2,1, 6,6,6 },
396
           { 4,3,1, 6,6,6 },
397
           { 1,3,5, 6,6,6 },
398

    
399
           { 0 , 6,6,6,6,6 },
400
           { 0 , 6,6,6,6,6 },
401
           { 0 , 6,6,6,6,6 },
402
           { 0 , 6,6,6,6,6 },
403

    
404
           { 1 , 6,6,6,6,6 },
405
           { 1 , 6,6,6,6,6 },
406
           { 1 , 6,6,6,6,6 },
407
           { 1 , 6,6,6,6,6 },
408

    
409
           { 2 , 6,6,6,6,6 },
410
           { 2 , 6,6,6,6,6 },
411
           { 2 , 6,6,6,6,6 },
412
           { 2 , 6,6,6,6,6 },
413

    
414
           { 3 , 6,6,6,6,6 },
415
           { 3 , 6,6,6,6,6 },
416
           { 3 , 6,6,6,6,6 },
417
           { 3 , 6,6,6,6,6 },
418

    
419
           { 4 , 6,6,6,6,6 },
420
           { 4 , 6,6,6,6,6 },
421
           { 4 , 6,6,6,6,6 },
422
           { 4 , 6,6,6,6,6 },
423

    
424
           { 5 , 6,6,6,6,6 },
425
           { 5 , 6,6,6,6,6 },
426
           { 5 , 6,6,6,6,6 },
427
           { 5 , 6,6,6,6,6 },
428
         };
429
      }
430

    
431
    return mFaceMap[cubit][cubitface];
432
    }
433

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

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

    
445
      if( ObjectControl.isInIconMode() )
446
        {
447
        stroke*=2.0f;
448
        }
449

    
450
      mStickers = new ObjectSticker[STICKERS.length];
451
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
452
      }
453

    
454
    return mStickers[sticker];
455
    }
456

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

    
459
  protected int getStickerIndex(int face)
460
    {
461
    return face/NUM_FACE_COLORS;
462
    }
463

    
464
///////////////////////////////////////////////////////////////////////////////////////////////////
465
// PUBLIC API
466

    
467
  public Static3D[] getRotationAxis()
468
    {
469
    return ROT_AXIS;
470
    }
471

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473

    
474
  public int[] getBasicAngle()
475
    {
476
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
477
    return mBasicAngle;
478
    }
479

    
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481

    
482
  public ObjectType intGetObjectType(int[] numLayers)
483
    {
484
    return ObjectType.HELI_3;
485
    }
486

    
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488

    
489
  public int getObjectName(int[] numLayers)
490
    {
491
    return R.string.heli3;
492
    }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

    
496
  public int getInventor(int[] numLayers)
497
    {
498
    return R.string.heli3_inventor;
499
    }
500

    
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502

    
503
  public int getYearOfInvention(int[] numLayers)
504
    {
505
    return 2006;
506
    }
507

    
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509

    
510
  public int getComplexity(int[] numLayers)
511
    {
512
    return 8;
513
    }
514
}
(11-11/25)