Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyContainer.java @ ccd8a6f2

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 java.io.InputStream;
13

    
14
import org.distorted.library.type.Static3D;
15
import org.distorted.library.type.Static4D;
16
import org.distorted.objectlib.helpers.FactoryCubit;
17
import org.distorted.objectlib.helpers.ObjectFaceShape;
18
import org.distorted.objectlib.helpers.ObjectShape;
19
import org.distorted.objectlib.helpers.ObjectSignature;
20
import org.distorted.objectlib.helpers.ObjectVertexEffects;
21
import org.distorted.objectlib.main.ObjectSignatures;
22
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
23
import org.distorted.objectlib.main.InitData;
24
import org.distorted.objectlib.main.ObjectType;
25
import org.distorted.objectlib.shape.ShapeHexahedron;
26
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
27

    
28
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING_SHAPEMOD;
29
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class TwistyContainer extends ShapeHexahedron
34
{
35
  static final Static3D[] ROT_AXIS = new Static3D[]
36
         {
37
           new Static3D( SQ6/3,-SQ3/3,  0.0f),
38
           new Static3D( SQ6/3, SQ3/3,  0.0f),
39
           new Static3D(  0.0f,-SQ3/3, SQ6/3),
40
           new Static3D(  0.0f, SQ3/3, SQ6/3)
41
         };
42

    
43
  private int[][] mEdges;
44
  private int[][] mBasicAngle;
45
  private float[][] mCuts;
46
  private int[][] mFaceMap;
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  public TwistyContainer(InitData data, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream stream)
51
    {
52
    super(data, meshState, iconMode, data.getNumLayers()[0], quat, move, scale, stream);
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
// we want colorful insides
57

    
58
  @Override
59
  public int getCubitFaceMap(int cubit, int face)
60
    {
61
    if( mFaceMap==null )
62
      {
63
      mFaceMap = new int[][]
64
         {
65
             { 3, 3, 3, 3, 3, 3},
66
             { 2, 2, 2, 2, 2, 2},
67

    
68
             { 0, 5, 5, 0, 0, 5},
69
             { 5, 1, 1, 5, 5, 1},
70
             { 1, 4, 4, 1, 1, 4},
71
             { 4, 0, 0, 4, 4, 0},
72

    
73
             { 4, 4, 4, 4, 4, 4},
74
             { 4, 4, 4, 4, 4, 4},
75
             { 0, 0, 0, 0, 0, 0},
76
             { 0, 0, 0, 0, 0, 0},
77
             { 5, 5, 5, 5, 5, 5},
78
             { 5, 5, 5, 5, 5, 5},
79
             { 1, 1, 1, 1, 1, 1},
80
             { 1, 1, 1, 1, 1, 1},
81
         };
82
      }
83

    
84
    return mFaceMap[cubit][face];
85
    }
86

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

    
89
  public int[][] getScrambleEdges()
90
    {
91
    if( mEdges==null ) mEdges = ScrambleEdgeGenerator.getScrambleEdgesSingle(mBasicAngle);
92
    return mEdges;
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  public float[][] getCuts(int[] numLayers)
98
    {
99
    if( mCuts==null )
100
      {
101
      float[] c = {0};
102
      mCuts = new float[][] {c,c,c,c};
103
      }
104

    
105
    return mCuts;
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
  public boolean[][] getLayerRotatable(int[] numLayers)
111
    {
112
    boolean[] tmp = {true,true};
113
    return new boolean[][] { tmp,tmp,tmp,tmp };
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  public int getTouchControlType()
119
    {
120
    return TC_CHANGING_SHAPEMOD;
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
  public int getTouchControlSplit()
126
    {
127
    return TYPE_NOT_SPLIT;
128
    }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
  public int[][][] getEnabled()
133
    {
134
    return null;
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  public float[] getDist3D(int[] numLayers)
140
    {
141
    return new float[] { 0.5f,0.5f,SQ2/2,SQ2/2,0.5f,0.5f};
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  public Static3D[] getFaceAxis()
147
    {
148
    return TouchControlHexahedron.FACE_AXIS;
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  public float[][] getCubitPositions(int[] numLayers)
154
    {
155
    return new float[][]
156
        {
157
            { 0.0f,  -SQ2, 0.0f},
158
            { 0.0f,   SQ2, 0.0f},
159

    
160
            { 1.0f,  0.0f,-1.0f},
161
            {-1.0f,  0.0f,-1.0f},
162
            {-1.0f,  0.0f, 1.0f},
163
            { 1.0f,  0.0f, 1.0f},
164

    
165
            { 0.0f,-SQ2/2, 1.0f},
166
            { 0.0f, SQ2/2, 1.0f},
167
            { 1.0f,-SQ2/2, 0.0f},
168
            { 1.0f, SQ2/2, 0.0f},
169
            { 0.0f,-SQ2/2,-1.0f},
170
            { 0.0f, SQ2/2,-1.0f},
171
            {-1.0f,-SQ2/2, 0.0f},
172
            {-1.0f, SQ2/2, 0.0f},
173
        };
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

    
178
  public Static4D getCubitQuats(int cubit, int[] numLayers)
179
    {
180
    switch(cubit)
181
      {
182
      case  0: return mObjectQuats[ 0];
183
      case  1: return mObjectQuats[10];
184

    
185
      case  2: return mObjectQuats[ 0];
186
      case  3: return new Static4D( 0.0f, SQ2/2, 0.0f,-SQ2/2);
187
      case  4: return mObjectQuats[11];
188
      case  5: return new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2);
189

    
190
      case  6: return mObjectQuats[ 0];
191
      case  7: return new Static4D( 0.0f, 0.0f, 1.0f, 0.0f);
192
      case  8: return new Static4D( 0.0f, SQ2/2, 0.0f,-SQ2/2);
193
      case  9: return mObjectQuats[10];
194
      case 10: return mObjectQuats[11];
195
      case 11: return new Static4D( 1.0f, 0.0f, 0.0f, 0.0f);
196
      case 12: return new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2);
197
      case 13: return mObjectQuats[ 9];
198
      }
199

    
200
    return null;
201
    }
202

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

    
205
  private float[][] getVertices(int variant)
206
    {
207
    if( variant==0 )
208
      {
209
      return new float[][] { {-1,0,1},{1,0,1},{1,0,-1},{-1,0,-1},{0,SQ2,0} };
210
      }
211
    else if( variant==1 )
212
      {
213
      return new float[][] { {-1,0,1},{0,0,1},{-1,0,0},{0,SQ2,0},{0,-SQ2,0} };
214
      }
215
    else
216
      {
217
      return new float[][] { {-1,-SQ2/2,0},{1,-SQ2/2,0},{0,SQ2/2,0},{0,SQ2/2,-1} };
218
      }
219
    }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
  public ObjectShape getObjectShape(int variant)
224
    {
225
    if( variant==0 )
226
      {
227
      int[][] indices = { {3,2,1,0},{0,1,4},{1,2,4},{2,3,4},{3,0,4} };
228
      return new ObjectShape(getVertices(variant), indices);
229
      }
230
    else if( variant==1 )
231
      {
232
      int[][] indices = { {4,3,1},{4,2,3},{2,0,3},{3,0,1},{1,0,4},{0,2,4} };
233
      return new ObjectShape(getVertices(variant), indices);
234
      }
235
    else
236
      {
237
      int[][] indices = { {0,1,2},{0,2,3},{1,3,2},{1,0,3} };
238
      return new ObjectShape(getVertices(variant), indices);
239
      }
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  public ObjectFaceShape getObjectFaceShape(int variant)
245
    {
246
    if( variant==0 )
247
      {
248
      float h1 = isInIconMode() ? 0.001f : 0.05f;
249
      float h2 = isInIconMode() ? 0.001f : 0.01f;
250
      float[][] bands   = { {h1,35,0.26f,0.7f,5,1,1}, {h2,15,0.1f,0.7f,5,1,1} };
251
      int[] bandIndices = { 0,1,1,1,1 };
252
      return new ObjectFaceShape(bands,bandIndices,null);
253
      }
254
    else if( variant==1 )
255
      {
256
      float h1 = isInIconMode() ? 0.001f : 0.04f;
257
      float h2 = isInIconMode() ? 0.001f : 0.01f;
258
      float[][] bands   = { {h1,25,0.26f,0.7f,5,1,1}, {h2,15,0.1f,0.7f,5,1,1} };
259
      int[] bandIndices = { 0,0,1,1,1,1 };
260
      return new ObjectFaceShape(bands,bandIndices,null);
261
      }
262
    else
263
      {
264
      float h1 = isInIconMode() ? 0.001f : 0.05f;
265
      float h2 = isInIconMode() ? 0.001f : 0.01f;
266
      float[][] bands   = { {h1,35,0.26f,0.7f,5,1,1}, {h2,15,0.1f,0.7f,5,1,1} };
267
      int[] bandIndices = { 0,1,1,1 };
268
      return new ObjectFaceShape(bands,bandIndices,null);
269
      }
270
    }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

    
274
  public ObjectVertexEffects getVertexEffects(int variant)
275
    {
276
    if( variant==0 )
277
      {
278
      float[][] corners = { {0.03f,0.20f} };
279
      int[] indices     = { 0,0,0,0,-1 };
280
      float[][] centers = { { 0.0f, SQ2, 0.0f} };
281
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
282
      }
283
    else if( variant==1 )
284
      {
285
      float[][] corners = { {0.03f,0.20f} };
286
      int[] indices     = { -1,0,0,0,0 };
287
      float[][] centers = { {-1,0,1} };
288
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
289
      }
290
    else
291
      {
292
      float[][] corners = { {0.03f,0.20f} };
293
      int[] indices     = { 0,0,0,-1 };
294
      float[][] centers = { {0.0f, SQ2/2, -1.0f} };
295
      return FactoryCubit.generateVertexEffect(getVertices(variant),corners,indices,centers,indices);
296
      }
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
  public int getNumCubitVariants(int[] numLayers)
302
    {
303
    return 3;
304
    }
305

    
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307

    
308
  public int getCubitVariant(int cubit, int[] numLayers)
309
    {
310
    return cubit<2 ? 0 : (cubit<6 ? 1:2);
311
    }
312

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

    
315
  public float getStickerRadius()
316
    {
317
    return 0.10f;
318
    }
319

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

    
322
  public float getStickerStroke()
323
    {
324
    return isInIconMode() ? 0.20f : 0.06f;
325
    }
326

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

    
329
  public float[][] getStickerAngles()
330
    {
331
    return null;
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335
// PUBLIC API
336

    
337
  public Static3D[] getRotationAxis()
338
    {
339
    return ROT_AXIS;
340
    }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
  public int[][] getBasicAngles()
345
    {
346
    if( mBasicAngle ==null )
347
      {
348
      int num = getNumLayers()[0];
349
      int[] tmp = new int[num];
350
      for(int i=0; i<num; i++) tmp[i] = 3;
351
      mBasicAngle = new int[][] { tmp,tmp,tmp,tmp };
352
      }
353

    
354
    return mBasicAngle;
355
    }
356

    
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

    
359
  public String getShortName()
360
    {
361
    return ObjectType.CONT_2.name();
362
    }
363

    
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365

    
366
  public ObjectSignature getSignature()
367
    {
368
    return new ObjectSignature(ObjectSignatures.CONT_2);
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
  public String getObjectName()
374
    {
375
    return "Container";
376
    }
377

    
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379

    
380
  public String getInventor()
381
    {
382
    return "Tony Fisher";
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
  public int getYearOfInvention()
388
    {
389
    return 1998;
390
    }
391

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

    
394
  public int getComplexity()
395
    {
396
    return 2;
397
    }
398

    
399
///////////////////////////////////////////////////////////////////////////////////////////////////
400

    
401
  public String[][] getTutorials()
402
    {
403
    return new String[][] {
404
                          {"gb","THndZ2H7OO4","Container Cube Tutorial","SuperAntoniovivaldi"},
405
                          {"es","8K2PeCAcpNU","Tutorial Container Puzzle","GioMart"},
406
                          {"ru","rh3rMuESOIM","Как собрать Container cube","RubicsGuide"},
407
                          {"fr","V4lmnbLjUdc","Résolution du Container Cube","skieur cubb"},
408
                          {"de","TRJEIgcda0Y","Container Cube Tutorial","Pezcraft"},
409
                          {"pl","jdJpUc-LaKY","Container Cube TUTORIAL PL","MrUK"},
410
                          {"br","44JnUyGTAD8","Tutorial do Cubo Container","Cubo vicio"},
411
                          {"kr","6HJKHLxaIPk","컨테이너 큐브 해법 강좌","굿맨's 큐브 이야기"},
412
                          {"vn","RLD9srIrDcI","Tutorial N.97 - Container","Duy Thích Rubik"},
413
                         };
414
    }
415
}
(5-5/41)