Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistySquare2.java @ 89704841

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 java.io.InputStream;
23

    
24
import org.distorted.library.type.Static3D;
25
import org.distorted.library.type.Static4D;
26

    
27
import org.distorted.objectlib.main.ObjectControl;
28
import org.distorted.objectlib.main.ObjectType;
29
import org.distorted.objectlib.helpers.ObjectShape;
30
import org.distorted.objectlib.helpers.ObjectSticker;
31
import org.distorted.objectlib.helpers.ScrambleState;
32

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

    
35
public class TwistySquare2 extends TwistySquare
36
{
37
  private ScrambleState[] mStates;
38
  private int[] mQuatNumber;
39
  private float[][] mCenters;
40
  private int[][] mStickerColor;
41
  private ObjectSticker[] mStickers;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
  public TwistySquare2(int[] numL, int meshState, Static4D quat, Static3D move, float scale, InputStream stream)
46
    {
47
    super(numL, meshState, quat, move, scale, stream);
48
    }
49

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

    
52
  public ScrambleState[] getScrambleStates()
53
    {
54
    if( mStates==null )
55
      {
56
      int[] SL_6 = new int[] { 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1};
57
      int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
58
      int[] LO_2 = new int[] { 0,-5,2, 0,-4,2, 0,-3,2, 0,-2,2, 0,-1,2, 0,1,2, 0,2,2, 0,3,2, 0,4,2, 0,5,2, 0,5,2 };
59
      int[] LO_3 = new int[] { 0,-5,3, 0,-4,3, 0,-3,3, 0,-2,3, 0,-1,3, 0,1,3, 0,2,3, 0,3,3, 0,4,3, 0,5,3, 0,5,3 };
60
      int[] LO_4 = new int[] { 0,-5,4, 0,-4,4, 0,-3,4, 0,-2,4, 0,-1,4, 0,1,4, 0,2,4, 0,3,4, 0,4,4, 0,5,4, 0,5,4 };
61

    
62
      mStates = new ScrambleState[]
63
        {
64
        new ScrambleState( new int[][] { LO_2, SL_6, LO_3 } ),  // 0
65
        new ScrambleState( new int[][] { LO_2, null, LO_3 } ),  // SL
66
        new ScrambleState( new int[][] { null, SL_1, LO_4 } ),  // LO
67
        new ScrambleState( new int[][] { LO_4, SL_1, null } ),  // UP
68
        new ScrambleState( new int[][] { null, SL_1, null } ),  // UL
69
        };
70
      }
71

    
72
    return mStates;
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  public int[] getSolvedQuats(int cubit, int[] numLayers)
78
    {
79
    return null;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  public ObjectShape getObjectShape(int variant)
85
    {
86
    if( variant==0 )
87
      {
88
      float[][] vertices = new float[][]
89
        {
90
         { -1.5f-X, 0.5f, 1.5f },
91
         {    0.0f, 0.5f, 1.5f },
92
         {    0.0f, 0.5f,-1.5f },
93
         { -1.5f+X, 0.5f,-1.5f },
94
         { -1.5f-X,-0.5f, 1.5f },
95
         {    0.0f,-0.5f, 1.5f },
96
         {    0.0f,-0.5f,-1.5f },
97
         { -1.5f+X,-0.5f,-1.5f }
98
        };
99

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

    
110
      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} };
111
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
112
      float[][] corners   = new float[][] { {0.03f,0.05f} };
113
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
114
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
115
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
116
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null, 3);
117
      }
118
    else if( variant==1 )
119
      {
120
      float[][] vertices = new float[][]
121
        {
122
         {  -X, 0.5f, 0.0f },
123
         {  +X, 0.5f, 0.0f },
124
         {0.0f, 0.5f,-1.5f },
125
         {  -X,-0.5f, 0.0f },
126
         {  +X,-0.5f, 0.0f },
127
         {0.0f,-0.5f,-1.5f },
128
        };
129

    
130
      int[][] vert_indices = new int[][]
131
        {
132
         {0,1,2},
133
         {3,4,1,0},
134
         {3,4,5},
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
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null, 2);
146
      }
147
    else
148
      {
149
      float[][] vertices = new float[][]
150
        {
151
         {-0.75f+X/2, 0.5f,  0.0f },
152
         { 0.75f-X/2, 0.5f,  0.0f },
153
         {-0.75f-X/2, 0.5f, -1.5f },
154
         {-0.75f+X/2,-0.5f,  0.0f },
155
         { 0.75f-X/2,-0.5f,  0.0f },
156
         {-0.75f-X/2,-0.5f, -1.5f }
157
        };
158
      int[][] vert_indices = new int[][]
159
        {
160
         {0,1,2},
161
         {3,4,1,0},
162
         {5,4,3},
163
         {4,5,2,1},
164
         {5,3,0,2}
165
        };
166

    
167
      float[][] bands     = new float[][] { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
168
      int[] bandIndices   = new int[] { 0,0,0,1,1 };
169
      float[][] corners   = new float[][] { {0.05f,0.13f} };
170
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
171
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
172
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
173
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null, 2);
174
      }
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  public Static4D getQuat(int cubit, int[] numLayers)
180
    {
181
    if( mQuats==null ) initializeQuats();
182

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

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

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

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

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

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

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

    
213
  public float[][] getCubitPositions(int[] numLayers)
214
    {
215
    if( mCenters ==null )
216
      {
217
      float Y = 0.75f + X/2;
218

    
219
      mCenters = new float[][]
220
        {
221
         { 1.5f, 0.0f, 0.0f },
222
         {-1.5f, 0.0f, 0.0f },
223

    
224
         { 0.0f, 1.0f, 1.5f },
225
         { 1.5f, 1.0f, 0.0f },
226
         { 0.0f, 1.0f,-1.5f },
227
         {-1.5f, 1.0f, 0.0f },
228
         { 0.0f,-1.0f, 1.5f },
229
         { 1.5f,-1.0f, 0.0f },
230
         { 0.0f,-1.0f,-1.5f },
231
         {-1.5f,-1.0f, 0.0f },
232

    
233
         {    Y, 1.0f, 1.5f },
234
         { 1.5f, 1.0f,   -Y },
235
         {   -Y, 1.0f,-1.5f },
236
         {-1.5f, 1.0f,    Y },
237
         {    Y,-1.0f, 1.5f },
238
         { 1.5f,-1.0f,   -Y },
239
         {   -Y,-1.0f,-1.5f },
240
         {-1.5f,-1.0f,    Y },
241

    
242
         { 1.5f, 1.0f,    Y },
243
         {    Y, 1.0f,-1.5f },
244
         {-1.5f, 1.0f,   -Y },
245
         {   -Y, 1.0f, 1.5f },
246
         { 1.5f,-1.0f,    Y },
247
         {    Y,-1.0f,-1.5f },
248
         {-1.5f,-1.0f,   -Y },
249
         {   -Y,-1.0f, 1.5f },
250
        };
251
      }
252

    
253
    return mCenters;
254
    }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

    
258
  public int getSolvedFunctionIndex()
259
    {
260
    return 3;
261
    }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
266
    {
267
    if( mStickerColor==null )
268
      {
269
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
270
      mStickerColor = new int[][]
271
        {
272
         { 4, 0, 5,-1,-1,-1 }, // 0
273
         { 5, 1, 4,-1,-1,-1 },
274

    
275
         { 2, 4,-1,-1,-1,-1 }, // 2
276
         { 2, 0,-1,-1,-1,-1 },
277
         { 2, 5,-1,-1,-1,-1 },
278
         { 2, 1,-1,-1,-1,-1 },
279
         { 3, 4,-1,-1,-1,-1 },
280
         { 3, 0,-1,-1,-1,-1 },
281
         { 3, 5,-1,-1,-1,-1 },
282
         { 3, 1,-1,-1,-1,-1 },
283

    
284
         { 2, 4,-1,-1,-1,-1 }, // 10
285
         { 2, 0,-1,-1,-1,-1 },
286
         { 2, 5,-1,-1,-1,-1 },
287
         { 2, 1,-1,-1,-1,-1 },
288
         {-1, 4, 3,-1,-1,-1 },
289
         {-1, 0, 3,-1,-1,-1 },
290
         {-1, 5, 3,-1,-1,-1 },
291
         {-1, 1, 3,-1,-1,-1 },
292

    
293
         {-1, 0, 2,-1,-1,-1 }, // 18
294
         {-1, 5, 2,-1,-1,-1 },
295
         {-1, 1, 2,-1,-1,-1 },
296
         {-1, 4, 2,-1,-1,-1 },
297
         { 3, 0,-1,-1,-1,-1 },
298
         { 3, 5,-1,-1,-1,-1 },
299
         { 3, 1,-1,-1,-1,-1 },
300
         { 3, 4,-1,-1,-1,-1 },
301
        };
302
      }
303

    
304
    return mStickerColor[cubit][face];
305
    }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
310
    {
311
    return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
312
    }
313

    
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

    
316
  private float getRadius()
317
    {
318
    return 0.12f;
319
    }
320

    
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322

    
323
  private float getStroke()
324
    {
325
    return ObjectControl.isInIconMode() ? 0.20f : 0.10f;
326
    }
327

    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

    
330
  private float[][] getAngles()
331
    {
332
    return null;
333
    }
334

    
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

    
337
  public ObjectSticker retSticker(int sticker)
338
    {
339
    if( mStickers==null )
340
      {
341
      float rad = getRadius();
342
      float str = getStroke();
343
      float[][] angles = getAngles();
344
      int numStickers = mStickerCoords.length;
345
      mStickers = new ObjectSticker[numStickers];
346

    
347
      for(int s=0; s<numStickers; s++)
348
        {
349
        float scale = mStickerScales[s];
350
        float radius = rad / scale;
351
        float stroke = str / scale;
352
        int len = mStickerCoords[s].length/2;
353
        float[] radii = new float[len];
354
        for(int r=0; r<len; r++) radii[r] = radius*computeRadiusCorrection(mStickerCoords[s],r,len);
355
        mStickers[s] = new ObjectSticker(mStickerCoords[s],angles==null ? null : angles[s],radii,stroke);
356
        }
357
      }
358

    
359
    return mStickers[sticker];
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363
// PUBLIC API
364

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

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public String getObjectName()
373
    {
374
    return "Square-2";
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public String getInventor()
380
    {
381
    return "David Litwin";
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
  public int getYearOfInvention()
387
    {
388
    return 1995;
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
  public int getComplexity()
394
    {
395
    return 3;
396
    }
397
}
(24-24/26)