Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import org.distorted.objectlib.ObjectShape;
25
import org.distorted.objectlib.ObjectSticker;
26
import org.distorted.objectlib.ScrambleState;
27
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
import org.distorted.objectlib.Movement6;
33
import org.distorted.objectlib.ObjectList;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class TwistySquare1 extends TwistySquare
38
{
39
  private static final int NUM_STICKERS = 6;
40

    
41
  private ObjectSticker[] mStickers;
42
  private int[] mQuatNumber;
43
  private float[][] mCenters;
44
  private int[][] mStickerColor;
45
  private int[][] mStickerType;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public TwistySquare1(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
50
                       DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
51
    {
52
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU1, res, scrWidth);
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  protected ScrambleState[] getScrambleStates()
58
    {
59
    return null;
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  int getScrambleType()
65
    {
66
    return 1;
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  protected int[] getSolvedQuats(int cubit, int numLayers)
72
    {
73
    if( mQuats==null ) initializeQuats();
74
    int status = retCubitSolvedStatus(cubit,numLayers);
75
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  protected ObjectShape getObjectShape(int cubit, int numLayers)
81
    {
82
    int variant = getCubitVariant(cubit,numLayers);
83

    
84
    if( variant==0 )
85
      {
86
      double[][] vertices = new double[][]
87
        {
88
         { -1.5-X, 0.5, 1.5 },
89
         {    0.0, 0.5, 1.5 },
90
         {    0.0, 0.5,-1.5 },
91
         { -1.5+X, 0.5,-1.5 },
92
         { -1.5-X,-0.5, 1.5 },
93
         {    0.0,-0.5, 1.5 },
94
         {    0.0,-0.5,-1.5 },
95
         { -1.5+X,-0.5,-1.5 }
96
        };
97

    
98
      int[][] vert_indices = new int[][]
99
        {
100
         {0,1,2,3},
101
         {4,5,6,7},
102
         {4,5,1,0},
103
         {5,6,2,1},
104
         {6,7,3,2},
105
         {7,4,0,3}
106
        };
107

    
108
      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} };
109
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
110
      float[][] corners   = new float[][] { {0.03f,0.05f} };
111
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
112
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
113
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
114

    
115
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
116
      }
117
    else if( variant==1 )
118
      {
119
      double[][] vertices = new double[][]
120
        {
121
         { -X, 0.5, 0.0 },
122
         { +X, 0.5, 0.0 },
123
         {0.0, 0.5,-1.5 },
124
         { -X,-0.5, 0.0 },
125
         { +X,-0.5, 0.0 },
126
         {0.0,-0.5,-1.5 },
127
        };
128

    
129
      int[][] vert_indices = new int[][]
130
        {
131
         {0,1,2},
132
         {3,4,5},
133
         {3,4,1,0},
134
         {4,5,2,1},
135
         {5,3,0,2}
136
        };
137

    
138
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
139
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
140
      float[][] corners   = new float[][] { {0.04f,0.15f} };
141
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
142
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
143
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
144

    
145
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
146
      }
147
    else
148
      {
149
      double[][] vertices = new double[][]
150
        {
151
         { X-1.5, 0.5,  0.0 },
152
         {   0.0, 0.5,  0.0 },
153
         {   0.0, 0.5,X-1.5 },
154
         {  -1.5, 0.5, -1.5 },
155
         { X-1.5,-0.5,  0.0 },
156
         {   0.0,-0.5,  0.0 },
157
         {   0.0,-0.5,X-1.5 },
158
         {  -1.5,-0.5, -1.5 }
159
        };
160
      int[][] vert_indices = new int[][]
161
        {
162
         {0,1,2,3},
163
         {4,5,6,7},
164
         {4,5,1,0},
165
         {5,6,2,1},
166
         {7,4,0,3},
167
         {6,7,3,2}
168
        };
169

    
170
      float[][] bands     = new float[][] { {0.038f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
171
      int[] bandIndices   = new int[] { 0,1,0,0,1,1 };
172
      float[][] corners   = new float[][] { {0.05f,0.13f} };
173
      int[] cornerIndices = new int[] { 0,0,0,-1,0,0,0,-1 };
174
      float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
175
      int[] centerIndices = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
176

    
177
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
178
      }
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  protected Static4D getQuat(int cubit, int numLayers)
184
    {
185
    if( mQuats==null ) initializeQuats();
186
    if( mQuatNumber ==null )
187
      {
188
      mQuatNumber = new int[]
189
        {
190
        0, 6,
191
        0, 9, 6, 3, 18, 15, 12, 21,
192
        0, 9, 6, 3, 15, 12, 21, 18
193
        };
194
      }
195

    
196
    return mQuats[mQuatNumber[cubit]];
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  protected int getNumCubitVariants(int numLayers)
202
    {
203
    return 3;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  protected int getCubitVariant(int cubit, int numLayers)
209
    {
210
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  protected ObjectSticker retSticker(int face)
216
    {
217
    if( mStickers==null )
218
      {
219
      float[][] STICKERS = new float[][]
220
        {
221
          { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
222
          { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
223
          { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
224
          { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
225
          { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
226
          { -0.2637079f, -0.38185397f, 0.38185397f, -0.38185397f, 0.38185397f, 0.2637079f, -0.5f, 0.5f } // corner top
227
        };
228

    
229
      final float R1 = 0.06f;
230
      final float R2 = 0.04f;
231
      final float R3 = 0.11f;
232
      final float R4 = 0.03f;
233
      final float R5 = 0.11f;
234
      final float R6 = 0.08f;
235
      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,R6} };
236
      final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.08f };
237

    
238
      mStickers = new ObjectSticker[NUM_STICKERS];
239

    
240
      for(int s=0; s<NUM_STICKERS; s++)
241
        {
242
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
243
        }
244
      }
245

    
246
    return mStickers[face/NUM_FACE_COLORS];
247
    }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

    
251
  protected float[][] getCubitPositions(int numLayers)
252
    {
253
    if( mCenters==null )
254
      {
255
      mCenters = new float[][]
256
        {
257
         { 1.5f, 0.0f, 0.0f },
258
         {-1.5f, 0.0f, 0.0f },
259

    
260
         { 0.0f, 1.0f, 1.5f },
261
         { 1.5f, 1.0f, 0.0f },
262
         { 0.0f, 1.0f,-1.5f },
263
         {-1.5f, 1.0f, 0.0f },
264
         { 0.0f,-1.0f, 1.5f },
265
         { 1.5f,-1.0f, 0.0f },
266
         { 0.0f,-1.0f,-1.5f },
267
         {-1.5f,-1.0f, 0.0f },
268

    
269
         { 1.0f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f },
270
         { 1.0f, 1.0f,-2.0f, 2.0f, 1.0f,-1.0f },
271
         {-1.0f, 1.0f,-2.0f,-2.0f, 1.0f,-1.0f },
272
         {-1.0f, 1.0f, 2.0f,-2.0f, 1.0f, 1.0f },
273
         { 1.0f,-1.0f, 2.0f, 2.0f,-1.0f, 1.0f },
274
         { 1.0f,-1.0f,-2.0f, 2.0f,-1.0f,-1.0f },
275
         {-1.0f,-1.0f,-2.0f,-2.0f,-1.0f,-1.0f },
276
         {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
277
        };
278
      }
279
    return mCenters;
280
    }
281

    
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

    
284
  protected int getSolvedFunctionIndex()
285
    {
286
    return 0;
287
    }
288

    
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

    
291
  protected int getNumStickerTypes(int numLayers)
292
    {
293
    return NUM_STICKERS;
294
    }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

    
298
  protected int getFaceColor(int cubit, int cubitface, int numLayers)
299
    {
300
    if( mStickerColor==null )
301
      {
302
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
303
      mStickerColor = new int[][]
304
        {
305
          { 0, 0, 4, 0, 5, 0 },
306
          { 0, 0, 5, 1, 4, 0 },
307

    
308
          { 2, 0, 4, 0, 0, 0 },
309
          { 2, 0, 0, 0, 0, 0 },
310
          { 2, 0, 5, 0, 0, 0 },
311
          { 2, 0, 1, 0, 0, 0 },
312
          { 3, 0, 4, 0, 0, 0 },
313
          { 3, 0, 0, 0, 0, 0 },
314
          { 3, 0, 5, 0, 0, 0 },
315
          { 3, 0, 1, 0, 0, 0 },
316

    
317
          { 2, 0, 4, 0, 0, 0 },
318
          { 2, 0, 0, 5, 0, 0 },
319
          { 2, 0, 5, 1, 0, 0 },
320
          { 2, 0, 1, 4, 0, 0 },
321
          { 3, 0, 0, 4, 0, 0 },
322
          { 3, 0, 5, 0, 0, 0 },
323
          { 3, 0, 1, 5, 0, 0 },
324
          { 3, 0, 4, 1, 0, 0 },
325
        };
326
      }
327

    
328
    if( mStickerType==null )
329
      {
330
      mStickerType = new int[][]
331
        {
332
          {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
333
          {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
334
          {             5,NUM_STICKERS,2,           2,NUM_STICKERS,NUM_STICKERS }
335
        };
336
      }
337

    
338
    int variant = getCubitVariant(cubit,numLayers);
339
    return 6*mStickerType[variant][cubitface] + mStickerColor[cubit][cubitface];
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
// PUBLIC API
344

    
345
  public int getObjectName(int numLayers)
346
    {
347
    return R.string.squa1;
348
    }
349

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

    
352
  public int getInventor(int numLayers)
353
    {
354
    return R.string.squa1_inventor;
355
    }
356

    
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

    
359
  public int getComplexity(int numLayers)
360
    {
361
    return 9;
362
    }
363
}
(23-23/25)