Project

General

Profile

Download (13.7 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistySquare2.java @ cc448c54

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.objectlib.objects;
21

    
22
import android.content.res.Resources;
23

    
24
import org.distorted.library.main.DistortedEffects;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static4D;
28

    
29
import org.distorted.objectlib.R;
30
import org.distorted.objectlib.main.ObjectList;
31
import org.distorted.objectlib.main.ObjectShape;
32
import org.distorted.objectlib.main.ObjectSticker;
33
import org.distorted.objectlib.main.ScrambleState;
34

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

    
37
public class TwistySquare2 extends TwistySquare
38
{
39
  private static final int NUM_STICKERS = 6;
40

    
41
  private ScrambleState[] mStates;
42
  private int[] mQuatNumber;
43
  private float[][] mCenters;
44
  private int[][] mStickerColor;
45
  private int[][] mStickerType;
46
  private ObjectSticker[] mStickers;
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  public TwistySquare2(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
51
                       DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
52
    {
53
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU2, res, scrWidth);
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  protected ScrambleState[] getScrambleStates()
59
    {
60
    if( mStates==null )
61
      {
62
      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};
63
      int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
64
      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 };
65
      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 };
66
      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 };
67

    
68
      mStates = new ScrambleState[]
69
        {
70
        new ScrambleState( new int[][] { LO_2, SL_6, LO_3 } ),  // 0
71
        new ScrambleState( new int[][] { LO_2, null, LO_3 } ),  // SL
72
        new ScrambleState( new int[][] { null, SL_1, LO_4 } ),  // LO
73
        new ScrambleState( new int[][] { LO_4, SL_1, null } ),  // UP
74
        new ScrambleState( new int[][] { null, SL_1, null } ),  // UL
75
        };
76
      }
77

    
78
    return mStates;
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  protected int[] getSolvedQuats(int cubit, int numLayers)
84
    {
85
    return null;
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  protected ObjectShape getObjectShape(int cubit, int numLayers)
91
    {
92
    int variant = getCubitVariant(cubit,numLayers);
93

    
94
    if( variant==0 )
95
      {
96
      double[][] vertices = new double[][]
97
        {
98
         { -1.5-X, 0.5, 1.5 },
99
         {    0.0, 0.5, 1.5 },
100
         {    0.0, 0.5,-1.5 },
101
         { -1.5+X, 0.5,-1.5 },
102
         { -1.5-X,-0.5, 1.5 },
103
         {    0.0,-0.5, 1.5 },
104
         {    0.0,-0.5,-1.5 },
105
         { -1.5+X,-0.5,-1.5 }
106
        };
107

    
108
      int[][] vert_indices = new int[][]
109
        {
110
         {0,1,2,3},
111
         {4,5,6,7},
112
         {4,5,1,0},
113
         {5,6,2,1},
114
         {6,7,3,2},
115
         {7,4,0,3}
116
        };
117

    
118
      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} };
119
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
120
      float[][] corners   = new float[][] { {0.03f,0.05f} };
121
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
122
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
123
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
124
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
125
      }
126
    else if( variant==1 )
127
      {
128
      double[][] vertices = new double[][]
129
        {
130
         { -X, 0.5, 0.0 },
131
         { +X, 0.5, 0.0 },
132
         {0.0, 0.5,-1.5 },
133
         { -X,-0.5, 0.0 },
134
         { +X,-0.5, 0.0 },
135
         {0.0,-0.5,-1.5 },
136
        };
137

    
138
      int[][] vert_indices = new int[][]
139
        {
140
         {0,1,2},
141
         {3,4,5},
142
         {3,4,1,0},
143
         {4,5,2,1},
144
         {5,3,0,2}
145
        };
146

    
147
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
148
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
149
      float[][] corners   = new float[][] { {0.04f,0.15f} };
150
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
151
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
152
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
153
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
154
      }
155
    else
156
      {
157
      double[][] vertices = new double[][]
158
        {
159
         {-0.75f+X/2, 0.5,  0.0 },
160
         { 0.75f-X/2, 0.5,  0.0 },
161
         {-0.75f-X/2, 0.5, -1.5 },
162
         {-0.75f+X/2,-0.5,  0.0 },
163
         { 0.75f-X/2,-0.5,  0.0 },
164
         {-0.75f-X/2,-0.5, -1.5 }
165
        };
166
      int[][] vert_indices = new int[][]
167
        {
168
         {0,1,2},
169
         {5,4,3},
170
         {3,4,1,0},
171
         {4,5,2,1},
172
         {5,3,0,2}
173
        };
174

    
175
      float[][] bands     = new float[][] { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
176
      int[] bandIndices   = new int[] { 0,0,0,1,1 };
177
      float[][] corners   = new float[][] { {0.05f,0.13f} };
178
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
179
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
180
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
181
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
182
      }
183
    }
184

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

    
187
  protected Static4D getQuat(int cubit, int numLayers)
188
    {
189
    if( mQuats==null ) initializeQuats();
190

    
191
    if( mQuatNumber ==null )
192
      {
193
      mQuatNumber = new int[]
194
        {
195
        0, 6,
196
        0, 9, 6, 3, 18, 15, 12, 21,
197
        0, 9, 6, 3, 0, 9, 6, 3,
198
        15, 12, 21, 18, 15, 12, 21, 18
199
        };
200
      }
201

    
202
    return mQuats[mQuatNumber[cubit]];
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  protected int getNumCubitVariants(int numLayers)
208
    {
209
    return 3;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  protected int getCubitVariant(int cubit, int numLayers)
215
    {
216
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  protected ObjectSticker retSticker(int face)
222
    {
223
    if( mStickers==null )
224
      {
225
      float[][] STICKERS = new float[][]
226
        {
227
          { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
228
          { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
229
          { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
230
          { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
231
          { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
232
          { -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f }                     // corner top
233
        };
234

    
235
      final float R1 = 0.06f;
236
      final float R2 = 0.04f;
237
      final float R3 = 0.11f;
238
      final float R4 = 0.03f;
239
      final float R5 = 0.11f;
240
      final float R6 = 0.025f;
241
      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} };
242
      final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.06f };
243

    
244
      mStickers = new ObjectSticker[NUM_STICKERS];
245

    
246
      for(int s=0; s<NUM_STICKERS; s++)
247
        {
248
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
249
        }
250
      }
251

    
252
    return mStickers[face/NUM_FACE_COLORS];
253
    }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

    
257
  protected float[][] getCubitPositions(int numLayers)
258
    {
259
    if( mCenters ==null )
260
      {
261
      float Y = 0.75f + X/2;
262

    
263
      mCenters = new float[][]
264
        {
265
         { 1.5f, 0.0f, 0.0f },
266
         {-1.5f, 0.0f, 0.0f },
267

    
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
         { 0.0f,-1.0f,-1.5f },
275
         {-1.5f,-1.0f, 0.0f },
276

    
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
         {   -Y,-1.0f,-1.5f },
284
         {-1.5f,-1.0f,    Y },
285

    
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
         {-1.5f,-1.0f,   -Y },
293
         {   -Y,-1.0f, 1.5f },
294
        };
295
      }
296

    
297
    return mCenters;
298
    }
299

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

    
302
  protected int getSolvedFunctionIndex()
303
    {
304
    return 3;
305
    }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
  protected int getNumStickerTypes(int numLayers)
310
    {
311
    return NUM_STICKERS;
312
    }
313

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

    
316
  protected int getFaceColor(int cubit, int cubitface, int numLayers)
317
    {
318
    if( mStickerColor==null )
319
      {
320
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
321
      mStickerColor = new int[][]
322
        {
323
         { 0, 0, 4, 0, 5, 0 }, // 0
324
         { 0, 0, 5, 1, 4, 0 },
325

    
326
         { 2, 0, 4, 0, 0, 0 }, // 2
327
         { 2, 0, 0, 0, 0, 0 },
328
         { 2, 0, 5, 0, 0, 0 },
329
         { 2, 0, 1, 0, 0, 0 },
330
         { 3, 0, 4, 0, 0, 0 },
331
         { 3, 0, 0, 0, 0, 0 },
332
         { 3, 0, 5, 0, 0, 0 },
333
         { 3, 0, 1, 0, 0, 0 },
334

    
335
         { 2, 0, 4, 0, 0, 0 }, // 10
336
         { 2, 0, 0, 0, 0, 0 },
337
         { 2, 0, 5, 0, 0, 0 },
338
         { 2, 0, 1, 0, 0, 0 },
339
         { 0, 3, 4, 0, 0, 0 },
340
         { 0, 3, 0, 0, 0, 0 },
341
         { 0, 3, 5, 0, 0, 0 },
342
         { 0, 3, 1, 0, 0, 0 },
343

    
344
         { 0, 2, 0, 0, 0, 0 }, // 18
345
         { 0, 2, 5, 0, 0, 0 },
346
         { 0, 2, 1, 0, 0, 0 },
347
         { 0, 2, 4, 0, 0, 0 },
348
         { 3, 0, 0, 0, 0, 0 },
349
         { 3, 0, 5, 0, 0, 0 },
350
         { 3, 0, 1, 0, 0, 0 },
351
         { 3, 0, 4, 0, 0, 0 },
352
        };
353
      }
354

    
355
    if( mStickerType==null )
356
      {
357
      mStickerType = new int[][]
358
        {
359
         {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
360
         {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
361
         {             5,NUM_STICKERS,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
362
         {  NUM_STICKERS,           5,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS }
363
        };
364
      }
365

    
366
    int type;
367

    
368
         if( cubit< 2             ) type = 0;
369
    else if( cubit<10             ) type = 1;
370
    else if( cubit>13 && cubit<22 ) type = 3;
371
    else                            type = 2;
372

    
373
    return 6*mStickerType[type][cubitface] + mStickerColor[cubit][cubitface];
374
    }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377
// PUBLIC API
378

    
379
  public int getObjectName(int numLayers)
380
    {
381
    return R.string.squa2;
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
  public int getInventor(int numLayers)
387
    {
388
    return R.string.squa2_inventor;
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
  public int getComplexity(int numLayers)
394
    {
395
    return 7;
396
    }
397
}
(24-24/25)