Project

General

Profile

« Previous | Next » 

Revision a57e6870

Added by Leszek Koltunski over 2 years ago

make numLayers into an int[] (preparation for Cuboids)
Caution: because of previous changes to cubit order in cube, the Solver is broken!

View differences:

src/main/java/org/distorted/objectlib/objects/TwistyCube.java
65 65

  
66 66
///////////////////////////////////////////////////////////////////////////////////////////////////
67 67

  
68
  public TwistyCube(int size, Static4D quat, Static3D move, DistortedTexture texture,
68
  public TwistyCube(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
69 69
                    MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
70 70
    {
71
    super(size, size, quat, move, texture, mesh, effects, res, scrWidth);
71
    super(numL, numL[0], quat, move, texture, mesh, effects, res, scrWidth);
72 72
    }
73 73

  
74 74
///////////////////////////////////////////////////////////////////////////////////////////////////
......
77 77
    {
78 78
    if( mStates==null )
79 79
      {
80
      int size = getNumLayers();
80
      int[] numL = getNumLayers();
81 81
      int[][] m = new int[16][];
82
      for(int i=1; i<16; i++) m[i] = createEdges(size,i);
82
      for(int i=1; i<16; i++) m[i] = createEdges(numL[0],i);
83 83

  
84 84
      mStates = new ScrambleState[]
85 85
        {
......
107 107

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

  
110
  protected int getResource(int numLayers)
110
  protected int getResource(int[] numLayers)
111 111
    {
112
    switch(numLayers)
112
    switch(numLayers[0])
113 113
      {
114 114
      case 2: return R.raw.cube2;
115 115
      case 3: return R.raw.cube3;
......
179 179

  
180 180
///////////////////////////////////////////////////////////////////////////////////////////////////
181 181

  
182
  protected int[] getSolvedQuats(int cubit, int numLayers)
182
  protected int[] getSolvedQuats(int cubit, int[] numLayers)
183 183
    {
184 184
    if( mQuats ==null ) initializeQuats();
185 185
    int status = retCubitSolvedStatus(cubit,numLayers);
......
195 195

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

  
198
  protected ObjectShape getObjectShape(int cubit, int numLayers)
198
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
199 199
    {
200 200
    int extraI, extraV, num;
201 201
    float height;
202 202
    int variant = getCubitVariant(cubit,numLayers);
203
    int numL = numLayers[0];
203 204

  
204
    switch(numLayers)
205
    switch(numL)
205 206
        {
206 207
        case 2 : num = 6; extraI = 2; extraV = 2; height = 0.045f; break;
207 208
        case 3 : num = 5; extraI = 2; extraV = 2; height = 0.045f; break;
......
246 247
      {
247 248
      int extraI2, extraV2, num2;
248 249

  
249
      switch(numLayers)
250
      switch(numL)
250 251
        {
251 252
        case 2 : num2 = 6; extraI2 = 2; extraV2 = 2; break;
252 253
        case 3 : num2 = 5; extraI2 = 1; extraV2 = 0; break;
......
267 268

  
268 269
///////////////////////////////////////////////////////////////////////////////////////////////////
269 270

  
270
  protected float[][] getCubitPositions(int numLayers)
271
  protected float[][] getCubitPositions(int[] numLayers)
271 272
    {
272
    if( numLayers==1 ) return new float[][] {{ 0.0f, 0.0f, 0.0f }};
273
    int numL = numLayers[0];
273 274

  
274
    int numCubits = getNumCornersAndEdges(numLayers) + 6*(numLayers-2)*(numLayers-2);
275
    if( numL==1 ) return new float[][] {{ 0.0f, 0.0f, 0.0f }};
276

  
277
    int numCubits = getNumCornersAndEdges(numL) + 6*(numL-2)*(numL-2);
275 278
    float[][] tmp = new float[numCubits][];
276 279

  
277
    final float LEN = 0.5f*(numLayers-1);
280
    final float LEN = 0.5f*(numL-1);
278 281
    int currentPosition = 0;
279 282

  
280 283
    tmp[currentPosition++] = new float[] {-LEN,-LEN,-LEN};
......
286 289
    tmp[currentPosition++] = new float[] {+LEN,+LEN,-LEN};
287 290
    tmp[currentPosition++] = new float[] {+LEN,+LEN,+LEN};
288 291

  
289
    for(int i=1; i<numLayers-1; i++)
292
    for(int i=1; i<numL-1; i++)
290 293
      tmp[currentPosition++] = new float[] { i-LEN,  -LEN,  -LEN };
291
    for(int i=1; i<numLayers-1; i++)
294
    for(int i=1; i<numL-1; i++)
292 295
      tmp[currentPosition++] = new float[] { i-LEN,  -LEN,  +LEN };
293
    for(int i=1; i<numLayers-1; i++)
296
    for(int i=1; i<numL-1; i++)
294 297
      tmp[currentPosition++] = new float[] { i-LEN,  +LEN,  -LEN };
295
    for(int i=1; i<numLayers-1; i++)
298
    for(int i=1; i<numL-1; i++)
296 299
      tmp[currentPosition++] = new float[] { i-LEN,  +LEN,  +LEN };
297
    for(int i=1; i<numLayers-1; i++)
300
    for(int i=1; i<numL-1; i++)
298 301
      tmp[currentPosition++] = new float[] {  -LEN, i-LEN,  -LEN };
299
    for(int i=1; i<numLayers-1; i++)
302
    for(int i=1; i<numL-1; i++)
300 303
      tmp[currentPosition++] = new float[] {  -LEN, i-LEN,  +LEN };
301
    for(int i=1; i<numLayers-1; i++)
304
    for(int i=1; i<numL-1; i++)
302 305
      tmp[currentPosition++] = new float[] {  +LEN, i-LEN,  -LEN };
303
    for(int i=1; i<numLayers-1; i++)
306
    for(int i=1; i<numL-1; i++)
304 307
      tmp[currentPosition++] = new float[] {  +LEN, i-LEN,  +LEN };
305
    for(int i=1; i<numLayers-1; i++)
308
    for(int i=1; i<numL-1; i++)
306 309
      tmp[currentPosition++] = new float[] {  -LEN,  -LEN, i-LEN };
307
    for(int i=1; i<numLayers-1; i++)
310
    for(int i=1; i<numL-1; i++)
308 311
      tmp[currentPosition++] = new float[] {  -LEN,  +LEN, i-LEN };
309
    for(int i=1; i<numLayers-1; i++)
312
    for(int i=1; i<numL-1; i++)
310 313
      tmp[currentPosition++] = new float[] {  +LEN,  -LEN, i-LEN };
311
    for(int i=1; i<numLayers-1; i++)
314
    for(int i=1; i<numL-1; i++)
312 315
      tmp[currentPosition++] = new float[] {  +LEN,  +LEN, i-LEN };
313 316

  
314
    for(int y=1; y<numLayers-1; y++)
315
      for(int z=1; z<numLayers-1; z++)
317
    for(int y=1; y<numL-1; y++)
318
      for(int z=1; z<numL-1; z++)
316 319
        tmp[currentPosition++] = new float[] {+LEN,y-LEN,z-LEN};
317 320

  
318
    for(int y=1; y<numLayers-1; y++)
319
      for(int z=1; z<numLayers-1; z++)
321
    for(int y=1; y<numL-1; y++)
322
      for(int z=1; z<numL-1; z++)
320 323
        tmp[currentPosition++] = new float[] {-LEN,y-LEN,z-LEN};
321 324

  
322
    for(int x=1; x<numLayers-1; x++)
323
      for(int z=1; z<numLayers-1; z++)
325
    for(int x=1; x<numL-1; x++)
326
      for(int z=1; z<numL-1; z++)
324 327
        tmp[currentPosition++] = new float[] {x-LEN,+LEN,z-LEN};
325 328

  
326
    for(int x=1; x<numLayers-1; x++)
327
      for(int z=1; z<numLayers-1; z++)
329
    for(int x=1; x<numL-1; x++)
330
      for(int z=1; z<numL-1; z++)
328 331
        tmp[currentPosition++] = new float[] {x-LEN,-LEN,z-LEN};
329 332

  
330
    for(int x=1; x<numLayers-1; x++)
331
      for(int y=1; y<numLayers-1; y++)
333
    for(int x=1; x<numL-1; x++)
334
      for(int y=1; y<numL-1; y++)
332 335
        tmp[currentPosition++] = new float[] {x-LEN,y-LEN,+LEN};
333 336

  
334
    for(int x=1; x<numLayers-1; x++)
335
      for(int y=1; y<numLayers-1; y++)
337
    for(int x=1; x<numL-1; x++)
338
      for(int y=1; y<numL-1; y++)
336 339
        tmp[currentPosition++] = new float[] {x-LEN,y-LEN,-LEN};
337 340

  
338 341
    return tmp;
......
340 343

  
341 344
///////////////////////////////////////////////////////////////////////////////////////////////////
342 345

  
343
  protected Static4D getQuat(int cubit, int numLayers)
346
  protected Static4D getQuat(int cubit, int[] numLayers)
344 347
    {
345 348
    if( mQuats ==null ) initializeQuats();
346 349

  
347
    int num = cubit - getNumCornersAndEdges(numLayers);
350
    int numL = numLayers[0];
351
    int num = cubit - getNumCornersAndEdges(numL);
348 352

  
349 353
    if( num>=0 )
350 354
      {
351
      int face = num/((numLayers-2)*(numLayers-2));
355
      int face = num/((numL-2)*(numL-2));
352 356

  
353 357
      switch(face)
354 358
        {
......
366 370

  
367 371
///////////////////////////////////////////////////////////////////////////////////////////////////
368 372

  
369
  protected int getNumCubitVariants(int numLayers)
373
  protected int getNumCubitVariants(int[] numLayers)
370 374
    {
371
    return numLayers>2 ? 2:1;
375
    return numLayers[0]>2 ? 2:1;
372 376
    }
373 377

  
374 378
///////////////////////////////////////////////////////////////////////////////////////////////////
375 379

  
376
  protected int getCubitVariant(int cubit, int numLayers)
380
  protected int getCubitVariant(int cubit, int[] numLayers)
377 381
    {
378
    return cubit < getNumCornersAndEdges(numLayers) ? 0 : 1;
382
    return cubit < getNumCornersAndEdges(numLayers[0]) ? 0 : 1;
379 383
    }
380 384

  
381 385
///////////////////////////////////////////////////////////////////////////////////////////////////
382 386

  
383
  protected int getFaceColor(int cubit, int cubitface, int numLayers)
387
  protected int getFaceColor(int cubit, int cubitface, int[] numLayers)
384 388
    {
385
    int cornersAndEdges = getNumCornersAndEdges(numLayers);
389
    int numL = numLayers[0];
390
    int cornersAndEdges = getNumCornersAndEdges(numL);
386 391

  
387 392
    if( cubit<cornersAndEdges )
388 393
      {
389
      return CUBITS[cubit].getRotRow(cubitface/2) == (cubitface%2==0 ? (1<<(numLayers-1)):1) ? cubitface : NUM_TEXTURES;
394
      return CUBITS[cubit].getRotRow(cubitface/2) == (cubitface%2==0 ? (1<<(numL-1)):1) ? cubitface : NUM_TEXTURES;
390 395
      }
391 396
    else
392 397
      {
393
      int numCentersPerFace = (numLayers-2)*(numLayers-2);
398
      int numCentersPerFace = (numL-2)*(numL-2);
394 399
      return cubitface == 4 ? (cubit-cornersAndEdges)/numCentersPerFace : NUM_TEXTURES;
395 400
      }
396 401
    }
......
409 414

  
410 415
      if( ObjectControl.isInIconMode() )
411 416
        {
412
        switch(getNumLayers())
417
        int[] numLayers = getNumLayers();
418

  
419
        switch(numLayers[0])
413 420
          {
414 421
          case 2: stroke*=1.8f; break;
415 422
          case 3: stroke*=2.0f; break;
......
434 441

  
435 442
///////////////////////////////////////////////////////////////////////////////////////////////////
436 443

  
437
  protected float[][] getCuts(int numLayers)
444
  protected float[][] getCuts(int[] numLayers)
438 445
    {
439
    if( numLayers<2 ) return null;
446
    int numL = numLayers[0];
447
    if( numL<2 ) return null;
440 448

  
441 449
    if( mCuts==null )
442 450
      {
443
      mCuts = new float[3][numLayers-1];
451
      mCuts = new float[3][numL-1];
444 452

  
445
      for(int i=0; i<numLayers-1; i++)
453
      for(int i=0; i<numL-1; i++)
446 454
        {
447
        float cut = (2-numLayers)*0.5f + i;
455
        float cut = (2-numL)*0.5f + i;
448 456
        mCuts[0][i] = cut;
449 457
        mCuts[1][i] = cut;
450 458
        mCuts[2][i] = cut;
......
456 464

  
457 465
///////////////////////////////////////////////////////////////////////////////////////////////////
458 466

  
459
  private void getLayerRotatable(int numLayers)
467
  private void getLayerRotatable(int[] numLayers)
460 468
    {
461 469
    if( mLayerRotatable==null )
462 470
      {
463 471
      int numAxis = ROT_AXIS.length;
464
      boolean[] tmp = new boolean[numLayers];
465
      for(int i=0; i<numLayers; i++) tmp[i] = true;
466 472
      mLayerRotatable = new boolean[numAxis][];
467
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
473

  
474
      for(int i=0; i<numAxis; i++)
475
        {
476
        mLayerRotatable[i] = new boolean[numLayers[i]];
477
        for(int j=0; j<numLayers[i]; j++) mLayerRotatable[i][j] = true;
478
        }
468 479
      }
469 480
    }
470 481

  
......
477 488

  
478 489
///////////////////////////////////////////////////////////////////////////////////////////////////
479 490

  
480
  protected int getNumStickerTypes(int numLayers)
491
  protected int getNumStickerTypes(int[] numLayers)
481 492
    {
482 493
    return 1;
483 494
    }
......
503 514
    {
504 515
    if( mMovement==null )
505 516
      {
506
      int numLayers = getNumLayers();
517
      int[] numLayers = getNumLayers();
507 518
      if( mCuts==null ) getCuts(numLayers);
508 519
      getLayerRotatable(numLayers);
509
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
520
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers[0],TYPE_NOT_SPLIT,ENABLED);
510 521
      }
511 522
    return mMovement;
512 523
    }
......
521 532

  
522 533
///////////////////////////////////////////////////////////////////////////////////////////////////
523 534

  
524
  public ObjectType intGetObjectType(int numLayers)
535
  public ObjectType intGetObjectType(int[] numLayers)
525 536
    {
526
    switch(numLayers)
537
    switch(numLayers[0])
527 538
      {
528 539
      case 2: return ObjectType.CUBE_2;
529 540
      case 3: return ObjectType.CUBE_3;
......
536 547

  
537 548
///////////////////////////////////////////////////////////////////////////////////////////////////
538 549

  
539
  public int getObjectName(int numLayers)
550
  public int getObjectName(int[] numLayers)
540 551
    {
541
    switch(numLayers)
552
    switch(numLayers[0])
542 553
      {
543 554
      case 2: return R.string.cube2;
544 555
      case 3: return R.string.cube3;
......
550 561

  
551 562
///////////////////////////////////////////////////////////////////////////////////////////////////
552 563

  
553
  public int getInventor(int numLayers)
564
  public int getInventor(int[] numLayers)
554 565
    {
555
    switch(numLayers)
566
    switch(numLayers[0])
556 567
      {
557 568
      case 2: return R.string.cube2_inventor;
558 569
      case 3: return R.string.cube3_inventor;
......
564 575

  
565 576
///////////////////////////////////////////////////////////////////////////////////////////////////
566 577

  
567
  public int getComplexity(int numLayers)
578
  public int getComplexity(int[] numLayers)
568 579
    {
569
    switch(numLayers)
580
    switch(numLayers[0])
570 581
      {
571 582
      case 2: return 4;
572 583
      case 3: return 6;

Also available in: Unified diff