Project

General

Profile

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

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

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.ObjectFaceShape;
16
import org.distorted.objectlib.helpers.ObjectShape;
17
import org.distorted.objectlib.helpers.ObjectSignature;
18
import org.distorted.objectlib.main.InitData;
19
import org.distorted.objectlib.main.ObjectType;
20

    
21
import java.io.InputStream;
22

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

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class TwistyStarminx extends TwistyMinx
31
{
32
  private float[][] mCuts;
33
  private float[][] mPosition;
34
  private int[] mQuatIndex;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

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

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

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

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

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

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

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

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

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

    
93
         0,35,55,38,48,41,42,58,57,46,29,59,
94

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

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

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

    
113
      mPosition = new float[NUM_EDGES+NUM_CENTERS+3*NUM_CORNERS][3];
114

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

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

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

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

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

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

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

    
154
    return mPosition;
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

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

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  public ObjectShape getObjectShape(int variant)
168
    {
169
    if( variant==0 ) // edge
170
      {
171
      float A = 1.5f;
172
      float B = 3*C2;
173
      float C = 3*SIN54;
174
      float X = (A*C)/(A+C);
175
      float Z1= A*(B-C)/(A+C);
176
      float Z2= B-A;
177

    
178
      float[][] vertices =
179
         {
180
             { 0, A,  0 },
181
             { 0,-A,  0 },
182
             {-X, 0,-Z1 },
183
             {+X, 0,-Z1 },
184
             {-X, 0,-Z2 },
185
             {+X, 0,-Z2 },
186
         };
187
      int[][] indices =
188
         {
189
             {2,1,0},
190
             {3,0,1},
191
             {2,4,1},
192
             {2,0,4},
193
             {3,1,5},
194
             {3,5,0},
195
             {1,5,4},
196
             {0,4,5}
197
         };
198

    
199
      return new ObjectShape(vertices, indices);
200
      }
201
    if( variant==1 ) // center
202
      {
203
      final double ANGLE = 0.825f*Math.PI;
204
      final float cosA  = (float)Math.cos(ANGLE);
205
      final float sinA  = (float)Math.sin(ANGLE);
206

    
207
      float TAN54 = SIN54/COS54;
208
      float R  = 1.5f*(TAN54-(1/TAN54));
209
      float X1 = R*COS54;
210
      float Y1 = R*SIN54;
211
      float X2 = R*COS18;
212
      float Y2 = R*SIN18;
213
      float Z  = 1.6f*R;  // about
214

    
215
      float[][] vertices =
216
        {
217
          {-X1,-Y1*sinA,-Y1*cosA},
218
          {-X2,+Y2*sinA,+Y2*cosA},
219
          { 0 ,+R*sinA ,+R*cosA },
220
          {+X2,+Y2*sinA,+Y2*cosA},
221
          {+X1,-Y1*sinA,-Y1*cosA},
222
          { 0 , Z*cosA ,-Z*sinA }
223
        };
224

    
225
      int[][] indices =
226
        {
227
          {4,3,2,1,0},
228
          {5,1,0},
229
          {5,2,1},
230
          {5,3,2},
231
          {5,4,3},
232
          {5,0,4}
233
        };
234

    
235
      return new ObjectShape(vertices, indices);
236
      }
237
    else
238
      {
239
      float A = 1.5f;
240
      float B = 3*C2;
241
      float K = 1/(4*SIN54*SIN54);
242
      float X = A*K;
243
      float Y = (B-A)*K/2;
244
      float Z = B*K/2;
245

    
246
      float[][] vertices =
247
         {
248
             { 0,-Y,   Z },
249
             {-X, Y,  -Z },
250
             {+X, Y,  -Z },
251
             { 0,-Y,-3*Z },
252
         };
253
      int[][] indices =
254
         {
255
             {2,1,0},
256
             {1,2,3},
257
             {2,0,3},
258
             {1,3,0}
259
         };
260

    
261
      return new ObjectShape(vertices, indices);
262
      }
263
    }
264

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

    
267
  public ObjectFaceShape getObjectFaceShape(int variant)
268
    {
269
    if( variant==0 )
270
      {
271
      float h1 = isInIconMode() ? 0.001f : 0.025f;
272
      float[][] bands     = { {h1,8,0.5f,0.2f,5,1,0}, {0.001f, 1,0.5f,0.2f,4,0,0} };
273
      int[] bandIndices   = { 0,0,1,1,1,1,1,1 };
274
      float[][] corners   = { { 0.025f, 0.20f } };
275
      int[] cornerIndices = { 0,0,0,0,-1,-1 };
276
      float[][] centers   = { { 0.0f,0.0f,-1.0f } };
277
      int[] centerIndices = { 0,0,0,0,-1,-1 };
278
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
279
      }
280
    else if( variant==1 )
281
      {
282
      final double ANGLE = 0.825f*Math.PI;
283
      final float cosA  = (float)Math.cos(ANGLE);
284
      final float sinA  = (float)Math.sin(ANGLE);
285
      float TAN54 = SIN54/COS54;
286
      float R  = 2.0f*(TAN54-(1/TAN54));
287
      float h1 = isInIconMode() ? 0.001f : 0.04f;
288
      float[][] bands     = { {h1,10,0.5f,0.2f,4,0,0}, {0.001f, 1,0.5f,0.2f,3,0,0} };
289
      int[] bandIndices   = { 0,1,1,1,1,1 };
290
      float[][] corners   = { { 0.015f, 0.20f } };
291
      int[] cornerIndices = { 0,0,0,0,0,-1 };
292
      float[][] centers   = { { 0.0f,R*cosA,-R*sinA } };
293
      int[] centerIndices = { 0,0,0,0,0,-1 };
294
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
295
      }
296
    else
297
      {
298
      float Z = 3*C2/(4*SIN54*SIN54);
299
      float h1 = isInIconMode() ? 0.001f : 0.03f;
300
      float[][] bands     = { {h1,6,0.5f,0.2f,5,0,0}, {0.001f, 1,0.5f,0.2f,3,0,0} };
301
      int[] bandIndices   = { 0,1,1,1 };
302
      float[][] corners   = { { 0.015f, 0.20f } };
303
      int[] cornerIndices = { 0,0,0,-1 };
304
      float[][] centers   = { { 0.0f,0.0f,-Z } };
305
      int[] centerIndices = { 0,0,0,-1 };
306
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
307
      }
308
    }
309

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

    
312
  public int getNumCubitVariants(int[] numLayers)
313
    {
314
    return 3;
315
    }
316

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

    
319
  public int getCubitVariant(int cubit, int[] numLayers)
320
    {
321
    return cubit<NUM_EDGES ? 0: (cubit<NUM_CENTERS+NUM_EDGES ? 1:2);
322
    }
323

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

    
326
  public float[][] getCuts(int[] numLayers)
327
    {
328
    if( mCuts==null )
329
      {
330
      float CUT = 1.0f; // about
331
      float[] cut = new float[] { -CUT,+CUT };
332
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
333
      }
334

    
335
    return mCuts;
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

    
340
  public float getStickerRadius()
341
    {
342
    return 0.18f;
343
    }
344

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

    
347
  public float getStickerStroke()
348
    {
349
    return isInIconMode() ? 0.22f : 0.15f;
350
    }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
  public float[][] getStickerAngles()
355
    {
356
    return null;
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
// PUBLIC API
361

    
362
  public String getShortName()
363
    {
364
    return ObjectType.STAR_3.name();
365
    }
366

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

    
369
  public ObjectSignature getSignature()
370
    {
371
    return new ObjectSignature(ObjectType.STAR_3);
372
    }
373

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

    
376
  public String getObjectName()
377
    {
378
    return "Starminx I";
379
    }
380

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

    
383
  public String getInventor()
384
    {
385
    return "Aleh Hladzilin";
386
    }
387

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

    
390
  public int getYearOfInvention()
391
    {
392
    return 2009;
393
    }
394

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

    
397
  public int getComplexity()
398
    {
399
    return 4;
400
    }
401

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

    
404
  public String[][] getTutorials()
405
    {
406
    return new String[][]{
407
                          {"gb","NqYFonhf2rw","Face Turning Starminx Tutorial","twistypuzzling"},
408
                          {"pl","7LotUfg90HI","Starminx Cube TUTORIAL PL 1/2","MrUK"},
409
                          {"pl","nH2doGM1Das","Starminx Cube TUTORIAL PL 2/2","MrUK"},
410
                          {"kr","8bIQVCKWBvw","스타밍크스 해법  1/2","듀나메스 큐브 해법연구소"},
411
                          {"kr","4WU5iJyM7jI","스타밍크스 해법  2/2","듀나메스 큐브 해법연구소"},
412
                          {"vn","QhSaboIX3Fs","Tutorial N.183 - Starminx","Duy Thích Rubik"},
413
                         };
414
    }
415
}
(32-32/36)