Project

General

Profile

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

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

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.helpers.ObjectSignature;
28
import org.distorted.objectlib.main.InitData;
29
import org.distorted.objectlib.main.ObjectType;
30

    
31
import java.io.InputStream;
32

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

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

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

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

    
48
  public TwistyStarminx(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
49
    {
50
    super(data, meshState, iconMode, quat, move, scale, stream);
51
    }
52

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

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

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

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

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

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

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

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

    
103
         0,35,55,38,48,41,42,58,57,46,29,59,
104

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

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

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

    
123
      mPosition = new float[NUM_EDGES+NUM_CENTERS+3*NUM_CORNERS][3];
124

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

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

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

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

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

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

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

    
164
    return mPosition;
165
    }
166

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

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

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

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

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

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

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

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

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

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

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

    
271
      return new ObjectShape(vertices, indices);
272
      }
273
    }
274

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

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

    
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

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

    
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

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

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

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

    
345
    return mCuts;
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
  public float getStickerRadius()
351
    {
352
    return 0.18f;
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

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

    
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

    
364
  public float[][] getStickerAngles()
365
    {
366
    return null;
367
    }
368

    
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370
// PUBLIC API
371

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

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

    
379
  public ObjectSignature getSignature()
380
    {
381
    return new ObjectSignature(ObjectType.STAR_3);
382
    }
383

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

    
386
  public String getObjectName()
387
    {
388
    return "Starminx I";
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
  public String getInventor()
394
    {
395
    return "Aleh Hladzilin";
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

    
400
  public int getYearOfInvention()
401
    {
402
    return 2009;
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  public int getComplexity()
408
    {
409
    return 4;
410
    }
411

    
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

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