Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyStarminx.java @ aacf5e27

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 org.distorted.library.helpers.QuatHelper;
13
import org.distorted.library.type.Static3D;
14
import org.distorted.library.type.Static4D;
15
import org.distorted.objectlib.helpers.FactoryCubit;
16
import org.distorted.objectlib.helpers.ObjectFaceShape;
17
import org.distorted.objectlib.helpers.ObjectShape;
18
import org.distorted.objectlib.helpers.ObjectSignature;
19
import org.distorted.objectlib.helpers.ObjectVertexEffects;
20
import org.distorted.objectlib.main.InitAssets;
21
import org.distorted.objectlib.main.InitData;
22
import org.distorted.objectlib.main.ObjectSignatures;
23
import org.distorted.objectlib.main.ObjectType;
24

    
25
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
26
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.C2;
27
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.COS54;
28
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.SIN54;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
public class TwistyStarminx extends TwistyDodecahedron
33
{
34
  private float[][] mCuts;
35
  private float[][] mPosition;
36
  private int[] mQuatIndex;
37

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

    
40
  public TwistyStarminx(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
41
    {
42
    super(meshState, iconMode, quat, move, scale, data, asset);
43
    }
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
  @Override
48
  public int getInternalColor()
49
    {
50
    return 0xff222222;
51
    }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  @Override
56
  public int getTouchControlSplit()
57
    {
58
    return TYPE_NOT_SPLIT;
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  @Override
64
  public int[][][] getEnabled()
65
    {
66
    return new int[][][]
67
      {
68
          {{1,2,3,4,5}},
69
          {{0,2,3,4,5}},
70
          {{0,2,3,4,5}},
71
          {{1,2,3,4,5}},
72
          {{0,1,3,4,5}},
73
          {{0,1,2,4,5}},
74
          {{0,1,2,4,5}},
75
          {{0,1,3,4,5}},
76
          {{0,1,2,3,5}},
77
          {{0,1,2,3,4}},
78
          {{0,1,2,3,4}},
79
          {{0,1,2,3,5}},
80
      };
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  private void setQuatIndex()
86
    {
87
    if( mQuatIndex==null )
88
      {
89
      mQuatIndex = new int[]
90
        {
91
         0,17,12,13,20, 4,25, 5,24,16,
92
         9,21, 1,34, 8,11,30,43,26,14,
93
        15,45,33,28,10, 2,29, 6, 7, 3,
94

    
95
         0,35,55,38,48,41,42,58,57,46,29,59,
96

    
97
         0,36,44, 29, 2, 7, 59,20,24, 48,42,58,
98
        18,13,50, 53,41,43, 22,16,39, 49,33,38,
99
        11, 8,34, 54,51,56, 10, 1,47, 52,25,32,
100
        17,12,35, 27,30,46, 19, 4,31, 26, 3,14,
101
         9,21,55, 28,37,57, 23, 5,40, 45, 6,15
102
        };
103
      }
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public float[][] getCubitPositions(int[] numLayers)
109
    {
110
    if( mPosition==null )
111
      {
112
      if( mEdgeMap==null ) initializeEdgeMap();
113
      if( mCenterCoords==null ) initializeCenterCoords();
114

    
115
      mPosition = new float[NUM_EDGES+NUM_CENTERS+3*NUM_CORNERS][3];
116

    
117
      for(int edge=0; edge<NUM_EDGES; edge++)
118
        {
119
        float[] c1 = mCorners[ mEdgeMap[edge][0] ];
120
        float[] c2 = mCorners[ mEdgeMap[edge][1] ];
121

    
122
        mPosition[edge][0] = (c1[0]+c2[0])/2;
123
        mPosition[edge][1] = (c1[1]+c2[1])/2;
124
        mPosition[edge][2] = (c1[2]+c2[2])/2;
125
        }
126

    
127
      for(int center=0; center<NUM_CENTERS; center++)
128
        {
129
        int index = center+NUM_EDGES;
130
        mPosition[index][0] = mCenterCoords[center][0];
131
        mPosition[index][1] = mCenterCoords[center][1];
132
        mPosition[index][2] = mCenterCoords[center][2];
133
        }
134

    
135
      float A = 1.5f;
136
      float B = 3*C2;
137
      float K = 1/(4*SIN54*SIN54);
138
      float Y = (B-A)*K/2;
139
      float Z = B*K/2;
140
      float[] result = new float[4];
141
      setQuatIndex();
142

    
143
      for(int petal=0; petal<3*NUM_CORNERS; petal++)
144
        {
145
        int index  = petal+NUM_EDGES+NUM_CENTERS;
146
        int corner = petal/3;
147

    
148
        QuatHelper.rotateVectorByQuat(result,0.0f,Y,-Z,1.0f, mObjectQuats[mQuatIndex[index]] );
149

    
150
        mPosition[index][0] = mCorners[corner][0] + result[0];
151
        mPosition[index][1] = mCorners[corner][1] + result[1];
152
        mPosition[index][2] = mCorners[corner][2] + result[2];
153
        }
154
      }
155

    
156
    return mPosition;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public Static4D getCubitQuats(int cubit, int[] numLayers)
162
    {
163
    setQuatIndex();
164
    return mObjectQuats[mQuatIndex[cubit]];
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  private float[][] getVertices(int variant)
170
    {
171
    if( variant==0 )
172
      {
173
      float A = 1.5f;
174
      float B = 3*C2;
175
      float C = 3*SIN54;
176
      float X = (A*C)/(A+C);
177
      float Z1= A*(B-C)/(A+C);
178
      float Z2= B-A;
179

    
180
      return new float[][]
181
         {
182
             { 0, A,  0 },
183
             { 0,-A,  0 },
184
             {-X, 0,-Z1 },
185
             {+X, 0,-Z1 },
186
             {-X, 0,-Z2 },
187
             {+X, 0,-Z2 },
188
         };
189
      }
190
    else if( variant==1 )
191
      {
192
      final double ANGLE = 0.825f*Math.PI;
193
      final float cosA  = (float)Math.cos(ANGLE);
194
      final float sinA  = (float)Math.sin(ANGLE);
195

    
196
      float TAN54 = SIN54/COS54;
197
      float R  = 1.5f*(TAN54-(1/TAN54));
198
      float X1 = R*COS54;
199
      float Y1 = R*SIN54;
200
      float X2 = R*COS18;
201
      float Y2 = R*SIN18;
202
      float Z  = 1.6f*R;  // about
203

    
204
      return new float[][]
205
        {
206
          {-X1,-Y1*sinA,-Y1*cosA},
207
          {-X2, Y2*sinA, Y2*cosA},
208
          { 0 , R*sinA , R*cosA },
209
          {+X2, Y2*sinA, Y2*cosA},
210
          {+X1,-Y1*sinA,-Y1*cosA},
211
          { 0 , Z*cosA ,-Z*sinA }
212
        };
213

    
214
      }
215
    else
216
      {
217
      float A = 1.5f;
218
      float B = 3*C2;
219
      float K = 1/(4*SIN54*SIN54);
220
      float X = A*K;
221
      float Y = (B-A)*K/2;
222
      float Z = B*K/2;
223

    
224
      return new float[][]
225
         {
226
             { 0,-Y,   Z },
227
             {-X, Y,  -Z },
228
             {+X, Y,  -Z },
229
             { 0,-Y,-3*Z },
230
         };
231
      }
232
    }
233

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

    
236
  public ObjectShape getObjectShape(int variant)
237
    {
238
    if( variant==0 ) // edge
239
      {
240
      int[][] indices =
241
         {
242
             {2,1,0},
243
             {3,0,1},
244
             {2,4,1},
245
             {2,0,4},
246
             {3,1,5},
247
             {3,5,0},
248
             {1,5,4},
249
             {0,4,5}
250
         };
251

    
252
      return new ObjectShape(getVertices(variant), indices);
253
      }
254
    if( variant==1 ) // center
255
      {
256
      int[][] indices =
257
        {
258
          {4,3,2,1,0},
259
          {5,1,0},
260
          {5,2,1},
261
          {5,3,2},
262
          {5,4,3},
263
          {5,0,4}
264
        };
265

    
266
      return new ObjectShape(getVertices(variant), indices);
267
      }
268
    else
269
      {
270
      int[][] indices =
271
         {
272
             {2,1,0},
273
             {1,2,3},
274
             {2,0,3},
275
             {1,3,0}
276
         };
277

    
278
      return new ObjectShape(getVertices(variant), indices);
279
      }
280
    }
281

    
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

    
284
  public ObjectFaceShape getObjectFaceShape(int variant)
285
    {
286
    if( variant==0 )
287
      {
288
      float h1 = isInIconMode() ? 0.001f : 0.025f;
289
      float[][] bands = { {h1,8,0.5f,0.2f,5,1,0}, {0.001f, 1,0.5f,0.2f,4,0,0} };
290
      int[] indices   = { 0,0,1,1,1,1,1,1 };
291
      return new ObjectFaceShape(bands,indices,null);
292
      }
293
    else if( variant==1 )
294
      {
295
      float h1 = isInIconMode() ? 0.001f : 0.04f;
296
      float[][] bands = { {h1,10,0.5f,0.2f,4,0,0}, {0.001f, 1,0.5f,0.2f,3,0,0} };
297
      int[] indices   = { 0,1,1,1,1,1 };
298
      return new ObjectFaceShape(bands,indices,null);
299
      }
300
    else
301
      {
302
      float h1 = isInIconMode() ? 0.001f : 0.03f;
303
      float[][] bands = { {h1,6,0.5f,0.2f,5,0,0}, {0.001f, 1,0.5f,0.2f,3,0,0} };
304
      int[] indices   = { 0,1,1,1 };
305
      return new ObjectFaceShape(bands,indices,null);
306
      }
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
  public ObjectVertexEffects getVertexEffects(int variant)
312
    {
313
    if( variant==0 )
314
      {
315
      float[][] corners = { { 0.025f, 0.20f } };
316
      int[] indices     = { 0,0,0,0,-1,-1 };
317
      float[][] centers = { { 0.0f,0.0f,-1.0f } };
318
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
319
      }
320
    else if( variant==1 )
321
      {
322
      final double ANGLE = 0.825f*Math.PI;
323
      final float cosA  = (float)Math.cos(ANGLE);
324
      final float sinA  = (float)Math.sin(ANGLE);
325
      float TAN54 = SIN54/COS54;
326
      float R  = 2.0f*(TAN54-(1/TAN54));
327
      float[][] corners = { { 0.015f, 0.20f } };
328
      int[] indices     = { 0,0,0,0,0,-1 };
329
      float[][] centers = { { 0.0f,R*cosA,-R*sinA } };
330
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
331
      }
332
    else
333
      {
334
      float Z = 3*C2/(4*SIN54*SIN54);
335
      float[][] corners = { { 0.015f, 0.20f } };
336
      int[] indices     = { 0,0,0,-1 };
337
      float[][] centers = { { 0.0f,0.0f,-Z } };
338
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
339
      }
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
  public int getNumCubitVariants(int[] numLayers)
345
    {
346
    return 3;
347
    }
348

    
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350

    
351
  public int getCubitVariant(int cubit, int[] numLayers)
352
    {
353
    return cubit<NUM_EDGES ? 0: (cubit<NUM_CENTERS+NUM_EDGES ? 1:2);
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
  public float[][] getCuts(int[] numLayers)
359
    {
360
    if( mCuts==null )
361
      {
362
      float CUT = 1.0f; // about
363
      float[] cut = new float[] { -CUT,+CUT };
364
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
365
      }
366

    
367
    return mCuts;
368
    }
369

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

    
372
  public float getStickerRadius()
373
    {
374
    return 0.18f;
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public float getStickerStroke()
380
    {
381
    return isInIconMode() ? 0.22f : 0.15f;
382
    }
383

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

    
386
  public float[][] getStickerAngles()
387
    {
388
    return null;
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392
// PUBLIC API
393

    
394
  public String getShortName()
395
    {
396
    return ObjectType.STAR_3.name();
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  public ObjectSignature getSignature()
402
    {
403
    return new ObjectSignature(ObjectSignatures.STAR_3);
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  public String getObjectName()
409
    {
410
    return "Starminx I";
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
  public String getInventor()
416
    {
417
    return "Aleh Hladzilin";
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421

    
422
  public int getYearOfInvention()
423
    {
424
    return 2009;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public int getComplexity()
430
    {
431
    return 4;
432
    }
433

    
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

    
436
  public String[][] getTutorials()
437
    {
438
    return new String[][]{
439
                          {"gb","NqYFonhf2rw","Face Turning Starminx Tutorial","twistypuzzling"},
440
                          {"pl","7LotUfg90HI","Starminx Cube TUTORIAL PL 1/2","MrUK"},
441
                          {"pl","nH2doGM1Das","Starminx Cube TUTORIAL PL 2/2","MrUK"},
442
                          {"kr","8bIQVCKWBvw","스타밍크스 해법  1/2","듀나메스 큐브 해법연구소"},
443
                          {"kr","4WU5iJyM7jI","스타밍크스 해법  2/2","듀나메스 큐브 해법연구소"},
444
                          {"vn","QhSaboIX3Fs","Tutorial N.183 - Starminx","Duy Thích Rubik"},
445
                         };
446
    }
447
}
(40-40/44)