Project

General

Profile

« Previous | Next » 

Revision a64e07d0

Added by Leszek Koltunski over 3 years ago

Beginnings of Megaminx & Gigaminx

View differences:

src/main/java/org/distorted/objects/TwistyKilominx.java
32 32
import org.distorted.library.type.Static4D;
33 33
import org.distorted.main.R;
34 34

  
35
import java.util.Random;
36

  
37
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
38

  
39 35
///////////////////////////////////////////////////////////////////////////////////////////////////
40 36

  
41
public class TwistyKilominx extends TwistyObject
37
public class TwistyKilominx extends TwistyMinx
42 38
{
43
  private static final int FACES_PER_CUBIT =6;
44

  
45
  static final float C0 = (SQ5-1)/4;                       // cos(72 deg)
46
  static final float C1 = (SQ5+1)/4;                       // cos(36 deg)
47
  static final float C2 = (SQ5+3)/4;
48
  static final float LEN= (float)(Math.sqrt(1.25f+0.5f*SQ5));
49

  
50
  // the six rotation axis of a Kilominx. Must be normalized.
51
  static final Static3D[] ROT_AXIS = new Static3D[]
52
         {
53
           new Static3D( C2/LEN, C1/LEN, 0      ),
54
           new Static3D(-C2/LEN, C1/LEN, 0      ),
55
           new Static3D( 0     , C2/LEN, C1/LEN ),
56
           new Static3D( 0     ,-C2/LEN, C1/LEN ),
57
           new Static3D( C1/LEN, 0     , C2/LEN ),
58
           new Static3D( C1/LEN, 0     ,-C2/LEN )
59
         };
60

  
61
  private static final int MINX_LGREEN = 0xff53aa00;
62
  private static final int MINX_PINK   = 0xfffd7ab7;
63
  private static final int MINX_SANDY  = 0xffefd48b;
64
  private static final int MINX_LBLUE  = 0xff00a2d7;
65
  private static final int MINX_ORANGE = 0xffff6200;
66
  private static final int MINX_VIOLET = 0xff7d59a4;
67
  private static final int MINX_DGREEN = 0xff007a47;
68
  private static final int MINX_DRED   = 0xffbd0000;
69
  private static final int MINX_DBLUE  = 0xff1a29b2;
70
  private static final int MINX_DYELLOW= 0xffffc400;
71
  private static final int MINX_WHITE  = 0xffffffff;
72
  private static final int MINX_GREY   = 0xff727c7b;
73

  
74
  private static final int[] FACE_COLORS = new int[]
75
         {
76
           MINX_LGREEN, MINX_PINK   , MINX_SANDY , MINX_LBLUE,
77
           MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
78
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
79
         };
80

  
81
  // All 60 legal rotation quats of a Kilominx
82
  private static final Static4D[] QUATS = new Static4D[]
83
         {
84
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
85
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
86
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
87
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
88

  
89
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
90
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
91
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
92
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
93
           new Static4D( -0.5f,  0.5f,  0.5f,  0.5f ),
94
           new Static4D( -0.5f,  0.5f, -0.5f,  0.5f ),
95
           new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
96
           new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
97

  
98
           new Static4D(  0.5f,    C1,    C0,  0.0f ),
99
           new Static4D(  0.5f,    C1,   -C0,  0.0f ),
100
           new Static4D(  0.5f,   -C1,    C0,  0.0f ),
101
           new Static4D(  0.5f,   -C1,   -C0,  0.0f ),
102
           new Static4D(    C0,  0.5f,    C1,  0.0f ),
103
           new Static4D(    C0,  0.5f,   -C1,  0.0f ),
104
           new Static4D(   -C0,  0.5f,    C1,  0.0f ),
105
           new Static4D(   -C0,  0.5f,   -C1,  0.0f ),
106
           new Static4D(    C1,    C0,  0.5f,  0.0f ),
107
           new Static4D(    C1,   -C0,  0.5f,  0.0f ),
108
           new Static4D(   -C1,    C0,  0.5f,  0.0f ),
109
           new Static4D(   -C1,   -C0,  0.5f,  0.0f ),
110

  
111
           new Static4D(  0.0f,    C0,    C1,  0.5f ),
112
           new Static4D(  0.0f,    C0,   -C1,  0.5f ),
113
           new Static4D(  0.0f,   -C0,    C1,  0.5f ),
114
           new Static4D(  0.0f,   -C0,   -C1,  0.5f ),
115
           new Static4D(    C0,    C1,  0.0f,  0.5f ),
116
           new Static4D(    C0,   -C1,  0.0f,  0.5f ),
117
           new Static4D(   -C0,    C1,  0.0f,  0.5f ),
118
           new Static4D(   -C0,   -C1,  0.0f,  0.5f ),
119
           new Static4D(    C1,  0.0f,    C0,  0.5f ),
120
           new Static4D(    C1,  0.0f,   -C0,  0.5f ),
121
           new Static4D(   -C1,  0.0f,    C0,  0.5f ),
122
           new Static4D(   -C1,  0.0f,   -C0,  0.5f ),
123

  
124
           new Static4D(  0.0f,    C1,  0.5f,    C0 ),
125
           new Static4D(  0.0f,    C1, -0.5f,    C0 ),
126
           new Static4D(  0.0f,   -C1,  0.5f,    C0 ),
127
           new Static4D(  0.0f,   -C1, -0.5f,    C0 ),
128
           new Static4D(  0.5f,  0.0f,    C1,    C0 ),
129
           new Static4D(  0.5f,  0.0f,   -C1,    C0 ),
130
           new Static4D( -0.5f,  0.0f,    C1,    C0 ),
131
           new Static4D( -0.5f,  0.0f,   -C1,    C0 ),
132
           new Static4D(    C1,  0.5f,  0.0f,    C0 ),
133
           new Static4D(    C1, -0.5f,  0.0f,    C0 ),
134
           new Static4D(   -C1,  0.5f,  0.0f,    C0 ),
135
           new Static4D(   -C1, -0.5f,  0.0f,    C0 ),
136

  
137
           new Static4D(  0.0f,  0.5f,    C0,    C1 ),
138
           new Static4D(  0.0f,  0.5f,   -C0,    C1 ),
139
           new Static4D(  0.0f, -0.5f,    C0,    C1 ),
140
           new Static4D(  0.0f, -0.5f,   -C0,    C1 ),
141
           new Static4D(  0.5f,    C0,  0.0f,    C1 ),
142
           new Static4D(  0.5f,   -C0,  0.0f,    C1 ),
143
           new Static4D( -0.5f,    C0,  0.0f,    C1 ),
144
           new Static4D( -0.5f,   -C0,  0.0f,    C1 ),
145
           new Static4D(    C0,  0.0f,  0.5f,    C1 ),
146
           new Static4D(    C0,  0.0f, -0.5f,    C1 ),
147
           new Static4D(   -C0,  0.0f,  0.5f,    C1 ),
148
           new Static4D(   -C0,  0.0f, -0.5f,    C1 ),
149
         };
150

  
151
  private static final int[][] mFaceMap =
152
         {
153
           {  0, 1, 8, 12,12,12 },
154
           {  6, 5,10, 12,12,12 },
155
           {  1, 0,11, 12,12,12 },
156
           {  5, 6, 3, 12,12,12 },
157
           {  0, 9, 4, 12,12,12 },
158
           {  5, 4, 9, 12,12,12 },
159
           {  7, 1, 2, 12,12,12 },
160
           {  2, 6, 7, 12,12,12 },
161
           { 10, 9, 8, 12,12,12 },
162
           {  4, 3,11, 12,12,12 },
163
           {  7,10, 8, 12,12,12 },
164
           {  3, 2,11, 12,12,12 },
165
           {  0, 8, 9, 12,12,12 },
166
           {  9,10, 5, 12,12,12 },
167
           {  0, 4,11, 12,12,12 },
168
           {  4, 5, 3, 12,12,12 },
169
           {  1, 7, 8, 12,12,12 },
170
           {  7, 6,10, 12,12,12 },
171
           {  2, 1,11, 12,12,12 },
172
           {  6, 2, 3, 12,12,12 },
173
         };
174

  
175 39
  private static MeshBase mMesh;
176 40

  
177 41
///////////////////////////////////////////////////////////////////////////////////////////////////
178 42

  
179
  TwistyKilominx(int size, Static4D quat, DistortedTexture texture,
180
                 MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
181
    {
182
    super(size, size, 30, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
183
    }
184

  
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

  
187
  float getScreenRatio()
188
    {
189
    return 0.9f;
190
    }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

  
194
  Static4D[] getQuats()
195
    {
196
    return QUATS;
197
    }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
  int getNumFaces()
202
    {
203
    return FACE_COLORS.length;
204
    }
205

  
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

  
208
  boolean shouldResetTextureMaps()
43
  TwistyKilominx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
44
                 DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
209 45
    {
210
    return false;
46
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
211 47
    }
212 48

  
213 49
///////////////////////////////////////////////////////////////////////////////////////////////////
214 50

  
215
  int getNumStickerTypes()
51
  int getNumStickerTypes(int numLayers)
216 52
    {
217 53
    return 1;
218 54
    }
......
224 60
    return new float[] { -0.5f , 0.5f };
225 61
    }
226 62

  
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

  
229
  int getNumCubitFaces()
230
    {
231
    return FACES_PER_CUBIT;
232
    }
233

  
234 63
///////////////////////////////////////////////////////////////////////////////////////////////////
235 64

  
236 65
  Static3D[] getCubitPositions(int numLayers)
237 66
    {
238
    final Static3D[] CENTERS = new Static3D[20];
239

  
240
    CENTERS[ 0] = new Static3D( 0.0f, 0.5f,   C2);
241
    CENTERS[ 1] = new Static3D( 0.0f, 0.5f,  -C2);
242
    CENTERS[ 2] = new Static3D( 0.0f,-0.5f,   C2);
243
    CENTERS[ 3] = new Static3D( 0.0f,-0.5f,  -C2);
244
    CENTERS[ 4] = new Static3D(   C2, 0.0f, 0.5f);
245
    CENTERS[ 5] = new Static3D(   C2, 0.0f,-0.5f);
246
    CENTERS[ 6] = new Static3D(  -C2, 0.0f, 0.5f);
247
    CENTERS[ 7] = new Static3D(  -C2, 0.0f,-0.5f);
248
    CENTERS[ 8] = new Static3D( 0.5f,   C2, 0.0f);
249
    CENTERS[ 9] = new Static3D( 0.5f,  -C2, 0.0f);
250
    CENTERS[10] = new Static3D(-0.5f,   C2, 0.0f);
251
    CENTERS[11] = new Static3D(-0.5f,  -C2, 0.0f);
252
    CENTERS[12] = new Static3D(   C1,   C1,   C1);
253
    CENTERS[13] = new Static3D(   C1,   C1,  -C1);
254
    CENTERS[14] = new Static3D(   C1,  -C1,   C1);
255
    CENTERS[15] = new Static3D(   C1,  -C1,  -C1);
256
    CENTERS[16] = new Static3D(  -C1,   C1,   C1);
257
    CENTERS[17] = new Static3D(  -C1,   C1,  -C1);
258
    CENTERS[18] = new Static3D(  -C1,  -C1,   C1);
259
    CENTERS[19] = new Static3D(  -C1,  -C1,  -C1);
260

  
261
    return CENTERS;
67
    return CORNERS;
262 68
    }
263 69

  
264 70
///////////////////////////////////////////////////////////////////////////////////////////////////
265 71

  
266 72
  private int getQuat(int cubit)
267 73
    {
268
    switch(cubit)
269
      {
270
      case  0: return 0;
271
      case  1: return 2;
272
      case  2: return 3;
273
      case  3: return 1;
274
      case  4: return 40;
275
      case  5: return 31;
276
      case  6: return 41;
277
      case  7: return 30;
278
      case  8: return 39;
279
      case  9: return 35;
280
      case 10: return 36;
281
      case 11: return 34;
282
      case 12: return 56;
283
      case 13: return 32;
284
      case 14: return 43;
285
      case 15: return 21;
286
      case 16: return 48;
287
      case 17: return 28;
288
      case 18: return 42;
289
      case 19: return 23;
290
      }
291

  
292
    return 0;
74
    return ( cubit>=0 && cubit<20 ) ? QUAT_INDICES[cubit] : 0;
293 75
    }
294 76

  
295 77
///////////////////////////////////////////////////////////////////////////////////////////////////
296 78

  
297
  MeshBase createCubitMesh(int cubit)
79
  MeshBase createCubitMesh(int cubit, int numLayers)
298 80
    {
299
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createMinxCornerMesh();
81
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createKilominxCornerMesh();
300 82
    MeshBase mesh = mMesh.copy(true);
301 83

  
302 84
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) );
......
309 91

  
310 92
  int getFaceColor(int cubit, int cubitface, int numLayers)
311 93
    {
312
    return mFaceMap[cubit][cubitface];
94
    return cubitface>=0 && cubitface<3 ? mCornerFaceMap[cubit][cubitface] : NUM_TEXTURES*NUM_FACES;
313 95
    }
314 96

  
315 97
///////////////////////////////////////////////////////////////////////////////////////////////////
......
335 117
    canvas.drawLine(left+MID-WID,top+HEI,left+MID+WID,top+HEI,paint);
336 118
    }
337 119

  
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

  
340
  float returnMultiplier()
341
    {
342
    return 2.0f;
343
    }
344

  
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

  
347
  float[] getRowChances()
348
    {
349
    return new float[] { 0.5f, 0.5f, 1.0f };
350
    }
351

  
352 120
///////////////////////////////////////////////////////////////////////////////////////////////////
353 121
// PUBLIC API
354

  
355
  public Static3D[] getRotationAxis()
356
    {
357
    return ROT_AXIS;
358
    }
359

  
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

  
362
  public int getBasicAngle()
363
    {
364
    return 5;
365
    }
366

  
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

  
369
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
370
    {
371
    int numAxis = ROTATION_AXIS.length;
372

  
373
    if( oldRotAxis == START_AXIS )
374
      {
375
      return rnd.nextInt(numAxis);
376
      }
377
    else
378
      {
379
      int newVector = rnd.nextInt(numAxis-1);
380
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
381
      }
382
    }
383

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

  
386
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
387
    {
388
    float rowFloat = rnd.nextFloat();
389

  
390
    for(int row=0; row<mRowChances.length; row++)
391
      {
392
      if( rowFloat<=mRowChances[row] ) return row;
393
      }
394

  
395
    return 0;
396
    }
397

  
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399 122
// The Kilominx is solved if and only if:
400 123
//
401
// all cubits are rotated with the same quat.
124
// All cubits are rotated with the same quat.
402 125

  
403 126
  public boolean isSolved()
404 127
    {
......
412 135
    return true;
413 136
    }
414 137

  
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416
// only needed for solvers - there are no Kilominx solvers ATM)
417

  
418
  public String retObjectString()
419
    {
420
    return "";
421
    }
422

  
423 138
///////////////////////////////////////////////////////////////////////////////////////////////////
424 139

  
425 140
  public int getObjectName(int numLayers)

Also available in: Unified diff