Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyWindmill.java @ 5f54927b

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.ObjectControl;
31
import org.distorted.objectlib.main.ObjectType;
32
import org.distorted.objectlib.main.ShapeHexahedron;
33
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
34

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

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

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

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

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

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

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

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

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

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

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

    
82
      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};
83

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

    
105
    return mStates;
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

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

    
119
    return mCuts;
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

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

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

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

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

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

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

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

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

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

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

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

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

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

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

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

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

    
207
    return mCenters;
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  public Static4D getCubitQuats(int cubit, int[] numLayers)
213
    {
214
    int I0 =0; int I1 =6; int I2 =5; int I3 =4;
215
    if( mQuatIndex==null ) mQuatIndex = new int[] {I0,I1,I2,I3,I0,I1,I2,I3,I0,I1,I2,I3, I0,I1,I2,I3,I0,I1,I2,I3,I0,I1,I2,I3, 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

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

    
337
      float[][] bands   = { {0.03f,20,0.2f,0.4f,5,1,1}, {0.02f,20,0.2f,0.4f,5,1,1} };
338
      int[] bandIndices = { 0,0,0,1,1,1 };
339
      float[][] corners = { {0.03f,0.09f} };
340
      int[] indices     = { 0,0,0,0,-1,-1,-1,-1 };
341
      float[][] centers = { {h-l, 0.5f, -H } };
342
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
343
      }
344
    else
345
      {
346
      float[][] bands   = { {0.05f,35,0.25f,0.7f,5,1,0}, {0.04f,35,0.25f,0.7f,5,1,0} };
347
      int[] bandIndices = { 1,0,0,1,1,1 };
348
      float[][] corners = { {0.04f,0.12f} };
349
      int[] indices     = { 0,0,0,0,0,0,0,0 };
350
      float[][] centers = { {0.0f, 0.0f, 0.0f } };
351
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
352
      }
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  public int getNumCubitVariants(int[] numLayers)
358
    {
359
    return 3;
360
    }
361

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
  public int getCubitVariant(int cubit, int[] numLayers)
365
    {
366
    return cubit<12 ? 0 : (cubit<24 ? 1:2);
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

    
371
  public float getStickerRadius()
372
    {
373
    return 0.10f;
374
    }
375

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

    
378
  public float getStickerStroke()
379
    {
380
    return ObjectControl.isInIconMode() ? 0.22f : 0.10f;
381
    }
382

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

    
385
  public float[][] getStickerAngles()
386
    {
387
    return null;
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
// PUBLIC API
392

    
393
  public Static3D[] getRotationAxis()
394
    {
395
    return ROT_AXIS;
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  public int[] getBasicAngles()
401
    {
402
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 4,4,4 };
403
    return mBasicAngle;
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  public String getShortName()
409
    {
410
    return ObjectType.WIND_3.name();
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
  public long getSignature()
416
    {
417
    return ObjectType.WIND_3.ordinal();
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public String getObjectName()
423
    {
424
    return "Windmill Cube";
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public String getInventor()
430
    {
431
    return "Katsuhiko Okamoto";
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public int getYearOfInvention()
437
    {
438
    return 2003;
439
    }
440

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

    
443
  public int getComplexity()
444
    {
445
    return 2;
446
    }
447

    
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449

    
450
  public String[][] getTutorials()
451
    {
452
    return new String[][]{
453
                          {"gb","Jh8Bg7gT3PI","Windmill Cube Tutorial","Cube Solve Hero"},
454
                          {"es","wVyJs7AboKk","Como resolver Windmill","Tutoriales Rubik"},
455
                          {"ru","vavVAuEplKI","Как собрать Мельницу","Алексей Ярыгин"},
456
                          {"fr","qiVsyF1nn7o","Résolution du Windmill Cube","asthalis"},
457
                          {"de","JCYcAd0iCKk","Windmill Cube Tutorial","Pezcraft"},
458
                          {"pl","GZI_PtcURaA","Windmill TUTORIAL PL","MrUk"},
459
                          {"br","TXNVMp70lVE","Resolução do Windmill Cube","Pedro Filho"},
460
                          {"kr","gELuvKW2Itw","윈드밀  큐브 해법 강좌","굿맨's 큐브 이야기"},
461
                         };
462
    }
463
}
(33-33/33)