Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyIvy.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 TwistyIvy extends Twisty6
37
{
38
  static final Static3D[] ROT_AXIS = new Static3D[]
39
         {
40
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
41
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
42
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
43
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
44
         };
45

    
46
  private static final int NUM_STICKERS = 2;
47
  public static final float IVY_D = 0.006f;
48
  private static final int  IVY_N = 8;
49

    
50
  private ScrambleState[] mStates;
51
  private int[] mBasicAngle;
52
  private Static4D[] mQuats;
53
  private int[][] mFaceMap;
54
  private ObjectSticker[] mStickers;
55
  private Movement mMovement;
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

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

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  ScrambleState[] getScrambleStates()
68
    {
69
    if( mStates==null )
70
      {
71
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
72

    
73
      mStates = new ScrambleState[]
74
        {
75
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
76
        };
77
      }
78

    
79
    return mStates;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  private void initializeQuats()
85
    {
86
    mQuats = new Static4D[]
87
         {
88
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
89
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
90
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
91
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
92

    
93
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
94
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
95
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
96
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
97
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
98
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
99
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
100
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
101
         };
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  int[] getSolvedQuats(int cubit, int numLayers)
107
    {
108
    if( mQuats==null ) initializeQuats();
109
    int status = retCubitSolvedStatus(cubit,numLayers);
110
    return status<0 ? null : buildSolvedQuats(MovementIvy.FACE_AXIS[status],mQuats);
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  Static4D[] getQuats()
116
    {
117
    if( mQuats==null ) initializeQuats();
118
    return mQuats;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  int getSolvedFunctionIndex()
124
    {
125
    return 0;
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  int getNumStickerTypes(int numLayers)
131
    {
132
    return NUM_STICKERS;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  float[][] getCuts(int numLayers)
138
    {
139
    float[] cut = new float[] {0.0f};
140
    return new float[][] { cut,cut,cut,cut };
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  int getNumCubitFaces()
146
    {
147
    return 6;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  float[][] getCubitPositions(int numLayers)
153
    {
154
    final float DIST_CORNER = numLayers-1;
155
    final float DIST_CENTER = numLayers-1;
156

    
157
    final float[][] CENTERS = new float[10][];
158

    
159
    CENTERS[0] = new float[] { DIST_CORNER, DIST_CORNER, DIST_CORNER };
160
    CENTERS[1] = new float[] {-DIST_CORNER, DIST_CORNER,-DIST_CORNER };
161
    CENTERS[2] = new float[] {-DIST_CORNER,-DIST_CORNER, DIST_CORNER };
162
    CENTERS[3] = new float[] { DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
163
    CENTERS[4] = new float[] { DIST_CENTER,           0,           0 };
164
    CENTERS[5] = new float[] {-DIST_CENTER,           0,           0 };
165
    CENTERS[6] = new float[] {           0, DIST_CENTER,           0 };
166
    CENTERS[7] = new float[] {           0,-DIST_CENTER,           0 };
167
    CENTERS[8] = new float[] {           0,           0, DIST_CENTER };
168
    CENTERS[9] = new float[] {           0,           0,-DIST_CENTER };
169

    
170
    return CENTERS;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  ObjectShape getObjectShape(int cubit, int numLayers)
176
    {
177
    int variant = getCubitVariant(cubit,numLayers);
178

    
179
    if( variant==0 )
180
      {
181
      final float angle = (float)Math.PI/(2*IVY_N);
182
      final float CORR  = 1.0f - 2*IVY_D;
183

    
184
      float[][] centers= new float[][] { {-1.0f,-1.0f,-1.0f} };
185
      float[][] corners= new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
186
      int[] cornerIndices= new int[3*(IVY_N+1)+4];
187
      int[] centerIndices= new int[3*(IVY_N+1)+4];
188
      double[][] vertices= new double[3*(IVY_N+1)+4][3];
189
      int[][] vertIndices= new int[6][IVY_N+4];
190
      int[] bandIndices  = new int[] { 0,0,0,1,1,1 };
191

    
192
      float[][] bands =
193
        {
194
          {+0.015f,20,0.2f,0.5f,7,1,2},
195
          {-0.100f,20,0.2f,0.0f,2,1,2}
196
        };
197

    
198
      for(int i=0; i<3*(IVY_N+1); i++)
199
        {
200
        cornerIndices[i+4] = -1;
201
        centerIndices[i+4] = -1;
202
        }
203

    
204
      cornerIndices[0] = 1;
205
      cornerIndices[1] = 0;
206
      cornerIndices[2] = 0;
207
      cornerIndices[3] = 0;
208

    
209
      centerIndices[0] = 0;
210
      centerIndices[1] = 0;
211
      centerIndices[2] = 0;
212
      centerIndices[3] = 0;
213

    
214
      vertices[0][0] = 0.0;
215
      vertices[0][1] = 0.0;
216
      vertices[0][2] = 0.0;
217
      vertices[1][0] =-2.0;
218
      vertices[1][1] = 0.0;
219
      vertices[1][2] = 0.0;
220
      vertices[2][0] = 0.0;
221
      vertices[2][1] =-2.0;
222
      vertices[2][2] = 0.0;
223
      vertices[3][0] = 0.0;
224
      vertices[3][1] = 0.0;
225
      vertices[3][2] =-2.0;
226

    
227
      vertIndices[0][0] = 2;
228
      vertIndices[0][1] = 0;
229
      vertIndices[0][2] = 1;
230
      vertIndices[3][0] = 2;
231
      vertIndices[3][1] = 0;
232
      vertIndices[3][2] = 1;
233

    
234
      vertIndices[1][0] = 3;
235
      vertIndices[1][1] = 0;
236
      vertIndices[1][2] = 2;
237
      vertIndices[4][0] = 3;
238
      vertIndices[4][1] = 0;
239
      vertIndices[4][2] = 2;
240

    
241
      vertIndices[2][0] = 1;
242
      vertIndices[2][1] = 0;
243
      vertIndices[2][2] = 3;
244
      vertIndices[5][0] = 1;
245
      vertIndices[5][1] = 0;
246
      vertIndices[5][2] = 3;
247

    
248
      int N1 = 4;
249
      int N2 = N1 + IVY_N + 1;
250
      int N3 = N2 + IVY_N + 1;
251

    
252
      for(int i=0; i<=IVY_N; i++)
253
        {
254
        double cos1 = Math.cos((IVY_N-i)*angle);
255
        double sin1 = Math.sin((IVY_N-i)*angle);
256
        double cos2 = Math.cos((      i)*angle);
257
        double sin2 = Math.sin((      i)*angle);
258

    
259
        vertices[N1+i][0] = CORR*(2*cos1-1.0) - 1.0;
260
        vertices[N1+i][1] = CORR*(2*sin1-1.0) - 1.0;
261
        vertices[N1+i][2] = 0.0;
262

    
263
        vertices[N2+i][0] = 0.0;
264
        vertices[N2+i][1] = CORR*(2*sin2-1.0) - 1.0;
265
        vertices[N2+i][2] = CORR*(2*cos2-1.0) - 1.0;
266

    
267
        vertices[N3+i][0] = CORR*(2*cos2-1.0) - 1.0;
268
        vertices[N3+i][1] = 0.0;
269
        vertices[N3+i][2] = CORR*(2*sin2-1.0) - 1.0;
270

    
271
        vertIndices[0][i+3] = N1 + i;
272
        vertIndices[1][i+3] = N2 + i;
273
        vertIndices[2][i+3] = N3 + i;
274
        vertIndices[3][i+3] = N1 + i;
275
        vertIndices[4][i+3] = N2 + i;
276
        vertIndices[5][i+3] = N3 + i;
277
        }
278

    
279
      float C = 1.0f - SQ2/2;
280
      float[] convexCenter = new float[] {-C,-C,-C};
281
      return new ObjectShape(vertices,vertIndices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), convexCenter);
282
      }
283
    else
284
      {
285
      final float angle = (float)Math.PI/(2*IVY_N);
286
      final float CORR  = 1.0f - 2*IVY_D;
287
      double[][] vertices = new double[2*IVY_N][3];
288
      int[][] vert_indices = new int[2][2*IVY_N];
289

    
290
      int[] bandIndices= new int[] { 0,1 };
291
      int[] indexes    = new int[2*IVY_N];
292
      float[][] corners= new float[][] { {0.05f,0.20f} };
293
      float[][] centers= new float[][] { {-0.0f,-0.0f,-1.0f} };
294

    
295
      for(int i=0; i<IVY_N; i++)
296
        {
297
        double sin = Math.sin(i*angle);
298
        double cos = Math.cos(i*angle);
299

    
300
        vertices[i      ][0] = CORR*(1.0f-2*cos);
301
        vertices[i      ][1] = CORR*(1.0f-2*sin);
302
        vertices[i      ][2] = 0;
303
        vertices[i+IVY_N][0] = CORR*(2*cos-1.0f);
304
        vertices[i+IVY_N][1] = CORR*(2*sin-1.0f);
305
        vertices[i+IVY_N][2] = 0;
306
        }
307

    
308
      for(int i=0; i<2*IVY_N; i++)
309
        {
310
        vert_indices[0][i] = i;
311
        vert_indices[1][i] = 2*IVY_N-1-i;
312
        }
313

    
314
      for(int i=0; i<2*IVY_N; i++)
315
        {
316
        indexes[i] = -1;
317
        }
318
      indexes[0] = indexes[IVY_N] = 0;
319

    
320
      float[][] bands =
321
        {
322
          {+0.03f,35,0.5f,0.5f,5,0,0},
323
          {+0.10f,45,0.5f,0.0f,2,0,0}
324
        };
325

    
326
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,indexes,centers,indexes,getNumCubitFaces(), null);
327
      }
328
    }
329

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

    
332
  Static4D getQuat(int cubit, int numLayers)
333
    {
334
    if( mQuats==null ) initializeQuats();
335

    
336
    switch(cubit)
337
      {
338
      case  0: return mQuats[0];
339
      case  1: return mQuats[2];
340
      case  2: return mQuats[3];
341
      case  3: return mQuats[1];
342

    
343
      case  4: return mQuats[8];
344
      case  5: return mQuats[11];
345
      case  6: return mQuats[10];
346
      case  7: return mQuats[9];
347
      case  8: return mQuats[0];
348
      case  9: return mQuats[2];
349
      }
350

    
351
    return mQuats[0];
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  int getNumCubitVariants(int numLayers)
357
    {
358
    return 2;
359
    }
360

    
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362

    
363
  int getCubitVariant(int cubit, int numLayers)
364
    {
365
    return cubit<4 ? 0:1;
366
    }
367

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

    
370
  int getFaceColor(int cubit, int cubitface, int numLayers)
371
    {
372
    if( mFaceMap==null )
373
      {
374
      mFaceMap = new int[][]
375
         {
376
           {  4, 0, 2, 12,12,12 },
377
           {  5, 1, 2, 12,12,12 },
378
           {  4, 1, 3, 12,12,12 },
379
           {  5, 0, 3, 12,12,12 },
380

    
381
           {  6, 12,12,12,12,12 },
382
           {  7, 12,12,12,12,12 },
383
           {  8, 12,12,12,12,12 },
384
           {  9, 12,12,12,12,12 },
385
           { 10, 12,12,12,12,12 },
386
           { 11, 12,12,12,12,12 },
387
         };
388
      }
389

    
390
    return mFaceMap[cubit][cubitface];
391
    }
392

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

    
395
  ObjectSticker retSticker(int face)
396
    {
397
    if( mStickers==null )
398
      {
399
      float[][] STICKERS = new float[][] { { 0.29258922f, -0.5f, 0.29258922f, 0.29258922f, -0.5f, 0.29258922f }, { -0.5f, 0.5f, 0.5f, -0.5f } };
400
      mStickers = new ObjectSticker[NUM_STICKERS];
401
      float D = (float)(Math.PI/4);
402
      final float[][] angles = { { 0,0,D },{ D,D } };
403
      final float[][] radii  = { { 0,0.04f,0 },{ 0.06f,0.06f } };
404
      final float[] strokes = { 0.03f, 0.08f };
405
      for(int s=0; s<NUM_STICKERS; s++) mStickers[s] = new ObjectSticker(STICKERS[s], angles[s],radii[s],strokes[s]);
406
      }
407

    
408
    return mStickers[face/NUM_FACE_COLORS];
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412
// PUBLIC API
413

    
414
  public Static3D[] getRotationAxis()
415
    {
416
    return ROT_AXIS;
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  public Movement getMovement()
422
    {
423
    if( mMovement==null ) mMovement = new MovementIvy();
424
    return mMovement;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public int[] getBasicAngle()
430
    {
431
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
432
    return mBasicAngle;
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  public int getObjectName(int numLayers)
438
    {
439
    return R.string.ivy2;
440
    }
441

    
442
///////////////////////////////////////////////////////////////////////////////////////////////////
443

    
444
  public int getInventor(int numLayers)
445
    {
446
    return R.string.ivy2_inventor;
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public int getComplexity(int numLayers)
452
    {
453
    return 1;
454
    }
455
}
(33-33/48)