Project

General

Profile

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

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

1 8409826d 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 2af26e29 Leszek Koltunski
import java.io.InputStream;
23
24 8409826d Leszek Koltunski
import org.distorted.library.type.Static3D;
25
import org.distorted.library.type.Static4D;
26
import org.distorted.objectlib.helpers.ObjectFaceShape;
27
import org.distorted.objectlib.helpers.ObjectShape;
28 1d581993 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectSignature;
29 8409826d Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
30
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 2af26e29 Leszek Koltunski
public class TwistyCrystal extends TwistyMinx
34 8409826d Leszek Koltunski
{
35 2af26e29 Leszek Koltunski
  private static final float A = (SQ5+5)/10;
36 8409826d Leszek Koltunski
37
  private float[][] mCuts;
38
  private float[][] mPosition;
39
  private int[] mQuatIndex;
40
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 3bf19410 Leszek Koltunski
  public TwistyCrystal(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
44 8409826d Leszek Koltunski
    {
45 3bf19410 Leszek Koltunski
    super(numL, meshState, iconMode, quat, move, scale, stream);
46 8409826d Leszek Koltunski
    }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50
  public float[][] getCubitPositions(int[] numLayers)
51
    {
52
    if( mPosition==null )
53
      {
54
      if( mEdgeMap==null ) initializeEdgeMap();
55
      if( mCenterCoords==null ) initializeCenterCoords();
56
57
      mPosition = new float[NUM_EDGES+NUM_CORNERS][3];
58
59
      for(int edge=0; edge<NUM_EDGES; edge++)
60
        {
61
        float[] c1 = mCorners[ mEdgeMap[edge][0] ];
62
        float[] c2 = mCorners[ mEdgeMap[edge][1] ];
63
64
        mPosition[edge][0] = (c1[0]+c2[0])/2;
65
        mPosition[edge][1] = (c1[1]+c2[1])/2;
66
        mPosition[edge][2] = (c1[2]+c2[2])/2;
67
        }
68
69
      System.arraycopy(mCorners, 0, mPosition, NUM_EDGES, NUM_CORNERS);
70
      }
71
72
    return mPosition;
73
    }
74
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
77
  public Static4D getCubitQuats(int cubit, int[] numLayers)
78
    {
79 a4af26c1 Leszek Koltunski
    if( mQuatIndex==null ) mQuatIndex = new int[] {  0,17,12,13,20, 4,25, 5,24,16,
80 8409826d Leszek Koltunski
                                                     9,21, 1,34, 8,11,30,43,26,14,
81
                                                    15,45,33,28,10, 2,29, 6, 7, 3,
82
83
                                                     0, 2,20,42,13,41,16,33, 8,51,
84
                                                     1,25,12,27, 4, 3,21,28, 5, 6 };
85
    return mObjectQuats[mQuatIndex[cubit]];
86
    }
87
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
90
  public ObjectShape getObjectShape(int variant)
91
    {
92 a4af26c1 Leszek Koltunski
    float[] blueCenter = mCenterCoords[0];
93
    float[] greeCenter = mCenterCoords[1];
94
    float[] pinkCenter = mCenterCoords[2];
95
96 8409826d Leszek Koltunski
    if( variant==0 )
97
      {
98 a4af26c1 Leszek Koltunski
      float B = greeCenter[2]-mCorners[0][2];
99 8409826d Leszek Koltunski
      float C = A*mCorners[0][1]+(1.0f-A)*mCorners[2][1];
100 a4af26c1 Leszek Koltunski
      float D = greeCenter[0];
101 8409826d Leszek Koltunski
102
      float[][] vertices =
103
         {
104
             { 0.0f, C, 0,0f },
105
             { 0.0f,-C, 0,0f },
106
             {   -D,0.0f,  B },
107
             {   +D,0.0f,  B },
108
         };
109
      int[][] indices =
110
         {
111
             {1,0,2},
112
             {0,1,3},
113
             {2,3,1},
114
             {3,2,0}
115
         };
116
117
      return new ObjectShape(vertices, indices);
118
      }
119
    else
120
      {
121
      float X = mCorners[0][0];
122
      float Y = mCorners[0][1];
123
      float Z = mCorners[0][2];
124
125
      float X1 = A*mCorners[0][0]+(1.0f-A)*mCorners[16][0];
126
      float Y1 = A*mCorners[0][1]+(1.0f-A)*mCorners[16][1];
127
      float Z1 = A*mCorners[0][2]+(1.0f-A)*mCorners[16][2];
128
      float X2 = A*mCorners[0][0]+(1.0f-A)*mCorners[12][0];
129
      float Y2 = A*mCorners[0][1]+(1.0f-A)*mCorners[12][1];
130
      float Z2 = A*mCorners[0][2]+(1.0f-A)*mCorners[12][2];
131
      float X3 = A*mCorners[0][0]+(1.0f-A)*mCorners[ 2][0];
132
      float Y3 = A*mCorners[0][1]+(1.0f-A)*mCorners[ 2][1];
133
      float Z3 = A*mCorners[0][2]+(1.0f-A)*mCorners[ 2][2];
134
135
      float[][] vertices =
136
         {
137
             {0.0f, 0.0f, 0.0f},
138
             {X1-X, Y1-Y, Z1-Z},
139
             {X2-X, Y2-Y, Z2-Z},
140
             {X3-X, Y3-Y, Z3-Z},
141 a4af26c1 Leszek Koltunski
             { greeCenter[0]-X, greeCenter[1]-Y, greeCenter[2]-Z },
142
             { pinkCenter[0]-X, pinkCenter[1]-Y, pinkCenter[2]-Z },
143
             { blueCenter[0]-X, blueCenter[1]-Y, blueCenter[2]-Z }
144 8409826d Leszek Koltunski
         };
145
      int[][] indices =
146
         {
147
             { 5,3,0,1 },
148
             { 4,2,0,3 },
149
             { 6,1,0,2 },
150
             { 5,4,3 },
151
             { 4,6,2 },
152
             { 6,5,1 },
153
             { 6,4,5 }
154
         };
155
156
      return new ObjectShape(vertices, indices);
157
      }
158
    }
159
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162
  public ObjectFaceShape getObjectFaceShape(int variant)
163
    {
164
    if( variant==0 )
165
      {
166 3bf19410 Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.03f;
167
      float h2 = isInIconMode() ? 0.001f : 0.01f;
168
      float[][] bands     = { {h1,17,0.5f,0.2f,5,1,0}, {h2, 1,0.5f,0.2f,5,1,0} };
169 8409826d Leszek Koltunski
      int[] bandIndices   = { 0,0,1,1 };
170
      float[][] corners   = { { 0.015f, 0.20f } };
171
      int[] cornerIndices = { 0,0,0,0 };
172
      float[][] centers   = { { 0.0f,0.0f,-mCorners[0][2] } };
173
      int[] centerIndices = { 0,0,0,0 };
174
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
175
      }
176
    else
177
      {
178 3bf19410 Leszek Koltunski
      float h1 = isInIconMode() ? 0.001f : 0.03f;
179
      float h2 = isInIconMode() ? 0.001f : 0.01f;
180
      float[][] bands     = { {h1,17,0.5f,0.2f,5,1,0}, {h2, 1,0.5f,0.2f,5,1,0}, {h2, 1,0.5f,0.2f,3,0,0} };
181 8409826d Leszek Koltunski
      int[] bandIndices   = { 0,0,0,1,1,1,2 };
182
      float[][] corners   = { { 0.01f, 0.20f } };
183
      int[] cornerIndices = { 0,0,0,0,0,0,0 };
184
      float[][] centers   = { { 0.0f,-1.5f,-mCorners[0][2] } };
185
      int[] centerIndices = { 0,0,0,0,0,0,0 };
186
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
187
      }
188
    }
189
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
192
  public int getNumCubitVariants(int[] numLayers)
193
    {
194
    return 2;
195
    }
196
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
199
  public int getCubitVariant(int cubit, int[] numLayers)
200
    {
201
    return cubit<NUM_EDGES ? 0:1;
202
    }
203
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205
206
  public float[][] getCuts(int[] numLayers)
207
    {
208
    if( mCuts==null )
209
      {
210 be694bb0 Leszek Koltunski
      float CUT = 1.5f; // TODO
211 8409826d Leszek Koltunski
      float[] cut = new float[] { -CUT,+CUT };
212
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
213
      }
214
215
    return mCuts;
216
    }
217
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
220
  public float getStickerRadius()
221
    {
222
    return 0.18f;
223
    }
224
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226
227
  public float getStickerStroke()
228
    {
229 3bf19410 Leszek Koltunski
    return isInIconMode() ? 0.22f : 0.15f;
230 8409826d Leszek Koltunski
    }
231
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233
234
  public float[][] getStickerAngles()
235
    {
236
    return null;
237
    }
238
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240
// PUBLIC API
241
242
  public String getShortName()
243
    {
244
    return ObjectType.CRYS_3.name();
245
    }
246
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248
249 1d581993 Leszek Koltunski
  public ObjectSignature getSignature()
250 8409826d Leszek Koltunski
    {
251 1d581993 Leszek Koltunski
    return new ObjectSignature(ObjectType.CRYS_3);
252 8409826d Leszek Koltunski
    }
253
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255
256
  public String getObjectName()
257
    {
258
    return "Pyraminx Crystal";
259
    }
260
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262
263
  public String getInventor()
264
    {
265
    return "Aleh Hladzilin";
266
    }
267
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269
270
  public int getYearOfInvention()
271
    {
272
    return 2006;
273
    }
274
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276
277
  public int getComplexity()
278
    {
279
    return 3;
280
    }
281
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283
284
  public String[][] getTutorials()
285
    {
286
    return new String[][]{
287 726f9e63 Leszek Koltunski
                          {"gb","tFSGC9esay0","Pyraminx Crystal Tutorial","twistypuzzling"},
288
                          {"es","AmrIwSICFB8","Como resolver Pyraminx Crystal","Tutoriales Rubik"},
289
                          {"ru","3AKeT8JIU0E","Как собрать Crystal Pyraminx","RBcuber"},
290
                          {"fr","SPsrHhQzmVg","Résolution du Pyraminx Crystal","asthalis"},
291
                          {"de","EH4sw7_21eA","Crystal Pyraminx Tutorial","GerCubing"},
292
                          {"pl","AmrIwSICFB8","Crystal Pyraminx TUTORIAL PL","MrUK"},
293 bae32b77 Leszek Koltunski
                          {"br","13pz0cNBVow","Como resolver o Pyraminx Crystal 1/3","RafaelCinoto"},
294
                          {"br","eT654oZsBg0","Como resolver o Pyraminx Crystal 2/3","RafaelCinoto"},
295
                          {"br","MnooQbVFbfU","Como resolver o Pyraminx Crystal 3/3","RafaelCinoto"},
296 726f9e63 Leszek Koltunski
                          {"kr","o-w_ZzDrfFU","피라밍크스 크리스탈 해법 1/2","SlowCuberToumai"},
297
                          {"kr","ExMg8SAge4Q","피라밍크스 크리스탈 해법 2/2","SlowCuberToumai"},
298 a399e91b Leszek Koltunski
                          {"vn","MxF4bKlnIMU","Tutorial N.28 - Pyraminx Crystal","Duy Thích Rubik"},
299 8409826d Leszek Koltunski
                         };
300
    }
301
}