Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyJing.java @ 59a971c1

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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 static org.distorted.objectlib.touchcontrol.TouchControl.TC_TETRAHEDRON;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
24

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.helpers.ObjectFaceShape;
31
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
32
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ScrambleState;
36
import org.distorted.objectlib.main.ShapeTetrahedron;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TwistyJing extends ShapeTetrahedron
41
{
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
44
           new Static3D(     0,-SQ3/3,-SQ6/3),
45
           new Static3D(     0,-SQ3/3,+SQ6/3),
46
           new Static3D(+SQ6/3,+SQ3/3,     0),
47
           new Static3D(-SQ6/3,+SQ3/3,     0),
48
         };
49

    
50
  static final float F = 0.48f;  // length of the edge of the corner cubit. Keep<0.5
51
                                 // Assuming the length of the edge of the whole
52
                                 // tetrahedron is 2.0 (ie standard, equal to numLayers)
53

    
54
  private ScrambleState[] mStates;
55
  private int[] mBasicAngle;
56
  private int[] mRotQuat;
57
  private Static4D[] mQuats;
58
  private float[][] mCuts;
59
  private float[][] mCenters;
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  public TwistyJing(int[] numL, int meshState, Static4D quat, Static3D move, float scale, InputStream stream)
64
    {
65
    super(numL, meshState, numL[0], quat, move, scale, stream);
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
  public ScrambleState[] getScrambleStates()
71
    {
72
    if( mStates==null )
73
      {
74
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
75

    
76
      mStates = new ScrambleState[]
77
        {
78
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
79
        };
80
      }
81

    
82
    return mStates;
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  private void initializeQuats()
88
    {
89
    mQuats = new Static4D[]
90
         {
91
         new Static4D(  0.0f,   0.0f,   0.0f,  1.0f),
92
         new Static4D(  0.0f,   1.0f,   0.0f,  0.0f),
93
         new Static4D( SQ2/2,   0.5f,   0.0f,  0.5f),
94
         new Static4D(-SQ2/2,   0.5f,   0.0f,  0.5f),
95
         new Static4D(  0.0f,  -0.5f, -SQ2/2,  0.5f),
96
         new Static4D(  0.0f,  -0.5f,  SQ2/2,  0.5f),
97
         new Static4D( SQ2/2,   0.5f,   0.0f, -0.5f),
98
         new Static4D(-SQ2/2,   0.5f,   0.0f, -0.5f),
99
         new Static4D(  0.0f,  -0.5f, -SQ2/2, -0.5f),
100
         new Static4D(  0.0f,  -0.5f,  SQ2/2, -0.5f),
101
         new Static4D( SQ2/2,   0.0f,  SQ2/2,  0.0f),
102
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,  0.0f)
103
         };
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public int[] getSolvedQuats(int cubit, int[] numLayers)
109
    {
110
    if( mQuats==null ) initializeQuats();
111
    int status = retCubitSolvedStatus(cubit,numLayers);
112
    return status<0 ? null : buildSolvedQuats(TouchControlTetrahedron.FACE_AXIS[status],mQuats);
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
  public float[][] getCubitPositions(int[] numLayers)
118
    {
119
    if( mCenters==null )
120
      {
121
      mCenters = new float[][]
122
         {
123
           { 0.000f, -SQ2/2, 1.000f },
124
           { 0.000f, -SQ2/2,-1.000f },
125
           {-1.000f,  SQ2/2, 0.000f },
126
           { 1.000f,  SQ2/2, 0.000f },
127

    
128
           { 0.000f, -SQ2/2, 0.000f },
129
           {-0.500f, 0.000f, 0.500f },
130
           { 0.500f, 0.000f, 0.500f },
131
           {-0.500f, 0.000f,-0.500f },
132
           { 0.500f, 0.000f,-0.500f },
133
           { 0.000f,  SQ2/2, 0.000f },
134

    
135
           { 0.000f,  SQ2/6, 1.0f/3 },
136
           { 0.000f,  SQ2/6,-1.0f/3 },
137
           {-1.0f/3, -SQ2/6, 0.000f },
138
           { 1.0f/3, -SQ2/6, 0.000f },
139
         };
140
      }
141

    
142
    return mCenters;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  public Static4D[] getQuats()
148
    {
149
    if( mQuats==null ) initializeQuats();
150
    return mQuats;
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  public int getSolvedFunctionIndex()
156
    {
157
    return 0;
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  public float[][] getCuts(int[] numLayers)
163
    {
164
    if( mCuts==null )
165
      {
166
      float[] cut = { (F-0.5f)*(SQ6/3) };
167
      mCuts = new float[][] { cut,cut,cut,cut };
168
      }
169

    
170
    return mCuts;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  public boolean[][] getLayerRotatable(int[] numLayers)
176
    {
177
    boolean[] tmp = {true,true};
178
    return new boolean[][] { tmp,tmp,tmp,tmp };
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public int getTouchControlType()
184
    {
185
    return TC_TETRAHEDRON;
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
  public int getTouchControlSplit()
191
    {
192
    return TYPE_NOT_SPLIT;
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  public int[][][] getEnabled()
198
    {
199
    return new int[][][]
200
      {
201
          {{1,2,3}},{{0,2,3}},{{0,1,3}},{{0,1,2}}
202
      };
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  public float[] getDist3D(int[] numLayers)
208
    {
209
    return TouchControlTetrahedron.D3D;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  public Static3D[] getFaceAxis()
215
    {
216
    return TouchControlTetrahedron.FACE_AXIS;
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  public ObjectShape getObjectShape(int variant)
222
    {
223
    final float X = F/2;
224
    final float Y = F*SQ2/2;
225
    final float Z =-F/2;
226
    final float L = (2.0f-3*F);
227
    final float X2= L/2;
228
    final float Y2= L*SQ2/2;
229
    final float Z2=-L/2;
230
    final float D = F/L;
231
    final float G = 1.0f-F;
232

    
233
    if( variant==0 )
234
      {
235
      float[][] vertices =
236
          {
237
             {   0,   0,   0 },
238
             {   X,   Y,   Z },
239
             {   0, 2*Y, 2*Z },
240
             {  -X,   Y,   Z },
241
             {   0,   0,    -F },
242
             {   X,   Y,   Z-F },
243
             {   0, 2*Y, 2*Z-F },
244
             {  -X,   Y,   Z-F },
245
          };
246
      int[][] indices =
247
          {
248
             {0,1,2,3},
249
             {1,0,4,5},
250
             {7,4,0,3},
251
             {1,5,6,2},
252
             {7,3,2,6},
253
             {4,7,6,5}
254
          };
255

    
256
      return new ObjectShape(vertices, indices);
257
      }
258
    else if( variant==1 )
259
      {
260
      float[][] vertices =
261
          {
262
             {   0,   0,     G },
263
             {   X,   Y,   Z+G },
264
             {   0, 2*Y, 2*Z+G },
265
             {  -X,   Y,   Z+G },
266
             {   0,   0,    -G },
267
             {   X,   Y,  -Z-G },
268
             {   0, 2*Y,-2*Z-G },
269
             {  -X,   Y,  -Z-G },
270
          };
271
      int[][] indices =
272
          {
273
             {0,4,5,1},
274
             {3,7,4,0},
275
             {0,1,2,3},
276
             {4,7,6,5},
277
             {1,5,6,2},
278
             {2,6,7,3}
279
          };
280

    
281
      return new ObjectShape(vertices, indices);
282
      }
283
    else
284
      {
285
      float[][] vertices =
286
          {
287
             {        0,   -2*Y2/3,       -2*Z2/3 },
288
             {       X2,      Y2/3,          Z2/3 },
289
             {      -X2,      Y2/3,          Z2/3 },
290
             {        0,   -2*Y2/3,-2*Z2/3+2*D*Z2 },
291
             {  X2-D*X2, Y2/3-D*Y2,     Z2/3+D*Z2 },
292
             { -X2+D*X2, Y2/3-D*Y2,     Z2/3+D*Z2 },
293
          };
294
      int[][] indices =
295
          {
296
             {0,1,2},
297
             {3,5,4},
298
             {0,3,4,1},
299
             {5,3,0,2},
300
             {4,5,2,1}
301
          };
302

    
303
      return new ObjectShape(vertices, indices);
304
      }
305
    }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
  public ObjectFaceShape getObjectFaceShape(int variant)
310
    {
311
    final float Y = F*SQ2/2;
312
    final float Z =-F/2;
313
    final float L = (2.0f-3*F);
314

    
315
    if( variant==0 )
316
      {
317
      float[][] bands     = { {0.015f,35,0.25f*F,0.5f*F,5,1,1},{0.001f,35,0.25f*F,0.5f*F,5,1,1} };
318
      int[] bandIndices   = { 0,0,0,1,1,1 };
319
      float[][] corners   = { {0.08f,0.20f*F},{0.07f,0.20f*F} };
320
      int[] cornerIndices = { 0,1,1,-1,1,-1,-1,-1 };
321
      float[][] centers   = { { 0.0f, Y, Z-F/2} };
322
      int[] centerIndices = { 0,0,0,-1,0,-1,-1,-1 };
323
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
324
      }
325
    else if( variant==1 )
326
      {
327
      float[][] bands     = { {0.015f,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
328
      int[] bandIndices   = { 0,0,1,1,1,1 };
329
      float[][] corners   = { {0.07f,0.20f*F} };
330
      int[] cornerIndices = { 0,0,-1,0,0,0,-1,0 };
331
      float[][] centers   = { { 0, F*SQ2/2, 0 } };
332
      int[] centerIndices = { 0,0,-1,0,0,0,-1,0 };
333
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
334
      }
335
    else
336
      {
337
      float[][] bands     = { {0.020f,35,0.20f*L,0.6f*L,5,1,1}, {0.001f,35,0.05f*L,0.1f*L,5,1,1} };
338
      int[] bandIndices   = { 0,1,1,1,1,1 };
339
      float[][] corners   = { {0.04f,0.6f*F} };
340
      int[] cornerIndices = { 0,0,0,-1,-1,-1 };
341
      float[][] centers   = { { 0, -2*Y/3, 4*Z/3 } };
342
      int[] centerIndices = { 0,0,0,-1,-1,-1 };
343
      return new ObjectFaceShape(bands,bandIndices,corners,cornerIndices,centers,centerIndices,null);
344
      }
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  public Static4D getQuat(int cubit, int[] numLayers)
350
    {
351
    if( mQuats==null ) initializeQuats();
352
    if( mRotQuat ==null ) mRotQuat = new int[] {0,1,2,7,0,2,7,6,3,10,0,1,3,5};
353
    return mQuats[mRotQuat[cubit]];
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

    
358
  public int getNumCubitVariants(int[] numLayers)
359
    {
360
    return 3;
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  public int getCubitVariant(int cubit, int[] numLayers)
366
    {
367
    return cubit<4 ? 0 : (cubit<10?1:2);
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public float getStickerRadius()
373
    {
374
    return 0.04f;
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

    
379
  public float getStickerStroke()
380
    {
381
    return ObjectControl.isInIconMode() ? 0.08f : 0.04f;
382
    }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
  public float[][] getStickerAngles()
387
    {
388
    return null;
389
    }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392
// PUBLIC API
393

    
394
  public Static3D[] getRotationAxis()
395
    {
396
    return ROT_AXIS;
397
    }
398

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

    
401
  public int[] getBasicAngle()
402
    {
403
    if( mBasicAngle ==null ) mBasicAngle = new int[] { 3,3,3,3 };
404
    return mBasicAngle;
405
    }
406

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408

    
409
  public ObjectType intGetObjectType(int[] numLayers)
410
    {
411
    return ObjectType.JING_2;
412
    }
413

    
414
///////////////////////////////////////////////////////////////////////////////////////////////////
415

    
416
  public String getObjectName()
417
    {
418
    return "Jing Pyraminx";
419
    }
420

    
421
///////////////////////////////////////////////////////////////////////////////////////////////////
422

    
423
  public String getInventor()
424
    {
425
    return "Tony Fisher";
426
    }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

    
430
  public int getYearOfInvention()
431
    {
432
    return 1991;
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  public int getComplexity()
438
    {
439
    return 1;
440
    }
441
}
(13-13/26)