Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySquare1.java @ 967c1d17

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.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.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

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
class TwistySquare1 extends TwistySquare
36
{
37
  private static final int NUM_STICKERS = 6;
38

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

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

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

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  ScrambleState[] getScrambleStates()
56
    {
57
    return null;
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  int getScrambleType()
63
    {
64
    return 1;
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  ObjectShape getObjectShape(int cubit, int numLayers)
79
    {
80
    int variant = getCubitVariant(cubit,numLayers);
81

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

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

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

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

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

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

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

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

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

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

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

    
194
    return mQuats[mQuatNumber[cubit]];
195
    }
196

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

    
199
  int getNumCubitVariants(int numLayers)
200
    {
201
    return 3;
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

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

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

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

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

    
236
      mStickers = new ObjectSticker[NUM_STICKERS];
237

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

    
244
    return mStickers[face/NUM_FACE_COLORS];
245
    }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

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

    
258
         { 0.0f, 1.0f, 1.5f },
259
         { 1.5f, 1.0f, 0.0f },
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

    
267
         { 1.0f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f },
268
         { 1.0f, 1.0f,-2.0f, 2.0f, 1.0f,-1.0f },
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
        };
276
      }
277
    return mCenters;
278
    }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
  int getSolvedFunctionIndex()
283
    {
284
    return 0;
285
    }
286

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

    
289
  int getNumStickerTypes(int numLayers)
290
    {
291
    return NUM_STICKERS;
292
    }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

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

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

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

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

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

    
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341
// PUBLIC API
342

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

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

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

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  public int getComplexity(int numLayers)
358
    {
359
    return 9;
360
    }
361
}
(36-36/38)