Project

General

Profile

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

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

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 Twisty6
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 ScrambleState[] mStates;
50
  private int[] mBasicAngle;
51
  private Static4D[] mQuats;
52
  private float[][] mCenters;
53
  private int[] mQuatIndices;
54
  private int[][] mFaceMap;
55
  private ObjectSticker[] mStickers;
56
  private Movement mMovement;
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  TwistyHelicopter(int size, Static4D quat, DistortedTexture texture,
61
                   MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
62
    {
63
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.HELI, res, scrWidth);
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  ScrambleState[] getScrambleStates()
69
    {
70
    if( mStates==null )
71
      {
72
      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
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  int[] getSolvedQuats(int cubit, int numLayers)
131
    {
132
    if( mQuats==null ) initializeQuats();
133
    int status = retCubitSolvedStatus(cubit,numLayers);
134
    return status<0 ? null : buildSolvedQuats(MovementHelicopter.FACE_AXIS[status],mQuats);
135
    }
136

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

    
139
  Static4D[] getQuats()
140
    {
141
    if( mQuats==null ) initializeQuats();
142
    return mQuats;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  int getSolvedFunctionIndex()
148
    {
149
    return 0;
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  int getNumStickerTypes(int numLayers)
155
    {
156
    return 1;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  float[][] getCuts(int size)
162
    {
163
    float[] cut = new float[] { -3*SQ2/4, +3*SQ2/4 };
164
    return new float[][] { cut,cut,cut,cut,cut,cut };
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  int getNumCubitFaces()
170
    {
171
    return 4;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  float[][] getCubitPositions(int size)
177
    {
178
    if( mCenters==null )
179
      {
180
      float DIST_CORNER = 1.50f;
181
      float DIST_CENTER = 1.50f;
182
      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
    }
229

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
  ObjectShape getObjectShape(int cubit, int numLayers)
233
    {
234
    int variant = getCubitVariant(cubit,numLayers);
235

    
236
    if( variant==0 )
237
      {
238
      double[][] vertices = new double[][]
239
          {
240
            {-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
            { 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
      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
      int[] bandIndices   = new int[] { 0,0,0,1,1,1 };
259
      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
      int[] centerIndices = new int[] { 0,0,0,-1,0 };
263
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
264
      }
265
    else
266
      {
267
      double[][] vertices = new double[][]
268
          {
269
            { 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
          };
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
      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
      int[] bandIndices   = new int[] { 0,1,1,1 };
285
      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
      int[] centerIndices = new int[] { 0,0,0,-1 };
289
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
290
      }
291
    }
292

    
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294

    
295
  Static4D getQuat(int cubit, int numLayers)
296
    {
297
    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
    }
301

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

    
304
  int getNumCubitVariants(int numLayers)
305
    {
306
    return 2;
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
  int getCubitVariant(int cubit, int numLayers)
312
    {
313
    return cubit<8 ? 0:1;
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  int getFaceColor(int cubit, int cubitface, int size)
319
    {
320
    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
    return mFaceMap[cubit][cubitface];
366
    }
367

    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369

    
370
  ObjectSticker retSticker(int face)
371
    {
372
    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
    return mStickers[face/NUM_FACE_COLORS];
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386
// PUBLIC API
387

    
388
  public Static3D[] getRotationAxis()
389
    {
390
    return ROT_AXIS;
391
    }
392

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

    
395
  public Movement getMovement()
396
    {
397
    if( mMovement==null ) mMovement = new MovementHelicopter();
398
    return mMovement;
399
    }
400

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402

    
403
  public int[] getBasicAngle()
404
    {
405
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 2,2,2,2,2,2 };
406
    return mBasicAngle;
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
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
}
(32-32/48)