Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyMirrorSkewb.java @ 361fd0de

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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 static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
13
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
14

    
15
import org.distorted.library.type.Static3D;
16
import org.distorted.library.type.Static4D;
17
import org.distorted.objectlib.helpers.FactoryCubit;
18
import org.distorted.objectlib.helpers.FactoryShape;
19
import org.distorted.objectlib.helpers.ObjectFaceShape;
20
import org.distorted.objectlib.helpers.ObjectShape;
21
import org.distorted.objectlib.helpers.ObjectVertexEffects;
22
import org.distorted.objectlib.main.InitAssets;
23
import org.distorted.objectlib.metadata.ListObjects;
24
import org.distorted.objectlib.metadata.Metadata;
25
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
26
import org.distorted.objectlib.shape.ShapeHexahedron;
27
import org.distorted.objectlib.signature.ObjectConstants;
28
import org.distorted.objectlib.signature.ObjectSignature;
29
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
30

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

    
33
public class TwistyMirrorSkewb extends ShapeHexahedron
34
{
35
  public static final Static3D[] ROT_AXIS =
36
         {
37
           new Static3D( SQ3/3, SQ3/3, SQ3/3),
38
           new Static3D( SQ3/3, SQ3/3,-SQ3/3),
39
           new Static3D( SQ3/3,-SQ3/3, SQ3/3),
40
           new Static3D( SQ3/3,-SQ3/3,-SQ3/3)
41
         };
42

    
43
  private static final int[] FACE_COLORS = new int[] { COLOR_WHITE };
44
  private static final float[] MIRROR_VEC = { 0.10f, 0.15f, 0.20f };
45

    
46
  private int[][] mEdges;
47
  private int[][] mBasicAngle;
48
  private float[][] mCuts;
49
  private float[][] mPositions;
50
  private ObjectShape[] mShapes;
51
  private float[][] mCutPlanes;
52
  private float[] mDist3D, mDist;
53
  private float[][] mPotentialVertices;
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  public TwistyMirrorSkewb(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
58
    {
59
    super(iconMode, 2*meta.getNumLayers()[0]-2, quat, move, scale, meta, asset);
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

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

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  @Override
73
  public int getColor(int face)
74
    {
75
    return FACE_COLORS[face];
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  @Override
81
  public int getNumFaceColors()
82
    {
83
    return 1;
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  @Override
89
  public float[][] returnRotationFactor()
90
    {
91
    int numL = getNumLayers()[0];
92
    float[] f = new float[numL];
93
    for(int i=0; i<numL; i++) f[i] = 1.7f;
94
    return new float[][] { f,f,f,f };
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
  public int[][] getScrambleEdges()
100
    {
101
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
102
    return mEdges;
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public float[][] getCuts(int[] numLayers)
108
    {
109
    if( mCuts==null )
110
      {
111
      float[] c = {0};
112
      mCuts = new float[][] {c,c,c,c};
113
      }
114

    
115
    return mCuts;
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  public boolean[][] getLayerRotatable(int[] numLayers)
121
    {
122
    boolean[] tmp = {true,true};
123
    return new boolean[][] { tmp,tmp,tmp,tmp };
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public int getTouchControlType()
129
    {
130
    return TC_CHANGING_SHAPEMOD;
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  public int getTouchControlSplit()
136
    {
137
    return TYPE_NOT_SPLIT;
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  public int[][][] getEnabled()
143
    {
144
    return null;
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148
// 'full' dists (not divided by numLayers)
149

    
150
  private float[] getDist()
151
    {
152
    if( mDist==null )
153
      {
154
      float DX = MIRROR_VEC[0];
155
      float DY = MIRROR_VEC[1];
156
      float DZ = MIRROR_VEC[2];
157
      mDist = new float[] { 1+DX, 1-DX, 1+DY, 1-DY, 1+DZ, 1-DZ };
158
      }
159

    
160
    return mDist;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
// 'regular' dists for the touchControl (have to be divided by numLayers)
165

    
166
  public float[] getDist3D(int[] numLayers)
167
    {
168
    if( mDist3D==null )
169
      {
170
      float[] d = getDist();
171
      mDist3D = new float[] { d[0]/2, d[1]/2, d[2]/2, d[3]/2, d[4]/2, d[5]/2 };
172
      }
173

    
174
    return mDist3D;
175
    }
176

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

    
179
  public Static3D[] getFaceAxis()
180
    {
181
    return TouchControlHexahedron.FACE_AXIS;
182
    }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

    
186
  private float[][] getPositions()
187
    {
188
    if( mPositions==null )
189
      {
190
      final float COR = 1.0f;
191
      final float CEN = 1.0f;
192
      final float X = MIRROR_VEC[0];
193
      final float Y = MIRROR_VEC[1];
194
      final float Z = MIRROR_VEC[2];
195

    
196
      mPositions = new float[8+6][];
197

    
198
      mPositions[0] = new float[]{ COR+X,  COR+Y,  COR+Z };
199
      mPositions[1] = new float[]{ COR+X,  COR+Y, -COR+Z };
200
      mPositions[2] = new float[]{ COR+X, -COR+Y,  COR+Z };
201
      mPositions[3] = new float[]{ COR+X, -COR+Y, -COR+Z };
202
      mPositions[4] = new float[]{-COR+X,  COR+Y,  COR+Z };
203
      mPositions[5] = new float[]{-COR+X,  COR+Y, -COR+Z };
204
      mPositions[6] = new float[]{-COR+X, -COR+Y,  COR+Z };
205
      mPositions[7] = new float[]{-COR+X, -COR+Y, -COR+Z };
206

    
207
      mPositions[ 8] = new float[]{     X,     Y, CEN+Z };
208
      mPositions[ 9] = new float[]{     X,     Y,-CEN+Z };
209
      mPositions[10] = new float[]{     X, CEN+Y,     Z };
210
      mPositions[11] = new float[]{     X,-CEN+Y,     Z };
211
      mPositions[12] = new float[]{ CEN+X,     Y,     Z };
212
      mPositions[13] = new float[]{-CEN+X,     Y,     Z };
213
      }
214

    
215
    return mPositions;
216
    }
217

    
218

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

    
221
  public float[][] getCubitPositions(int[] numLayers)
222
    {
223
    return getPositions();
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  public Static4D getCubitQuats(int cubit, int[] numLayers)
229
    {
230
    return mObjectQuats[0];
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
  private void createCutPlanes()
236
    {
237
    int numPlanes = 6+4;
238
    mCutPlanes = new float[numPlanes][];
239
    Static3D[] faceAxis = getFaceAxis();
240
    float[] dist = getDist();
241

    
242
    for(int p=0; p<6; p++)
243
      {
244
      Static3D ax = faceAxis[p];
245
      mCutPlanes[p] = new float[] { ax.get0(), ax.get1(), ax.get2(), dist[p] };
246
      }
247

    
248
    for(int p=6; p<10; p++)
249
      {
250
      Static3D ax = ROT_AXIS[p-6];
251
      mCutPlanes[p] = new float[] { ax.get0(), ax.get1(), ax.get2(), 0 };
252
      }
253
    }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

    
257
  private float[] internalPoint(int variant)
258
    {
259
    float[][] pos = getPositions();
260
    float[] position = pos[variant];
261
    float[][] center = computeVertexEffectCenter(variant);
262
    float[] cent = center[0];
263

    
264
    float[] ret = new float[3];
265

    
266
    float A = 0.1f;
267

    
268
    ret[0] = position[0] + A*cent[0];
269
    ret[1] = position[1] + A*cent[1];
270
    ret[2] = position[2] + A*cent[2];
271

    
272
    return ret;
273
    }
274

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

    
277
  public ObjectShape getObjectShape(int variant)
278
    {
279
    if( mShapes==null )
280
      {
281
      int[] numLayers = getNumLayers();
282
      int numV = getNumCubitVariants(numLayers);
283
      mShapes = new ObjectShape[numV];
284
      createCutPlanes();
285
      mPotentialVertices = FactoryShape.computePotentialVertices(mCutPlanes);
286
      }
287

    
288
    if( mShapes[variant]==null )
289
      {
290
      float[][] pos = getPositions();
291
      float[] point = internalPoint(variant);
292
      mShapes[variant] = FactoryShape.createShape(mCutPlanes,mPotentialVertices,pos[variant],point);
293
      }
294

    
295
    return mShapes[variant];
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

    
300
  public ObjectFaceShape getObjectFaceShape(int variant)
301
    {
302
    ObjectShape shape = getObjectShape(variant);
303
    int[][] ind    = shape.getVertIndices();
304
    float[][] vert = shape.getVertices();
305
    float[][] pos  = getPositions();
306
    int[] indices  = FactoryShape.produceBandIndices(vert, pos[variant], ind, getFaceAxis(), getDist() );
307

    
308
    if( variant<8 )
309
      {
310
      int N = 5;
311
      int E = 2;
312
      float height = isInIconMode() ? 0.001f : 0.04f;
313
      float[][] bands = { {height,35,0.16f,0.7f,N,E,E}, {0.001f, 35,1.00f,0.0f,N,E,E} };
314
      return new ObjectFaceShape(bands,indices,null);
315
      }
316
    else
317
      {
318
      int N = 5;
319
      int E = 1;
320
      float height = isInIconMode() ? 0.001f : 0.05f;
321
      float[][] bands = { {height,35,SQ2/8,0.9f,N,E,E}, {0.001f,35,1,0.0f,3,0,0} };
322
      return new ObjectFaceShape(bands,indices,null);
323
      }
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
  private float[][] computeVertexEffectCenter(int variant)
329
    {
330
    final float A = 1.0f;
331

    
332
    switch(variant)
333
      {
334
      case  0: return new float[][] { {-A,-A,-A} };
335
      case  1: return new float[][] { {-A,-A, A} };
336
      case  2: return new float[][] { {-A, A,-A} };
337
      case  3: return new float[][] { {-A, A, A} };
338
      case  4: return new float[][] { { A,-A,-A} };
339
      case  5: return new float[][] { { A,-A, A} };
340
      case  6: return new float[][] { { A, A,-A} };
341
      case  7: return new float[][] { { A, A, A} };
342
      case  8: return new float[][] { { 0, 0,-A} };
343
      case  9: return new float[][] { { 0, 0, A} };
344
      case 10: return new float[][] { { 0,-A, 0} };
345
      case 11: return new float[][] { { 0, A, 0} };
346
      case 12: return new float[][] { {-A, 0, 0} };
347
      case 13: return new float[][] { { A, 0, 0} };
348
      }
349

    
350
    return null;
351
    }
352

    
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354

    
355
  public ObjectVertexEffects getVertexEffects(int variant)
356
    {
357
    ObjectShape shape  = getObjectShape(variant);
358
    float[][] vertices = shape.getVertices();
359
    float[][] centers  = computeVertexEffectCenter(variant);
360
    float[][] pos      = getPositions();
361
    int[] indices      = FactoryShape.computeVertexEffectsIndices(vertices, pos[variant], getFaceAxis(), getDist() );
362
    float[][] corners  = variant<8 ? new float[][]{{0.03f, 0.20f}} : new float[][]{{0.03f, 0.15f}};
363

    
364
    return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

    
369
  public int getNumCubitVariants(int[] numLayers)
370
    {
371
    return 14;
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
  public int getCubitVariant(int cubit, int[] numLayers)
377
    {
378
    return cubit;
379
    }
380

    
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

    
383
  public float getStickerRadius()
384
    {
385
    return 0.08f;
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
  public float getStickerStroke()
391
    {
392
    return isInIconMode() ? 0.16f : 0.08f;
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

    
397
  public float[][][] getStickerAngles()
398
    {
399
    return null;
400
    }
401

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403
// PUBLIC API
404

    
405
  public Static3D[] getRotationAxis()
406
    {
407
    return ROT_AXIS;
408
    }
409

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

    
412
  public int[][] getBasicAngles()
413
    {
414
    if( mBasicAngle ==null )
415
      {
416
      int num = getNumLayers()[0];
417
      int[] tmp = new int[num];
418
      for(int i=0; i<num; i++) tmp[i] = 3;
419
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
420
      }
421

    
422
    return mBasicAngle;
423
    }
424

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

    
427
  public String getShortName()
428
    {
429
    return ListObjects.MSKE_2.name();
430
    }
431

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

    
434
  public ObjectSignature getSignature()
435
    {
436
    return new ObjectSignature(ObjectConstants.MSKE_2);
437
    }
438

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

    
441
  public String getObjectName()
442
    {
443
    return "Mirror Skewb";
444
    }
445

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

    
448
  public String getInventor()
449
    {
450
    return "Jaybert Estrella";
451
    }
452

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

    
455
  public int getYearOfInvention()
456
    {
457
    return 2017;
458
    }
459

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

    
462
  public float getComplexity()
463
    {
464
    return 2.03f;
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

    
469
  public String[][] getTutorials()
470
    {
471
    return null;
472
    }
473
}
(34-34/57)