Project

General

Profile

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

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

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.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

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

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

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

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

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

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

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

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

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

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

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

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

    
94
    if( variant==0 )
95
      {
96
      double[][] vertices = new double[][]
97
        {
98
         { -1.5-X, 0.5, 1.5 },
99
         {    0.0, 0.5, 1.5 },
100
         {    0.0, 0.5,-1.5 },
101
         { -1.5+X, 0.5,-1.5 },
102
         { -1.5-X,-0.5, 1.5 },
103
         {    0.0,-0.5, 1.5 },
104
         {    0.0,-0.5,-1.5 },
105
         { -1.5+X,-0.5,-1.5 }
106
        };
107

    
108
      int[][] vert_indices = new int[][]
109
        {
110
         {0,1,2,3},
111
         {4,5,6,7},
112
         {4,5,1,0},
113
         {5,6,2,1},
114
         {6,7,3,2},
115
         {7,4,0,3}
116
        };
117

    
118
      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} };
119
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
120
      float[][] corners   = new float[][] { {0.03f,0.05f} };
121
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
122
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
123
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
124

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

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

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

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

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

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

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

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

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

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210

    
211
  protected int getNumCubitVariants(int[] numLayers)
212
    {
213
    return 3;
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

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

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

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

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

    
248
      if( ObjectControl.isInIconMode() )
249
        {
250
        float mult = 2.0f;
251
        strokes[0]*=mult;
252
        strokes[1]*=mult;
253
        strokes[2]*=mult;
254
        strokes[3]*=mult;
255
        strokes[4]*=mult;
256
        strokes[5]*=mult;
257
        }
258

    
259
      mStickers = new ObjectSticker[NUM_STICKERS];
260

    
261
      for(int s=0; s<NUM_STICKERS; s++)
262
        {
263
        mStickers[s] = new ObjectSticker(STICKERS[s],null,radii[s],strokes[s]);
264
        }
265
      }
266

    
267
    return mStickers[face/NUM_FACE_COLORS];
268
    }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

    
272
  protected float[][] getCubitPositions(int[] numLayers)
273
    {
274
    if( mCenters==null )
275
      {
276
      mCenters = new float[][]
277
        {
278
         { 1.5f, 0.0f, 0.0f },
279
         {-1.5f, 0.0f, 0.0f },
280

    
281
         { 0.0f, 1.0f, 1.5f },
282
         { 1.5f, 1.0f, 0.0f },
283
         { 0.0f, 1.0f,-1.5f },
284
         {-1.5f, 1.0f, 0.0f },
285
         { 0.0f,-1.0f, 1.5f },
286
         { 1.5f,-1.0f, 0.0f },
287
         { 0.0f,-1.0f,-1.5f },
288
         {-1.5f,-1.0f, 0.0f },
289

    
290
         { 1.0f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f },
291
         { 1.0f, 1.0f,-2.0f, 2.0f, 1.0f,-1.0f },
292
         {-1.0f, 1.0f,-2.0f,-2.0f, 1.0f,-1.0f },
293
         {-1.0f, 1.0f, 2.0f,-2.0f, 1.0f, 1.0f },
294
         { 1.0f,-1.0f, 2.0f, 2.0f,-1.0f, 1.0f },
295
         { 1.0f,-1.0f,-2.0f, 2.0f,-1.0f,-1.0f },
296
         {-1.0f,-1.0f,-2.0f,-2.0f,-1.0f,-1.0f },
297
         {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
298
        };
299
      }
300
    return mCenters;
301
    }
302

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

    
305
  protected int getSolvedFunctionIndex()
306
    {
307
    return 0;
308
    }
309

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

    
312
  protected int getNumStickerTypes(int[] numLayers)
313
    {
314
    return NUM_STICKERS;
315
    }
316

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

    
319
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
320
    {
321
    if( mStickerColor==null )
322
      {
323
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
324
      mStickerColor = new int[][]
325
        {
326
          { 0, 0, 4, 0, 5, 0 },
327
          { 0, 0, 5, 1, 4, 0 },
328

    
329
          { 2, 0, 4, 0, 0, 0 },
330
          { 2, 0, 0, 0, 0, 0 },
331
          { 2, 0, 5, 0, 0, 0 },
332
          { 2, 0, 1, 0, 0, 0 },
333
          { 3, 0, 4, 0, 0, 0 },
334
          { 3, 0, 0, 0, 0, 0 },
335
          { 3, 0, 5, 0, 0, 0 },
336
          { 3, 0, 1, 0, 0, 0 },
337

    
338
          { 2, 0, 4, 0, 0, 0 },
339
          { 2, 0, 0, 5, 0, 0 },
340
          { 2, 0, 5, 1, 0, 0 },
341
          { 2, 0, 1, 4, 0, 0 },
342
          { 3, 0, 0, 4, 0, 0 },
343
          { 3, 0, 5, 0, 0, 0 },
344
          { 3, 0, 1, 5, 0, 0 },
345
          { 3, 0, 4, 1, 0, 0 },
346
        };
347
      }
348

    
349
    if( mStickerType==null )
350
      {
351
      mStickerType = new int[][]
352
        {
353
          {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
354
          {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
355
          {             5,NUM_STICKERS,2,           2,NUM_STICKERS,NUM_STICKERS }
356
        };
357
      }
358

    
359
    int variant = getCubitVariant(cubit,numLayers);
360
    return 6*mStickerType[variant][cubitface] + mStickerColor[cubit][cubitface];
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364
// PUBLIC API
365

    
366
  public ObjectType intGetObjectType(int[] numLayers)
367
    {
368
    return ObjectType.SQU1_3;
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
  public int getObjectName(int[] numLayers)
374
    {
375
    return R.string.squa1;
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
  public int getInventor(int[] numLayers)
381
    {
382
    return R.string.squa1_inventor;
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
  public int getComplexity(int[] numLayers)
388
    {
389
    return 9;
390
    }
391
}
(23-23/25)