Project

General

Profile

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

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

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