Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyCrystal.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 java.io.InputStream;
23

    
24
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
import org.distorted.objectlib.main.ObjectType;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
public class TwistyCrystal extends TwistyMinx
33
{
34
  private static final float A = (SQ5+5)/10;
35

    
36
  private float[][] mCuts;
37
  private float[][] mPosition;
38
  private int[] mQuatIndex;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
  public TwistyCrystal(int[] numL, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
43
    {
44
    super(numL, meshState, iconMode, quat, move, scale, stream);
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public float[][] getCubitPositions(int[] numLayers)
50
    {
51
    if( mPosition==null )
52
      {
53
      if( mEdgeMap==null ) initializeEdgeMap();
54
      if( mCenterCoords==null ) initializeCenterCoords();
55

    
56
      mPosition = new float[NUM_EDGES+NUM_CORNERS][3];
57

    
58
      for(int edge=0; edge<NUM_EDGES; edge++)
59
        {
60
        float[] c1 = mCorners[ mEdgeMap[edge][0] ];
61
        float[] c2 = mCorners[ mEdgeMap[edge][1] ];
62

    
63
        mPosition[edge][0] = (c1[0]+c2[0])/2;
64
        mPosition[edge][1] = (c1[1]+c2[1])/2;
65
        mPosition[edge][2] = (c1[2]+c2[2])/2;
66
        }
67

    
68
      System.arraycopy(mCorners, 0, mPosition, NUM_EDGES, NUM_CORNERS);
69
      }
70

    
71
    return mPosition;
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  public Static4D getCubitQuats(int cubit, int[] numLayers)
77
    {
78
    if( mQuatIndex==null ) mQuatIndex = new int[] {  0,17,12,13,20, 4,25, 5,24,16,
79
                                                     9,21, 1,34, 8,11,30,43,26,14,
80
                                                    15,45,33,28,10, 2,29, 6, 7, 3,
81

    
82
                                                     0, 2,20,42,13,41,16,33, 8,51,
83
                                                     1,25,12,27, 4, 3,21,28, 5, 6 };
84
    return mObjectQuats[mQuatIndex[cubit]];
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  public ObjectShape getObjectShape(int variant)
90
    {
91
    float[] blueCenter = mCenterCoords[0];
92
    float[] greeCenter = mCenterCoords[1];
93
    float[] pinkCenter = mCenterCoords[2];
94

    
95
    if( variant==0 )
96
      {
97
      float B = greeCenter[2]-mCorners[0][2];
98
      float C = A*mCorners[0][1]+(1.0f-A)*mCorners[2][1];
99
      float D = greeCenter[0];
100

    
101
      float[][] vertices =
102
         {
103
             { 0.0f, C, 0,0f },
104
             { 0.0f,-C, 0,0f },
105
             {   -D,0.0f,  B },
106
             {   +D,0.0f,  B },
107
         };
108
      int[][] indices =
109
         {
110
             {1,0,2},
111
             {0,1,3},
112
             {2,3,1},
113
             {3,2,0}
114
         };
115

    
116
      return new ObjectShape(vertices, indices);
117
      }
118
    else
119
      {
120
      float X = mCorners[0][0];
121
      float Y = mCorners[0][1];
122
      float Z = mCorners[0][2];
123

    
124
      float X1 = A*mCorners[0][0]+(1.0f-A)*mCorners[16][0];
125
      float Y1 = A*mCorners[0][1]+(1.0f-A)*mCorners[16][1];
126
      float Z1 = A*mCorners[0][2]+(1.0f-A)*mCorners[16][2];
127
      float X2 = A*mCorners[0][0]+(1.0f-A)*mCorners[12][0];
128
      float Y2 = A*mCorners[0][1]+(1.0f-A)*mCorners[12][1];
129
      float Z2 = A*mCorners[0][2]+(1.0f-A)*mCorners[12][2];
130
      float X3 = A*mCorners[0][0]+(1.0f-A)*mCorners[ 2][0];
131
      float Y3 = A*mCorners[0][1]+(1.0f-A)*mCorners[ 2][1];
132
      float Z3 = A*mCorners[0][2]+(1.0f-A)*mCorners[ 2][2];
133

    
134
      float[][] vertices =
135
         {
136
             {0.0f, 0.0f, 0.0f},
137
             {X1-X, Y1-Y, Z1-Z},
138
             {X2-X, Y2-Y, Z2-Z},
139
             {X3-X, Y3-Y, Z3-Z},
140
             { greeCenter[0]-X, greeCenter[1]-Y, greeCenter[2]-Z },
141
             { pinkCenter[0]-X, pinkCenter[1]-Y, pinkCenter[2]-Z },
142
             { blueCenter[0]-X, blueCenter[1]-Y, blueCenter[2]-Z }
143
         };
144
      int[][] indices =
145
         {
146
             { 5,3,0,1 },
147
             { 4,2,0,3 },
148
             { 6,1,0,2 },
149
             { 5,4,3 },
150
             { 4,6,2 },
151
             { 6,5,1 },
152
             { 6,4,5 }
153
         };
154

    
155
      return new ObjectShape(vertices, indices);
156
      }
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public ObjectFaceShape getObjectFaceShape(int variant)
162
    {
163
    if( variant==0 )
164
      {
165
      float h1 = isInIconMode() ? 0.001f : 0.03f;
166
      float h2 = isInIconMode() ? 0.001f : 0.01f;
167
      float[][] bands     = { {h1,17,0.5f,0.2f,5,1,0}, {h2, 1,0.5f,0.2f,5,1,0} };
168
      int[] bandIndices   = { 0,0,1,1 };
169
      float[][] corners   = { { 0.015f, 0.20f } };
170
      int[] cornerIndices = { 0,0,0,0 };
171
      float[][] centers   = { { 0.0f,0.0f,-mCorners[0][2] } };
172
      int[] centerIndices = { 0,0,0,0 };
173
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
174
      }
175
    else
176
      {
177
      float h1 = isInIconMode() ? 0.001f : 0.03f;
178
      float h2 = isInIconMode() ? 0.001f : 0.01f;
179
      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} };
180
      int[] bandIndices   = { 0,0,0,1,1,1,2 };
181
      float[][] corners   = { { 0.01f, 0.20f } };
182
      int[] cornerIndices = { 0,0,0,0,0,0,0 };
183
      float[][] centers   = { { 0.0f,-1.5f,-mCorners[0][2] } };
184
      int[] centerIndices = { 0,0,0,0,0,0,0 };
185
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
186
      }
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
  public int getNumCubitVariants(int[] numLayers)
192
    {
193
    return 2;
194
    }
195

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

    
198
  public int getCubitVariant(int cubit, int[] numLayers)
199
    {
200
    return cubit<NUM_EDGES ? 0:1;
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  public float[][] getCuts(int[] numLayers)
206
    {
207
    if( mCuts==null )
208
      {
209
      float CUT = 1.5f; // TODO
210
      float[] cut = new float[] { -CUT,+CUT };
211
      mCuts = new float[][] { cut,cut,cut,cut,cut,cut };
212
      }
213

    
214
    return mCuts;
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  public float getStickerRadius()
220
    {
221
    return 0.18f;
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public float getStickerStroke()
227
    {
228
    return isInIconMode() ? 0.22f : 0.15f;
229
    }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

    
233
  public float[][] getStickerAngles()
234
    {
235
    return null;
236
    }
237

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239
// PUBLIC API
240

    
241
  public String getShortName()
242
    {
243
    return ObjectType.CRYS_3.name();
244
    }
245

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

    
248
  public long getSignature()
249
    {
250
    return ObjectType.CRYS_3.ordinal();
251
    }
252

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

    
255
  public String getObjectName()
256
    {
257
    return "Pyraminx Crystal";
258
    }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

    
262
  public String getInventor()
263
    {
264
    return "Aleh Hladzilin";
265
    }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
  public int getYearOfInvention()
270
    {
271
    return 2006;
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
  public int getComplexity()
277
    {
278
    return 3;
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
  public String[][] getTutorials()
284
    {
285
    return new String[][]{
286
                          {"gb","tFSGC9esay0","Pyraminx Crystal Tutorial","twistypuzzling"},
287
                          {"es","AmrIwSICFB8","Como resolver Pyraminx Crystal","Tutoriales Rubik"},
288
                          {"ru","3AKeT8JIU0E","Как собрать Crystal Pyraminx","RBcuber"},
289
                          {"fr","SPsrHhQzmVg","Résolution du Pyraminx Crystal","asthalis"},
290
                          {"de","EH4sw7_21eA","Crystal Pyraminx Tutorial","GerCubing"},
291
                          {"pl","AmrIwSICFB8","Crystal Pyraminx TUTORIAL PL","MrUK"},
292
                          {"br","13pz0cNBVow","Como resolver o Pyraminx Crystal 1/3","RafaelCinoto"},
293
                          {"br","eT654oZsBg0","Como resolver o Pyraminx Crystal 2/3","RafaelCinoto"},
294
                          {"br","MnooQbVFbfU","Como resolver o Pyraminx Crystal 3/3","RafaelCinoto"},
295
                          {"kr","o-w_ZzDrfFU","피라밍크스 크리스탈 해법 1/2","SlowCuberToumai"},
296
                          {"kr","ExMg8SAge4Q","피라밍크스 크리스탈 해법 2/2","SlowCuberToumai"},
297
                          {"vn","MxF4bKlnIMU","Tutorial N.28 - Pyraminx Crystal","Duy Thích Rubik"},
298
                         };
299
    }
300
}
(9-9/36)