Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySquare2.java @ 0021af58

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
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.Static4D;
31
import org.distorted.main.R;
32

    
33
import java.util.Random;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
class TwistySquare2 extends TwistySquare
38
{
39
  private static final float Y = 0.75f + X/2;
40
  private static final float Z = 0.75f - X/2;
41

    
42
  private static final int[] QUAT_NUMBER = new int[]
43
    {
44
      0, 6,
45
      0, 9, 6, 3, 18, 15, 12, 21,
46
      0, 9, 6, 3, 0, 9, 6, 3,
47
      15, 12, 21, 18, 15, 12, 21, 18
48
    };
49

    
50
  // centers of the 2 middles + 8 edges + 8 left corners + 8 right corners
51
  private static final float[][] CENTERS = new float[][]
52
    {
53
      { 1.5f, 0.0f, 0.0f },
54
      {-1.5f, 0.0f, 0.0f },
55

    
56
      { 0.0f, 1.0f, 1.5f },
57
      { 1.5f, 1.0f, 0.0f },
58
      { 0.0f, 1.0f,-1.5f },
59
      {-1.5f, 1.0f, 0.0f },
60
      { 0.0f,-1.0f, 1.5f },
61
      { 1.5f,-1.0f, 0.0f },
62
      { 0.0f,-1.0f,-1.5f },
63
      {-1.5f,-1.0f, 0.0f },
64

    
65
      {    Y, 1.0f, 1.5f },
66
      { 1.5f, 1.0f,   -Y },
67
      {   -Y, 1.0f,-1.5f },
68
      {-1.5f, 1.0f,    Y },
69
      {    Y,-1.0f, 1.5f },
70
      { 1.5f,-1.0f,   -Y },
71
      {   -Y,-1.0f,-1.5f },
72
      {-1.5f,-1.0f,    Y },
73

    
74
      { 1.5f, 1.0f,    Y },
75
      {    Y, 1.0f,-1.5f },
76
      {-1.5f, 1.0f,   -Y },
77
      {   -Y, 1.0f, 1.5f },
78
      { 1.5f,-1.0f,    Y },
79
      {    Y,-1.0f,-1.5f },
80
      {-1.5f,-1.0f,   -Y },
81
      {   -Y,-1.0f, 1.5f },
82
    };
83

    
84
  private static final double[][] VERTICES_CORNER = new double[][]
85
    {
86
      { X-1.5+Z, 0.5,  0.0 },
87
      {       Z, 0.5,  0.0 },
88
      {  -1.5+Z, 0.5, -1.5 },
89
      { X-1.5+Z,-0.5,  0.0 },
90
      {       Z,-0.5,  0.0 },
91
      {  -1.5+Z,-0.5, -1.5 }
92
    };
93

    
94
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
95
    {
96
      {0,1,2},   // counterclockwise!
97
      {5,4,3},
98
      {3,4,1,0},
99
      {4,5,2,1},
100
      {5,3,0,2}
101
    };
102

    
103
  private static final float[][] STICKERS = new float[][]
104
    {
105
      { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
106
      { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
107
      { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
108
      { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
109
      { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
110
      { -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f }                     // corner top
111
    };
112

    
113
  private static final int NUM_STICKERS = STICKERS.length;
114

    
115
  private static final int[][] mStickerType = new int[][]
116
    {
117
      {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
118
      {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
119
      {             5,NUM_STICKERS,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
120
      {  NUM_STICKERS,           5,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS }
121
    };
122

    
123
  // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
124
  private static final int[][] mStickerColor = new int[][]
125
    {
126
      { 0, 0, 4, 0, 5, 0 }, // 0
127
      { 0, 0, 5, 1, 4, 0 },
128

    
129
      { 2, 0, 4, 0, 0, 0 }, // 2
130
      { 2, 0, 0, 0, 0, 0 },
131
      { 2, 0, 5, 0, 0, 0 },
132
      { 2, 0, 1, 0, 0, 0 },
133
      { 3, 0, 4, 0, 0, 0 },
134
      { 3, 0, 0, 0, 0, 0 },
135
      { 3, 0, 5, 0, 0, 0 },
136
      { 3, 0, 1, 0, 0, 0 },
137

    
138
      { 2, 0, 4, 0, 0, 0 }, // 10
139
      { 2, 0, 0, 0, 0, 0 },
140
      { 2, 0, 5, 0, 0, 0 },
141
      { 2, 0, 1, 0, 0, 0 },
142
      { 0, 3, 4, 0, 0, 0 },
143
      { 0, 3, 0, 0, 0, 0 },
144
      { 0, 3, 5, 0, 0, 0 },
145
      { 0, 3, 1, 0, 0, 0 },
146

    
147
      { 0, 2, 0, 0, 0, 0 }, // 18
148
      { 0, 2, 5, 0, 0, 0 },
149
      { 0, 2, 1, 0, 0, 0 },
150
      { 0, 2, 4, 0, 0, 0 },
151
      { 3, 0, 0, 0, 0, 0 },
152
      { 3, 0, 5, 0, 0, 0 },
153
      { 3, 0, 1, 0, 0, 0 },
154
      { 3, 0, 4, 0, 0, 0 },
155
    };
156

    
157
  private static final ObjectSticker[] mStickers;
158

    
159
  static
160
    {
161
    mStickers = new ObjectSticker[NUM_STICKERS];
162
    final float R1 = 0.06f;
163
    final float R2 = 0.04f;
164
    final float R3 = 0.11f;
165
    final float R4 = 0.03f;
166
    final float R5 = 0.11f;
167
    final float R6 = 0.025f;
168
    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} };
169
    final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.06f };
170

    
171
    for(int s=0; s<NUM_STICKERS; s++)
172
      {
173
      mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
174
      }
175
    }
176

    
177
  private int mCurrState;
178
  private int mIndexExcluded;
179
  private final ScrambleState[] mStates;
180
  private int[][] mScrambleTable;
181
  private int[] mNumOccurences;
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  TwistySquare2(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
186
                DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
187
    {
188
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU2, res, scrWidth);
189

    
190
    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};
191
    int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
192
    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 };
193
    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 };
194
    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 };
195

    
196
    mStates = new ScrambleState[]
197
      {
198
      new ScrambleState( new int[][] { LO_2, SL_6, LO_3 } ),  // 0
199
      new ScrambleState( new int[][] { LO_2, null, LO_3 } ),  // SL
200
      new ScrambleState( new int[][] { null, SL_1, LO_4 } ),  // LO
201
      new ScrambleState( new int[][] { LO_4, SL_1, null } ),  // UP
202
      new ScrambleState( new int[][] { null, SL_1, null } ),  // UL
203
      };
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  int[] getSolvedQuats(int cubit, int numLayers)
209
    {
210
    return null;
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  ObjectShape getObjectShape(int cubit, int numLayers)
216
    {
217
    int variant = getCubitVariant(cubit,numLayers);
218

    
219
    if( variant==0 )
220
      {
221
      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} };
222
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
223
      float[][] corners   = new float[][] { {0.03f,0.05f} };
224
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
225
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
226
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
227
      return new ObjectShape(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
228
      }
229
    else if( variant==1 )
230
      {
231
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
232
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
233
      float[][] corners   = new float[][] { {0.04f,0.15f} };
234
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
235
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
236
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
237
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
238
      }
239
    else
240
      {
241
      float[][] bands     = new float[][] { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
242
      int[] bandIndices   = new int[] { 0,0,0,1,1 };
243
      float[][] corners   = new float[][] { {0.05f,0.13f} };
244
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
245
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
246
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
247
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
248
      }
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

    
253
  Static4D getQuat(int cubit, int numLayers)
254
    {
255
    return QUATS[QUAT_NUMBER[cubit]];
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  int getNumCubitVariants(int numLayers)
261
    {
262
    return 3;
263
    }
264

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

    
267
  int getCubitVariant(int cubit, int numLayers)
268
    {
269
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
270
    }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

    
274
  ObjectSticker retSticker(int face)
275
    {
276
    return mStickers[face/NUM_FACES];
277
    }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

    
281
  float[][] getCubitPositions(int numLayers)
282
    {
283
    return CENTERS;
284
    }
285

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

    
288
  int getSolvedFunctionIndex()
289
    {
290
    return 3;
291
    }
292

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

    
295
  int getNumStickerTypes(int numLayers)
296
    {
297
    return NUM_STICKERS;
298
    }
299

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

    
302
  int getFaceColor(int cubit, int cubitface, int numLayers)
303
    {
304
    int type;
305

    
306
         if( cubit< 2             ) type = 0;
307
    else if( cubit<10             ) type = 1;
308
    else if( cubit>13 && cubit<22 ) type = 3;
309
    else                            type = 2;
310

    
311
    return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
312
    }
313

    
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

    
316
  private void initializeScrambling()
317
    {
318
    int numLayers = getNumLayers();
319

    
320
    if( mScrambleTable ==null )
321
      {
322
      mScrambleTable = new int[NUM_AXIS][numLayers];
323
      }
324
    if( mNumOccurences ==null )
325
      {
326
      int max=0;
327

    
328
      for (ScrambleState mState : mStates)
329
        {
330
        int tmp = mState.getTotal(-1);
331
        if (max < tmp) max = tmp;
332
        }
333

    
334
      mNumOccurences = new int[max];
335
      }
336

    
337
    for(int i=0; i<NUM_AXIS; i++)
338
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
// PUBLIC API
343

    
344
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
345
    {
346
    if( curr==0 )
347
      {
348
      mCurrState     = 0;
349
      mIndexExcluded =-1;
350
      initializeScrambling();
351
      }
352

    
353
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
354

    
355
    scramble[curr][0] = info[0];
356
    scramble[curr][1] = info[1];
357
    scramble[curr][2] = info[2];
358

    
359
    mCurrState     = info[3];
360
    mIndexExcluded = info[0];
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  public int getObjectName(int numLayers)
366
    {
367
    return R.string.squa2;
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public int getInventor(int numLayers)
373
    {
374
    return R.string.squa2_inventor;
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public int getComplexity(int numLayers)
380
    {
381
    return 7;
382
    }
383
}
(40-40/41)