Project

General

Profile

Download (13.7 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistySquare2.java @ 588ace55

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