Project

General

Profile

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

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

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.helpers.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.metadata.Metadata;
19
import org.distorted.objectlib.helpers.ObjectVertexEffects;
20
import org.distorted.objectlib.main.InitAssets;
21
import org.distorted.objectlib.metadata.ListObjects;
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 TwistyDodecahedron
31
{
32
  private float[][] mCuts;
33
  private float[][] mPosition;
34
  private int[] mQuatIndex;
35

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

    
38
  public TwistyStarminx(int iconMode, Static4D quat, Static3D move, float scale, Metadata meta, InitAssets asset)
39
    {
40
    super(iconMode, quat, move, scale, meta, asset);
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 ) mEdgeMap = 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
  private float[][] getVertices(int variant)
168
    {
169
    if( variant==0 )
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
      return new float[][]
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
      }
188
    else if( variant==1 )
189
      {
190
      final double ANGLE = 0.825f*Math.PI;
191
      final float cosA  = (float)Math.cos(ANGLE);
192
      final float sinA  = (float)Math.sin(ANGLE);
193

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

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

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

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

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

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

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

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

    
276
      return new ObjectShape(getVertices(variant), indices);
277
      }
278
    }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
  public ObjectFaceShape getObjectFaceShape(int variant)
283
    {
284
    int angle = 15;
285
    float R = 0.7f;
286
    float S = 0.5f;
287

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

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

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

    
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345

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

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

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

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

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

    
369
    return mCuts;
370
    }
371

    
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

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

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

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

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387

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

    
393
///////////////////////////////////////////////////////////////////////////////////////////////////
394
// PUBLIC API
395

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

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402

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