Project

General

Profile

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

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

1 49cd8581 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 49cd8581 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 49cd8581 Leszek Koltunski
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 efa81f0c Leszek Koltunski
public class TwistyIvy extends Twisty6
37 49cd8581 Leszek Koltunski
{
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 e01fa67a Leszek Koltunski
  private static final int NUM_STICKERS = 2;
47 4d27a99b Leszek Koltunski
  public static final float IVY_D = 0.006f;
48 e01fa67a Leszek Koltunski
  private static final int  IVY_N = 8;
49 9c06394a Leszek Koltunski
50 91792184 Leszek Koltunski
  private ScrambleState[] mStates;
51 e01fa67a Leszek Koltunski
  private int[] mBasicAngle;
52
  private Static4D[] mQuats;
53
  private int[][] mFaceMap;
54
  private ObjectSticker[] mStickers;
55 e9a87113 Leszek Koltunski
  private Movement mMovement;
56 0ad6b867 Leszek Koltunski
57 49cd8581 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59
  TwistyIvy(int size, Static4D quat, DistortedTexture texture,
60
            MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
61
    {
62 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.IVY, res, scrWidth);
63 49cd8581 Leszek Koltunski
    }
64
65 91792184 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 e01fa67a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 a480ee80 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
105
106
  int[] getSolvedQuats(int cubit, int numLayers)
107
    {
108 e01fa67a Leszek Koltunski
    if( mQuats==null ) initializeQuats();
109 a480ee80 Leszek Koltunski
    int status = retCubitSolvedStatus(cubit,numLayers);
110 e01fa67a Leszek Koltunski
    return status<0 ? null : buildSolvedQuats(MovementIvy.FACE_AXIS[status],mQuats);
111 a480ee80 Leszek Koltunski
    }
112
113 49cd8581 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
114
115
  Static4D[] getQuats()
116
    {
117 e01fa67a Leszek Koltunski
    if( mQuats==null ) initializeQuats();
118
    return mQuats;
119 49cd8581 Leszek Koltunski
    }
120
121 169219a7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
122
123
  int getSolvedFunctionIndex()
124
    {
125
    return 0;
126
    }
127
128 49cd8581 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
129
130 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
131 49cd8581 Leszek Koltunski
    {
132 9c06394a Leszek Koltunski
    return NUM_STICKERS;
133 49cd8581 Leszek Koltunski
    }
134
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
137 e6734aa9 Leszek Koltunski
  float[][] getCuts(int numLayers)
138 49cd8581 Leszek Koltunski
    {
139 e6734aa9 Leszek Koltunski
    float[] cut = new float[] {0.0f};
140
    return new float[][] { cut,cut,cut,cut };
141 49cd8581 Leszek Koltunski
    }
142
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
145
  int getNumCubitFaces()
146
    {
147 efa81f0c Leszek Koltunski
    return 6;
148 49cd8581 Leszek Koltunski
    }
149
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
152 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int numLayers)
153 49cd8581 Leszek Koltunski
    {
154 4d27a99b Leszek Koltunski
    final float DIST_CORNER = numLayers-1;
155
    final float DIST_CENTER = numLayers-1;
156 49cd8581 Leszek Koltunski
157 e6cf7283 Leszek Koltunski
    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 49cd8581 Leszek Koltunski
170
    return CENTERS;
171
    }
172
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175 a2a4df1b Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
176 49cd8581 Leszek Koltunski
    {
177 a2a4df1b Leszek Koltunski
    int variant = getCubitVariant(cubit,numLayers);
178
179
    if( variant==0 )
180 49cd8581 Leszek Koltunski
      {
181 a2a4df1b Leszek Koltunski
      final float angle = (float)Math.PI/(2*IVY_N);
182
      final float CORR  = 1.0f - 2*IVY_D;
183
184 4d27a99b Leszek Koltunski
      float[][] centers= new float[][] { {-1.0f,-1.0f,-1.0f} };
185
      float[][] corners= new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
186 a2a4df1b Leszek Koltunski
      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 4d27a99b Leszek Koltunski
      vertices[1][0] =-2.0;
218 a2a4df1b Leszek Koltunski
      vertices[1][1] = 0.0;
219
      vertices[1][2] = 0.0;
220
      vertices[2][0] = 0.0;
221 4d27a99b Leszek Koltunski
      vertices[2][1] =-2.0;
222 a2a4df1b Leszek Koltunski
      vertices[2][2] = 0.0;
223
      vertices[3][0] = 0.0;
224
      vertices[3][1] = 0.0;
225 4d27a99b Leszek Koltunski
      vertices[3][2] =-2.0;
226 a2a4df1b Leszek Koltunski
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 4d27a99b Leszek Koltunski
        vertices[N1+i][0] = CORR*(2*cos1-1.0) - 1.0;
260
        vertices[N1+i][1] = CORR*(2*sin1-1.0) - 1.0;
261 a2a4df1b Leszek Koltunski
        vertices[N1+i][2] = 0.0;
262
263
        vertices[N2+i][0] = 0.0;
264 4d27a99b Leszek Koltunski
        vertices[N2+i][1] = CORR*(2*sin2-1.0) - 1.0;
265
        vertices[N2+i][2] = CORR*(2*cos2-1.0) - 1.0;
266 a2a4df1b Leszek Koltunski
267 4d27a99b Leszek Koltunski
        vertices[N3+i][0] = CORR*(2*cos2-1.0) - 1.0;
268 a2a4df1b Leszek Koltunski
        vertices[N3+i][1] = 0.0;
269 4d27a99b Leszek Koltunski
        vertices[N3+i][2] = CORR*(2*sin2-1.0) - 1.0;
270 a2a4df1b Leszek Koltunski
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 4d27a99b Leszek Koltunski
      float C = 1.0f - SQ2/2;
280 a2a4df1b Leszek Koltunski
      float[] convexCenter = new float[] {-C,-C,-C};
281
      return new ObjectShape(vertices,vertIndices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), convexCenter);
282 49cd8581 Leszek Koltunski
      }
283 a2a4df1b Leszek Koltunski
    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 4d27a99b Leszek Koltunski
      float[][] corners= new float[][] { {0.05f,0.20f} };
293
      float[][] centers= new float[][] { {-0.0f,-0.0f,-1.0f} };
294 49cd8581 Leszek Koltunski
295 a2a4df1b Leszek Koltunski
      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 4d27a99b Leszek Koltunski
        vertices[i      ][0] = CORR*(1.0f-2*cos);
301
        vertices[i      ][1] = CORR*(1.0f-2*sin);
302 a2a4df1b Leszek Koltunski
        vertices[i      ][2] = 0;
303 4d27a99b Leszek Koltunski
        vertices[i+IVY_N][0] = CORR*(2*cos-1.0f);
304
        vertices[i+IVY_N][1] = CORR*(2*sin-1.0f);
305 a2a4df1b Leszek Koltunski
        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 49cd8581 Leszek Koltunski
    }
329
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331
332 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
333 49cd8581 Leszek Koltunski
    {
334 e01fa67a Leszek Koltunski
    if( mQuats==null ) initializeQuats();
335
336 a2a4df1b Leszek Koltunski
    switch(cubit)
337 a0b48da6 Leszek Koltunski
      {
338 e01fa67a Leszek Koltunski
      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 a0b48da6 Leszek Koltunski
      }
350
351 e01fa67a Leszek Koltunski
    return mQuats[0];
352 a2a4df1b Leszek Koltunski
    }
353 49cd8581 Leszek Koltunski
354 a2a4df1b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
355 47d98cd5 Leszek Koltunski
356 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
357 a2a4df1b Leszek Koltunski
    {
358
    return 2;
359
    }
360 47d98cd5 Leszek Koltunski
361 a2a4df1b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
362 47d98cd5 Leszek Koltunski
363 a2a4df1b Leszek Koltunski
  int getCubitVariant(int cubit, int numLayers)
364
    {
365
    return cubit<4 ? 0:1;
366
    }
367 47d98cd5 Leszek Koltunski
368 49cd8581 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
369
370
  int getFaceColor(int cubit, int cubitface, int numLayers)
371
    {
372 e01fa67a Leszek Koltunski
    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 18a5f95f Leszek Koltunski
    return mFaceMap[cubit][cubitface];
391 49cd8581 Leszek Koltunski
    }
392
393 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
394 9ce78850 Leszek Koltunski
395 9c06394a Leszek Koltunski
  ObjectSticker retSticker(int face)
396
    {
397 e01fa67a Leszek Koltunski
    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 abf36986 Leszek Koltunski
    return mStickers[face/NUM_FACE_COLORS];
409 49cd8581 Leszek Koltunski
    }
410
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412 e1dc3366 Leszek Koltunski
// PUBLIC API
413 49cd8581 Leszek Koltunski
414 e1dc3366 Leszek Koltunski
  public Static3D[] getRotationAxis()
415
    {
416
    return ROT_AXIS;
417
    }
418
419 e9a87113 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
420
421
  public Movement getMovement()
422
    {
423
    if( mMovement==null ) mMovement = new MovementIvy();
424
    return mMovement;
425
    }
426
427 e1dc3366 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
428
429
  public int[] getBasicAngle()
430
    {
431 e01fa67a Leszek Koltunski
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
432
    return mBasicAngle;
433 e1dc3366 Leszek Koltunski
    }
434
435 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 49cd8581 Leszek Koltunski
}