Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyWindmill.java @ 31de4259

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.helpers.ObjectShape;
29
import org.distorted.objectlib.scrambling.ScrambleState;
30
import org.distorted.objectlib.main.ObjectType;
31
import org.distorted.objectlib.main.ShapeHexahedron;
32
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
33

    
34
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
35
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
36

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

    
39
public class TwistyWindmill extends ShapeHexahedron
40
{
41
  private static final float X = 1.8f;  // the cut goes from a corner and splits the opposing side 1.2 / 1.8
42
  private static final float L = (float)Math.sqrt(9+X*X);
43

    
44
  static final Static3D[] ROT_AXIS = new Static3D[]
45
         {
46
           new Static3D(  3/L, 0.0f, X/L),
47
           new Static3D( 0.0f, 1.0f,0.0f),
48
           new Static3D( -X/L, 0.0f, 3/L),
49
         };
50

    
51
  private ScrambleState[] mStates;
52
  private int[][] mBasicAngle;
53
  private float[][] mCuts;
54
  private float[][] mPositions;
55
  private int[] mQuatIndex;
56

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

    
59
  public TwistyWindmill(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
60
    {
61
    super(numL, meshState, iconMode, numL[0], quat, move, scale, stream);
62
    }
63

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

    
66
  @Override
67
  public int getInternalColor()
68
    {
69
    return 0xff333333;
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
// same as in a 3x3
74

    
75
  public ScrambleState[] getScrambleStates()
76
    {
77
    if( mStates==null )
78
      {
79
      int[][] m = new int[16][];
80

    
81
      for(int i=0; i<16; i++) m[i] = new int[] { 0,-1,i,0,1,i,0,2,i, 1,-1,i,1,1,i,1,2,i, 2,-1,i,2,1,i,2,2,i};
82

    
83
      mStates = new ScrambleState[]
84
          {
85
          new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  //  0 0
86
          new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  //  1 x
87
          new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  //  2 y
88
          new ScrambleState( new int[][] { m[ 8], m[ 9],  null } ),  //  3 z
89
          new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  //  4 xy
90
          new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  //  5 xz
91
          new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  //  6 yx
92
          new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  //  7 yz
93
          new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  //  8 zx
94
          new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  //  9 zy
95
          new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // 10 xyx
96
          new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // 11 xzx
97
          new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // 12 yxy
98
          new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // 13 yzy
99
          new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // 14 zxz
100
          new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // 15 zyz
101
          };
102
      }
103

    
104
    return mStates;
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  public float[][] getCuts(int[] numLayers)
110
    {
111
    if( mCuts==null )
112
      {
113
      float C = 3*SQ5/10;
114
      float[] cut = new float[] {-C,+C};
115
      mCuts = new float[][] { cut,cut,cut };
116
      }
117

    
118
    return mCuts;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  public boolean[][] getLayerRotatable(int[] numLayers)
124
    {
125
    boolean[] tmp = new boolean[] {true,true,true};
126
    return new boolean[][] { tmp,tmp,tmp };
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public int getTouchControlType()
132
    {
133
    return TC_CHANGING_SHAPEMOD;
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public int getTouchControlSplit()
139
    {
140
    return TYPE_NOT_SPLIT;
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  public int[][][] getEnabled()
146
    {
147
    return null;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  public float[] getDist3D(int[] numLayers)
153
    {
154
    return TouchControlHexahedron.D3D;
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  public Static3D[] getFaceAxis()
160
    {
161
    return TouchControlHexahedron.FACE_AXIS;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  public float[][] getCubitPositions(int[] numLayers)
167
    {
168
    if( mPositions==null )
169
      {
170
      final float DIS1 = -X/2 + 1.5f;
171
      final float DIS2 = -X/2;
172

    
173
      mPositions = new float[][]
174
         {
175
             { DIS1, 1.0f, 1.5f },
176
             { 1.5f, 1.0f,-DIS1 },
177
             {-DIS1, 1.0f,-1.5f },
178
             {-1.5f, 1.0f, DIS1 },
179
             { DIS1, 0.0f, 1.5f },
180
             { 1.5f, 0.0f,-DIS1 },
181
             {-DIS1, 0.0f,-1.5f },
182
             {-1.5f, 0.0f, DIS1 },
183
             { DIS1,-1.0f, 1.5f },
184
             { 1.5f,-1.0f,-DIS1 },
185
             {-DIS1,-1.0f,-1.5f },
186
             {-1.5f,-1.0f, DIS1 },
187

    
188
             { DIS2, 1.0f, 1.5f },
189
             { 1.5f, 1.0f,-DIS2 },
190
             {-DIS2, 1.0f,-1.5f },
191
             {-1.5f, 1.0f, DIS2 },
192
             { DIS2, 0.0f, 1.5f },
193
             { 1.5f, 0.0f,-DIS2 },
194
             {-DIS2, 0.0f,-1.5f },
195
             {-1.5f, 0.0f, DIS2 },
196
             { DIS2,-1.0f, 1.5f },
197
             { 1.5f,-1.0f,-DIS2 },
198
             {-DIS2,-1.0f,-1.5f },
199
             {-1.5f,-1.0f, DIS2 },
200

    
201
             { 0.0f, 1.0f, 0.0f },
202
             { 0.0f,-1.0f, 0.0f },
203
         };
204
      }
205

    
206
    return mPositions;
207
    }
208

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

    
211
  public Static4D getCubitQuats(int cubit, int[] numLayers)
212
    {
213
    if( mQuatIndex==null ) mQuatIndex = new int[] { 0,6,5,4,0,6,5,4,0,6,5,4,
214
                                                    0,6,5,4,0,6,5,4,0,6,5,4,
215
                                                    0,0 };
216
    return mObjectQuats[mQuatIndex[cubit]];
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  public ObjectShape getObjectShape(int variant)
222
    {
223
    if( variant==0 )
224
      {
225
      final float h = 3*X*X/(X*X+9);
226
      final float d = h*X/3;
227
      final float l = X/2;
228

    
229
      float[][] vertices =
230
          {
231
             {  -l, 0.5f, 0.0f },
232
             {   l, 0.5f, 0.0f },
233
             {   l,-0.5f, 0.0f },
234
             {  -l,-0.5f, 0.0f },
235
             { d-l, 0.5f,   -h },
236
             { d-l,-0.5f,   -h },
237
          };
238

    
239
      int[][] indices =
240
          {
241
             { 3,2,1,0 },
242
             { 0,1,4 },
243
             { 5,2,3 },
244
             { 5,3,0,4 },
245
             { 2,5,4,1 },
246
          };
247

    
248
      return new ObjectShape(vertices, indices);
249
      }
250
    else if( variant==1 )
251
      {
252
      final float h = 3*X*X/(X*X+9);
253
      final float d = h*X/3;
254
      final float H = 3*h/X;
255
      final float l = (3-X)/2;
256

    
257
      float[][] vertices =
258
          {
259
             { -l, 0.5f, 0.0f },
260
             {  l, 0.5f, 0.0f },
261
             {  l,-0.5f, 0.0f },
262
             { -l,-0.5f, 0.0f },
263
             {h-l, 0.5f,  -H  },
264
             {d+l, 0.5f,  -h  },
265
             {d+l,-0.5f,  -h  },
266
             {h-l,-0.5f,  -H  }
267
          };
268

    
269
      int[][] indices =
270
          {
271
             { 3,2,1,0 },
272
             { 0,1,5,4 },
273
             { 7,6,2,3 },
274
             { 2,6,5,1 },
275
             { 6,7,4,5 },
276
             { 7,3,0,4 }
277
          };
278

    
279
      return new ObjectShape(vertices, indices);
280
      }
281
    else
282
      {
283
      final float h = 3*X*X/(X*X+9);
284
      final float H = 3*h/X;
285
      final float x = 1.5f-H;
286
      final float y = 1.5f-h;
287

    
288
      float[][] vertices =
289
          {
290
             { -y, 0.5f, x },
291
             {  x, 0.5f, y },
292
             {  x,-0.5f, y },
293
             { -y,-0.5f, x },
294
             { -x, 0.5f,-y },
295
             {  y, 0.5f,-x },
296
             {  y,-0.5f,-x },
297
             { -x,-0.5f,-y }
298
          };
299

    
300
      int[][] indices =
301
          {
302
             { 3,2,1,0 },
303
             { 0,1,5,4 },
304
             { 7,6,2,3 },
305
             { 2,6,5,1 },
306
             { 6,7,4,5 },
307
             { 7,3,0,4 }
308
          };
309

    
310
      return new ObjectShape(vertices, indices);
311
      }
312
    }
313

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

    
316
  public ObjectFaceShape getObjectFaceShape(int variant)
317
    {
318
    if( variant==0 )
319
      {
320
      final float h = 3*X*X/(X*X+9);
321
      final float d = h*X/3;
322
      final float l = X/2;
323
      float h1 = isInIconMode() ? 0.001f : 0.025f;
324
      float h2 = isInIconMode() ? 0.001f : 0.020f;
325

    
326
      float[][] bands   = { {h1,20,0.2f,0.4f,5,1,1}, {h2,20,0.2f,0.4f,5,1,1} };
327
      int[] bandIndices = { 0,0,0,1,1 };
328
      float[][] corners = { {0.04f,0.09f} };
329
      int[] indices     = { 0,0,0,0,-1,-1 };
330
      float[][] centers = { { d-l, 0.0f,-h } };
331
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
332
      }
333
    else if( variant==1 )
334
      {
335
      final float h = 3*X*X/(X*X+9);
336
      final float H = 3*h/X;
337
      final float l = (3-X)/2;
338
      float h1 = isInIconMode() ? 0.001f : 0.03f;
339
      float h2 = isInIconMode() ? 0.001f : 0.02f;
340

    
341
      float[][] bands   = { {h1,20,0.2f,0.4f,5,1,1}, {h2,20,0.2f,0.4f,5,1,1} };
342
      int[] bandIndices = { 0,0,0,1,1,1 };
343
      float[][] corners = { {0.03f,0.09f} };
344
      int[] indices     = { 0,0,0,0,-1,-1,-1,-1 };
345
      float[][] centers = { {h-l, 0.5f, -H } };
346
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
347
      }
348
    else
349
      {
350
      float h1 = isInIconMode() ? 0.001f : 0.05f;
351
      float h2 = isInIconMode() ? 0.001f : 0.04f;
352
      float[][] bands   = { {h1,35,0.25f,0.7f,5,1,0}, {h2,35,0.25f,0.7f,5,1,0} };
353
      int[] bandIndices = { 1,0,0,1,1,1 };
354
      float[][] corners = { {0.04f,0.12f} };
355
      int[] indices     = { 0,0,0,0,0,0,0,0 };
356
      float[][] centers = { {0.0f, 0.0f, 0.0f } };
357
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
358
      }
359
    }
360

    
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362

    
363
  public int getNumCubitVariants(int[] numLayers)
364
    {
365
    return 3;
366
    }
367

    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369

    
370
  public int getCubitVariant(int cubit, int[] numLayers)
371
    {
372
    return cubit<12 ? 0 : (cubit<24 ? 1:2);
373
    }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

    
377
  public float getStickerRadius()
378
    {
379
    return 0.10f;
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  public float getStickerStroke()
385
    {
386
    return isInIconMode() ? 0.22f : 0.10f;
387
    }
388

    
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390

    
391
  public float[][] getStickerAngles()
392
    {
393
    return null;
394
    }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
// PUBLIC API
398

    
399
  public Static3D[] getRotationAxis()
400
    {
401
    return ROT_AXIS;
402
    }
403

    
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

    
406
  public int[][] getBasicAngles()
407
    {
408
    if( mBasicAngle ==null )
409
      {
410
      int num = getNumLayers()[0];
411
      int[] tmp = new int[num];
412
      for(int i=0; i<num; i++) tmp[i] = 4;
413
      mBasicAngle = new int[][] { tmp,tmp,tmp };
414
      }
415
    return mBasicAngle;
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  public String getShortName()
421
    {
422
    return ObjectType.WIND_3.name();
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426

    
427
  public long getSignature()
428
    {
429
    return ObjectType.WIND_3.ordinal();
430
    }
431

    
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433

    
434
  public String getObjectName()
435
    {
436
    return "Windmill Cube";
437
    }
438

    
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

    
441
  public String getInventor()
442
    {
443
    return "Katsuhiko Okamoto";
444
    }
445

    
446
///////////////////////////////////////////////////////////////////////////////////////////////////
447

    
448
  public int getYearOfInvention()
449
    {
450
    return 2003;
451
    }
452

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

    
455
  public int getComplexity()
456
    {
457
    return 2;
458
    }
459

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

    
462
  public String[][] getTutorials()
463
    {
464
    return new String[][]{
465
                          {"gb","Jh8Bg7gT3PI","Windmill Cube Tutorial","Cube Solve Hero"},
466
                          {"es","wVyJs7AboKk","Como resolver Windmill","Tutoriales Rubik"},
467
                          {"ru","vavVAuEplKI","Как собрать Мельницу","Алексей Ярыгин"},
468
                          {"fr","qiVsyF1nn7o","Résolution du Windmill Cube","asthalis"},
469
                          {"de","JCYcAd0iCKk","Windmill Cube Tutorial","Pezcraft"},
470
                          {"pl","GZI_PtcURaA","Windmill TUTORIAL PL","MrUk"},
471
                          {"br","TXNVMp70lVE","Resolução do Windmill Cube","Pedro Filho"},
472
                          {"kr","gELuvKW2Itw","윈드밀  큐브 해법 강좌","굿맨's 큐브 이야기"},
473
                          {"vn","diiy8OqqtrE","Tutorial N.16 - Windmill Cube","Duy Thích Rubik"},
474
                         };
475
    }
476
}
(36-36/36)