Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyMirror.java @ e289dc14

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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 static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_MIRROR;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
24

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.helpers.ObjectFaceShape;
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objectlib.main.ObjectType;
33
import org.distorted.objectlib.helpers.ObjectShape;
34
import org.distorted.objectlib.helpers.ScrambleState;
35
import org.distorted.objectlib.main.ShapeHexahedron;
36
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
37

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

    
40
public class TwistyMirror extends ShapeHexahedron
41
{
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
44
           new Static3D(1,0,0),
45
           new Static3D(0,1,0),
46
           new Static3D(0,0,1)
47
         };
48

    
49
  private static final int[] FACE_COLORS = new int[] { COLOR_WHITE };
50
  private static final float DX = 0.10f;
51
  private static final float DY = 0.25f;
52
  private static final float DZ = 0.40f;
53

    
54
  private ScrambleState[] mStates;
55
  private float[][] mCuts;
56
  private int[] mBasicAngle;
57
  private float[][] mPositions;
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

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

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  @Override
69
  public int getColor(int face)
70
    {
71
    return FACE_COLORS[face];
72
    }
73

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

    
76
  @Override
77
  public int getNumFaceColors()
78
    {
79
    return 1;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  public ScrambleState[] getScrambleStates()
85
    {
86
    if( mStates==null )
87
      {
88
      int[] numLayers = getNumLayers();
89
      int[][] m = new int[16][];
90
      for(int i=1; i<16; i++) m[i] = createEdges(numLayers[0],i);
91

    
92
      mStates = new ScrambleState[]
93
        {
94
        new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  // 0
95
        new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  // x
96
        new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  // y
97
        new ScrambleState( new int[][] { m[ 8], m[ 8],  null } ),  // z
98
        new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  // xy
99
        new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  // xz
100
        new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  // yx
101
        new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  // yz
102
        new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  // zx
103
        new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  // zy
104
        new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // xyx
105
        new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // xzx
106
        new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // yxy
107
        new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // yzy
108
        new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // zxz
109
        new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // zyz
110
        };
111
      }
112

    
113
    return mStates;
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  private int[] createEdges(int size, int vertex)
119
    {
120
    int[] ret = new int[9*size];
121

    
122
    for(int l=0; l<size; l++)
123
      {
124
      ret[9*l  ] = l;
125
      ret[9*l+1] =-1;
126
      ret[9*l+2] = vertex;
127
      ret[9*l+3] = l;
128
      ret[9*l+4] = 1;
129
      ret[9*l+5] = vertex;
130
      ret[9*l+6] = l;
131
      ret[9*l+7] = 2;
132
      ret[9*l+8] = vertex;
133
      }
134

    
135
    return ret;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  private int getRow(int cubit, int numLayers, int dim)
141
    {
142
    return (int)(mPositions[cubit][dim] + 0.5f*(numLayers-1));
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  public float[][] getCubitPositions(int[] numLayers)
148
    {
149
    if( mPositions==null )
150
      {
151
      int numL = numLayers[0];
152
      int numCubits = getNumCubitVariants(numLayers);
153
      mPositions = new float[numCubits][];
154

    
155
      float diff = 0.5f*(numL-1);
156
      int currentPosition = 0;
157

    
158
      for(int x = 0; x<numL; x++)
159
        for(int y = 0; y<numL; y++)
160
          for(int z = 0; z<numL; z++)
161
            if( x==0 || x==numL-1 || y==0 || y==numL-1 || z==0 || z==numL-1 )
162
              {
163
              mPositions[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
164
              }
165
      }
166

    
167
    return mPositions;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  public Static4D getCubitQuats(int cubit, int[] numLayers)
173
    {
174
    return mObjectQuats[0];
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  public ObjectShape getObjectShape(int variant)
180
    {
181
    int numL = getNumLayers()[0];
182
    int xrow = getRow(variant,numL,0);  // cubit == variant
183
    int yrow = getRow(variant,numL,1);
184
    int zrow = getRow(variant,numL,2);
185

    
186
    float XL = -0.5f + (xrow==     0 ? DX : 0);
187
    float XR = +0.5f + (xrow==numL-1 ? DX : 0);
188
    float YL = -0.5f - (yrow==     0 ? DY : 0);
189
    float YR = +0.5f - (yrow==numL-1 ? DY : 0);
190
    float ZL = -0.5f - (zrow==     0 ? DZ : 0);
191
    float ZR = +0.5f - (zrow==numL-1 ? DZ : 0);
192

    
193
    float[][] vertices =
194
          {
195
              { XR, YR, ZR },
196
              { XR, YR, ZL },
197
              { XR, YL, ZR },
198
              { XR, YL, ZL },
199
              { XL, YR, ZR },
200
              { XL, YR, ZL },
201
              { XL, YL, ZR },
202
              { XL, YL, ZL },
203
          };
204

    
205
    int[][] indices =
206
          {
207
              {2,3,1,0},
208
              {7,6,4,5},
209
              {4,0,1,5},
210
              {7,3,2,6},
211
              {6,2,0,4},
212
              {3,7,5,1}
213
          };
214

    
215
    return new ObjectShape(vertices, indices);
216
    }
217

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
  public ObjectFaceShape getObjectFaceShape(int variant)
221
    {
222
    int extraI, extraV, num, numL = getNumLayers()[0];
223
    float height;
224

    
225
    switch(numL)
226
      {
227
      case 2 : num = 6; extraI = 2; extraV = 2; height = 0.045f; break;
228
      case 3 : num = 5; extraI = 2; extraV = 2; height = 0.045f; break;
229
      case 4 : num = 5; extraI = 0; extraV = 0; height = 0.045f; break;
230
      default: num = 4; extraI = 0; extraV = 0; height = 0.045f; break;
231
      }
232

    
233
    float[][] bands     = { {height,35,0.5f,0.7f,num,extraI,extraV} };
234
    int[] bandIndices   = { 0,0,0,0,0,0 };
235
    float[][] corners   = { {0.036f,0.12f} };
236
    int[] cornerIndices = { 0,0,0,0,0,0,0,0 };
237
    float[][] centers   = { {0.0f, 0.0f, 0.0f} };
238
    int[] centerIndices = { 0,0,0,0,0,0,0,0 };
239

    
240
    return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
  public int getNumCubitVariants(int[] numLayers)
246
    {
247
    int numL = numLayers[0];
248
    return numL>1 ? 6*numL*numL - 12*numL + 8 : 1;
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

    
253
  public int getCubitVariant(int cubit, int[] numLayers)
254
    {
255
    return cubit;
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  public float[][] getCuts(int[] numLayers)
261
    {
262
    if( mCuts==null )
263
      {
264
      int numL = numLayers[0];
265
      mCuts = new float[3][numL-1];
266

    
267
      for(int i=0; i<numL-1; i++)
268
        {
269
        float cut = (2-numL)*0.5f + i;
270
        mCuts[0][i] = cut;
271
        mCuts[1][i] = cut;
272
        mCuts[2][i] = cut;
273
        }
274
      }
275

    
276
    return mCuts;
277
    }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

    
281
  public boolean[][] getLayerRotatable(int[] numLayers)
282
    {
283
    int num = numLayers[0];
284
    boolean[] tmp = new boolean[num];
285
    for(int i=0; i<num; i++) tmp[i] = true;
286
    return new boolean[][] { tmp,tmp,tmp };
287
    }
288

    
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

    
291
  public int getTouchControlType()
292
    {
293
    return TC_CHANGING_MIRROR;
294
    }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

    
298
  public int getTouchControlSplit()
299
    {
300
    return TYPE_NOT_SPLIT;
301
    }
302

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

    
305
  public int[][][] getEnabled()
306
    {
307
    return null;
308
    }
309

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

    
312
  public float[] getDist3D(int[] numLayers)
313
    {
314
    int N = numLayers[0];
315
    return new float[] { 0.5f+DX/N, 0.5f-DX/N, 0.5f-DY/N, 0.5f+DY/N, 0.5f-DZ/N, 0.5f+DZ/N };
316
    }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

    
320
  public Static3D[] getFaceAxis()
321
    {
322
    return TouchControlHexahedron.FACE_AXIS;
323
    }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
  public float getStickerRadius()
328
    {
329
    return 0.10f;
330
    }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
  public float getStickerStroke()
335
    {
336
    float stroke = 0.08f;
337

    
338
    if( ObjectControl.isInIconMode() )
339
      {
340
      int[] numLayers = getNumLayers();
341
      stroke*= ( numLayers[0]==2 ? 1.8f : 2.0f );
342
      }
343

    
344
    return stroke;
345
    }
346

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

    
349
  public float[][] getStickerAngles()
350
    {
351
    return null;
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355
// PUBLIC API
356

    
357
  public Static3D[] getRotationAxis()
358
    {
359
    return ROT_AXIS;
360
    }
361

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

    
364
  public int[] getBasicAngles()
365
    {
366
    if( mBasicAngle==null ) mBasicAngle = new int[] { 4,4,4 };
367
    return mBasicAngle;
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public ObjectType intGetObjectType(int[] numLayers)
373
    {
374
    switch(numLayers[0])
375
      {
376
      case 2: return ObjectType.MIRR_2;
377
      case 3: return ObjectType.MIRR_3;
378
      case 4: return ObjectType.MIRR_4;
379
      }
380

    
381
    return ObjectType.MIRR_2;
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
  public String getObjectName()
387
    {
388
    switch(getNumLayers()[0])
389
      {
390
      case 2: return "Pocket Mirror";
391
      case 3: return "Mirror Cube";
392
      case 4: return "Master Mirror Blocks";
393
      }
394
    return "Pocket Mirror";
395
    }
396

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

    
399
  public String getInventor()
400
    {
401
    switch(getNumLayers()[0])
402
      {
403
      case 2: return "Thomas de Bruin";
404
      case 3: return "Hidetoshi Takeji";
405
      case 4: return "Traiphum Prungtaengkit";
406
      }
407
    return "Hidetoshi Takeji";
408
    }
409

    
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411

    
412
  public int getYearOfInvention()
413
    {
414
    switch(getNumLayers()[0])
415
      {
416
      case 2: return 2007;
417
      case 3: return 2006;
418
      case 4: return 2014;
419
      }
420
    return 2006;
421
    }
422

    
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424

    
425
  public int getComplexity()
426
    {
427
    switch(getNumLayers()[0])
428
      {
429
      case 2: return 1;
430
      case 3: return 2;
431
      case 4: return 3;
432
      }
433
    return 2;
434
    }
435
}
(17-17/27)