Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyMirrorJing.java @ 8f5116ec

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_MIRROR;
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.ShapeTetrahedron;
27
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class TwistyMirrorJing extends ShapeTetrahedron
32
{
33
  public static final Static3D[] ROT_AXIS = new Static3D[]
34
         {
35
           new Static3D(     0,-SQ3/3,-SQ6/3),
36
           new Static3D(     0,-SQ3/3, SQ6/3),
37
           new Static3D( SQ6/3, SQ3/3,     0),
38
           new Static3D(-SQ6/3, SQ3/3,     0),
39
         };
40

    
41
  private static final float JING_F = 0.48f;
42

    
43
  private static final int[] FACE_COLORS = new int[] { COLOR_WHITE };
44
  private static final float[] MIRROR_VEC = { 0.06f, 0.07f, 0.08f };
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 TwistyMirrorJing(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
58
    {
59
    super(iconMode, meta.getNumLayers()[0], quat, move, scale, meta, asset);
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
// here we cannot automatically detect the outer monochromatic walls -> use the old way.
64

    
65
  @Override
66
  public int getSolvedFunctionIndex()
67
    {
68
    return 0;
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
  @Override
74
  public int[][] getSolvedQuats()
75
    {
76
    return getOldSolvedQuats();
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
  @Override
82
  public int getInternalColor()
83
    {
84
    return 0xff333333;
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  @Override
90
  public int getColor(int face)
91
    {
92
    return FACE_COLORS[face];
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  @Override
98
  public int getNumFaceColors()
99
    {
100
    return 1;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  @Override
106
  public float[][] returnRotationFactor()
107
    {
108
    float[] f = { 1.4f, 2.0f };
109
    return new float[][] { f,f,f,f };
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public int[][] getScrambleEdges()
115
    {
116
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
117
    return mEdges;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  public float[][] getCuts(int[] numLayers)
123
    {
124
    if( mCuts==null )
125
      {
126
      float[] c = new float[] { (JING_F-0.51f)*(SQ6/3) };
127
      mCuts = new float[][] {c,c,c,c};
128
      }
129

    
130
    return mCuts;
131
    }
132

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

    
135
  public boolean[][] getLayerRotatable(int[] numLayers)
136
    {
137
    boolean[] tmp = {true,true};
138
    return new boolean[][] { tmp,tmp,tmp,tmp };
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  public int getTouchControlType()
144
    {
145
    return TC_CHANGING_MIRROR;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  public int getTouchControlSplit()
151
    {
152
    return TYPE_NOT_SPLIT;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public int[][][] getEnabled()
158
    {
159
    return null;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163
// 'full' dists (not divided by numLayers)
164

    
165
  private float[] getDist()
166
    {
167
    if( mDist==null )
168
      {
169
      float DX = MIRROR_VEC[0];
170
      float DY = MIRROR_VEC[1];
171
      float DZ = MIRROR_VEC[2];
172
      Static3D[] axis = getFaceAxis();
173
      mDist = new float[4];
174

    
175
      for( int a=0; a<4; a++ )
176
        {
177
        Static3D ax = axis[a];
178
        float d = ax.get0()*DX + ax.get1()*DY + ax.get2()*DZ;
179
        mDist[a] = SQ6/6 + d;
180
        }
181
      }
182

    
183
    return mDist;
184
    }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187
// 'regular' dists for the touchControl (have to be divided by numLayers)
188

    
189
  public float[] getDist3D(int[] numLayers)
190
    {
191
    if( mDist3D==null )
192
      {
193
      float[] d = getDist();
194
      mDist3D = new float[] { d[0]/2, d[1]/2, d[2]/2, d[3]/2 };
195
      }
196

    
197
    return mDist3D;
198
    }
199

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

    
202
  public Static3D[] getFaceAxis()
203
    {
204
    return TouchControlTetrahedron.FACE_AXIS;
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  private float[][] getPositions()
210
    {
211
    if( mPositions==null )
212
      {
213
      final float X = MIRROR_VEC[0];
214
      final float Y = MIRROR_VEC[1];
215
      final float Z = MIRROR_VEC[2];
216

    
217
      mPositions = new float[][]
218
        {
219
          { 0.000f +X, -SQ2/2 +Y,  1.000f +Z },
220
          { 0.000f +X, -SQ2/2 +Y, -1.000f +Z },
221
          {-1.000f +X,  SQ2/2 +Y,  0.000f +Z },
222
          { 1.000f +X,  SQ2/2 +Y,  0.000f +Z },
223

    
224
          { 0.000f +X, -SQ2/2 +Y,  0.000f +Z },
225
          {-0.500f +X, 0.000f +Y,  0.500f +Z },
226
          { 0.500f +X, 0.000f +Y,  0.500f +Z },
227
          {-0.500f +X, 0.000f +Y, -0.500f +Z },
228
          { 0.500f +X, 0.000f +Y, -0.500f +Z },
229
          { 0.000f +X,  SQ2/2 +Y,  0.000f +Z },
230

    
231
          { 0.000f +X,  SQ2/6 +Y,  1.0f/3 +Z },
232
          { 0.000f +X,  SQ2/6 +Y, -1.0f/3 +Z },
233
          {-1.0f/3 +X, -SQ2/6 +Y,  0.000f +Z },
234
          { 1.0f/3 +X, -SQ2/6 +Y,  0.000f +Z },
235
        };
236
      }
237

    
238
    return mPositions;
239
    }
240

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

    
243
  public float[][] getCubitPositions(int[] numLayers)
244
    {
245
    return getPositions();
246
    }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  public Static4D getCubitQuats(int cubit, int[] numLayers)
251
    {
252
    return mObjectQuats[0];
253
    }
254

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

    
257
  private void createCutPlanes()
258
    {
259
    int numPlanes = 2*4;
260
    mCutPlanes = new float[numPlanes][];
261
    Static3D[] faceAxis = getFaceAxis();
262
    float[] dist = getDist();
263
    int[] numLayers = getNumLayers();
264
    float[][] cuts = getCuts(numLayers);
265
    float cut = cuts[0][0];
266

    
267
    for(int p=0; p<4; p++)
268
      {
269
      Static3D ax = faceAxis[p];
270
      mCutPlanes[p] = new float[] { ax.get0(), ax.get1(), ax.get2(), dist[p] };
271
      }
272

    
273
    for(int p=4; p<8; p++)
274
      {
275
      Static3D ax = ROT_AXIS[p-4];
276
      mCutPlanes[p] = new float[] { ax.get0(), ax.get1(), ax.get2(), cut };
277
      }
278
    }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
  private float[] internalPoint(int variant)
283
    {
284
    float[][] pos = getPositions();
285
    float[] position = pos[variant];
286

    
287
    float[] ret = new float[3];
288

    
289
    float A = 0.9f;
290

    
291
    ret[0] = A*position[0];
292
    ret[1] = A*position[1];
293
    ret[2] = A*position[2];
294

    
295
    return ret;
296
    }
297

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

    
300
  public ObjectShape getObjectShape(int variant)
301
    {
302
    if( mShapes==null )
303
      {
304
      int[] numLayers = getNumLayers();
305
      int numV = getNumCubitVariants(numLayers);
306
      mShapes = new ObjectShape[numV];
307
      createCutPlanes();
308
      mPotentialVertices = FactoryShape.computePotentialVertices(mCutPlanes);
309
      }
310

    
311
    if( mShapes[variant]==null )
312
      {
313
      float[][] pos = getPositions();
314
      float[] point = internalPoint(variant);
315
      mShapes[variant] = FactoryShape.createShape(mCutPlanes,mPotentialVertices,pos[variant],point);
316
      }
317

    
318
    return mShapes[variant];
319
    }
320

    
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322

    
323
  public ObjectFaceShape getObjectFaceShape(int variant)
324
    {
325
    ObjectShape shape = getObjectShape(variant);
326
    int[][] ind    = shape.getVertIndices();
327
    float[][] vert = shape.getVertices();
328
    float[][] pos  = getPositions();
329
    int[] indices  = FactoryShape.produceBandIndices(vert, pos[variant], ind, getFaceAxis(), getDist() );
330

    
331
    if( variant<4 )
332
      {
333
      int N = 5;
334
      int E = 1;
335
      float height = isInIconMode() ? 0.001f : 0.02f;
336
      float[][] bands = { {height,35,0.3f,0.5f,N,E,E}, {0.001f,35,0.3f,0.5f,N,E,E} };
337
      return new ObjectFaceShape(bands,indices,null);
338
      }
339
    else if( variant<10 )
340
      {
341
      int N = 5;
342
      int E = 0;
343
      float height = isInIconMode() ? 0.001f : 0.02f;
344
      float[][] bands = { {height,35,0.3f,0.5f,N,E,E}, {0.001f,35,0.3f,0.5f,N,E,E} };
345
      return new ObjectFaceShape(bands,indices,null);
346
      }
347
    else
348
      {
349
      int N = 5;
350
      int E = 0;
351
      float height = isInIconMode() ? 0.001f : 0.02f;
352
      float[][] bands = { {height,35,0.3f,0.5f,N,E,E}, {0.001f,35,0.3f,0.5f,3,0,0} };
353
      return new ObjectFaceShape(bands,indices,null);
354
      }
355
    }
356

    
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

    
359
  private float[][] computeVertexEffectCenter(int variant)
360
    {
361
    float A;
362

    
363
         if( variant< 4 ) A = -0.4f;
364
    else if( variant<10 ) A = -1.0f;
365
    else                  A = -0.9f;
366

    
367
    float[][] positions = getPositions();
368
    float[] p = positions[variant];
369

    
370
    return new float[][] {{ A*p[0], A*p[1], A*p[2] }};
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
  public ObjectVertexEffects getVertexEffects(int variant)
376
    {
377
    ObjectShape shape  = getObjectShape(variant);
378
    float[][] vertices = shape.getVertices();
379
    float[][] centers  = computeVertexEffectCenter(variant);
380
    float[][] pos      = getPositions();
381
    int[] indices      = FactoryShape.computeVertexEffectsIndices(vertices, pos[variant], getFaceAxis(), getDist() );
382

    
383
    float S,R;
384
         if( variant< 4 ) { S = 0.05f; R=0.15f; }
385
    else if( variant<10 ) { S = 0.05f; R=0.10f; }
386
    else                  { S = 0.05f; R=0.15f; }
387

    
388
    float[][] corners = {{S,R}};
389

    
390
    return FactoryCubit.generateVertexEffect(vertices,corners,indices,centers,indices);
391
    }
392

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394

    
395
  public int getNumCubitVariants(int[] numLayers)
396
    {
397
    return 14;
398
    }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

    
402
  public int getCubitVariant(int cubit, int[] numLayers)
403
    {
404
    return cubit;
405
    }
406

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408

    
409
  public float getStickerRadius()
410
    {
411
    return 0.06f;
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415

    
416
  public float getStickerStroke()
417
    {
418
    return isInIconMode() ? 0.10f : 0.05f;
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

    
423
  public float[][][] getStickerAngles()
424
    {
425
    return null;
426
    }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429
// PUBLIC API
430

    
431
  public Static3D[] getRotationAxis()
432
    {
433
    return ROT_AXIS;
434
    }
435

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

    
438
  public int[][] getBasicAngles()
439
    {
440
    if( mBasicAngle ==null )
441
      {
442
      int num = getNumLayers()[0];
443
      int[] tmp = new int[num];
444
      for(int i=0; i<num; i++) tmp[i] = 3;
445
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
446
      }
447

    
448
    return mBasicAngle;
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

    
453
  public String getShortName()
454
    {
455
    return ListObjects.MJIN_2.name();
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  public String[][] getTutorials()
461
    {
462
    return null;
463
    }
464
}
(32-32/59)