Project

General

Profile

« Previous | Next » 

Revision e2b9e87e

Added by Leszek Koltunski almost 3 years ago

Introduce Square-2 (unfinished)

View differences:

src/main/java/org/distorted/objects/TwistySquare1.java
38 38

  
39 39
///////////////////////////////////////////////////////////////////////////////////////////////////
40 40

  
41
class TwistySquare1 extends TwistyObject
41
class TwistySquare1 extends TwistySquare
42 42
{
43
  private static final int LAST_SL = 0; // automatic rotations: last rot was a 'slash' i.e. along ROT_AXIS[1]
44
  private static final int LAST_UP = 1; // last rot was along ROT_AXIS[0], upper layer and forelast was a slash
45
  private static final int LAST_LO = 2; // last rot was along ROT_AXIS[0], lower layer and forelast was a slash
46
  private static final int LAST_UL = 3; // two last rots were along ROT_AXIS[0] (so the next must be a slash)
47

  
48
  private static final float COS15 = (SQ6+SQ2)/4;
49
  private static final float SIN15 = (SQ6-SQ2)/4;
50
  private static final float     X = 3*(2-SQ3)/2;
51

  
52
  static final Static3D[] ROT_AXIS = new Static3D[]
53
    {
54
      new Static3D(0,1,0),
55
      new Static3D(COS15,0,SIN15)
56
    };
57

  
58
  private static final int[] BASIC_ANGLE = new int[] { 12,2 };
59

  
60
  private static final int[] FACE_COLORS = new int[]
61
    {
62
      COLOR_YELLOW, COLOR_WHITE,
63
      COLOR_BLUE  , COLOR_GREEN,
64
      COLOR_RED   , COLOR_ORANGE
65
    };
66

  
67
  private static final Static4D[] QUATS = new Static4D[]
68
    {
69
      new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
70
      new Static4D(  0.0f, SIN15,  0.0f, COS15 ),
71
      new Static4D(  0.0f,  0.5f,  0.0f, SQ3/2 ),
72
      new Static4D(  0.0f, SQ2/2,  0.0f, SQ2/2 ),
73
      new Static4D(  0.0f, SQ3/2,  0.0f,  0.5f ),
74
      new Static4D(  0.0f, COS15,  0.0f, SIN15 ),
75
      new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
76
      new Static4D(  0.0f, COS15,  0.0f,-SIN15 ),
77
      new Static4D(  0.0f, SQ3/2,  0.0f, -0.5f ),
78
      new Static4D(  0.0f, SQ2/2,  0.0f,-SQ2/2 ),
79
      new Static4D(  0.0f,  0.5f,  0.0f,-SQ3/2 ),
80
      new Static4D(  0.0f, SIN15,  0.0f,-COS15 ),
81

  
82
      new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
83
      new Static4D( COS15,  0.0f, SIN15,  0.0f ),
84
      new Static4D( SQ3/2,  0.0f,  0.5f,  0.0f ),
85
      new Static4D( SQ2/2,  0.0f, SQ2/2,  0.0f ),
86
      new Static4D(  0.5f,  0.0f, SQ3/2,  0.0f ),
87
      new Static4D( SIN15,  0.0f, COS15,  0.0f ),
88
      new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
89
      new Static4D(-SIN15,  0.0f, COS15,  0.0f ),
90
      new Static4D( -0.5f,  0.0f, SQ3/2,  0.0f ),
91
      new Static4D(-SQ2/2,  0.0f, SQ2/2,  0.0f ),
92
      new Static4D(-SQ3/2,  0.0f,  0.5f,  0.0f ),
93
      new Static4D(-COS15,  0.0f, SIN15,  0.0f )
94
    };
95

  
96 43
  private static final int[] QUAT_NUMBER = new int[]
97 44
    {
98 45
      0, 6,
......
125 72
      {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
126 73
    };
127 74

  
128
  private static final double[][] VERTICES_MIDDLE = new double[][]
129
    {
130
      { -1.5-X, 0.5, 1.5 },
131
      {    0.0, 0.5, 1.5 },
132
      {    0.0, 0.5,-1.5 },
133
      { -1.5+X, 0.5,-1.5 },
134
      { -1.5-X,-0.5, 1.5 },
135
      {    0.0,-0.5, 1.5 },
136
      {    0.0,-0.5,-1.5 },
137
      { -1.5+X,-0.5,-1.5 }
138
    };
139

  
140
  private static final int[][] VERT_INDEXES_MIDDLE = new int[][]
141
    {
142
      {0,1,2,3},   // counterclockwise!
143
      {4,5,6,7},
144
      {4,5,1,0},
145
      {5,6,2,1},
146
      {6,7,3,2},
147
      {7,4,0,3}
148
    };
149

  
150
  private static final double[][] VERTICES_EDGE = new double[][]
151
    {
152
      { -X, 0.5, 0.0 },
153
      { +X, 0.5, 0.0 },
154
      {0.0, 0.5,-1.5 },
155
      { -X,-0.5, 0.0 },
156
      { +X,-0.5, 0.0 },
157
      {0.0,-0.5,-1.5 },
158
    };
159

  
160
  private static final int[][] VERT_INDEXES_EDGE = new int[][]
161
    {
162
      {0,1,2},   // counterclockwise!
163
      {3,4,5},
164
      {3,4,1,0},
165
      {4,5,2,1},
166
      {5,3,0,2}
167
    };
168

  
169 75
  private static final double[][] VERTICES_CORNER = new double[][]
170 76
    {
171 77
      { X-1.5, 0.5,  0.0 },
......
239 145
      { 5,11,14,20},
240 146
    };
241 147

  
242
  // QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
243
  private static final int[][] QUAT_MULT = new int[][]
244
    {
245
      {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
246
      {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
247
      {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
248
      {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
249
      {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
250
      {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
251
      {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
252
      {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
253
      {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
254
      {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
255
      { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
256
      { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
257
      { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
258
      { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
259
      { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
260
      { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
261
      { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
262
      { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
263
      { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
264
      { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
265
      { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
266
      { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
267
      { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
268
      { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
269
    };
270

  
271
  private static MeshBase[] mMeshes;
272

  
273 148
  private final int[][] mPermittedAngles;
274 149
  private final int[] mCornerQuat;
275
  private int mLastRot, mPermittedUp, mPermittedDo;
150
  private int mPermittedUp, mPermittedDo;
276 151

  
277 152
///////////////////////////////////////////////////////////////////////////////////////////////////
278 153

  
279 154
  TwistySquare1(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
280 155
                DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
281 156
    {
282
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.SQU1, res, scrWidth);
157
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU1, res, scrWidth);
283 158

  
284 159
    mLastRot = LAST_SL;
285 160
    mPermittedAngles = new int[2][BASIC_ANGLE[0]];
......
293 168
    return QUATS[QUAT_NUMBER[cubit]];
294 169
    }
295 170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
  MeshBase createCornerCubitMesh()
174
    {
175
    if( mMeshes[2]==null )
176
      {
177
      float[][] bands= new float[][]
178
        {
179
          {0.038f,35,0.9f,1.0f, 5,2,1},
180
          {0.001f,35,0.9f,1.0f, 5,2,1}
181
        };
182
      int[] bandIndexes   = new int[] { 0,1,0,0,1,1 };
183
      float[][] corners   = new float[][] { {0.05f,0.13f} };
184
      int[] cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
185
      float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
186
      int[] centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
187

  
188
      FactoryCubit factory = FactoryCubit.getInstance();
189
      factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
190
      mMeshes[2] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
191
                                              bands, bandIndexes,
192
                                              corners, cornerIndexes,
193
                                              centers, centerIndexes,
194
                                              getNumCubitFaces() );
195
      }
196
    return mMeshes[2].copy(true);
197
    }
198

  
296 199
///////////////////////////////////////////////////////////////////////////////////////////////////
297 200

  
298 201
  MeshBase createCubitMesh(int cubit, int numLayers)
......
301 204
      {
302 205
      FactoryCubit factory = FactoryCubit.getInstance();
303 206
      factory.clear();
304
      mMeshes = new MeshBase[3];
207
      mMeshes = new MeshBase[4];
305 208
      }
306 209

  
307 210
    MeshBase mesh;
308 211

  
309
    if( cubit<2 )
310
      {
311
      if( mMeshes[0]==null )
312
        {
313
        float[][] bands= new float[][]
314
          {
315
             {0.040f,35,0.8f,1.0f,5,2,1},
316
             {0.020f,35,0.8f,1.0f,5,2,1},
317
             {0.001f,35,0.8f,1.0f,5,2,1}
318
          };
319
        int[] bandIndexes   = new int[] { 2,2,1,1,0,2 };
320
        float[][] corners   = new float[][] { {0.04f,0.05f} };
321
        int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
322
        float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
323
        int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
324

  
325
        FactoryCubit factory = FactoryCubit.getInstance();
326
        factory.createNewFaceTransform(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE);
327
        mMeshes[0] = factory.createRoundedSolid(VERTICES_MIDDLE, VERT_INDEXES_MIDDLE,
328
                                                bands, bandIndexes,
329
                                                corners, cornerIndexes,
330
                                                centers, centerIndexes,
331
                                                getNumCubitFaces() );
332
        }
333
      mesh = mMeshes[0].copy(true);
334
      }
335
    else if( cubit<10 )
336
      {
337
      if( mMeshes[1]==null )
338
        {
339
        float[][] bands= new float[][]
340
          {
341
            {0.038f,35,0.5f,0.9f, 5,2,1},
342
            {0.001f,35,0.5f,0.9f, 5,2,1}
343
          };
344
        int[] bandIndexes   = new int[] { 0,1,0,1,1 };
345
        float[][] corners   = new float[][] { {0.05f,0.20f} };
346
        int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
347
        float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
348
        int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
349

  
350
        FactoryCubit factory = FactoryCubit.getInstance();
351
        factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
352
        mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
353
                                                bands, bandIndexes,
354
                                                corners, cornerIndexes,
355
                                                centers, centerIndexes,
356
                                                getNumCubitFaces() );
357
        }
358
      mesh = mMeshes[1].copy(true);
359
      }
360
    else
361
      {
362
      if( mMeshes[2]==null )
363
        {
364
        float[][] bands= new float[][]
365
          {
366
            {0.038f,35,0.9f,1.0f, 5,2,1},
367
            {0.001f,35,0.9f,1.0f, 5,2,1}
368
          };
369
        int[] bandIndexes   = new int[] { 0,1,0,0,1,1 };
370
        float[][] corners   = new float[][] { {0.07f,0.20f} };
371
        int[] cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
372
        float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
373
        int[] centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
374

  
375
        FactoryCubit factory = FactoryCubit.getInstance();
376
        factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
377
        mMeshes[2] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
378
                                                bands, bandIndexes,
379
                                                corners, cornerIndexes,
380
                                                centers, centerIndexes,
381
                                                getNumCubitFaces() );
382
        }
383
      mesh = mMeshes[2].copy(true);
384
      }
212
         if( cubit< 2 ) mesh = createMiddleCubitMesh();
213
    else if( cubit<10 ) mesh = createEdgeCubitMesh();
214
    else                mesh = createCornerCubitMesh();
385 215

  
386 216
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
387 217
    mesh.apply(quat,0xffffffff,0);
......
419 249
    return CENTERS;
420 250
    }
421 251

  
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

  
424
  Static4D[] getQuats()
425
    {
426
    return QUATS;
427
    }
428

  
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

  
431
  boolean shouldResetTextureMaps()
432
    {
433
    return false;
434
    }
435

  
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

  
438
  int getNumFaces()
439
    {
440
    return FACE_COLORS.length;
441
    }
442

  
443 252
///////////////////////////////////////////////////////////////////////////////////////////////////
444 253

  
445 254
  int getNumStickerTypes(int numLayers)
......
447 256
    return STICKERS.length;
448 257
    }
449 258

  
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451

  
452
  int getNumCubitFaces()
453
    {
454
    return 6;
455
    }
456

  
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

  
459
  float getScreenRatio()
460
    {
461
    return 0.5f;
462
    }
463

  
464 259
///////////////////////////////////////////////////////////////////////////////////////////////////
465 260

  
466 261
  int getFaceColor(int cubit, int cubitface, int numLayers)
......
474 269
    return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
475 270
    }
476 271

  
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

  
479
  float returnMultiplier()
480
    {
481
    return 1.0f;
482
    }
483

  
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485

  
486
  float[][] getCuts(int numLayers)
487
    {
488
    return new float[][] { {-0.5f,+0.5f}, {0.0f} };
489
    }
490

  
491 272
///////////////////////////////////////////////////////////////////////////////////////////////////
492 273
// this implements the fact that corner cubits have multiple 'centers' and this means the cubit
493 274
// might span more than one layer along a given axis - i.e. that this is a bandaged puzzle.
......
709 490
///////////////////////////////////////////////////////////////////////////////////////////////////
710 491
// PUBLIC API
711 492

  
712
  public Static3D[] getRotationAxis()
713
    {
714
    return ROT_AXIS;
715
    }
716

  
717
///////////////////////////////////////////////////////////////////////////////////////////////////
718

  
719
  public int[] getBasicAngle()
720
    {
721
    return BASIC_ANGLE;
722
    }
723

  
724
///////////////////////////////////////////////////////////////////////////////////////////////////
725

  
726 493
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
727 494
    {
728 495
    int layer, nextAngle;
......
791 558
      }
792 559
    }
793 560

  
794
///////////////////////////////////////////////////////////////////////////////////////////////////
795

  
796
  public boolean isSolved()
797
    {
798
    int index = CUBITS[0].mQuatIndex;
799

  
800
    for(int i=1; i<NUM_CUBITS; i++)
801
      {
802
      if( CUBITS[i].mQuatIndex != index ) return false;
803
      }
804

  
805
    return true;
806
    }
807

  
808
///////////////////////////////////////////////////////////////////////////////////////////////////
809
// only needed for solvers - there are no Square solvers ATM)
810

  
811
  public String retObjectString()
812
    {
813
    return "";
814
    }
815

  
816 561
///////////////////////////////////////////////////////////////////////////////////////////////////
817 562

  
818 563
  public int getObjectName(int numLayers)

Also available in: Unified diff