Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyHelicopter.java @ 8005e762

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.TYPE_SPLIT_EDGE;
23
24
import android.content.res.Resources;
25
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedTexture;
28
import org.distorted.library.mesh.MeshSquare;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31
32
import org.distorted.objectlib.R;
33
import org.distorted.objectlib.main.Movement;
34
import org.distorted.objectlib.main.Movement6;
35 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
36 29b82486 Leszek Koltunski
import org.distorted.objectlib.main.ObjectShape;
37
import org.distorted.objectlib.main.ObjectSticker;
38
import org.distorted.objectlib.main.ScrambleState;
39
import org.distorted.objectlib.main.Twisty6;
40
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43
public class TwistyHelicopter extends Twisty6
44
{
45
  // the six rotation axis of a Helicopter. Must be normalized.
46
  static final Static3D[] ROT_AXIS = new Static3D[]
47
         {
48
           new Static3D(     0, +SQ2/2, -SQ2/2),
49
           new Static3D(     0, -SQ2/2, -SQ2/2),
50
           new Static3D(+SQ2/2,      0, -SQ2/2),
51
           new Static3D(-SQ2/2,      0, -SQ2/2),
52
           new Static3D(+SQ2/2, -SQ2/2,      0),
53
           new Static3D(-SQ2/2, -SQ2/2,      0)
54
         };
55
56
  private static final int[][][] ENABLED = new int[][][]
57
      {
58
          {{2,5},{2,4},{3,4},{3,5}},
59
          {{2,4},{2,5},{3,5},{3,4}},
60
          {{0,5},{1,5},{1,4},{0,4}},
61
          {{0,4},{1,4},{1,5},{0,5}},
62
          {{1,3},{0,3},{0,2},{1,2}},
63
          {{0,3},{1,3},{1,2},{0,2}},
64
      };
65
66
  private ScrambleState[] mStates;
67
  private int[] mBasicAngle;
68
  private Static4D[] mQuats;
69
  private float[][] mCuts;
70
  private boolean[][] mLayerRotatable;
71
  private float[][] mCenters;
72
  private int[] mQuatIndices;
73
  private int[][] mFaceMap;
74
  private ObjectSticker[] mStickers;
75
  private Movement mMovement;
76
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79
  public TwistyHelicopter(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
80
                          DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
81
    {
82 61aa85e4 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, res, scrWidth);
83 29b82486 Leszek Koltunski
    }
84
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
87
  protected ScrambleState[] getScrambleStates()
88
    {
89
    if( mStates==null )
90
      {
91
      mStates = new ScrambleState[]
92
        {
93
        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} } ),
94
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
95
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
96
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
97
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
98
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
99
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
100
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
101
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
102
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
103
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
104
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
105
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
106
        };
107
      }
108
109
    return mStates;
110
    }
111
112 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
113
114
  protected int getResource(int numLayers)
115
    {
116
    return R.raw.heli;
117
    }
118
119 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
120
121
  private void initializeQuats()
122
    {
123
    mQuats = new Static4D[]
124
         {
125
         new Static4D( 0.00f,  0.00f,  0.00f,  1.00f ),
126
         new Static4D( 1.00f,  0.00f,  0.00f,  0.00f ),
127
         new Static4D( 0.00f,  1.00f,  0.00f,  0.00f ),
128
         new Static4D( 0.00f,  0.00f,  1.00f,  0.00f ),
129
130
         new Static4D( SQ2/2,  SQ2/2,  0.00f,  0.00f ),
131
         new Static4D( SQ2/2, -SQ2/2,  0.00f,  0.00f ),
132
         new Static4D( SQ2/2,  0.00f,  SQ2/2,  0.00f ),
133
         new Static4D( SQ2/2,  0.00f, -SQ2/2,  0.00f ),
134
         new Static4D( SQ2/2,  0.00f,  0.00f,  SQ2/2 ),
135
         new Static4D( SQ2/2,  0.00f,  0.00f, -SQ2/2 ),
136
         new Static4D( 0.00f,  SQ2/2,  SQ2/2,  0.00f ),
137
         new Static4D( 0.00f,  SQ2/2, -SQ2/2,  0.00f ),
138
         new Static4D( 0.00f,  SQ2/2,  0.00f,  SQ2/2 ),
139
         new Static4D( 0.00f,  SQ2/2,  0.00f, -SQ2/2 ),
140
         new Static4D( 0.00f,  0.00f,  SQ2/2,  SQ2/2 ),
141
         new Static4D( 0.00f,  0.00f,  SQ2/2, -SQ2/2 ),
142
143
         new Static4D( 0.50f,  0.50f,  0.50f,  0.50f ),
144
         new Static4D( 0.50f,  0.50f,  0.50f, -0.50f ),
145
         new Static4D( 0.50f,  0.50f, -0.50f,  0.50f ),
146
         new Static4D( 0.50f,  0.50f, -0.50f, -0.50f ),
147
         new Static4D( 0.50f, -0.50f,  0.50f,  0.50f ),
148
         new Static4D( 0.50f, -0.50f,  0.50f, -0.50f ),
149
         new Static4D( 0.50f, -0.50f, -0.50f,  0.50f ),
150
         new Static4D( 0.50f, -0.50f, -0.50f, -0.50f )
151
         };
152
    }
153
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155
156
  protected int[] getSolvedQuats(int cubit, int numLayers)
157
    {
158
    if( mQuats==null ) initializeQuats();
159
    int status = retCubitSolvedStatus(cubit,numLayers);
160
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
161
    }
162
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
165
  protected Static4D[] getQuats()
166
    {
167
    if( mQuats==null ) initializeQuats();
168
    return mQuats;
169
    }
170
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172
173
  protected int getSolvedFunctionIndex()
174
    {
175
    return 0;
176
    }
177
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179
180
  protected int getNumStickerTypes(int numLayers)
181
    {
182
    return 1;
183
    }
184
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186
187
  protected float[][] getCuts(int size)
188
    {
189
    if( mCuts==null )
190
      {
191
      float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
192
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
193
      }
194
195
    return mCuts;
196
    }
197
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
200
  private void getLayerRotatable(int numLayers)
201
    {
202
    if( mLayerRotatable==null )
203
      {
204
      int numAxis = ROT_AXIS.length;
205
      boolean[] tmp = new boolean[] {true,false,true};
206
      mLayerRotatable = new boolean[numAxis][];
207
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
208
      }
209
    }
210
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212
213
  protected int getNumCubitFaces()
214
    {
215
    return 4;
216
    }
217
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
220
  protected float[][] getCubitPositions(int size)
221
    {
222
    if( mCenters==null )
223
      {
224
      float DIST_CORNER = 1.50f;
225
      float DIST_CENTER = 1.50f;
226
      float XY_CENTER = DIST_CORNER/3;
227
228
      mCenters = new float[][]
229
         {
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
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
236
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
237
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
238
239
             {   DIST_CENTER,     XY_CENTER,     XY_CENTER },
240
             {   DIST_CENTER,     XY_CENTER,    -XY_CENTER },
241
             {   DIST_CENTER,    -XY_CENTER,     XY_CENTER },
242
             {   DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
243
244
             {  -DIST_CENTER,     XY_CENTER,     XY_CENTER },
245
             {  -DIST_CENTER,     XY_CENTER,    -XY_CENTER },
246
             {  -DIST_CENTER,    -XY_CENTER,     XY_CENTER },
247
             {  -DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
248
249
             {   XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
250
             {   XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
251
             {  -XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
252
             {  -XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
253
254
             {   XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
255
             {   XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
256
             {  -XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
257
             {  -XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
258
259
             {   XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
260
             {   XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
261
             {  -XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
262
             {  -XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
263
264
             {   XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
265
             {   XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
266
             {  -XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
267
             {  -XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
268
         };
269
      }
270
271
    return mCenters;
272
    }
273
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275
276
  protected ObjectShape getObjectShape(int cubit, int numLayers)
277
    {
278
    int variant = getCubitVariant(cubit,numLayers);
279
280
    if( variant==0 )
281
      {
282
      double[][] vertices = new double[][]
283
          {
284
            {-1.50f, 0.00f, 0.00f},
285
            { 0.00f,-1.50f, 0.00f},
286
            { 0.00f, 0.00f,-1.50f},
287
            {-0.75f,-0.75f,-0.75f},
288
            { 0.00f, 0.00f, 0.00f}
289
          };
290
291
      int[][] vert_indices = new int[][]
292
          {
293
            {0,1,4},
294
            {2,0,4},
295
            {1,2,4},
296
            {3,1,0},
297
            {3,2,1},
298
            {3,0,2}
299
          };
300
301
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,5} };
302
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
303
      float[][] corners   = new float[][] { {0.08f,0.20f} };
304
      int[] cornerIndices = new int[] { 0,0,0,0,0 };
305
      float[][] centers   = new float[][] { {-0.75f, -0.75f, -0.75f} };
306
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
307
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
308
      }
309
    else
310
      {
311
      double[][] vertices = new double[][]
312
          {
313
            { 0.50f, 0.50f, 0.00f },
314
            {-1.00f, 0.50f, 0.00f },
315
            { 0.50f,-1.00f, 0.00f },
316
            {-0.25f,-0.25f,-0.75f },
317
          };
318
319
      int[][] vert_indices = new int[][]
320
          {
321
            { 0,1,2 },
322
            { 2,1,3 },
323
            { 0,1,3 },
324
            { 2,0,3 }
325
          };
326
327
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
328
      int[] bandIndices   = new int[] { 0,1,1,1 };
329
      float[][] corners   = new float[][] { {0.06f,0.20f} };
330
      int[] cornerIndices = new int[] { 0,0,0,-1 };
331
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.75f} };
332
      int[] centerIndices = new int[] { 0,0,0,-1 };
333
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
334
      }
335
    }
336
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338
339
  protected Static4D getQuat(int cubit, int numLayers)
340
    {
341
    if( mQuats==null ) initializeQuats();
342
    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 };
343
    return mQuats[mQuatIndices[cubit]];
344
    }
345
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347
348
  protected int getNumCubitVariants(int numLayers)
349
    {
350
    return 2;
351
    }
352
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354
355
  protected int getCubitVariant(int cubit, int numLayers)
356
    {
357
    return cubit<8 ? 0:1;
358
    }
359
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361
362
  protected int getFaceColor(int cubit, int cubitface, int size)
363
    {
364
    if( mFaceMap==null )
365
      {
366
      mFaceMap = new int[][]
367
         {
368
           { 4,2,0, 6,6,6 },
369
           { 0,2,5, 6,6,6 },
370
           { 4,0,3, 6,6,6 },
371
           { 5,3,0, 6,6,6 },
372
           { 1,2,4, 6,6,6 },
373
           { 5,2,1, 6,6,6 },
374
           { 4,3,1, 6,6,6 },
375
           { 1,3,5, 6,6,6 },
376
377
           { 0 , 6,6,6,6,6 },
378
           { 0 , 6,6,6,6,6 },
379
           { 0 , 6,6,6,6,6 },
380
           { 0 , 6,6,6,6,6 },
381
382
           { 1 , 6,6,6,6,6 },
383
           { 1 , 6,6,6,6,6 },
384
           { 1 , 6,6,6,6,6 },
385
           { 1 , 6,6,6,6,6 },
386
387
           { 2 , 6,6,6,6,6 },
388
           { 2 , 6,6,6,6,6 },
389
           { 2 , 6,6,6,6,6 },
390
           { 2 , 6,6,6,6,6 },
391
392
           { 3 , 6,6,6,6,6 },
393
           { 3 , 6,6,6,6,6 },
394
           { 3 , 6,6,6,6,6 },
395
           { 3 , 6,6,6,6,6 },
396
397
           { 4 , 6,6,6,6,6 },
398
           { 4 , 6,6,6,6,6 },
399
           { 4 , 6,6,6,6,6 },
400
           { 4 , 6,6,6,6,6 },
401
402
           { 5 , 6,6,6,6,6 },
403
           { 5 , 6,6,6,6,6 },
404
           { 5 , 6,6,6,6,6 },
405
           { 5 , 6,6,6,6,6 },
406
         };
407
      }
408
409
    return mFaceMap[cubit][cubitface];
410
    }
411
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413
414
  protected ObjectSticker retSticker(int face)
415
    {
416
    if( mStickers==null )
417
      {
418
      float[][] STICKERS = new float[][] { { -0.5f, 0.25f, 0.25f, -0.5f, 0.25f, 0.25f } };
419
      float radius = 0.03f;
420
      float stroke = 0.05f;
421
      float[] radii = new float[] {radius,radius,radius};
422
      mStickers = new ObjectSticker[STICKERS.length];
423
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
424
      }
425
426
    return mStickers[face/NUM_FACE_COLORS];
427
    }
428
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430
// PUBLIC API
431
432
  public Static3D[] getRotationAxis()
433
    {
434
    return ROT_AXIS;
435
    }
436
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438
439
  public Movement getMovement()
440
    {
441
    if( mMovement==null )
442
      {
443
      int numLayers = getNumLayers();
444
      if( mCuts==null ) getCuts(numLayers);
445
      getLayerRotatable(numLayers);
446
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_EDGE,ENABLED);
447
      }
448
    return mMovement;
449
    }
450
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452
453
  public int[] getBasicAngle()
454
    {
455
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
456
    return mBasicAngle;
457
    }
458
459 61aa85e4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
460
461 8005e762 Leszek Koltunski
  public ObjectType intGetObjectList(int numLayers)
462 61aa85e4 Leszek Koltunski
    {
463 8005e762 Leszek Koltunski
    return ObjectType.HELI_3;
464 61aa85e4 Leszek Koltunski
    }
465
466 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
467
468
  public int getObjectName(int numLayers)
469
    {
470
    return R.string.heli3;
471
    }
472
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474
475
  public int getInventor(int numLayers)
476
    {
477
    return R.string.heli3_inventor;
478
    }
479
480
///////////////////////////////////////////////////////////////////////////////////////////////////
481
482
  public int getComplexity(int numLayers)
483
    {
484
    return 8;
485
    }
486
}