Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyHelicopter.java @ a76d9cb4

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