Project

General

Profile

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

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

1 29b82486 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.objectlib.objects;
21
22
import android.content.res.Resources;
23
24 ecf3d6e3 Leszek Koltunski
import org.distorted.library.type.Static3D;
25 29b82486 Leszek Koltunski
import org.distorted.library.type.Static4D;
26
27
import org.distorted.objectlib.R;
28 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
29 8005e762 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
30 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
31
import org.distorted.objectlib.helpers.ObjectSticker;
32
import org.distorted.objectlib.helpers.ScrambleState;
33 29b82486 Leszek Koltunski
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36
public class TwistySquare2 extends TwistySquare
37
{
38
  private static final int NUM_STICKERS = 6;
39
40
  private ScrambleState[] mStates;
41
  private int[] mQuatNumber;
42
  private float[][] mCenters;
43
  private int[][] mStickerColor;
44
  private int[][] mStickerType;
45
  private ObjectSticker[] mStickers;
46
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
49 7ba38dd4 Leszek Koltunski
  public TwistySquare2(int[] numL, Static4D quat, Static3D move, Resources res)
50 29b82486 Leszek Koltunski
    {
51 7ba38dd4 Leszek Koltunski
    super(numL, quat, move, res);
52 29b82486 Leszek Koltunski
    }
53
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56 f9a81f52 Leszek Koltunski
  public ScrambleState[] getScrambleStates()
57 29b82486 Leszek Koltunski
    {
58
    if( mStates==null )
59
      {
60
      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
    }
78
79 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
80
81 a57e6870 Leszek Koltunski
  protected int getResource(int[] numLayers)
82 4e1dc313 Leszek Koltunski
    {
83 55fa6993 Leszek Koltunski
    return R.raw.squ2_3;
84 4e1dc313 Leszek Koltunski
    }
85
86 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
87
88 7b832206 Leszek Koltunski
  public int[] getSolvedQuats(int cubit, int[] numLayers)
89 29b82486 Leszek Koltunski
    {
90
    return null;
91
    }
92
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
95 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
96 29b82486 Leszek Koltunski
    {
97
    if( variant==0 )
98
      {
99
      double[][] vertices = new double[][]
100
        {
101
         { -1.5-X, 0.5, 1.5 },
102
         {    0.0, 0.5, 1.5 },
103
         {    0.0, 0.5,-1.5 },
104
         { -1.5+X, 0.5,-1.5 },
105
         { -1.5-X,-0.5, 1.5 },
106
         {    0.0,-0.5, 1.5 },
107
         {    0.0,-0.5,-1.5 },
108
         { -1.5+X,-0.5,-1.5 }
109
        };
110
111
      int[][] vert_indices = new int[][]
112
        {
113
         {0,1,2,3},
114
         {4,5,6,7},
115
         {4,5,1,0},
116
         {5,6,2,1},
117
         {6,7,3,2},
118
         {7,4,0,3}
119
        };
120
121
      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} };
122
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
123
      float[][] corners   = new float[][] { {0.03f,0.05f} };
124
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
125
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
126
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
127
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
128
      }
129
    else if( variant==1 )
130
      {
131
      double[][] vertices = new double[][]
132
        {
133
         { -X, 0.5, 0.0 },
134
         { +X, 0.5, 0.0 },
135
         {0.0, 0.5,-1.5 },
136
         { -X,-0.5, 0.0 },
137
         { +X,-0.5, 0.0 },
138
         {0.0,-0.5,-1.5 },
139
        };
140
141
      int[][] vert_indices = new int[][]
142
        {
143
         {0,1,2},
144
         {3,4,5},
145
         {3,4,1,0},
146
         {4,5,2,1},
147
         {5,3,0,2}
148
        };
149
150
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
151
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
152
      float[][] corners   = new float[][] { {0.04f,0.15f} };
153
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
154
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
155
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
156
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
157
      }
158
    else
159
      {
160
      double[][] vertices = new double[][]
161
        {
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
         {-0.75f+X/2,-0.5,  0.0 },
166
         { 0.75f-X/2,-0.5,  0.0 },
167
         {-0.75f-X/2,-0.5, -1.5 }
168
        };
169
      int[][] vert_indices = new int[][]
170
        {
171
         {0,1,2},
172
         {5,4,3},
173
         {3,4,1,0},
174
         {4,5,2,1},
175
         {5,3,0,2}
176
        };
177
178
      float[][] bands     = new float[][] { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
179
      int[] bandIndices   = new int[] { 0,0,0,1,1 };
180
      float[][] corners   = new float[][] { {0.05f,0.13f} };
181
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
182
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
183
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
184
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
185
      }
186
    }
187
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
190 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
191 29b82486 Leszek Koltunski
    {
192
    if( mQuats==null ) initializeQuats();
193
194
    if( mQuatNumber ==null )
195
      {
196
      mQuatNumber = new int[]
197
        {
198
        0, 6,
199
        0, 9, 6, 3, 18, 15, 12, 21,
200
        0, 9, 6, 3, 0, 9, 6, 3,
201
        15, 12, 21, 18, 15, 12, 21, 18
202
        };
203
      }
204
205
    return mQuats[mQuatNumber[cubit]];
206
    }
207
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
210 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
211 29b82486 Leszek Koltunski
    {
212
    return 3;
213
    }
214
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216
217 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
218 29b82486 Leszek Koltunski
    {
219
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
220
    }
221
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
224 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
225 29b82486 Leszek Koltunski
    {
226
    if( mStickers==null )
227
      {
228
      float[][] STICKERS = new float[][]
229
        {
230
          { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
231
          { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
232
          { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
233
          { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
234
          { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
235
          { -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f }                     // corner top
236
        };
237
238
      final float R1 = 0.06f;
239
      final float R2 = 0.04f;
240
      final float R3 = 0.11f;
241
      final float R4 = 0.03f;
242
      final float R5 = 0.11f;
243
      final float R6 = 0.025f;
244
      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} };
245 8592461c Leszek Koltunski
      float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.06f };
246
247
      if( ObjectControl.isInIconMode() )
248
        {
249
        float mult = 2.0f;
250
        strokes[0]*=mult;
251
        strokes[1]*=mult;
252
        strokes[2]*=mult;
253
        strokes[3]*=mult;
254
        strokes[4]*=mult;
255
        strokes[5]*=mult;
256
        }
257 29b82486 Leszek Koltunski
258
      mStickers = new ObjectSticker[NUM_STICKERS];
259
260
      for(int s=0; s<NUM_STICKERS; s++)
261
        {
262
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
263
        }
264
      }
265
266 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
267
    }
268
269 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
270
271 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
272 29b82486 Leszek Koltunski
    {
273
    if( mCenters ==null )
274
      {
275
      float Y = 0.75f + X/2;
276
277
      mCenters = new float[][]
278
        {
279
         { 1.5f, 0.0f, 0.0f },
280
         {-1.5f, 0.0f, 0.0f },
281
282
         { 0.0f, 1.0f, 1.5f },
283
         { 1.5f, 1.0f, 0.0f },
284
         { 0.0f, 1.0f,-1.5f },
285
         {-1.5f, 1.0f, 0.0f },
286
         { 0.0f,-1.0f, 1.5f },
287
         { 1.5f,-1.0f, 0.0f },
288
         { 0.0f,-1.0f,-1.5f },
289
         {-1.5f,-1.0f, 0.0f },
290
291
         {    Y, 1.0f, 1.5f },
292
         { 1.5f, 1.0f,   -Y },
293
         {   -Y, 1.0f,-1.5f },
294
         {-1.5f, 1.0f,    Y },
295
         {    Y,-1.0f, 1.5f },
296
         { 1.5f,-1.0f,   -Y },
297
         {   -Y,-1.0f,-1.5f },
298
         {-1.5f,-1.0f,    Y },
299
300
         { 1.5f, 1.0f,    Y },
301
         {    Y, 1.0f,-1.5f },
302
         {-1.5f, 1.0f,   -Y },
303
         {   -Y, 1.0f, 1.5f },
304
         { 1.5f,-1.0f,    Y },
305
         {    Y,-1.0f,-1.5f },
306
         {-1.5f,-1.0f,   -Y },
307
         {   -Y,-1.0f, 1.5f },
308
        };
309
      }
310
311
    return mCenters;
312
    }
313
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315
316 59c20632 Leszek Koltunski
  public int getSolvedFunctionIndex()
317 29b82486 Leszek Koltunski
    {
318
    return 3;
319
    }
320
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
323 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
324 29b82486 Leszek Koltunski
    {
325
    return NUM_STICKERS;
326
    }
327
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
330 a75ae1ee Leszek Koltunski
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
331 29b82486 Leszek Koltunski
    {
332 a75ae1ee Leszek Koltunski
    if( mStickerType==null )
333 29b82486 Leszek Koltunski
      {
334 a75ae1ee Leszek Koltunski
      mStickerType = new int[][]
335 29b82486 Leszek Koltunski
        {
336 a75ae1ee Leszek Koltunski
         { -1,-1, 0, 1, 2,-1 },
337
         {  3,-1, 4,-1,-1,-1 },
338
         {  5, 5, 2,-1,-1,-1 },
339 29b82486 Leszek Koltunski
        };
340
      }
341
342 a75ae1ee Leszek Koltunski
    return mStickerType[variant][face];
343
    }
344
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346
347
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
348
    {
349
    if( mStickerColor==null )
350 29b82486 Leszek Koltunski
      {
351 a75ae1ee Leszek Koltunski
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
352
      mStickerColor = new int[][]
353 29b82486 Leszek Koltunski
        {
354 a75ae1ee Leszek Koltunski
         {-1,-1, 4, 0, 5,-1 }, // 0
355
         {-1,-1, 5, 1, 4,-1 },
356
357
         { 2,-1, 4,-1,-1,-1 }, // 2
358
         { 2,-1, 0,-1,-1,-1 },
359
         { 2,-1, 5,-1,-1,-1 },
360
         { 2,-1, 1,-1,-1,-1 },
361
         { 3,-1, 4,-1,-1,-1 },
362
         { 3,-1, 0,-1,-1,-1 },
363
         { 3,-1, 5,-1,-1,-1 },
364
         { 3,-1, 1,-1,-1,-1 },
365
366
         { 2,-1, 4,-1,-1,-1 }, // 10
367
         { 2,-1, 0,-1,-1,-1 },
368
         { 2,-1, 5,-1,-1,-1 },
369
         { 2,-1, 1,-1,-1,-1 },
370
         {-1, 3, 4,-1,-1,-1 },
371
         {-1, 3, 0,-1,-1,-1 },
372
         {-1, 3, 5,-1,-1,-1 },
373
         {-1, 3, 1,-1,-1,-1 },
374
375
         {-1, 2, 0,-1,-1,-1 }, // 18
376
         {-1, 2, 5,-1,-1,-1 },
377
         {-1, 2, 1,-1,-1,-1 },
378
         {-1, 2, 4,-1,-1,-1 },
379
         { 3,-1, 0,-1,-1,-1 },
380
         { 3,-1, 5,-1,-1,-1 },
381
         { 3,-1, 1,-1,-1,-1 },
382
         { 3,-1, 4,-1,-1,-1 },
383 29b82486 Leszek Koltunski
        };
384
      }
385
386 a75ae1ee Leszek Koltunski
    return mStickerColor[cubit][face];
387 29b82486 Leszek Koltunski
    }
388
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390
// PUBLIC API
391
392 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
393 61aa85e4 Leszek Koltunski
    {
394 8005e762 Leszek Koltunski
    return ObjectType.SQU2_3;
395 61aa85e4 Leszek Koltunski
    }
396
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398
399 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
400 29b82486 Leszek Koltunski
    {
401
    return R.string.squa2;
402
    }
403
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405
406 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
407 29b82486 Leszek Koltunski
    {
408
    return R.string.squa2_inventor;
409
    }
410
411 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
412
413
  public int getYearOfInvention(int[] numLayers)
414
    {
415
    return 1995;
416
    }
417
418 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
419
420 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
421 29b82486 Leszek Koltunski
    {
422
    return 7;
423
    }
424
}