Project

General

Profile

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

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

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 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 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
231 29b82486 Leszek Koltunski
    {
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 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
273
    }
274
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276
277
  protected int getStickerIndex(int face)
278
    {
279
    return face/NUM_FACE_COLORS;
280 29b82486 Leszek Koltunski
    }
281
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283
284 a57e6870 Leszek Koltunski
  protected float[][] getCubitPositions(int[] numLayers)
285 29b82486 Leszek Koltunski
    {
286
    if( mCenters ==null )
287
      {
288
      float Y = 0.75f + X/2;
289
290
      mCenters = new float[][]
291
        {
292
         { 1.5f, 0.0f, 0.0f },
293
         {-1.5f, 0.0f, 0.0f },
294
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
         { 0.0f,-1.0f,-1.5f },
302
         {-1.5f,-1.0f, 0.0f },
303
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
         {   -Y,-1.0f,-1.5f },
311
         {-1.5f,-1.0f,    Y },
312
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
         {-1.5f,-1.0f,   -Y },
320
         {   -Y,-1.0f, 1.5f },
321
        };
322
      }
323
324
    return mCenters;
325
    }
326
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328
329 59c20632 Leszek Koltunski
  public int getSolvedFunctionIndex()
330 29b82486 Leszek Koltunski
    {
331
    return 3;
332
    }
333
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335
336 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
337 29b82486 Leszek Koltunski
    {
338
    return NUM_STICKERS;
339
    }
340
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
343 a57e6870 Leszek Koltunski
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
344 29b82486 Leszek Koltunski
    {
345
    if( mStickerColor==null )
346
      {
347
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
348
      mStickerColor = new int[][]
349
        {
350
         { 0, 0, 4, 0, 5, 0 }, // 0
351
         { 0, 0, 5, 1, 4, 0 },
352
353
         { 2, 0, 4, 0, 0, 0 }, // 2
354
         { 2, 0, 0, 0, 0, 0 },
355
         { 2, 0, 5, 0, 0, 0 },
356
         { 2, 0, 1, 0, 0, 0 },
357
         { 3, 0, 4, 0, 0, 0 },
358
         { 3, 0, 0, 0, 0, 0 },
359
         { 3, 0, 5, 0, 0, 0 },
360
         { 3, 0, 1, 0, 0, 0 },
361
362
         { 2, 0, 4, 0, 0, 0 }, // 10
363
         { 2, 0, 0, 0, 0, 0 },
364
         { 2, 0, 5, 0, 0, 0 },
365
         { 2, 0, 1, 0, 0, 0 },
366
         { 0, 3, 4, 0, 0, 0 },
367
         { 0, 3, 0, 0, 0, 0 },
368
         { 0, 3, 5, 0, 0, 0 },
369
         { 0, 3, 1, 0, 0, 0 },
370
371
         { 0, 2, 0, 0, 0, 0 }, // 18
372
         { 0, 2, 5, 0, 0, 0 },
373
         { 0, 2, 1, 0, 0, 0 },
374
         { 0, 2, 4, 0, 0, 0 },
375
         { 3, 0, 0, 0, 0, 0 },
376
         { 3, 0, 5, 0, 0, 0 },
377
         { 3, 0, 1, 0, 0, 0 },
378
         { 3, 0, 4, 0, 0, 0 },
379
        };
380
      }
381
382
    if( mStickerType==null )
383
      {
384
      mStickerType = new int[][]
385
        {
386
         {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
387
         {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
388
         {             5,NUM_STICKERS,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
389
         {  NUM_STICKERS,           5,2,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS }
390
        };
391
      }
392
393
    int type;
394
395
         if( cubit< 2             ) type = 0;
396
    else if( cubit<10             ) type = 1;
397
    else if( cubit>13 && cubit<22 ) type = 3;
398
    else                            type = 2;
399
400
    return 6*mStickerType[type][cubitface] + mStickerColor[cubit][cubitface];
401
    }
402
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404
// PUBLIC API
405
406 a57e6870 Leszek Koltunski
  public ObjectType intGetObjectType(int[] numLayers)
407 61aa85e4 Leszek Koltunski
    {
408 8005e762 Leszek Koltunski
    return ObjectType.SQU2_3;
409 61aa85e4 Leszek Koltunski
    }
410
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412
413 a57e6870 Leszek Koltunski
  public int getObjectName(int[] numLayers)
414 29b82486 Leszek Koltunski
    {
415
    return R.string.squa2;
416
    }
417
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419
420 a57e6870 Leszek Koltunski
  public int getInventor(int[] numLayers)
421 29b82486 Leszek Koltunski
    {
422
    return R.string.squa2_inventor;
423
    }
424
425 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
426
427
  public int getYearOfInvention(int[] numLayers)
428
    {
429
    return 1995;
430
    }
431
432 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
433
434 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
435 29b82486 Leszek Koltunski
    {
436
    return 7;
437
    }
438
}