Project

General

Profile

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

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

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