Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objectlib.objects;
21

    
22
import org.distorted.library.main.QuatHelper;
23
import org.distorted.library.type.Static3D;
24
import org.distorted.library.type.Static4D;
25
import org.distorted.objectlib.helpers.ObjectFaceShape;
26
import org.distorted.objectlib.helpers.ObjectShape;
27
import org.distorted.objectlib.main.ObjectType;
28

    
29
import java.io.InputStream;
30

    
31
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
32
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.C2;
33
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.COS54;
34
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.SIN54;
35

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

    
38
public class TwistyStarminx extends TwistyMinx
39
{
40
  private float[][] mCuts;
41
  private float[][] mPosition;
42
  private int[] mQuatIndex;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  public TwistyStarminx(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
47
    {
48
    super(numL, meshState, iconMode, quat, move, scale, stream);
49
    }
50

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

    
53
  @Override
54
  public int getInternalColor()
55
    {
56
    return 0xff222222;
57
    }
58

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

    
61
  @Override
62
  public int getTouchControlSplit()
63
    {
64
    return TYPE_NOT_SPLIT;
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  @Override
70
  public int[][][] getEnabled()
71
    {
72
    return new int[][][]
73
      {
74
          {{1,2,3,4,5}},
75
          {{0,2,3,4,5}},
76
          {{0,2,3,4,5}},
77
          {{1,2,3,4,5}},
78
          {{0,1,3,4,5}},
79
          {{0,1,2,4,5}},
80
          {{0,1,2,4,5}},
81
          {{0,1,3,4,5}},
82
          {{0,1,2,3,5}},
83
          {{0,1,2,3,4}},
84
          {{0,1,2,3,4}},
85
          {{0,1,2,3,5}},
86
      };
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

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

    
101
         0,35,55,38,48,41,42,58,57,46,29,59,
102

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

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

    
114
  public float[][] getCubitPositions(int[] numLayers)
115
    {
116
    if( mPosition==null )
117
      {
118
      if( mEdgeMap==null ) initializeEdgeMap();
119
      if( mCenterCoords==null ) initializeCenterCoords();
120

    
121
      mPosition = new float[NUM_EDGES+NUM_CENTERS+3*NUM_CORNERS][3];
122

    
123
      for(int edge=0; edge<NUM_EDGES; edge++)
124
        {
125
        float[] c1 = mCorners[ mEdgeMap[edge][0] ];
126
        float[] c2 = mCorners[ mEdgeMap[edge][1] ];
127

    
128
        mPosition[edge][0] = (c1[0]+c2[0])/2;
129
        mPosition[edge][1] = (c1[1]+c2[1])/2;
130
        mPosition[edge][2] = (c1[2]+c2[2])/2;
131
        }
132

    
133
      for(int center=0; center<NUM_CENTERS; center++)
134
        {
135
        int index = center+NUM_EDGES;
136
        mPosition[index][0] = mCenterCoords[center][0];
137
        mPosition[index][1] = mCenterCoords[center][1];
138
        mPosition[index][2] = mCenterCoords[center][2];
139
        }
140

    
141
      float A = 1.5f;
142
      float B = 3*C2;
143
      float K = 1/(4*SIN54*SIN54);
144
      float Y = (B-A)*K/2;
145
      float Z = B*K/2;
146
      float[] result = new float[4];
147
      setQuatIndex();
148

    
149
      for(int petal=0; petal<3*NUM_CORNERS; petal++)
150
        {
151
        int index  = petal+NUM_EDGES+NUM_CENTERS;
152
        int corner = petal/3;
153

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

    
156
        mPosition[index][0] = mCorners[corner][0] + result[0];
157
        mPosition[index][1] = mCorners[corner][1] + result[1];
158
        mPosition[index][2] = mCorners[corner][2] + result[2];
159
        }
160
      }
161

    
162
    return mPosition;
163
    }
164

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

    
167
  public Static4D getCubitQuats(int cubit, int[] numLayers)
168
    {
169
    setQuatIndex();
170
    return mObjectQuats[mQuatIndex[cubit]];
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  public ObjectShape getObjectShape(int variant)
176
    {
177
    if( variant==0 ) // edge
178
      {
179
      float A = 1.5f;
180
      float B = 3*C2;
181
      float C = 3*SIN54;
182
      float X = (A*C)/(A+C);
183
      float Z1= A*(B-C)/(A+C);
184
      float Z2= B-A;
185

    
186
      float[][] vertices =
187
         {
188
             { 0, A,  0 },
189
             { 0,-A,  0 },
190
             {-X, 0,-Z1 },
191
             {+X, 0,-Z1 },
192
             {-X, 0,-Z2 },
193
             {+X, 0,-Z2 },
194
         };
195
      int[][] indices =
196
         {
197
             {2,1,0},
198
             {3,0,1},
199
             {2,4,1},
200
             {2,0,4},
201
             {3,1,5},
202
             {3,5,0},
203
             {1,5,4},
204
             {0,4,5}
205
         };
206

    
207
      return new ObjectShape(vertices, indices);
208
      }
209
    if( variant==1 ) // center
210
      {
211
      final double ANGLE = 0.825f*Math.PI;
212
      final float cosA  = (float)Math.cos(ANGLE);
213
      final float sinA  = (float)Math.sin(ANGLE);
214

    
215
      float TAN54 = SIN54/COS54;
216
      float R  = 1.5f*(TAN54-(1/TAN54));
217
      float X1 = R*COS54;
218
      float Y1 = R*SIN54;
219
      float X2 = R*COS18;
220
      float Y2 = R*SIN18;
221
      float Z  = 1.6f*R;  // about
222

    
223
      float[][] vertices =
224
        {
225
          {-X1,-Y1*sinA,-Y1*cosA},
226
          {-X2,+Y2*sinA,+Y2*cosA},
227
          { 0 ,+R*sinA ,+R*cosA },
228
          {+X2,+Y2*sinA,+Y2*cosA},
229
          {+X1,-Y1*sinA,-Y1*cosA},
230
          { 0 , Z*cosA ,-Z*sinA }
231
        };
232

    
233
      int[][] indices =
234
        {
235
          {4,3,2,1,0},
236
          {5,1,0},
237
          {5,2,1},
238
          {5,3,2},
239
          {5,4,3},
240
          {5,0,4}
241
        };
242

    
243
      return new ObjectShape(vertices, indices);
244
      }
245
    else
246
      {
247
      float A = 1.5f;
248
      float B = 3*C2;
249
      float K = 1/(4*SIN54*SIN54);
250
      float X = A*K;
251
      float Y = (B-A)*K/2;
252
      float Z = B*K/2;
253

    
254
      float[][] vertices =
255
         {
256
             { 0,-Y,   Z },
257
             {-X, Y,  -Z },
258
             {+X, Y,  -Z },
259
             { 0,-Y,-3*Z },
260
         };
261
      int[][] indices =
262
         {
263
             {2,1,0},
264
             {1,2,3},
265
             {2,0,3},
266
             {1,3,0}
267
         };
268

    
269
      return new ObjectShape(vertices, indices);
270
      }
271
    }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
  public ObjectFaceShape getObjectFaceShape(int variant)
276
    {
277
    if( variant==0 )
278
      {
279
      float h1 = isInIconMode() ? 0.001f : 0.025f;
280
      float[][] bands     = { {h1,8,0.5f,0.2f,5,1,0}, {0.001f, 1,0.5f,0.2f,4,0,0} };
281
      int[] bandIndices   = { 0,0,1,1,1,1,1,1 };
282
      float[][] corners   = { { 0.025f, 0.20f } };
283
      int[] cornerIndices = { 0,0,0,0,-1,-1 };
284
      float[][] centers   = { { 0.0f,0.0f,-1.0f } };
285
      int[] centerIndices = { 0,0,0,0,-1,-1 };
286
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
287
      }
288
    else if( variant==1 )
289
      {
290
      final double ANGLE = 0.825f*Math.PI;
291
      final float cosA  = (float)Math.cos(ANGLE);
292
      final float sinA  = (float)Math.sin(ANGLE);
293
      float TAN54 = SIN54/COS54;
294
      float R  = 2.0f*(TAN54-(1/TAN54));
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[] bandIndices   = { 0,1,1,1,1,1 };
298
      float[][] corners   = { { 0.015f, 0.20f } };
299
      int[] cornerIndices = { 0,0,0,0,0,-1 };
300
      float[][] centers   = { { 0.0f,R*cosA,-R*sinA } };
301
      int[] centerIndices = { 0,0,0,0,0,-1 };
302
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
303
      }
304
    else
305
      {
306
      float Z = 3*C2/(4*SIN54*SIN54);
307
      float h1 = isInIconMode() ? 0.001f : 0.03f;
308
      float[][] bands     = { {h1,6,0.5f,0.2f,5,0,0}, {0.001f, 1,0.5f,0.2f,3,0,0} };
309
      int[] bandIndices   = { 0,1,1,1 };
310
      float[][] corners   = { { 0.015f, 0.20f } };
311
      int[] cornerIndices = { 0,0,0,-1 };
312
      float[][] centers   = { { 0.0f,0.0f,-Z } };
313
      int[] centerIndices = { 0,0,0,-1 };
314
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
315
      }
316
    }
317

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

    
320
  public int getNumCubitVariants(int[] numLayers)
321
    {
322
    return 3;
323
    }
324

    
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

    
327
  public int getCubitVariant(int cubit, int[] numLayers)
328
    {
329
    return cubit<NUM_EDGES ? 0: (cubit<NUM_CENTERS+NUM_EDGES ? 1:2);
330
    }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
  public float[][] getCuts(int[] numLayers)
335
    {
336
    if( mCuts==null )
337
      {
338
      float CUT = 1.0f; // about
339
      float[] cut = new float[] { -CUT,+CUT };
340
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
341
      }
342

    
343
    return mCuts;
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

    
348
  public float getStickerRadius()
349
    {
350
    return 0.18f;
351
    }
352

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

    
355
  public float getStickerStroke()
356
    {
357
    return isInIconMode() ? 0.22f : 0.15f;
358
    }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
  public float[][] getStickerAngles()
363
    {
364
    return null;
365
    }
366

    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
// PUBLIC API
369

    
370
  public String getShortName()
371
    {
372
    return ObjectType.STAR_3.name();
373
    }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376

    
377
  public long getSignature()
378
    {
379
    return ObjectType.STAR_3.ordinal();
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  public String getObjectName()
385
    {
386
    return "Starminx I";
387
    }
388

    
389
///////////////////////////////////////////////////////////////////////////////////////////////////
390

    
391
  public String getInventor()
392
    {
393
    return "Aleh Hladzilin";
394
    }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397

    
398
  public int getYearOfInvention()
399
    {
400
    return 2009;
401
    }
402

    
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404

    
405
  public int getComplexity()
406
    {
407
    return 3;
408
    }
409

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

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