Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.objects;
11

    
12
import java.io.InputStream;
13

    
14
import org.distorted.library.type.Static3D;
15
import org.distorted.library.type.Static4D;
16

    
17
import org.distorted.objectlib.helpers.FactoryCubit;
18
import org.distorted.objectlib.helpers.ObjectFaceShape;
19
import org.distorted.objectlib.helpers.ObjectShape;
20
import org.distorted.objectlib.helpers.ObjectSignature;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitData;
23
import org.distorted.objectlib.scrambling.ScrambleState;
24
import org.distorted.objectlib.main.ObjectType;
25
import org.distorted.objectlib.shape.ShapeHexahedron;
26
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
27

    
28
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
29
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class TwistyWindmill extends ShapeHexahedron
34
{
35
  private static final float X = 1.8f;  // the cut goes from a corner and splits the opposing side 1.2 / 1.8
36
  private static final float L = (float)Math.sqrt(9+X*X);
37

    
38
  static final Static3D[] ROT_AXIS = new Static3D[]
39
         {
40
           new Static3D(  3/L, 0.0f, X/L),
41
           new Static3D( 0.0f, 1.0f,0.0f),
42
           new Static3D( -X/L, 0.0f, 3/L),
43
         };
44

    
45
  private ScrambleState[] mStates;
46
  private int[][] mBasicAngle;
47
  private float[][] mCuts;
48
  private float[][] mPositions;
49
  private int[] mQuatIndex;
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  public TwistyWindmill(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
54
    {
55
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
56
    }
57

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

    
60
  @Override
61
  public int getInternalColor()
62
    {
63
    return 0xff333333;
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
// same as in a 3x3
68

    
69
  public ScrambleState[] getScrambleStates()
70
    {
71
    if( mStates==null )
72
      {
73
      int[][] m = new int[16][];
74

    
75
      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};
76

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

    
98
    return mStates;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  public float[][] getCuts(int[] numLayers)
104
    {
105
    if( mCuts==null )
106
      {
107
      float C = 3*SQ5/10;
108
      float[] cut = new float[] {-C,+C};
109
      mCuts = new float[][] { cut,cut,cut };
110
      }
111

    
112
    return mCuts;
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
  public boolean[][] getLayerRotatable(int[] numLayers)
118
    {
119
    boolean[] tmp = new boolean[] {true,true,true};
120
    return new boolean[][] { tmp,tmp,tmp };
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
  public int getTouchControlType()
126
    {
127
    return TC_CHANGING_SHAPEMOD;
128
    }
129

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

    
132
  public int getTouchControlSplit()
133
    {
134
    return TYPE_NOT_SPLIT;
135
    }
136

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

    
139
  public int[][][] getEnabled()
140
    {
141
    return null;
142
    }
143

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

    
146
  public float[] getDist3D(int[] numLayers)
147
    {
148
    return TouchControlHexahedron.D3D;
149
    }
150

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

    
153
  public Static3D[] getFaceAxis()
154
    {
155
    return TouchControlHexahedron.FACE_AXIS;
156
    }
157

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

    
160
  public float[][] getCubitPositions(int[] numLayers)
161
    {
162
    if( mPositions==null )
163
      {
164
      final float DIS1 = -X/2 + 1.5f;
165
      final float DIS2 = -X/2;
166

    
167
      mPositions = new float[][]
168
         {
169
             { DIS1, 1.0f, 1.5f },
170
             { 1.5f, 1.0f,-DIS1 },
171
             {-DIS1, 1.0f,-1.5f },
172
             {-1.5f, 1.0f, DIS1 },
173
             { DIS1, 0.0f, 1.5f },
174
             { 1.5f, 0.0f,-DIS1 },
175
             {-DIS1, 0.0f,-1.5f },
176
             {-1.5f, 0.0f, DIS1 },
177
             { DIS1,-1.0f, 1.5f },
178
             { 1.5f,-1.0f,-DIS1 },
179
             {-DIS1,-1.0f,-1.5f },
180
             {-1.5f,-1.0f, DIS1 },
181

    
182
             { DIS2, 1.0f, 1.5f },
183
             { 1.5f, 1.0f,-DIS2 },
184
             {-DIS2, 1.0f,-1.5f },
185
             {-1.5f, 1.0f, DIS2 },
186
             { DIS2, 0.0f, 1.5f },
187
             { 1.5f, 0.0f,-DIS2 },
188
             {-DIS2, 0.0f,-1.5f },
189
             {-1.5f, 0.0f, DIS2 },
190
             { DIS2,-1.0f, 1.5f },
191
             { 1.5f,-1.0f,-DIS2 },
192
             {-DIS2,-1.0f,-1.5f },
193
             {-1.5f,-1.0f, DIS2 },
194

    
195
             { 0.0f, 1.0f, 0.0f },
196
             { 0.0f,-1.0f, 0.0f },
197
         };
198
      }
199

    
200
    return mPositions;
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  public Static4D getCubitQuats(int cubit, int[] numLayers)
206
    {
207
    if( mQuatIndex==null ) mQuatIndex = new int[] { 0,6,5,4,0,6,5,4,0,6,5,4,
208
                                                    0,6,5,4,0,6,5,4,0,6,5,4,
209
                                                    0,0 };
210
    return mObjectQuats[mQuatIndex[cubit]];
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  private float[][] getVertices(int variant)
216
    {
217
    if( variant==0 )
218
      {
219
      final float h = 3*X*X/(X*X+9);
220
      final float d = h*X/3;
221
      final float l = X/2;
222

    
223
      return new float[][]
224
          {
225
             {  -l, 0.5f, 0.0f },
226
             {   l, 0.5f, 0.0f },
227
             {   l,-0.5f, 0.0f },
228
             {  -l,-0.5f, 0.0f },
229
             { d-l, 0.5f,   -h },
230
             { d-l,-0.5f,   -h },
231
          };
232
      }
233
    else if( variant==1 )
234
      {
235
      final float h = 3*X*X/(X*X+9);
236
      final float d = h*X/3;
237
      final float H = 3*h/X;
238
      final float l = (3-X)/2;
239

    
240
      return new float[][]
241
          {
242
             { -l, 0.5f, 0.0f },
243
             {  l, 0.5f, 0.0f },
244
             {  l,-0.5f, 0.0f },
245
             { -l,-0.5f, 0.0f },
246
             {h-l, 0.5f,  -H  },
247
             {d+l, 0.5f,  -h  },
248
             {d+l,-0.5f,  -h  },
249
             {h-l,-0.5f,  -H  }
250
          };
251
      }
252
    else
253
      {
254
      final float h = 3*X*X/(X*X+9);
255
      final float H = 3*h/X;
256
      final float x = 1.5f-H;
257
      final float y = 1.5f-h;
258

    
259
      return new float[][]
260
          {
261
             { -y, 0.5f, x },
262
             {  x, 0.5f, y },
263
             {  x,-0.5f, y },
264
             { -y,-0.5f, x },
265
             { -x, 0.5f,-y },
266
             {  y, 0.5f,-x },
267
             {  y,-0.5f,-x },
268
             { -x,-0.5f,-y }
269
          };
270
      }
271
    }
272

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

    
275
  public ObjectShape getObjectShape(int variant)
276
    {
277
    if( variant==0 )
278
      {
279
      int[][] indices =
280
          {
281
             { 3,2,1,0 },
282
             { 0,1,4 },
283
             { 5,2,3 },
284
             { 5,3,0,4 },
285
             { 2,5,4,1 },
286
          };
287

    
288
      return new ObjectShape(getVertices(variant),indices);
289
      }
290
    else if( variant==1 )
291
      {
292
      int[][] indices =
293
          {
294
             { 3,2,1,0 },
295
             { 0,1,5,4 },
296
             { 7,6,2,3 },
297
             { 2,6,5,1 },
298
             { 6,7,4,5 },
299
             { 7,3,0,4 }
300
          };
301

    
302
      return new ObjectShape(getVertices(variant),indices);
303
      }
304
    else
305
      {
306
      int[][] indices =
307
          {
308
             { 3,2,1,0 },
309
             { 0,1,5,4 },
310
             { 7,6,2,3 },
311
             { 2,6,5,1 },
312
             { 6,7,4,5 },
313
             { 7,3,0,4 }
314
          };
315

    
316
      return new ObjectShape(getVertices(variant),indices);
317
      }
318
    }
319

    
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

    
322
  public ObjectFaceShape getObjectFaceShape(int variant)
323
    {
324
    if( variant==0 )
325
      {
326
      float h1 = isInIconMode() ? 0.001f : 0.025f;
327
      float h2 = isInIconMode() ? 0.001f : 0.020f;
328
      float[][] bands = { {h1,20,0.2f,0.4f,5,1,1}, {h2,20,0.2f,0.4f,5,1,1} };
329
      int[] indices   = { 0,0,0,1,1 };
330
      return new ObjectFaceShape(bands,indices,null);
331
      }
332
    else if( variant==1 )
333
      {
334
      float h1 = isInIconMode() ? 0.001f : 0.03f;
335
      float h2 = isInIconMode() ? 0.001f : 0.02f;
336
      float[][] bands = { {h1,20,0.2f,0.4f,5,1,1}, {h2,20,0.2f,0.4f,5,1,1} };
337
      int[] indices   = { 0,0,0,1,1,1 };
338
      return new ObjectFaceShape(bands,indices,null);
339
      }
340
    else
341
      {
342
      float h1 = isInIconMode() ? 0.001f : 0.05f;
343
      float h2 = isInIconMode() ? 0.001f : 0.04f;
344
      float[][] bands= { {h1,35,0.25f,0.7f,5,1,0}, {h2,35,0.25f,0.7f,5,1,0} };
345
      int[] indices  = { 1,0,0,1,1,1 };
346
      return new ObjectFaceShape(bands,indices,null);
347
      }
348
    }
349

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

    
352
  public ObjectVertexEffects getVertexEffects(int variant)
353
    {
354
    if( variant==0 )
355
      {
356
      final float h = 3*X*X/(X*X+9);
357
      final float d = h*X/3;
358
      final float l = X/2;
359
      float[][] corners = { {0.04f,0.09f} };
360
      int[] indices     = { 0,0,0,0,-1,-1 };
361
      float[][] centers = { { d-l, 0.0f,-h } };
362
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
363
      }
364
    else if( variant==1 )
365
      {
366
      final float h = 3*X*X/(X*X+9);
367
      final float H = 3*h/X;
368
      final float l = (3-X)/2;
369
      float[][] corners = { {0.03f,0.09f} };
370
      int[] indices     = { 0,0,0,0,-1,-1,-1,-1 };
371
      float[][] centers = { {h-l, 0.5f, -H } };
372
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
373
      }
374
    else
375
      {
376
      float[][] corners = { {0.04f,0.12f} };
377
      int[] indices     = { 0,0,0,0,0,0,0,0 };
378
      float[][] centers = { {0.0f, 0.0f, 0.0f } };
379
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
380
      }
381
    }
382

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

    
385
  public int getNumCubitVariants(int[] numLayers)
386
    {
387
    return 3;
388
    }
389

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

    
392
  public int getCubitVariant(int cubit, int[] numLayers)
393
    {
394
    return cubit<12 ? 0 : (cubit<24 ? 1:2);
395
    }
396

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

    
399
  public float getStickerRadius()
400
    {
401
    return 0.10f;
402
    }
403

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

    
406
  public float getStickerStroke()
407
    {
408
    return isInIconMode() ? 0.22f : 0.10f;
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  public float[][] getStickerAngles()
414
    {
415
    return null;
416
    }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419
// PUBLIC API
420

    
421
  public Static3D[] getRotationAxis()
422
    {
423
    return ROT_AXIS;
424
    }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

    
428
  public int[][] getBasicAngles()
429
    {
430
    if( mBasicAngle ==null )
431
      {
432
      int num = getNumLayers()[0];
433
      int[] tmp = new int[num];
434
      for(int i=0; i<num; i++) tmp[i] = 4;
435
      mBasicAngle = new int[][] { tmp,tmp,tmp };
436
      }
437
    return mBasicAngle;
438
    }
439

    
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

    
442
  public String getShortName()
443
    {
444
    return ObjectType.WIND_3.name();
445
    }
446

    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

    
449
  public ObjectSignature getSignature()
450
    {
451
    return new ObjectSignature(ObjectType.WIND_3);
452
    }
453

    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

    
456
  public String getObjectName()
457
    {
458
    return "Windmill Cube";
459
    }
460

    
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

    
463
  public String getInventor()
464
    {
465
    return "Katsuhiko Okamoto";
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  public int getYearOfInvention()
471
    {
472
    return 2003;
473
    }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

    
477
  public int getComplexity()
478
    {
479
    return 2;
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

    
484
  public String[][] getTutorials()
485
    {
486
    return new String[][]{
487
                          {"gb","Jh8Bg7gT3PI","Windmill Cube Tutorial","Cube Solve Hero"},
488
                          {"es","wVyJs7AboKk","Como resolver Windmill","Tutoriales Rubik"},
489
                          {"ru","vavVAuEplKI","Как собрать Мельницу","Алексей Ярыгин"},
490
                          {"fr","qiVsyF1nn7o","Résolution du Windmill Cube","asthalis"},
491
                          {"de","JCYcAd0iCKk","Windmill Cube Tutorial","Pezcraft"},
492
                          {"pl","GZI_PtcURaA","Windmill TUTORIAL PL","MrUk"},
493
                          {"br","TXNVMp70lVE","Resolução do Windmill Cube","Pedro Filho"},
494
                          {"kr","gELuvKW2Itw","윈드밀  큐브 해법 강좌","굿맨's 큐브 이야기"},
495
                          {"vn","diiy8OqqtrE","Tutorial N.16 - Windmill Cube","Duy Thích Rubik"},
496
                         };
497
    }
498
}
(41-41/41)