Project

General

Profile

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

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

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