Project

General

Profile

Download (17.6 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyHelicopter.java @ 588ace55

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.objects;
21

    
22
import static org.distorted.objectlib.Movement.TYPE_SPLIT_EDGE;
23

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.objectlib.ObjectShape;
27
import org.distorted.objectlib.ObjectSticker;
28
import org.distorted.objectlib.ScrambleState;
29
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshSquare;
32
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34
import org.distorted.main.R;
35
import org.distorted.objectlib.Movement;
36
import org.distorted.objectlib.Movement6;
37
import org.distorted.objectlib.ObjectList;
38
import org.distorted.objectlib.Twisty6;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

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

    
55
  private static final int[][][] ENABLED = new int[][][]
56
      {
57
          {{2,5},{2,4},{3,4},{3,5}},
58
          {{2,4},{2,5},{3,5},{3,4}},
59
          {{0,5},{1,5},{1,4},{0,4}},
60
          {{0,4},{1,4},{1,5},{0,5}},
61
          {{1,3},{0,3},{0,2},{1,2}},
62
          {{0,3},{1,3},{1,2},{0,2}},
63
      };
64

    
65
  private ScrambleState[] mStates;
66
  private int[] mBasicAngle;
67
  private Static4D[] mQuats;
68
  private float[][] mCuts;
69
  private boolean[][] mLayerRotatable;
70
  private float[][] mCenters;
71
  private int[] mQuatIndices;
72
  private int[][] mFaceMap;
73
  private ObjectSticker[] mStickers;
74
  private Movement mMovement;
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  public TwistyHelicopter(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
79
                          DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
80
    {
81
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.HELI, res, scrWidth);
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  protected ScrambleState[] getScrambleStates()
87
    {
88
    if( mStates==null )
89
      {
90
      mStates = new ScrambleState[]
91
        {
92
        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} } ),
93
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
94
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
95
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
96
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
97
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
98
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
99
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
100
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
101
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
102
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
103
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
104
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
105
        };
106
      }
107

    
108
    return mStates;
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  private void initializeQuats()
114
    {
115
    mQuats = new Static4D[]
116
         {
117
         new Static4D( 0.00f,  0.00f,  0.00f,  1.00f ),
118
         new Static4D( 1.00f,  0.00f,  0.00f,  0.00f ),
119
         new Static4D( 0.00f,  1.00f,  0.00f,  0.00f ),
120
         new Static4D( 0.00f,  0.00f,  1.00f,  0.00f ),
121

    
122
         new Static4D( SQ2/2,  SQ2/2,  0.00f,  0.00f ),
123
         new Static4D( SQ2/2, -SQ2/2,  0.00f,  0.00f ),
124
         new Static4D( SQ2/2,  0.00f,  SQ2/2,  0.00f ),
125
         new Static4D( SQ2/2,  0.00f, -SQ2/2,  0.00f ),
126
         new Static4D( SQ2/2,  0.00f,  0.00f,  SQ2/2 ),
127
         new Static4D( SQ2/2,  0.00f,  0.00f, -SQ2/2 ),
128
         new Static4D( 0.00f,  SQ2/2,  SQ2/2,  0.00f ),
129
         new Static4D( 0.00f,  SQ2/2, -SQ2/2,  0.00f ),
130
         new Static4D( 0.00f,  SQ2/2,  0.00f,  SQ2/2 ),
131
         new Static4D( 0.00f,  SQ2/2,  0.00f, -SQ2/2 ),
132
         new Static4D( 0.00f,  0.00f,  SQ2/2,  SQ2/2 ),
133
         new Static4D( 0.00f,  0.00f,  SQ2/2, -SQ2/2 ),
134

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

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

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

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  protected Static4D[] getQuats()
158
    {
159
    if( mQuats==null ) initializeQuats();
160
    return mQuats;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  protected int getSolvedFunctionIndex()
166
    {
167
    return 0;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  protected int getNumStickerTypes(int numLayers)
173
    {
174
    return 1;
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  protected float[][] getCuts(int size)
180
    {
181
    if( mCuts==null )
182
      {
183
      float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
184
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
185
      }
186

    
187
    return mCuts;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  private void getLayerRotatable(int numLayers)
193
    {
194
    if( mLayerRotatable==null )
195
      {
196
      int numAxis = ROT_AXIS.length;
197
      boolean[] tmp = new boolean[] {true,false,true};
198
      mLayerRotatable = new boolean[numAxis][];
199
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
200
      }
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  protected int getNumCubitFaces()
206
    {
207
    return 4;
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  protected float[][] getCubitPositions(int size)
213
    {
214
    if( mCenters==null )
215
      {
216
      float DIST_CORNER = 1.50f;
217
      float DIST_CENTER = 1.50f;
218
      float XY_CENTER = DIST_CORNER/3;
219

    
220
      mCenters = new float[][]
221
         {
222
             {   DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
223
             {   DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
224
             {   DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
225
             {   DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
226
             {  -DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
227
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
228
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
229
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
230

    
231
             {   DIST_CENTER,     XY_CENTER,     XY_CENTER },
232
             {   DIST_CENTER,     XY_CENTER,    -XY_CENTER },
233
             {   DIST_CENTER,    -XY_CENTER,     XY_CENTER },
234
             {   DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
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
             {   XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
242
             {   XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
243
             {  -XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
244
             {  -XY_CENTER  ,   DIST_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  ,     XY_CENTER,   DIST_CENTER },
252
             {   XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
253
             {  -XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
254
             {  -XY_CENTER  ,    -XY_CENTER,   DIST_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
      }
262

    
263
    return mCenters;
264
    }
265

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

    
268
  protected ObjectShape getObjectShape(int cubit, int numLayers)
269
    {
270
    int variant = getCubitVariant(cubit,numLayers);
271

    
272
    if( variant==0 )
273
      {
274
      double[][] vertices = new double[][]
275
          {
276
            {-1.50f, 0.00f, 0.00f},
277
            { 0.00f,-1.50f, 0.00f},
278
            { 0.00f, 0.00f,-1.50f},
279
            {-0.75f,-0.75f,-0.75f},
280
            { 0.00f, 0.00f, 0.00f}
281
          };
282

    
283
      int[][] vert_indices = new int[][]
284
          {
285
            {0,1,4},
286
            {2,0,4},
287
            {1,2,4},
288
            {3,1,0},
289
            {3,2,1},
290
            {3,0,2}
291
          };
292

    
293
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,5} };
294
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
295
      float[][] corners   = new float[][] { {0.08f,0.20f} };
296
      int[] cornerIndices = new int[] { 0,0,0,0,0 };
297
      float[][] centers   = new float[][] { {-0.75f, -0.75f, -0.75f} };
298
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
299
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
300
      }
301
    else
302
      {
303
      double[][] vertices = new double[][]
304
          {
305
            { 0.50f, 0.50f, 0.00f },
306
            {-1.00f, 0.50f, 0.00f },
307
            { 0.50f,-1.00f, 0.00f },
308
            {-0.25f,-0.25f,-0.75f },
309
          };
310

    
311
      int[][] vert_indices = new int[][]
312
          {
313
            { 0,1,2 },
314
            { 2,1,3 },
315
            { 0,1,3 },
316
            { 2,0,3 }
317
          };
318

    
319
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
320
      int[] bandIndices   = new int[] { 0,1,1,1 };
321
      float[][] corners   = new float[][] { {0.06f,0.20f} };
322
      int[] cornerIndices = new int[] { 0,0,0,-1 };
323
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.75f} };
324
      int[] centerIndices = new int[] { 0,0,0,-1 };
325
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
326
      }
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  protected Static4D getQuat(int cubit, int numLayers)
332
    {
333
    if( mQuats==null ) initializeQuats();
334
    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 };
335
    return mQuats[mQuatIndices[cubit]];
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

    
340
  protected int getNumCubitVariants(int numLayers)
341
    {
342
    return 2;
343
    }
344

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

    
347
  protected int getCubitVariant(int cubit, int numLayers)
348
    {
349
    return cubit<8 ? 0:1;
350
    }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
  protected int getFaceColor(int cubit, int cubitface, int size)
355
    {
356
    if( mFaceMap==null )
357
      {
358
      mFaceMap = new int[][]
359
         {
360
           { 4,2,0, 6,6,6 },
361
           { 0,2,5, 6,6,6 },
362
           { 4,0,3, 6,6,6 },
363
           { 5,3,0, 6,6,6 },
364
           { 1,2,4, 6,6,6 },
365
           { 5,2,1, 6,6,6 },
366
           { 4,3,1, 6,6,6 },
367
           { 1,3,5, 6,6,6 },
368

    
369
           { 0 , 6,6,6,6,6 },
370
           { 0 , 6,6,6,6,6 },
371
           { 0 , 6,6,6,6,6 },
372
           { 0 , 6,6,6,6,6 },
373

    
374
           { 1 , 6,6,6,6,6 },
375
           { 1 , 6,6,6,6,6 },
376
           { 1 , 6,6,6,6,6 },
377
           { 1 , 6,6,6,6,6 },
378

    
379
           { 2 , 6,6,6,6,6 },
380
           { 2 , 6,6,6,6,6 },
381
           { 2 , 6,6,6,6,6 },
382
           { 2 , 6,6,6,6,6 },
383

    
384
           { 3 , 6,6,6,6,6 },
385
           { 3 , 6,6,6,6,6 },
386
           { 3 , 6,6,6,6,6 },
387
           { 3 , 6,6,6,6,6 },
388

    
389
           { 4 , 6,6,6,6,6 },
390
           { 4 , 6,6,6,6,6 },
391
           { 4 , 6,6,6,6,6 },
392
           { 4 , 6,6,6,6,6 },
393

    
394
           { 5 , 6,6,6,6,6 },
395
           { 5 , 6,6,6,6,6 },
396
           { 5 , 6,6,6,6,6 },
397
           { 5 , 6,6,6,6,6 },
398
         };
399
      }
400

    
401
    return mFaceMap[cubit][cubitface];
402
    }
403

    
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

    
406
  protected ObjectSticker retSticker(int face)
407
    {
408
    if( mStickers==null )
409
      {
410
      float[][] STICKERS = new float[][] { { -0.5f, 0.25f, 0.25f, -0.5f, 0.25f, 0.25f } };
411
      float radius = 0.03f;
412
      float stroke = 0.05f;
413
      float[] radii = new float[] {radius,radius,radius};
414
      mStickers = new ObjectSticker[STICKERS.length];
415
      mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
416
      }
417

    
418
    return mStickers[face/NUM_FACE_COLORS];
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422
// PUBLIC API
423

    
424
  public Static3D[] getRotationAxis()
425
    {
426
    return ROT_AXIS;
427
    }
428

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

    
431
  public Movement getMovement()
432
    {
433
    if( mMovement==null )
434
      {
435
      int numLayers = getNumLayers();
436
      if( mCuts==null ) getCuts(numLayers);
437
      getLayerRotatable(numLayers);
438
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_EDGE,ENABLED);
439
      }
440
    return mMovement;
441
    }
442

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

    
445
  public int[] getBasicAngle()
446
    {
447
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
448
    return mBasicAngle;
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

    
453
  public int getObjectName(int numLayers)
454
    {
455
    return R.string.heli3;
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  public int getInventor(int numLayers)
461
    {
462
    return R.string.heli3_inventor;
463
    }
464

    
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466

    
467
  public int getComplexity(int numLayers)
468
    {
469
    return 8;
470
    }
471
}
(11-11/25)