Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistySquare1.java @ 0310ac32

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.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
import org.distorted.library.type.Static4D;
28

    
29
import org.distorted.objectlib.R;
30
import org.distorted.objectlib.main.Movement6;
31
import org.distorted.objectlib.main.ObjectList;
32
import org.distorted.objectlib.main.ObjectShape;
33
import org.distorted.objectlib.main.ObjectSticker;
34
import org.distorted.objectlib.main.ScrambleState;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

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

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

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

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

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

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

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

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

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

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

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

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

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

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

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

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

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

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

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

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

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

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

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

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

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

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

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

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

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

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

    
239
      mStickers = new ObjectSticker[NUM_STICKERS];
240

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

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

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

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

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

    
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
         {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
278
        };
279
      }
280
    return mCenters;
281
    }
282

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

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

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

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

    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

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

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

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

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

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

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344
// PUBLIC API
345

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

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

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

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

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