Project

General

Profile

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

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

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 android.content.res.Resources;
23

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleState;
27
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
import org.distorted.main.R;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class TwistyHelicopter extends TwistyObject
37
{
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
  private static final int[] FACE_COLORS = new int[]
50
         {
51
           COLOR_YELLOW, COLOR_WHITE,
52
           COLOR_BLUE  , COLOR_GREEN,
53
           COLOR_RED   , COLOR_ORANGE
54
         };
55

    
56
  private static final int FACES_PER_CUBIT =6;
57

    
58
  private ScrambleState[] mStates;
59
  private int[] mBasicAngle;
60
  private Static4D[] mQuats;
61
  private float[][] mCenters;
62
  private int[] mQuatIndices;
63
  private int[][] mFaceMap;
64
  private ObjectSticker[] mStickers;
65
  private Movement mMovement;
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  TwistyHelicopter(int size, Static4D quat, DistortedTexture texture,
70
                   MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
71
    {
72
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.HELI, res, scrWidth);
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  ScrambleState[] getScrambleStates()
78
    {
79
    if( mStates==null )
80
      {
81
      mStates = new ScrambleState[]
82
        {
83
        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} } ),
84
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
85
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
86
        new ScrambleState( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
87
        new ScrambleState( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
88
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
89
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
90
        new ScrambleState( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
91
        new ScrambleState( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
92
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
93
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
94
        new ScrambleState( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
95
        new ScrambleState( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
96
        };
97
      }
98

    
99
    return mStates;
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  private void initializeQuats()
105
    {
106
    mQuats = new Static4D[]
107
         {
108
         new Static4D( 0.00f,  0.00f,  0.00f,  1.00f ),
109
         new Static4D( 1.00f,  0.00f,  0.00f,  0.00f ),
110
         new Static4D( 0.00f,  1.00f,  0.00f,  0.00f ),
111
         new Static4D( 0.00f,  0.00f,  1.00f,  0.00f ),
112

    
113
         new Static4D( SQ2/2,  SQ2/2,  0.00f,  0.00f ),
114
         new Static4D( SQ2/2, -SQ2/2,  0.00f,  0.00f ),
115
         new Static4D( SQ2/2,  0.00f,  SQ2/2,  0.00f ),
116
         new Static4D( SQ2/2,  0.00f, -SQ2/2,  0.00f ),
117
         new Static4D( SQ2/2,  0.00f,  0.00f,  SQ2/2 ),
118
         new Static4D( SQ2/2,  0.00f,  0.00f, -SQ2/2 ),
119
         new Static4D( 0.00f,  SQ2/2,  SQ2/2,  0.00f ),
120
         new Static4D( 0.00f,  SQ2/2, -SQ2/2,  0.00f ),
121
         new Static4D( 0.00f,  SQ2/2,  0.00f,  SQ2/2 ),
122
         new Static4D( 0.00f,  SQ2/2,  0.00f, -SQ2/2 ),
123
         new Static4D( 0.00f,  0.00f,  SQ2/2,  SQ2/2 ),
124
         new Static4D( 0.00f,  0.00f,  SQ2/2, -SQ2/2 ),
125

    
126
         new Static4D( 0.50f,  0.50f,  0.50f,  0.50f ),
127
         new Static4D( 0.50f,  0.50f,  0.50f, -0.50f ),
128
         new Static4D( 0.50f,  0.50f, -0.50f,  0.50f ),
129
         new Static4D( 0.50f,  0.50f, -0.50f, -0.50f ),
130
         new Static4D( 0.50f, -0.50f,  0.50f,  0.50f ),
131
         new Static4D( 0.50f, -0.50f,  0.50f, -0.50f ),
132
         new Static4D( 0.50f, -0.50f, -0.50f,  0.50f ),
133
         new Static4D( 0.50f, -0.50f, -0.50f, -0.50f )
134
         };
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  int[] getSolvedQuats(int cubit, int numLayers)
140
    {
141
    if( mQuats==null ) initializeQuats();
142
    int status = retCubitSolvedStatus(cubit,numLayers);
143
    return status<0 ? null : buildSolvedQuats(MovementHelicopter.FACE_AXIS[status],mQuats);
144
    }
145

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

    
148
  float getScreenRatio()
149
    {
150
    return 0.5f;
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  Static4D[] getQuats()
156
    {
157
    if( mQuats==null ) initializeQuats();
158
    return mQuats;
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  boolean shouldResetTextureMaps()
164
    {
165
    return false;
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  int getNumFaceColors()
171
    {
172
    return FACE_COLORS.length;
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  int getSolvedFunctionIndex()
178
    {
179
    return 0;
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  int getNumStickerTypes(int numLayers)
185
    {
186
    return 1;
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
  float[][] getCuts(int size)
192
    {
193
    float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
194
    return new float[][] { cut,cut,cut,cut,cut,cut };
195
    }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
  int getNumCubitFaces()
200
    {
201
    return FACES_PER_CUBIT;
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  float[][] getCubitPositions(int size)
207
    {
208
    if( mCenters==null )
209
      {
210
      float DIST_CORNER = 1.50f;
211
      float DIST_CENTER = 1.50f;
212
      float XY_CENTER = DIST_CORNER/3;
213

    
214
      mCenters = new float[][]
215
         {
216
             {   DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
217
             {   DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
218
             {   DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
219
             {   DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
220
             {  -DIST_CORNER,   DIST_CORNER,   DIST_CORNER },
221
             {  -DIST_CORNER,   DIST_CORNER,  -DIST_CORNER },
222
             {  -DIST_CORNER,  -DIST_CORNER,   DIST_CORNER },
223
             {  -DIST_CORNER,  -DIST_CORNER,  -DIST_CORNER },
224

    
225
             {   DIST_CENTER,     XY_CENTER,     XY_CENTER },
226
             {   DIST_CENTER,     XY_CENTER,    -XY_CENTER },
227
             {   DIST_CENTER,    -XY_CENTER,     XY_CENTER },
228
             {   DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
229

    
230
             {  -DIST_CENTER,     XY_CENTER,     XY_CENTER },
231
             {  -DIST_CENTER,     XY_CENTER,    -XY_CENTER },
232
             {  -DIST_CENTER,    -XY_CENTER,     XY_CENTER },
233
             {  -DIST_CENTER,    -XY_CENTER,    -XY_CENTER },
234

    
235
             {   XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
236
             {   XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
237
             {  -XY_CENTER  ,   DIST_CENTER,     XY_CENTER },
238
             {  -XY_CENTER  ,   DIST_CENTER,    -XY_CENTER },
239

    
240
             {   XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
241
             {   XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
242
             {  -XY_CENTER  ,  -DIST_CENTER,     XY_CENTER },
243
             {  -XY_CENTER  ,  -DIST_CENTER,    -XY_CENTER },
244

    
245
             {   XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
246
             {   XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
247
             {  -XY_CENTER  ,     XY_CENTER,   DIST_CENTER },
248
             {  -XY_CENTER  ,    -XY_CENTER,   DIST_CENTER },
249

    
250
             {   XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
251
             {   XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
252
             {  -XY_CENTER  ,     XY_CENTER,  -DIST_CENTER },
253
             {  -XY_CENTER  ,    -XY_CENTER,  -DIST_CENTER },
254
         };
255
      }
256

    
257
    return mCenters;
258
    }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

    
262
  ObjectShape getObjectShape(int cubit, int numLayers)
263
    {
264
    int variant = getCubitVariant(cubit,numLayers);
265

    
266
    if( variant==0 )
267
      {
268
      double[][] vertices = new double[][]
269
          {
270
            {-1.50f, 0.00f, 0.00f},
271
            { 0.00f,-1.50f, 0.00f},
272
            { 0.00f, 0.00f,-1.50f},
273
            {-0.75f,-0.75f,-0.75f},
274
            { 0.00f, 0.00f, 0.00f}
275
          };
276

    
277
      int[][] vert_indices = new int[][]
278
          {
279
            {0,1,4},
280
            {2,0,4},
281
            {1,2,4},
282
            {3,1,0},
283
            {3,2,1},
284
            {3,0,2}
285
          };
286

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

    
305
      int[][] vert_indices = new int[][]
306
          {
307
            { 0,1,2 },
308
            { 2,1,3 },
309
            { 0,1,3 },
310
            { 2,0,3 }
311
          };
312

    
313
      float[][] bands     = new float[][] { {0.028f,35,0.16f,0.7f,7,3,3}, {0.000f, 0,1.00f,0.0f,3,1,3} };
314
      int[] bandIndices   = new int[] { 0,1,1,1 };
315
      float[][] corners   = new float[][] { {0.06f,0.20f} };
316
      int[] cornerIndices = new int[] { 0,0,0,-1 };
317
      float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.75f} };
318
      int[] centerIndices = new int[] { 0,0,0,-1 };
319
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
320
      }
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

    
325
  Static4D getQuat(int cubit, int numLayers)
326
    {
327
    if( mQuats==null ) initializeQuats();
328
    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 };
329
    return mQuats[mQuatIndices[cubit]];
330
    }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
  int getNumCubitVariants(int numLayers)
335
    {
336
    return 2;
337
    }
338

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

    
341
  int getCubitVariant(int cubit, int numLayers)
342
    {
343
    return cubit<8 ? 0:1;
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

    
348
  int getFaceColor(int cubit, int cubitface, int size)
349
    {
350
    if( mFaceMap==null )
351
      {
352
      mFaceMap = new int[][]
353
         {
354
           { 4,2,0, 6,6,6 },
355
           { 0,2,5, 6,6,6 },
356
           { 4,0,3, 6,6,6 },
357
           { 5,3,0, 6,6,6 },
358
           { 1,2,4, 6,6,6 },
359
           { 5,2,1, 6,6,6 },
360
           { 4,3,1, 6,6,6 },
361
           { 1,3,5, 6,6,6 },
362

    
363
           { 0 , 6,6,6,6,6 },
364
           { 0 , 6,6,6,6,6 },
365
           { 0 , 6,6,6,6,6 },
366
           { 0 , 6,6,6,6,6 },
367

    
368
           { 1 , 6,6,6,6,6 },
369
           { 1 , 6,6,6,6,6 },
370
           { 1 , 6,6,6,6,6 },
371
           { 1 , 6,6,6,6,6 },
372

    
373
           { 2 , 6,6,6,6,6 },
374
           { 2 , 6,6,6,6,6 },
375
           { 2 , 6,6,6,6,6 },
376
           { 2 , 6,6,6,6,6 },
377

    
378
           { 3 , 6,6,6,6,6 },
379
           { 3 , 6,6,6,6,6 },
380
           { 3 , 6,6,6,6,6 },
381
           { 3 , 6,6,6,6,6 },
382

    
383
           { 4 , 6,6,6,6,6 },
384
           { 4 , 6,6,6,6,6 },
385
           { 4 , 6,6,6,6,6 },
386
           { 4 , 6,6,6,6,6 },
387

    
388
           { 5 , 6,6,6,6,6 },
389
           { 5 , 6,6,6,6,6 },
390
           { 5 , 6,6,6,6,6 },
391
           { 5 , 6,6,6,6,6 },
392
         };
393
      }
394

    
395
    return mFaceMap[cubit][cubitface];
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  int getColor(int face)
401
    {
402
    return FACE_COLORS[face];
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

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

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

    
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

    
424
  float returnMultiplier()
425
    {
426
    return 2.0f;
427
    }
428

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430
// PUBLIC API
431

    
432
  public Static3D[] getRotationAxis()
433
    {
434
    return ROT_AXIS;
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

    
439
  public Movement getMovement()
440
    {
441
    if( mMovement==null ) mMovement = new MovementHelicopter();
442
    return mMovement;
443
    }
444

    
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446

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

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

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

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

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

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public int getComplexity(int numLayers)
470
    {
471
    return 8;
472
    }
473
}
(28-28/44)