Project

General

Profile

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

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

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.helpers.ObjectFaceShape;
28
import org.distorted.objectlib.main.ObjectControl;
29
import org.distorted.objectlib.main.ObjectType;
30
import org.distorted.objectlib.helpers.ObjectShape;
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

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

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

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

    
51
  public ScrambleState[] getScrambleStates()
52
    {
53
    if( mStates==null )
54
      {
55
      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};
56
      int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
57
      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 };
58
      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 };
59
      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 };
60

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

    
71
    return mStates;
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

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

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

    
109
      return new ObjectShape(vertices, indices, getNumCubitFaces(), 3);
110
      }
111
    else if( variant==1 )
112
      {
113
      float[][] vertices =
114
        {
115
         {  -X, 0.5f, 0.0f },
116
         {  +X, 0.5f, 0.0f },
117
         {0.0f, 0.5f,-1.5f },
118
         {  -X,-0.5f, 0.0f },
119
         {  +X,-0.5f, 0.0f },
120
         {0.0f,-0.5f,-1.5f },
121
        };
122

    
123
      int[][] indices =
124
        {
125
         {0,1,2},
126
         {3,4,1,0},
127
         {3,4,5},
128
         {4,5,2,1},
129
         {5,3,0,2}
130
        };
131

    
132
      return new ObjectShape(vertices, indices, getNumCubitFaces(), 2);
133
      }
134
    else
135
      {
136
      float[][] vertices =
137
        {
138
         {-0.75f+X/2, 0.5f,  0.0f },
139
         { 0.75f-X/2, 0.5f,  0.0f },
140
         {-0.75f-X/2, 0.5f, -1.5f },
141
         {-0.75f+X/2,-0.5f,  0.0f },
142
         { 0.75f-X/2,-0.5f,  0.0f },
143
         {-0.75f-X/2,-0.5f, -1.5f }
144
        };
145
      int[][] indices =
146
        {
147
         {0,1,2},
148
         {3,4,1,0},
149
         {5,4,3},
150
         {4,5,2,1},
151
         {5,3,0,2}
152
        };
153

    
154
      return new ObjectShape(vertices, indices, getNumCubitFaces(), 2);
155
      }
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
  public ObjectFaceShape getObjectFaceShape(int variant)
161
    {
162
    if( variant==0 )
163
      {
164
      float[][] bands     = { {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} };
165
      int[] bandIndices   = { 2,2,1,1,0,2 };
166
      float[][] corners   = { {0.03f,0.05f} };
167
      int[] cornerIndices = { 0,0,0,0,0,0,0,0 };
168
      float[][] centers   = { { -0.75f, 0.0f, 0.0f} };
169
      int[] centerIndices = { 0,0,0,0,0,0,0,0 };
170
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
171
      }
172
    else if( variant==1 )
173
      {
174
      float[][] bands     = { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
175
      int[] bandIndices   = { 0,1,0,1,1 };
176
      float[][] corners   = { {0.04f,0.15f} };
177
      int[] cornerIndices = { 0,0,-1,0,0,-1 };
178
      float[][] centers   = { { 0.0f, 0.0f,-0.5f} };
179
      int[] centerIndices = { 0,0,-1,0,0,-1 };
180
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
181
      }
182
    else
183
      {
184
      float[][] bands     = { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
185
      int[] bandIndices   = { 0,0,0,1,1 };
186
      float[][] corners   = { {0.05f,0.13f} };
187
      int[] cornerIndices = { 0,0,-1,0,0,-1 };
188
      float[][] centers   = { { 0.0f, 0.0f,-0.5f} };
189
      int[] centerIndices = { 0,0,-1,0,0,-1 };
190
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
191
      }
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  public Static4D getQuat(int cubit, int[] numLayers)
197
    {
198
    if( mQuats==null ) initializeQuats();
199

    
200
    if( mQuatNumber ==null )
201
      {
202
      mQuatNumber = new int[]
203
        {
204
        0, 6,
205
        0, 9, 6, 3, 18, 15, 12, 21,
206
        0, 9, 6, 3, 0, 9, 6, 3,
207
        15, 12, 21, 18, 15, 12, 21, 18
208
        };
209
      }
210

    
211
    return mQuats[mQuatNumber[cubit]];
212
    }
213

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

    
216
  public int getNumCubitVariants(int[] numLayers)
217
    {
218
    return 3;
219
    }
220

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

    
223
  public int getCubitVariant(int cubit, int[] numLayers)
224
    {
225
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
  public float[][] getCubitPositions(int[] numLayers)
231
    {
232
    if( mCenters ==null )
233
      {
234
      float Y = 0.75f + X/2;
235

    
236
      mCenters = new float[][]
237
        {
238
         { 1.5f, 0.0f, 0.0f },
239
         {-1.5f, 0.0f, 0.0f },
240

    
241
         { 0.0f, 1.0f, 1.5f },
242
         { 1.5f, 1.0f, 0.0f },
243
         { 0.0f, 1.0f,-1.5f },
244
         {-1.5f, 1.0f, 0.0f },
245
         { 0.0f,-1.0f, 1.5f },
246
         { 1.5f,-1.0f, 0.0f },
247
         { 0.0f,-1.0f,-1.5f },
248
         {-1.5f,-1.0f, 0.0f },
249

    
250
         {    Y, 1.0f, 1.5f },
251
         { 1.5f, 1.0f,   -Y },
252
         {   -Y, 1.0f,-1.5f },
253
         {-1.5f, 1.0f,    Y },
254
         {    Y,-1.0f, 1.5f },
255
         { 1.5f,-1.0f,   -Y },
256
         {   -Y,-1.0f,-1.5f },
257
         {-1.5f,-1.0f,    Y },
258

    
259
         { 1.5f, 1.0f,    Y },
260
         {    Y, 1.0f,-1.5f },
261
         {-1.5f, 1.0f,   -Y },
262
         {   -Y, 1.0f, 1.5f },
263
         { 1.5f,-1.0f,    Y },
264
         {    Y,-1.0f,-1.5f },
265
         {-1.5f,-1.0f,   -Y },
266
         {   -Y,-1.0f, 1.5f },
267
        };
268
      }
269

    
270
    return mCenters;
271
    }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
  public int getSolvedFunctionIndex()
276
    {
277
    return 3;
278
    }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
283
    {
284
    if( mStickerColor==null )
285
      {
286
      // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
287
      mStickerColor = new int[][]
288
        {
289
         { 4, 0, 5,-1,-1,-1 }, // 0
290
         { 5, 1, 4,-1,-1,-1 },
291

    
292
         { 2, 4,-1,-1,-1,-1 }, // 2
293
         { 2, 0,-1,-1,-1,-1 },
294
         { 2, 5,-1,-1,-1,-1 },
295
         { 2, 1,-1,-1,-1,-1 },
296
         { 3, 4,-1,-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

    
301
         { 2, 4,-1,-1,-1,-1 }, // 10
302
         { 2, 0,-1,-1,-1,-1 },
303
         { 2, 5,-1,-1,-1,-1 },
304
         { 2, 1,-1,-1,-1,-1 },
305
         {-1, 4, 3,-1,-1,-1 },
306
         {-1, 0, 3,-1,-1,-1 },
307
         {-1, 5, 3,-1,-1,-1 },
308
         {-1, 1, 3,-1,-1,-1 },
309

    
310
         {-1, 0, 2,-1,-1,-1 }, // 18
311
         {-1, 5, 2,-1,-1,-1 },
312
         {-1, 1, 2,-1,-1,-1 },
313
         {-1, 4, 2,-1,-1,-1 },
314
         { 3, 0,-1,-1,-1,-1 },
315
         { 3, 5,-1,-1,-1,-1 },
316
         { 3, 1,-1,-1,-1,-1 },
317
         { 3, 4,-1,-1,-1,-1 },
318
        };
319
      }
320

    
321
    return mStickerColor[cubit][face];
322
    }
323

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

    
326
  public float getStickerRadius()
327
    {
328
    return 0.12f;
329
    }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
  public float getStickerStroke()
334
    {
335
    return ObjectControl.isInIconMode() ? 0.20f : 0.10f;
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

    
340
  public float[][] getStickerAngles()
341
    {
342
    return null;
343
    }
344

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346
// PUBLIC API
347

    
348
  public ObjectType intGetObjectType(int[] numLayers)
349
    {
350
    return ObjectType.SQU2_3;
351
    }
352

    
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354

    
355
  public String getObjectName()
356
    {
357
    return "Square-2";
358
    }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
  public String getInventor()
363
    {
364
    return "David Litwin";
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

    
369
  public int getYearOfInvention()
370
    {
371
    return 1995;
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
  public int getComplexity()
377
    {
378
    return 3;
379
    }
380
}
(24-24/26)