Project

General

Profile

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

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

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.helpers.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
// same as in a 3x3
67

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

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

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

    
97
    return mStates;
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

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

    
111
    return mCuts;
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

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

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

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

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

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

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

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

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

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

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

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

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

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

    
166
      mCenters = new float[][]
167
         {
168
             { DIS1, 1.0f, 1.5f },
169
             { 1.5f, 1.0f,-DIS1 },
170
             {-DIS1, 1.0f,-1.5f },
171
             {-1.5f, 1.0f, DIS1 },
172
             { DIS1, 0.0f, 1.5f },
173
             { 1.5f, 0.0f,-DIS1 },
174
             {-DIS1, 0.0f,-1.5f },
175
             {-1.5f, 0.0f, DIS1 },
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

    
181
             { DIS2, 1.0f, 1.5f },
182
             { 1.5f, 1.0f,-DIS2 },
183
             {-DIS2, 1.0f,-1.5f },
184
             {-1.5f, 1.0f, DIS2 },
185
             { DIS2, 0.0f, 1.5f },
186
             { 1.5f, 0.0f,-DIS2 },
187
             {-DIS2, 0.0f,-1.5f },
188
             {-1.5f, 0.0f, DIS2 },
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

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

    
199
    return mCenters;
200
    }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

    
204
  public Static4D getCubitQuats(int cubit, int[] numLayers)
205
    {
206
    int I0 =0; int I1 =6; int I2 =5; int I3 =4;
207
    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 };
208
    return mObjectQuats[mQuatIndex[cubit]];
209
    }
210

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

    
213
  public ObjectShape getObjectShape(int variant)
214
    {
215
    if( variant==0 )
216
      {
217
      final float h = 3*X*X/(X*X+9);
218
      final float d = h*X/3;
219
      final float l = X/2;
220

    
221
      float[][] vertices =
222
          {
223
             {  -l, 0.5f, 0.0f },
224
             {   l, 0.5f, 0.0f },
225
             {   l,-0.5f, 0.0f },
226
             {  -l,-0.5f, 0.0f },
227
             { d-l, 0.5f,   -h },
228
             { d-l,-0.5f,   -h },
229
          };
230

    
231
      int[][] indices =
232
          {
233
             { 3,2,1,0 },
234
             { 0,1,4 },
235
             { 5,2,3 },
236
             { 5,3,0,4 },
237
             { 2,5,4,1 },
238
          };
239

    
240
      return new ObjectShape(vertices, indices);
241
      }
242
    else if( variant==1 )
243
      {
244
      final float h = 3*X*X/(X*X+9);
245
      final float d = h*X/3;
246
      final float H = 3*h/X;
247
      final float l = (3-X)/2;
248

    
249
      float[][] vertices =
250
          {
251
             { -l, 0.5f, 0.0f },
252
             {  l, 0.5f, 0.0f },
253
             {  l,-0.5f, 0.0f },
254
             { -l,-0.5f, 0.0f },
255
             {h-l, 0.5f,  -H  },
256
             {d+l, 0.5f,  -h  },
257
             {d+l,-0.5f,  -h  },
258
             {h-l,-0.5f,  -H  }
259
          };
260

    
261
      int[][] indices =
262
          {
263
             { 3,2,1,0 },
264
             { 0,1,5,4 },
265
             { 7,6,2,3 },
266
             { 2,6,5,1 },
267
             { 6,7,4,5 },
268
             { 7,3,0,4 }
269
          };
270

    
271
      return new ObjectShape(vertices, indices);
272
      }
273
    else
274
      {
275
      final float h = 3*X*X/(X*X+9);
276
      final float H = 3*h/X;
277
      final float x = 1.5f-H;
278
      final float y = 1.5f-h;
279

    
280
      float[][] vertices =
281
          {
282
             { -y, 0.5f, x },
283
             {  x, 0.5f, y },
284
             {  x,-0.5f, y },
285
             { -y,-0.5f, x },
286
             { -x, 0.5f,-y },
287
             {  y, 0.5f,-x },
288
             {  y,-0.5f,-x },
289
             { -x,-0.5f,-y }
290
          };
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(vertices, indices);
303
      }
304
    }
305

    
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307

    
308
  public ObjectFaceShape getObjectFaceShape(int variant)
309
    {
310
    if( variant==0 )
311
      {
312
      final float h = 3*X*X/(X*X+9);
313
      final float d = h*X/3;
314
      final float l = X/2;
315

    
316
      float[][] bands   = { {0.03f,20,0.2f,0.4f,5,1,1}, {0.01f,20,0.2f,0.4f,5,1,1} };
317
      int[] bandIndices = { 0,0,0,1,1 };
318
      float[][] corners = { {0.04f,0.09f} };
319
      int[] indices     = { 0,0,0,0,-1,-1 };
320
      float[][] centers = { { d-l, 0.0f,-h } };
321
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
322
      }
323
    else if( variant==1 )
324
      {
325
      final float h = 3*X*X/(X*X+9);
326
      final float H = 3*h/X;
327
      final float l = (3-X)/2;
328

    
329
      float[][] bands   = { {0.03f,20,0.2f,0.4f,5,1,1}, {0.01f,20,0.2f,0.4f,5,1,1} };
330
      int[] bandIndices = { 0,0,0,1,1,1 };
331
      float[][] corners = { {0.03f,0.09f} };
332
      int[] indices     = { 0,0,0,0,-1,-1,-1,-1 };
333
      float[][] centers = { {h-l, 0.5f, -H } };
334
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
335
      }
336
    else
337
      {
338
      float[][] bands   = { {0.05f,35,0.25f,0.7f,5,1,0}, {0.01f,35,0.25f,0.7f,5,1,0} };
339
      int[] bandIndices = { 1,0,0,1,1,1 };
340
      float[][] corners = { {0.06f,0.12f} };
341
      int[] indices     = { 0,0,0,0,0,0,0,0 };
342
      float[][] centers = { {0.0f, 0.0f, 0.0f } };
343
      return new ObjectFaceShape(bands,bandIndices,corners,indices,centers,indices,null);
344
      }
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  public int getNumCubitVariants(int[] numLayers)
350
    {
351
    return 3;
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  public int getCubitVariant(int cubit, int[] numLayers)
357
    {
358
    return cubit<12 ? 0 : (cubit<24 ? 1:2);
359
    }
360

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

    
363
  public float getStickerRadius()
364
    {
365
    return 0.09f;
366
    }
367

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

    
370
  public float getStickerStroke()
371
    {
372
    return ObjectControl.isInIconMode() ? 0.20f : 0.09f;
373
    }
374

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

    
377
  public float[][] getStickerAngles()
378
    {
379
    return null;
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383
// PUBLIC API
384

    
385
  public Static3D[] getRotationAxis()
386
    {
387
    return ROT_AXIS;
388
    }
389

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

    
392
  public int[] getBasicAngles()
393
    {
394
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 4,4,4 };
395
    return mBasicAngle;
396
    }
397

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

    
400
  public ObjectType intGetObjectType(int[] numLayers)
401
    {
402
    return ObjectType.WIND_3;
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  public String getObjectName()
408
    {
409
    return "Windmill Cube";
410
    }
411

    
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

    
414
  public String getInventor()
415
    {
416
    return "Katsuhiko Okamoto";
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
  public int getYearOfInvention()
422
    {
423
    return 2003;
424
    }
425

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

    
428
  public int getComplexity()
429
    {
430
    return 2;
431
    }
432
}
(27-27/27)