Project

General

Profile

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

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

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.main.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.InitData;
21
import org.distorted.objectlib.main.ObjectSignatures;
22
import org.distorted.objectlib.main.ObjectType;
23

    
24
import java.io.InputStream;
25

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

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

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

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

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

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

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

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

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

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

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

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

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

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

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

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

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

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

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

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

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

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

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

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

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

    
157
    return mPosition;
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

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

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

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

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

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

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

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

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

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

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

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

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

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

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

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

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

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

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

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

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

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

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

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

    
368
    return mCuts;
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

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

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

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

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

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

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393
// PUBLIC API
394

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

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

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

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

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

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

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

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

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

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

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

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

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