Project

General

Profile

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

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

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