Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyHelicopter.java @ 8db55f55

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