Project

General

Profile

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

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

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 surfaceW, int surfaceH)
54
    {
55
    super(numL, quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
56
    }
57

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

    
60
  public 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
  public int getScrambleType()
75
    {
76
    return 1;
77
    }
78

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

    
81
  public 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
  public ObjectShape getObjectShape(int variant)
91
    {
92
    if( variant==0 )
93
      {
94
      double[][] vertices = new double[][]
95
        {
96
         { -1.5-X, 0.5, 1.5 },
97
         {    0.0, 0.5, 1.5 },
98
         {    0.0, 0.5,-1.5 },
99
         { -1.5+X, 0.5,-1.5 },
100
         { -1.5-X,-0.5, 1.5 },
101
         {    0.0,-0.5, 1.5 },
102
         {    0.0,-0.5,-1.5 },
103
         { -1.5+X,-0.5,-1.5 }
104
        };
105

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

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

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

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

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

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

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

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

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

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

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

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

    
209
  public int getNumCubitVariants(int[] numLayers)
210
    {
211
    return 3;
212
    }
213

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

    
216
  public int getCubitVariant(int cubit, int[] numLayers)
217
    {
218
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
219
    }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

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

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

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

    
257
      mStickers = new ObjectSticker[NUM_STICKERS];
258

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

    
265
    return mStickers[sticker];
266
    }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269

    
270
  protected int getStickerIndex(int face)
271
    {
272
    return face/NUM_FACE_COLORS;
273
    }
274

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

    
277
  public float[][] getCubitPositions(int[] numLayers)
278
    {
279
    if( mCenters==null )
280
      {
281
      mCenters = new float[][]
282
        {
283
         { 1.5f, 0.0f, 0.0f },
284
         {-1.5f, 0.0f, 0.0f },
285

    
286
         { 0.0f, 1.0f, 1.5f },
287
         { 1.5f, 1.0f, 0.0f },
288
         { 0.0f, 1.0f,-1.5f },
289
         {-1.5f, 1.0f, 0.0f },
290
         { 0.0f,-1.0f, 1.5f },
291
         { 1.5f,-1.0f, 0.0f },
292
         { 0.0f,-1.0f,-1.5f },
293
         {-1.5f,-1.0f, 0.0f },
294

    
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
         {-1.0f, 1.0f, 2.0f,-2.0f, 1.0f, 1.0f },
299
         { 1.0f,-1.0f, 2.0f, 2.0f,-1.0f, 1.0f },
300
         { 1.0f,-1.0f,-2.0f, 2.0f,-1.0f,-1.0f },
301
         {-1.0f,-1.0f,-2.0f,-2.0f,-1.0f,-1.0f },
302
         {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
303
        };
304
      }
305
    return mCenters;
306
    }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

    
310
  public int getSolvedFunctionIndex()
311
    {
312
    return 0;
313
    }
314

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

    
317
  public int getNumStickerTypes(int[] numLayers)
318
    {
319
    return NUM_STICKERS;
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
325
    {
326
    if( mStickerColor==null )
327
      {
328
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
329
      mStickerColor = new int[][]
330
        {
331
          { 0, 0, 4, 0, 5, 0 },
332
          { 0, 0, 5, 1, 4, 0 },
333

    
334
          { 2, 0, 4, 0, 0, 0 },
335
          { 2, 0, 0, 0, 0, 0 },
336
          { 2, 0, 5, 0, 0, 0 },
337
          { 2, 0, 1, 0, 0, 0 },
338
          { 3, 0, 4, 0, 0, 0 },
339
          { 3, 0, 0, 0, 0, 0 },
340
          { 3, 0, 5, 0, 0, 0 },
341
          { 3, 0, 1, 0, 0, 0 },
342

    
343
          { 2, 0, 4, 0, 0, 0 },
344
          { 2, 0, 0, 5, 0, 0 },
345
          { 2, 0, 5, 1, 0, 0 },
346
          { 2, 0, 1, 4, 0, 0 },
347
          { 3, 0, 0, 4, 0, 0 },
348
          { 3, 0, 5, 0, 0, 0 },
349
          { 3, 0, 1, 5, 0, 0 },
350
          { 3, 0, 4, 1, 0, 0 },
351
        };
352
      }
353

    
354
    if( mStickerType==null )
355
      {
356
      mStickerType = new int[][]
357
        {
358
          {  NUM_STICKERS,NUM_STICKERS,0,           1,           2,NUM_STICKERS },
359
          {             3,NUM_STICKERS,4,NUM_STICKERS,NUM_STICKERS,NUM_STICKERS },
360
          {             5,NUM_STICKERS,2,           2,NUM_STICKERS,NUM_STICKERS }
361
        };
362
      }
363

    
364
    int variant = getCubitVariant(cubit,numLayers);
365
    return 6*mStickerType[variant][cubitface] + mStickerColor[cubit][cubitface];
366
    }
367

    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369
// PUBLIC API
370

    
371
  public ObjectType intGetObjectType(int[] numLayers)
372
    {
373
    return ObjectType.SQU1_3;
374
    }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
  public int getObjectName(int[] numLayers)
379
    {
380
    return R.string.squa1;
381
    }
382

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

    
385
  public int getInventor(int[] numLayers)
386
    {
387
    return R.string.squa1_inventor;
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
  public int getYearOfInvention(int[] numLayers)
393
    {
394
    return 1999;
395
    }
396

    
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398

    
399
  public int getComplexity(int[] numLayers)
400
    {
401
    return 9;
402
    }
403
}
(23-23/25)