Project

General

Profile

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

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

1 53a8ad99 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 ca846c17 Leszek Koltunski
import org.distorted.library.main.QuatHelper;
23 53a8ad99 Leszek Koltunski
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 1d581993 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectSignature;
28 53a8ad99 Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
29
30
import java.io.InputStream;
31
32 733f67ce Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
33 11981a15 Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.C2;
34 6074bff6 Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.COS54;
35
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.SIN54;
36 11981a15 Leszek Koltunski
37 53a8ad99 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39
public class TwistyStarminx extends TwistyMinx
40
{
41
  private float[][] mCuts;
42
  private float[][] mPosition;
43
  private int[] mQuatIndex;
44
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46
47
  public TwistyStarminx(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
48
    {
49
    super(numL, meshState, iconMode, quat, move, scale, stream);
50
    }
51
52 733f67ce Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
53
54
  @Override
55
  public int getInternalColor()
56
    {
57
    return 0xff222222;
58
    }
59
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62
  @Override
63
  public int getTouchControlSplit()
64
    {
65
    return TYPE_NOT_SPLIT;
66
    }
67
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
70
  @Override
71
  public int[][][] getEnabled()
72
    {
73
    return new int[][][]
74
      {
75
          {{1,2,3,4,5}},
76
          {{0,2,3,4,5}},
77
          {{0,2,3,4,5}},
78
          {{1,2,3,4,5}},
79
          {{0,1,3,4,5}},
80
          {{0,1,2,4,5}},
81
          {{0,1,2,4,5}},
82
          {{0,1,3,4,5}},
83
          {{0,1,2,3,5}},
84
          {{0,1,2,3,4}},
85
          {{0,1,2,3,4}},
86
          {{0,1,2,3,5}},
87
      };
88
    }
89
90 ca846c17 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92
  private void setQuatIndex()
93
    {
94
    if( mQuatIndex==null )
95
      {
96
      mQuatIndex = new int[]
97
        {
98 a4af26c1 Leszek Koltunski
         0,17,12,13,20, 4,25, 5,24,16,
99 ca846c17 Leszek Koltunski
         9,21, 1,34, 8,11,30,43,26,14,
100
        15,45,33,28,10, 2,29, 6, 7, 3,
101
102 a4af26c1 Leszek Koltunski
         0,35,55,38,48,41,42,58,57,46,29,59,
103 ca846c17 Leszek Koltunski
104
         0,36,44, 29, 2, 7, 59,20,24, 48,42,58,
105
        18,13,50, 53,41,43, 22,16,39, 49,33,38,
106
        11, 8,34, 54,51,56, 10, 1,47, 52,25,32,
107
        17,12,35, 27,30,46, 19, 4,31, 26, 3,14,
108
         9,21,55, 28,37,57, 23, 5,40, 45, 6,15
109
        };
110
      }
111
    }
112
113 53a8ad99 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
114
115
  public float[][] getCubitPositions(int[] numLayers)
116
    {
117
    if( mPosition==null )
118
      {
119
      if( mEdgeMap==null ) initializeEdgeMap();
120
      if( mCenterCoords==null ) initializeCenterCoords();
121
122 6074bff6 Leszek Koltunski
      mPosition = new float[NUM_EDGES+NUM_CENTERS+3*NUM_CORNERS][3];
123 53a8ad99 Leszek Koltunski
124
      for(int edge=0; edge<NUM_EDGES; edge++)
125
        {
126
        float[] c1 = mCorners[ mEdgeMap[edge][0] ];
127
        float[] c2 = mCorners[ mEdgeMap[edge][1] ];
128
129
        mPosition[edge][0] = (c1[0]+c2[0])/2;
130
        mPosition[edge][1] = (c1[1]+c2[1])/2;
131
        mPosition[edge][2] = (c1[2]+c2[2])/2;
132
        }
133 6074bff6 Leszek Koltunski
134
      for(int center=0; center<NUM_CENTERS; center++)
135
        {
136
        int index = center+NUM_EDGES;
137
        mPosition[index][0] = mCenterCoords[center][0];
138
        mPosition[index][1] = mCenterCoords[center][1];
139
        mPosition[index][2] = mCenterCoords[center][2];
140
        }
141
142 ca846c17 Leszek Koltunski
      float A = 1.5f;
143
      float B = 3*C2;
144
      float K = 1/(4*SIN54*SIN54);
145
      float Y = (B-A)*K/2;
146
      float Z = B*K/2;
147
      float[] result = new float[4];
148
      setQuatIndex();
149
150 6074bff6 Leszek Koltunski
      for(int petal=0; petal<3*NUM_CORNERS; petal++)
151
        {
152
        int index  = petal+NUM_EDGES+NUM_CENTERS;
153
        int corner = petal/3;
154 ca846c17 Leszek Koltunski
155
        QuatHelper.rotateVectorByQuat(result,0.0f,Y,-Z,1.0f, mObjectQuats[mQuatIndex[index]] );
156
157
        mPosition[index][0] = mCorners[corner][0] + result[0];
158
        mPosition[index][1] = mCorners[corner][1] + result[1];
159
        mPosition[index][2] = mCorners[corner][2] + result[2];
160 6074bff6 Leszek Koltunski
        }
161 53a8ad99 Leszek Koltunski
      }
162
163
    return mPosition;
164
    }
165
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
168
  public Static4D getCubitQuats(int cubit, int[] numLayers)
169
    {
170 ca846c17 Leszek Koltunski
    setQuatIndex();
171 53a8ad99 Leszek Koltunski
    return mObjectQuats[mQuatIndex[cubit]];
172
    }
173
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
176
  public ObjectShape getObjectShape(int variant)
177
    {
178
    if( variant==0 ) // edge
179
      {
180 6074bff6 Leszek Koltunski
      float A = 1.5f;
181
      float B = 3*C2;
182
      float C = 3*SIN54;
183
      float X = (A*C)/(A+C);
184
      float Z1= A*(B-C)/(A+C);
185
      float Z2= B-A;
186 53a8ad99 Leszek Koltunski
187
      float[][] vertices =
188
         {
189 6074bff6 Leszek Koltunski
             { 0, A,  0 },
190
             { 0,-A,  0 },
191
             {-X, 0,-Z1 },
192
             {+X, 0,-Z1 },
193
             {-X, 0,-Z2 },
194
             {+X, 0,-Z2 },
195 53a8ad99 Leszek Koltunski
         };
196
      int[][] indices =
197
         {
198 11981a15 Leszek Koltunski
             {2,1,0},
199
             {3,0,1},
200
             {2,4,1},
201
             {2,0,4},
202
             {3,1,5},
203
             {3,5,0},
204
             {1,5,4},
205
             {0,4,5}
206 53a8ad99 Leszek Koltunski
         };
207
208
      return new ObjectShape(vertices, indices);
209
      }
210 6074bff6 Leszek Koltunski
    if( variant==1 ) // center
211
      {
212
      final double ANGLE = 0.825f*Math.PI;
213
      final float cosA  = (float)Math.cos(ANGLE);
214
      final float sinA  = (float)Math.sin(ANGLE);
215
216
      float TAN54 = SIN54/COS54;
217
      float R  = 1.5f*(TAN54-(1/TAN54));
218
      float X1 = R*COS54;
219
      float Y1 = R*SIN54;
220
      float X2 = R*COS18;
221
      float Y2 = R*SIN18;
222 79b60250 Leszek Koltunski
      float Z  = 1.6f*R;  // about
223 6074bff6 Leszek Koltunski
224
      float[][] vertices =
225
        {
226
          {-X1,-Y1*sinA,-Y1*cosA},
227
          {-X2,+Y2*sinA,+Y2*cosA},
228
          { 0 ,+R*sinA ,+R*cosA },
229
          {+X2,+Y2*sinA,+Y2*cosA},
230
          {+X1,-Y1*sinA,-Y1*cosA},
231
          { 0 , Z*cosA ,-Z*sinA }
232
        };
233
234
      int[][] indices =
235
        {
236 f9d4556a Leszek Koltunski
          {4,3,2,1,0},
237 6074bff6 Leszek Koltunski
          {5,1,0},
238
          {5,2,1},
239
          {5,3,2},
240
          {5,4,3},
241
          {5,0,4}
242
        };
243
244
      return new ObjectShape(vertices, indices);
245
      }
246
    else
247
      {
248
      float A = 1.5f;
249
      float B = 3*C2;
250
      float K = 1/(4*SIN54*SIN54);
251
      float X = A*K;
252 ca846c17 Leszek Koltunski
      float Y = (B-A)*K/2;
253
      float Z = B*K/2;
254 53a8ad99 Leszek Koltunski
255 6074bff6 Leszek Koltunski
      float[][] vertices =
256
         {
257 ca846c17 Leszek Koltunski
             { 0,-Y,   Z },
258 6074bff6 Leszek Koltunski
             {-X, Y,  -Z },
259
             {+X, Y,  -Z },
260 ca846c17 Leszek Koltunski
             { 0,-Y,-3*Z },
261 6074bff6 Leszek Koltunski
         };
262
      int[][] indices =
263
         {
264
             {2,1,0},
265
             {1,2,3},
266
             {2,0,3},
267
             {1,3,0}
268
         };
269
270
      return new ObjectShape(vertices, indices);
271
      }
272 53a8ad99 Leszek Koltunski
    }
273
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275
276
  public ObjectFaceShape getObjectFaceShape(int variant)
277
    {
278
    if( variant==0 )
279
      {
280 733f67ce Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.025f;
281 1bd4a248 Leszek Koltunski
      float[][] bands     = { {h1,8,0.5f,0.2f,5,1,0}, {0.001f, 1,0.5f,0.2f,4,0,0} };
282 11981a15 Leszek Koltunski
      int[] bandIndices   = { 0,0,1,1,1,1,1,1 };
283 1bd4a248 Leszek Koltunski
      float[][] corners   = { { 0.025f, 0.20f } };
284 11981a15 Leszek Koltunski
      int[] cornerIndices = { 0,0,0,0,-1,-1 };
285
      float[][] centers   = { { 0.0f,0.0f,-1.0f } };
286
      int[] centerIndices = { 0,0,0,0,-1,-1 };
287 53a8ad99 Leszek Koltunski
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
288
      }
289 6074bff6 Leszek Koltunski
    else if( variant==1 )
290
      {
291 1bd4a248 Leszek Koltunski
      final double ANGLE = 0.825f*Math.PI;
292
      final float cosA  = (float)Math.cos(ANGLE);
293
      final float sinA  = (float)Math.sin(ANGLE);
294
      float TAN54 = SIN54/COS54;
295
      float R  = 2.0f*(TAN54-(1/TAN54));
296 f9d4556a Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.04f;
297 733f67ce Leszek Koltunski
      float[][] bands     = { {h1,10,0.5f,0.2f,4,0,0}, {0.001f, 1,0.5f,0.2f,3,0,0} };
298 6074bff6 Leszek Koltunski
      int[] bandIndices   = { 0,1,1,1,1,1 };
299
      float[][] corners   = { { 0.015f, 0.20f } };
300
      int[] cornerIndices = { 0,0,0,0,0,-1 };
301 1bd4a248 Leszek Koltunski
      float[][] centers   = { { 0.0f,R*cosA,-R*sinA } };
302 6074bff6 Leszek Koltunski
      int[] centerIndices = { 0,0,0,0,0,-1 };
303
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
304
      }
305
    else
306
      {
307
      float Z = 3*C2/(4*SIN54*SIN54);
308 f9d4556a Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.03f;
309 733f67ce Leszek Koltunski
      float[][] bands     = { {h1,6,0.5f,0.2f,5,0,0}, {0.001f, 1,0.5f,0.2f,3,0,0} };
310 6074bff6 Leszek Koltunski
      int[] bandIndices   = { 0,1,1,1 };
311
      float[][] corners   = { { 0.015f, 0.20f } };
312
      int[] cornerIndices = { 0,0,0,-1 };
313
      float[][] centers   = { { 0.0f,0.0f,-Z } };
314
      int[] centerIndices = { 0,0,0,-1 };
315
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
316
      }
317 53a8ad99 Leszek Koltunski
    }
318
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320
321
  public int getNumCubitVariants(int[] numLayers)
322
    {
323 6074bff6 Leszek Koltunski
    return 3;
324 53a8ad99 Leszek Koltunski
    }
325
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
328
  public int getCubitVariant(int cubit, int[] numLayers)
329
    {
330
    return cubit<NUM_EDGES ? 0: (cubit<NUM_CENTERS+NUM_EDGES ? 1:2);
331
    }
332
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334
335
  public float[][] getCuts(int[] numLayers)
336
    {
337
    if( mCuts==null )
338
      {
339 79b60250 Leszek Koltunski
      float CUT = 1.0f; // about
340 53a8ad99 Leszek Koltunski
      float[] cut = new float[] { -CUT,+CUT };
341
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
342
      }
343
344
    return mCuts;
345
    }
346
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348
349
  public float getStickerRadius()
350
    {
351
    return 0.18f;
352
    }
353
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355
356
  public float getStickerStroke()
357
    {
358
    return isInIconMode() ? 0.22f : 0.15f;
359
    }
360
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362
363
  public float[][] getStickerAngles()
364
    {
365
    return null;
366
    }
367
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369
// PUBLIC API
370
371
  public String getShortName()
372
    {
373
    return ObjectType.STAR_3.name();
374
    }
375
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377
378 1d581993 Leszek Koltunski
  public ObjectSignature getSignature()
379 53a8ad99 Leszek Koltunski
    {
380 1d581993 Leszek Koltunski
    return new ObjectSignature(ObjectType.STAR_3);
381 53a8ad99 Leszek Koltunski
    }
382
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384
385
  public String getObjectName()
386
    {
387
    return "Starminx I";
388
    }
389
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
392
  public String getInventor()
393
    {
394
    return "Aleh Hladzilin";
395
    }
396
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398
399
  public int getYearOfInvention()
400
    {
401
    return 2009;
402
    }
403
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405
406
  public int getComplexity()
407
    {
408 c6b9671a Leszek Koltunski
    return 4;
409 53a8ad99 Leszek Koltunski
    }
410
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412
413
  public String[][] getTutorials()
414
    {
415
    return new String[][]{
416
                          {"gb","NqYFonhf2rw","Face Turning Starminx Tutorial","twistypuzzling"},
417
                          {"pl","7LotUfg90HI","Starminx Cube TUTORIAL PL 1/2","MrUK"},
418
                          {"pl","nH2doGM1Das","Starminx Cube TUTORIAL PL 2/2","MrUK"},
419
                          {"kr","8bIQVCKWBvw","스타밍크스 해법  1/2","듀나메스 큐브 해법연구소"},
420
                          {"kr","4WU5iJyM7jI","스타밍크스 해법  2/2","듀나메스 큐브 해법연구소"},
421
                          {"vn","QhSaboIX3Fs","Tutorial N.183 - Starminx","Duy Thích Rubik"},
422
                         };
423
    }
424
}