Project

General

Profile

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

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

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
  protected 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
  protected 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
  protected 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
  protected int getNumStickerTypes(int[] numLayers)
170
    {
171
    return 1;
172
    }
173

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

    
176
  protected 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
  protected 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
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
301
    {
302
    int variant = getCubitVariant(cubit,numLayers);
303

    
304
    if( variant==0 )
305
      {
306
      double[][] vertices = new double[][]
307
          {
308
            {-1.50f, 0.00f, 0.00f},
309
            { 0.00f,-1.50f, 0.00f},
310
            { 0.00f, 0.00f,-1.50f},
311
            {-0.75f,-0.75f,-0.75f},
312
            { 0.00f, 0.00f, 0.00f}
313
          };
314

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

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

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

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

    
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362

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

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

    
372
  protected int getNumCubitVariants(int[] numLayers)
373
    {
374
    return 2;
375
    }
376

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

    
379
  protected int getCubitVariant(int cubit, int[] numLayers)
380
    {
381
    return cubit<8 ? 0:1;
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

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

    
401
           { 0 , 6,6,6,6,6 },
402
           { 0 , 6,6,6,6,6 },
403
           { 0 , 6,6,6,6,6 },
404
           { 0 , 6,6,6,6,6 },
405

    
406
           { 1 , 6,6,6,6,6 },
407
           { 1 , 6,6,6,6,6 },
408
           { 1 , 6,6,6,6,6 },
409
           { 1 , 6,6,6,6,6 },
410

    
411
           { 2 , 6,6,6,6,6 },
412
           { 2 , 6,6,6,6,6 },
413
           { 2 , 6,6,6,6,6 },
414
           { 2 , 6,6,6,6,6 },
415

    
416
           { 3 , 6,6,6,6,6 },
417
           { 3 , 6,6,6,6,6 },
418
           { 3 , 6,6,6,6,6 },
419
           { 3 , 6,6,6,6,6 },
420

    
421
           { 4 , 6,6,6,6,6 },
422
           { 4 , 6,6,6,6,6 },
423
           { 4 , 6,6,6,6,6 },
424
           { 4 , 6,6,6,6,6 },
425

    
426
           { 5 , 6,6,6,6,6 },
427
           { 5 , 6,6,6,6,6 },
428
           { 5 , 6,6,6,6,6 },
429
           { 5 , 6,6,6,6,6 },
430
         };
431
      }
432

    
433
    return mFaceMap[cubit][cubitface];
434
    }
435

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

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

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

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

    
456
    return mStickers[face/NUM_FACE_COLORS];
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
// PUBLIC API
461

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

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

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

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

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

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

    
484
  public int getObjectName(int[] numLayers)
485
    {
486
    return R.string.heli3;
487
    }
488

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

    
491
  public int getInventor(int[] numLayers)
492
    {
493
    return R.string.heli3_inventor;
494
    }
495

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

    
498
  public int getYearOfInvention(int[] numLayers)
499
    {
500
    return 2006;
501
    }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
  public int getComplexity(int[] numLayers)
506
    {
507
    return 8;
508
    }
509
}
(11-11/25)