Project

General

Profile

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

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

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

    
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.main.Movement6;
32
import org.distorted.objectlib.main.ObjectType;
33
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.helpers.ObjectSticker;
35
import org.distorted.objectlib.helpers.ScrambleState;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

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

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  public TwistySquare1(int size, Static4D quat, Static3D move, DistortedTexture texture,
52
                       MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
53
    {
54
    super(size, quat, move, texture, mesh, effects, res, scrWidth);
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  protected int getResource(int numLayers)
67
    {
68
    return R.raw.squa1;
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
  protected int getScrambleType()
74
    {
75
    return 1;
76
    }
77

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

    
80
  protected int[] getSolvedQuats(int cubit, int numLayers)
81
    {
82
    if( mQuats==null ) initializeQuats();
83
    int status = retCubitSolvedStatus(cubit,numLayers);
84
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status],mQuats);
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  protected ObjectShape getObjectShape(int cubit, int numLayers)
90
    {
91
    int variant = getCubitVariant(cubit,numLayers);
92

    
93
    if( variant==0 )
94
      {
95
      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
      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

    
124
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
125
      }
126
    else if( variant==1 )
127
      {
128
      double[][] vertices = new double[][]
129
        {
130
         { -X, 0.5, 0.0 },
131
         { +X, 0.5, 0.0 },
132
         {0.0, 0.5,-1.5 },
133
         { -X,-0.5, 0.0 },
134
         { +X,-0.5, 0.0 },
135
         {0.0,-0.5,-1.5 },
136
        };
137

    
138
      int[][] vert_indices = new int[][]
139
        {
140
         {0,1,2},
141
         {3,4,5},
142
         {3,4,1,0},
143
         {4,5,2,1},
144
         {5,3,0,2}
145
        };
146

    
147
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
148
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
149
      float[][] corners   = new float[][] { {0.04f,0.15f} };
150
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
151
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
152
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
153

    
154
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
155
      }
156
    else
157
      {
158
      double[][] vertices = new double[][]
159
        {
160
         { X-1.5, 0.5,  0.0 },
161
         {   0.0, 0.5,  0.0 },
162
         {   0.0, 0.5,X-1.5 },
163
         {  -1.5, 0.5, -1.5 },
164
         { X-1.5,-0.5,  0.0 },
165
         {   0.0,-0.5,  0.0 },
166
         {   0.0,-0.5,X-1.5 },
167
         {  -1.5,-0.5, -1.5 }
168
        };
169
      int[][] vert_indices = new int[][]
170
        {
171
         {0,1,2,3},
172
         {4,5,6,7},
173
         {4,5,1,0},
174
         {5,6,2,1},
175
         {7,4,0,3},
176
         {6,7,3,2}
177
        };
178

    
179
      float[][] bands     = new float[][] { {0.038f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
180
      int[] bandIndices   = new int[] { 0,1,0,0,1,1 };
181
      float[][] corners   = new float[][] { {0.05f,0.13f} };
182
      int[] cornerIndices = new int[] { 0,0,0,-1,0,0,0,-1 };
183
      float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
184
      int[] centerIndices = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
185

    
186
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
187
      }
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  protected Static4D getQuat(int cubit, int numLayers)
193
    {
194
    if( mQuats==null ) initializeQuats();
195
    if( mQuatNumber ==null )
196
      {
197
      mQuatNumber = new int[]
198
        {
199
        0, 6,
200
        0, 9, 6, 3, 18, 15, 12, 21,
201
        0, 9, 6, 3, 15, 12, 21, 18
202
        };
203
      }
204

    
205
    return mQuats[mQuatNumber[cubit]];
206
    }
207

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

    
210
  protected int getNumCubitVariants(int numLayers)
211
    {
212
    return 3;
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
  protected int getCubitVariant(int cubit, int numLayers)
218
    {
219
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  protected ObjectSticker retSticker(int face)
225
    {
226
    if( mStickers==null )
227
      {
228
      float[][] STICKERS = new float[][]
229
        {
230
          { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
231
          { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
232
          { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
233
          { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
234
          { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
235
          { -0.2637079f, -0.38185397f, 0.38185397f, -0.38185397f, 0.38185397f, 0.2637079f, -0.5f, 0.5f } // corner top
236
        };
237

    
238
      final float R1 = 0.06f;
239
      final float R2 = 0.04f;
240
      final float R3 = 0.11f;
241
      final float R4 = 0.03f;
242
      final float R5 = 0.11f;
243
      final float R6 = 0.08f;
244
      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} };
245
      final float[] strokes = { 0.05f,0.04f,0.09f,0.05f,0.08f,0.08f };
246

    
247
      mStickers = new ObjectSticker[NUM_STICKERS];
248

    
249
      for(int s=0; s<NUM_STICKERS; s++)
250
        {
251
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
252
        }
253
      }
254

    
255
    return mStickers[face/NUM_FACE_COLORS];
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  protected float[][] getCubitPositions(int numLayers)
261
    {
262
    if( mCenters==null )
263
      {
264
      mCenters = new float[][]
265
        {
266
         { 1.5f, 0.0f, 0.0f },
267
         {-1.5f, 0.0f, 0.0f },
268

    
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
         { 0.0f,-1.0f,-1.5f },
276
         {-1.5f,-1.0f, 0.0f },
277

    
278
         { 1.0f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f },
279
         { 1.0f, 1.0f,-2.0f, 2.0f, 1.0f,-1.0f },
280
         {-1.0f, 1.0f,-2.0f,-2.0f, 1.0f,-1.0f },
281
         {-1.0f, 1.0f, 2.0f,-2.0f, 1.0f, 1.0f },
282
         { 1.0f,-1.0f, 2.0f, 2.0f,-1.0f, 1.0f },
283
         { 1.0f,-1.0f,-2.0f, 2.0f,-1.0f,-1.0f },
284
         {-1.0f,-1.0f,-2.0f,-2.0f,-1.0f,-1.0f },
285
         {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
286
        };
287
      }
288
    return mCenters;
289
    }
290

    
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

    
293
  protected int getSolvedFunctionIndex()
294
    {
295
    return 0;
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

    
300
  protected int getNumStickerTypes(int numLayers)
301
    {
302
    return NUM_STICKERS;
303
    }
304

    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

    
307
  protected int getFaceColor(int cubit, int cubitface, int numLayers)
308
    {
309
    if( mStickerColor==null )
310
      {
311
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
312
      mStickerColor = new int[][]
313
        {
314
          { 0, 0, 4, 0, 5, 0 },
315
          { 0, 0, 5, 1, 4, 0 },
316

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

    
326
          { 2, 0, 4, 0, 0, 0 },
327
          { 2, 0, 0, 5, 0, 0 },
328
          { 2, 0, 5, 1, 0, 0 },
329
          { 2, 0, 1, 4, 0, 0 },
330
          { 3, 0, 0, 4, 0, 0 },
331
          { 3, 0, 5, 0, 0, 0 },
332
          { 3, 0, 1, 5, 0, 0 },
333
          { 3, 0, 4, 1, 0, 0 },
334
        };
335
      }
336

    
337
    if( mStickerType==null )
338
      {
339
      mStickerType = new int[][]
340
        {
341
          {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
342
          {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
343
          {             5,NUM_STICKERS,2,           2,NUM_STICKERS,NUM_STICKERS }
344
        };
345
      }
346

    
347
    int variant = getCubitVariant(cubit,numLayers);
348
    return 6*mStickerType[variant][cubitface] + mStickerColor[cubit][cubitface];
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352
// PUBLIC API
353

    
354
  public ObjectType intGetObjectType(int numLayers)
355
    {
356
    return ObjectType.SQU1_3;
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

    
361
  public int getObjectName(int numLayers)
362
    {
363
    return R.string.squa1;
364
    }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
  public int getInventor(int numLayers)
369
    {
370
    return R.string.squa1_inventor;
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
  public int getComplexity(int numLayers)
376
    {
377
    return 9;
378
    }
379
}
(23-23/25)