Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySquare2.java @ abf36986

1 e2b9e87e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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 fd836c4e Leszek Koltunski
import org.distorted.helpers.ObjectShape;
25 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
26 0021af58 Leszek Koltunski
import org.distorted.helpers.ScrambleState;
27 e2b9e87e 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.Static4D;
31
import org.distorted.main.R;
32
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35
class TwistySquare2 extends TwistySquare
36
{
37 d5380277 Leszek Koltunski
  private static final int NUM_STICKERS = 6;
38 9c06394a Leszek Koltunski
39 91792184 Leszek Koltunski
  private ScrambleState[] mStates;
40 d5380277 Leszek Koltunski
  private int[] mQuatNumber;
41
  private float[][] mCenters;
42
  private int[][] mStickerColor;
43
  private int[][] mStickerType;
44
  private ObjectSticker[] mStickers;
45 0021af58 Leszek Koltunski
46 e2b9e87e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
47
48
  TwistySquare2(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
49
                DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
50
    {
51
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU2, res, scrWidth);
52 91792184 Leszek Koltunski
    }
53 0021af58 Leszek Koltunski
54 91792184 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
55 0021af58 Leszek Koltunski
56 91792184 Leszek Koltunski
  ScrambleState[] getScrambleStates()
57
    {
58
    if( mStates==null )
59 0021af58 Leszek Koltunski
      {
60 91792184 Leszek Koltunski
      int[] SL_6 = new int[] { 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1};
61
      int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
62
      int[] LO_2 = new int[] { 0,-5,2, 0,-4,2, 0,-3,2, 0,-2,2, 0,-1,2, 0,1,2, 0,2,2, 0,3,2, 0,4,2, 0,5,2, 0,5,2 };
63
      int[] LO_3 = new int[] { 0,-5,3, 0,-4,3, 0,-3,3, 0,-2,3, 0,-1,3, 0,1,3, 0,2,3, 0,3,3, 0,4,3, 0,5,3, 0,5,3 };
64
      int[] LO_4 = new int[] { 0,-5,4, 0,-4,4, 0,-3,4, 0,-2,4, 0,-1,4, 0,1,4, 0,2,4, 0,3,4, 0,4,4, 0,5,4, 0,5,4 };
65
66
      mStates = new ScrambleState[]
67
        {
68
        new ScrambleState( new int[][] { LO_2, SL_6, LO_3 } ),  // 0
69
        new ScrambleState( new int[][] { LO_2, null, LO_3 } ),  // SL
70
        new ScrambleState( new int[][] { null, SL_1, LO_4 } ),  // LO
71
        new ScrambleState( new int[][] { LO_4, SL_1, null } ),  // UP
72
        new ScrambleState( new int[][] { null, SL_1, null } ),  // UL
73
        };
74
      }
75
76
    return mStates;
77 e2b9e87e Leszek Koltunski
    }
78
79 a480ee80 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
80
81
  int[] getSolvedQuats(int cubit, int numLayers)
82
    {
83
    return null;
84
    }
85
86 e2b9e87e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
87
88 fd836c4e Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
89 e2b9e87e Leszek Koltunski
    {
90 fd836c4e Leszek Koltunski
    int variant = getCubitVariant(cubit,numLayers);
91 e2b9e87e Leszek Koltunski
92 fd836c4e Leszek Koltunski
    if( variant==0 )
93
      {
94 d5380277 Leszek Koltunski
      double[][] vertices = new double[][]
95
        {
96
         { -1.5-X, 0.5, 1.5 },
97
         {    0.0, 0.5, 1.5 },
98
         {    0.0, 0.5,-1.5 },
99
         { -1.5+X, 0.5,-1.5 },
100
         { -1.5-X,-0.5, 1.5 },
101
         {    0.0,-0.5, 1.5 },
102
         {    0.0,-0.5,-1.5 },
103
         { -1.5+X,-0.5,-1.5 }
104
        };
105
106
      int[][] vert_indices = new int[][]
107
        {
108
         {0,1,2,3},
109
         {4,5,6,7},
110
         {4,5,1,0},
111
         {5,6,2,1},
112
         {6,7,3,2},
113
         {7,4,0,3}
114
        };
115
116 fd836c4e Leszek Koltunski
      float[][] bands     = new float[][] { {0.040f,35,0.8f,1.0f,5,2,1}, {0.020f,35,0.8f,1.0f,5,2,1}, {0.001f,35,0.8f,1.0f,5,2,1} };
117
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
118
      float[][] corners   = new float[][] { {0.03f,0.05f} };
119
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
120
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
121
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
122 d5380277 Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
123 fd836c4e Leszek Koltunski
      }
124
    else if( variant==1 )
125
      {
126 d5380277 Leszek Koltunski
      double[][] vertices = new double[][]
127
        {
128
         { -X, 0.5, 0.0 },
129
         { +X, 0.5, 0.0 },
130
         {0.0, 0.5,-1.5 },
131
         { -X,-0.5, 0.0 },
132
         { +X,-0.5, 0.0 },
133
         {0.0,-0.5,-1.5 },
134
        };
135
136
      int[][] vert_indices = new int[][]
137
        {
138
         {0,1,2},
139
         {3,4,5},
140
         {3,4,1,0},
141
         {4,5,2,1},
142
         {5,3,0,2}
143
        };
144
145 fd836c4e Leszek Koltunski
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
146
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
147
      float[][] corners   = new float[][] { {0.04f,0.15f} };
148
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
149
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
150
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
151 d5380277 Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
152 fd836c4e Leszek Koltunski
      }
153
    else
154 e2b9e87e Leszek Koltunski
      {
155 d5380277 Leszek Koltunski
      double[][] vertices = new double[][]
156
        {
157
         {-0.75f+X/2, 0.5,  0.0 },
158
         { 0.75f-X/2, 0.5,  0.0 },
159
         {-0.75f-X/2, 0.5, -1.5 },
160
         {-0.75f+X/2,-0.5,  0.0 },
161
         { 0.75f-X/2,-0.5,  0.0 },
162
         {-0.75f-X/2,-0.5, -1.5 }
163
        };
164
      int[][] vert_indices = new int[][]
165
        {
166
         {0,1,2},
167
         {5,4,3},
168
         {3,4,1,0},
169
         {4,5,2,1},
170
         {5,3,0,2}
171
        };
172
173 fd836c4e Leszek Koltunski
      float[][] bands     = new float[][] { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
174
      int[] bandIndices   = new int[] { 0,0,0,1,1 };
175 e2b9e87e Leszek Koltunski
      float[][] corners   = new float[][] { {0.05f,0.13f} };
176 fd836c4e Leszek Koltunski
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
177 e2b9e87e Leszek Koltunski
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
178 fd836c4e Leszek Koltunski
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
179 d5380277 Leszek Koltunski
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
180 e2b9e87e Leszek Koltunski
      }
181 fd836c4e Leszek Koltunski
    }
182
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184
185 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
186 fd836c4e Leszek Koltunski
    {
187 d5380277 Leszek Koltunski
    if( mQuats==null ) initializeQuats();
188
189
    if( mQuatNumber ==null )
190
      {
191
      mQuatNumber = new int[]
192
        {
193
        0, 6,
194
        0, 9, 6, 3, 18, 15, 12, 21,
195
        0, 9, 6, 3, 0, 9, 6, 3,
196
        15, 12, 21, 18, 15, 12, 21, 18
197
        };
198
      }
199
200
    return mQuats[mQuatNumber[cubit]];
201 fd836c4e Leszek Koltunski
    }
202
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204
205 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
206 fd836c4e Leszek Koltunski
    {
207
    return 3;
208
    }
209
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211
212
  int getCubitVariant(int cubit, int numLayers)
213
    {
214
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
215 e2b9e87e Leszek Koltunski
    }
216
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218
219 9c06394a Leszek Koltunski
  ObjectSticker retSticker(int face)
220 e2b9e87e Leszek Koltunski
    {
221 d5380277 Leszek Koltunski
    if( mStickers==null )
222
      {
223
      float[][] STICKERS = new float[][]
224
        {
225
          { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
226
          { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
227
          { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
228
          { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
229
          { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
230
          { -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f }                     // corner top
231
        };
232
233
      final float R1 = 0.06f;
234
      final float R2 = 0.04f;
235
      final float R3 = 0.11f;
236
      final float R4 = 0.03f;
237
      final float R5 = 0.11f;
238
      final float R6 = 0.025f;
239
      final float[][] radii  = { {R1,R1,R1,R1},{R2,R2,R2,R2},{R3,R3,R3,R3},{R4,R4,R4},{R5,R5,R5,R5},{R6,R6,R6} };
240
      final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.06f };
241
242
      mStickers = new ObjectSticker[NUM_STICKERS];
243
244
      for(int s=0; s<NUM_STICKERS; s++)
245
        {
246
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
247
        }
248
      }
249
250 abf36986 Leszek Koltunski
    return mStickers[face/NUM_FACE_COLORS];
251 e2b9e87e Leszek Koltunski
    }
252
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254
255
  float[][] getCubitPositions(int numLayers)
256
    {
257 d5380277 Leszek Koltunski
    if( mCenters ==null )
258
      {
259
      float Y = 0.75f + X/2;
260
261
      mCenters = new float[][]
262
        {
263
         { 1.5f, 0.0f, 0.0f },
264
         {-1.5f, 0.0f, 0.0f },
265
266
         { 0.0f, 1.0f, 1.5f },
267
         { 1.5f, 1.0f, 0.0f },
268
         { 0.0f, 1.0f,-1.5f },
269
         {-1.5f, 1.0f, 0.0f },
270
         { 0.0f,-1.0f, 1.5f },
271
         { 1.5f,-1.0f, 0.0f },
272
         { 0.0f,-1.0f,-1.5f },
273
         {-1.5f,-1.0f, 0.0f },
274
275
         {    Y, 1.0f, 1.5f },
276
         { 1.5f, 1.0f,   -Y },
277
         {   -Y, 1.0f,-1.5f },
278
         {-1.5f, 1.0f,    Y },
279
         {    Y,-1.0f, 1.5f },
280
         { 1.5f,-1.0f,   -Y },
281
         {   -Y,-1.0f,-1.5f },
282
         {-1.5f,-1.0f,    Y },
283
284
         { 1.5f, 1.0f,    Y },
285
         {    Y, 1.0f,-1.5f },
286
         {-1.5f, 1.0f,   -Y },
287
         {   -Y, 1.0f, 1.5f },
288
         { 1.5f,-1.0f,    Y },
289
         {    Y,-1.0f,-1.5f },
290
         {-1.5f,-1.0f,   -Y },
291
         {   -Y,-1.0f, 1.5f },
292
        };
293
      }
294
295
    return mCenters;
296 e2b9e87e Leszek Koltunski
    }
297
298 e42a9e87 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
299
300
  int getSolvedFunctionIndex()
301
    {
302
    return 3;
303
    }
304
305 e2b9e87e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
306
307
  int getNumStickerTypes(int numLayers)
308
    {
309 9c06394a Leszek Koltunski
    return NUM_STICKERS;
310 e2b9e87e Leszek Koltunski
    }
311
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313
314
  int getFaceColor(int cubit, int cubitface, int numLayers)
315
    {
316 d5380277 Leszek Koltunski
    if( mStickerColor==null )
317
      {
318
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
319
      mStickerColor = new int[][]
320
        {
321
         { 0, 0, 4, 0, 5, 0 }, // 0
322
         { 0, 0, 5, 1, 4, 0 },
323
324
         { 2, 0, 4, 0, 0, 0 }, // 2
325
         { 2, 0, 0, 0, 0, 0 },
326
         { 2, 0, 5, 0, 0, 0 },
327
         { 2, 0, 1, 0, 0, 0 },
328
         { 3, 0, 4, 0, 0, 0 },
329
         { 3, 0, 0, 0, 0, 0 },
330
         { 3, 0, 5, 0, 0, 0 },
331
         { 3, 0, 1, 0, 0, 0 },
332
333
         { 2, 0, 4, 0, 0, 0 }, // 10
334
         { 2, 0, 0, 0, 0, 0 },
335
         { 2, 0, 5, 0, 0, 0 },
336
         { 2, 0, 1, 0, 0, 0 },
337
         { 0, 3, 4, 0, 0, 0 },
338
         { 0, 3, 0, 0, 0, 0 },
339
         { 0, 3, 5, 0, 0, 0 },
340
         { 0, 3, 1, 0, 0, 0 },
341
342
         { 0, 2, 0, 0, 0, 0 }, // 18
343
         { 0, 2, 5, 0, 0, 0 },
344
         { 0, 2, 1, 0, 0, 0 },
345
         { 0, 2, 4, 0, 0, 0 },
346
         { 3, 0, 0, 0, 0, 0 },
347
         { 3, 0, 5, 0, 0, 0 },
348
         { 3, 0, 1, 0, 0, 0 },
349
         { 3, 0, 4, 0, 0, 0 },
350
        };
351
      }
352
353
    if( mStickerType==null )
354
      {
355
      mStickerType = new int[][]
356
        {
357
         {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
358
         {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
359
         {             5,NUM_STICKERS,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
360
         {  NUM_STICKERS,           5,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS }
361
        };
362
      }
363
364 e2b9e87e Leszek Koltunski
    int type;
365
366
         if( cubit< 2             ) type = 0;
367
    else if( cubit<10             ) type = 1;
368
    else if( cubit>13 && cubit<22 ) type = 3;
369
    else                            type = 2;
370
371
    return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
372
    }
373
374 0021af58 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
375
// PUBLIC API
376 e2b9e87e Leszek Koltunski
377
  public int getObjectName(int numLayers)
378
    {
379
    return R.string.squa2;
380
    }
381
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383
384
  public int getInventor(int numLayers)
385
    {
386
    return R.string.squa2_inventor;
387
    }
388
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390
391
  public int getComplexity(int numLayers)
392
    {
393
    return 7;
394
    }
395
}