Project

General

Profile

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

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

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