Project

General

Profile

« Previous | Next » 

Revision fdccfe1e

Added by Leszek Koltunski over 2 years ago

Introduce the third type of a cuboid's cubit: the edge.
Makes the meshes much smaller!

View differences:

src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
180 180
         new Static4D(  0.0f,   1.0f,   0.0f,   0.0f),
181 181
         new Static4D(  0.0f,   0.0f,   1.0f,   0.0f),
182 182

  
183
         new Static4D( SQ2/2,  SQ2/2,  0.0f ,   0.0f),
183
         new Static4D( SQ2/2,  SQ2/2,  0.0f ,   0.0f),  // 4
184 184
         new Static4D( SQ2/2, -SQ2/2,  0.0f ,   0.0f),
185 185
         new Static4D( SQ2/2,   0.0f,  SQ2/2,   0.0f),
186 186
         new Static4D(-SQ2/2,   0.0f,  SQ2/2,   0.0f),
187 187
         new Static4D( SQ2/2,   0.0f,   0.0f,  SQ2/2),
188 188
         new Static4D( SQ2/2,   0.0f,   0.0f, -SQ2/2),
189
         new Static4D(  0.0f,  SQ2/2,  SQ2/2,   0.0f),
189
         new Static4D(  0.0f,  SQ2/2,  SQ2/2,   0.0f),  // 10
190 190
         new Static4D(  0.0f,  SQ2/2, -SQ2/2,   0.0f),
191 191
         new Static4D(  0.0f,  SQ2/2,   0.0f,  SQ2/2),
192 192
         new Static4D(  0.0f,  SQ2/2,   0.0f, -SQ2/2),
193 193
         new Static4D(  0.0f,   0.0f,  SQ2/2,  SQ2/2),
194 194
         new Static4D(  0.0f,   0.0f,  SQ2/2, -SQ2/2),
195 195

  
196
         new Static4D(  0.5f,   0.5f,   0.5f,   0.5f),
196
         new Static4D(  0.5f,   0.5f,   0.5f,   0.5f),  // 16
197 197
         new Static4D(  0.5f,   0.5f,  -0.5f,   0.5f),
198 198
         new Static4D(  0.5f,   0.5f,  -0.5f,  -0.5f),
199 199
         new Static4D(  0.5f,  -0.5f,   0.5f,  -0.5f),
200
         new Static4D( -0.5f,  -0.5f,  -0.5f,   0.5f),
200
         new Static4D( -0.5f,  -0.5f,  -0.5f,   0.5f),  // 20
201 201
         new Static4D( -0.5f,   0.5f,  -0.5f,  -0.5f),
202 202
         new Static4D( -0.5f,   0.5f,   0.5f,  -0.5f),
203 203
         new Static4D( -0.5f,   0.5f,   0.5f,   0.5f)
......
258 258
    if( variant==0 )
259 259
      {
260 260
      float[][] bands   = new float[][] { {height,35,0.5f,0.7f,num,extraI,extraV} };
261
      int[] bandIndices = new int[] { 0,0,0,0,0,0};
261
      int[] bandIndices = new int[] {0,0,0,0,0,0};
262
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
263
      }
264
    else if( variant==1 )
265
      {
266
      int extraI2 = numL<=3 ? num-2 : 0;
267

  
268
      float[][] bands   = new float[][]
269
        {
270
          {height,35,0.5f,0.7f,num,extraI,extraV},
271
          {height,35,0.5f,0.7f,  2,extraI2,    0},
272
        };
273

  
274
      int[] bandIndices = new int[] {1,1,1,0,1,0};
262 275
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
263 276
      }
264 277
    else
......
271 284
          {height,35,0.5f,0.7f,  2,extraI2,     0},
272 285
          {height,35,0.5f,0.7f,  2,      0,     0},
273 286
        };
274
      int[] bandIndices = new int[] { 1,1,1,1,0,2};
287
      int[] bandIndices = new int[] {1,1,1,1,0,2};
275 288
      return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
276 289
      }
277 290
    }
278 291

  
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

  
294
  private int getEdgeNum(int cubit, int[] numLayers)
295
    {
296
    int x = numLayers[0];
297
    int y = numLayers[1];
298
    int z = numLayers[2];
299

  
300
    if(x==1 || y==1 || z==1 ) return 0;
301

  
302
    int numCorners = getNumCorners(numLayers);
303
    int numEdges   = getNumEdges(numLayers);
304
    int num = cubit - numCorners;
305

  
306
    if( num>=0 && num<numEdges )
307
      {
308
      int numLR = (x-2);
309
      if( num<  numLR ) return 0;
310
      if( num<2*numLR ) return 1;
311
      if( num<3*numLR ) return 2;
312
      if( num<4*numLR ) return 3;
313
      num -= 4*numLR;
314

  
315
      int numTD = (y-2);
316
      if( num<  numTD ) return 4;
317
      if( num<2*numTD ) return 5;
318
      if( num<3*numTD ) return 6;
319
      if( num<4*numTD ) return 7;
320
      num -= 4*numTD;
321

  
322
      int numFB = (z-2);
323
      if( num<  numFB ) return 8;
324
      if( num<2*numFB ) return 9;
325
      if( num<3*numFB ) return 10;
326
      if( num<4*numFB ) return 11;
327
      }
328

  
329
    return -1;
330
    }
331

  
279 332
///////////////////////////////////////////////////////////////////////////////////////////////////
280 333

  
281 334
  private int getCenterNum(int cubit, int[] numLayers)
282 335
    {
283
    int num = cubit - getNumCornersAndEdges(numLayers);
336
    int numCorners = getNumCorners(numLayers);
337
    int numEdges   = getNumEdges(numLayers);
338
    int num = cubit - numCorners - numEdges;
284 339

  
285 340
    if( num>=0 )
286 341
      {
......
304 359

  
305 360
///////////////////////////////////////////////////////////////////////////////////////////////////
306 361

  
307
  private int getNumCornersAndEdges(int[] numLayers)
362
  private int getNumCorners(int[] numLayers)
308 363
    {
309 364
    int x = numLayers[0];
310 365
    int y = numLayers[1];
311 366
    int z = numLayers[2];
312 367

  
313
    return ( x==1 || y==1 || z==1 ) ? x*y*z : 4*( (x-2)+(y-2)+(z-2) ) + 8;
368
    return ( x==1 || y==1 || z==1 ) ? x*y*z : 8;
369
    }
370

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

  
373
  private int getNumEdges(int[] numLayers)
374
    {
375
    int x = numLayers[0];
376
    int y = numLayers[1];
377
    int z = numLayers[2];
378

  
379
    return ( x==1 || y==1 || z==1 ) ? x*y*z : 4*( (x-2)+(y-2)+(z-2) );
314 380
    }
315 381

  
316 382
///////////////////////////////////////////////////////////////////////////////////////////////////
......
409 475
    {
410 476
    if( mQuats ==null ) initializeQuats();
411 477

  
412
    int centerNum = getCenterNum(cubit,numLayers);
478
    int variant = getCubitVariant(cubit,numLayers);
413 479

  
414
    switch(centerNum)
480
    switch(variant)
415 481
      {
416
      case 0 : return mQuats[13];
417
      case 1 : return mQuats[12];
418
      case 2 : return mQuats[ 8];
419
      case 3 : return mQuats[ 9];
420
      case 4 : return mQuats[ 0];
421
      case 5 : return mQuats[ 1];
422
      default: return mQuats[ 0];
482
      case 0: return mQuats[0];
483
      case 1: int edgeEdge   = getEdgeNum(cubit,numLayers);
484
              switch(edgeEdge)
485
                {
486
                case  0: return mQuats[ 0];
487
                case  1: return mQuats[ 8];
488
                case  2: return mQuats[ 9];
489
                case  3: return mQuats[ 1];
490
                case  4: return mQuats[20];
491
                case  5: return mQuats[ 4];
492
                case  6: return mQuats[23];
493
                case  7: return mQuats[ 5];
494
                case  8: return mQuats[16];
495
                case  9: return mQuats[ 6];
496
                case 10: return mQuats[22];
497
                case 11: return mQuats[ 7];
498
                }
499
              break;
500
      case 2: int centerFace = getCenterNum(cubit,numLayers);
501
              switch(centerFace)
502
                {
503
                case 0 : return mQuats[13];
504
                case 1 : return mQuats[12];
505
                case 2 : return mQuats[ 8];
506
                case 3 : return mQuats[ 9];
507
                case 4 : return mQuats[ 0];
508
                case 5 : return mQuats[ 1];
509
                }
423 510
      }
511

  
512
    return mQuats[0];
424 513
    }
425 514

  
426 515
///////////////////////////////////////////////////////////////////////////////////////////////////
427 516

  
428 517
  public int getNumCubitVariants(int[] numLayers)
429 518
    {
430
    return numLayers[0]>2 ? 2:1;
519
    final int X = numLayers[0];
520
    final int Y = numLayers[1];
521
    final int Z = numLayers[2];
522

  
523
    if( X==1 || Y==1 || Z==1 ) return 1;
524
    if( X<=2 && Y<=2 && Z<=2 ) return 1;
525

  
526
    return 3;
431 527
    }
432 528

  
433 529
///////////////////////////////////////////////////////////////////////////////////////////////////
434 530

  
435 531
  public int getCubitVariant(int cubit, int[] numLayers)
436 532
    {
437
    return cubit < getNumCornersAndEdges(numLayers) ? 0 : 1;
533
    int numCorners = getNumCorners(numLayers);
534
    if( cubit < numCorners          ) return 0;
535
    int numEdges = getNumEdges(numLayers);
536
    if( cubit < numCorners+numEdges ) return 1;
537

  
538
    return 2;
438 539
    }
439 540

  
440 541
///////////////////////////////////////////////////////////////////////////////////////////////////
......
448 549

  
449 550
  public int getCubitFaceColor(int cubit, int face, int[] numLayers)
450 551
    {
451
    int centerNum = getCenterNum(cubit,numLayers);
552
    int variant = getCubitVariant(cubit,numLayers);
452 553

  
453
    if( centerNum<0 )
454
      {
455
      int axis = face/2;
456
      return CUBITS[cubit].getRotRow(axis) == (face%2==0 ? (1<<(numLayers[axis]-1)):1) ? face : -1;
457
      }
458
    else
554
    switch(variant)
459 555
      {
460
      return face==4 ? centerNum : -1;
556
      case 0: int axis = face/2;
557
              return CUBITS[cubit].getRotRow(axis) == (face%2==0 ? (1<<(numLayers[axis]-1)):1) ? face : -1;
558
      case 1: if( face!=3 && face !=5 ) return -1;
559
              int edge = getEdgeNum(cubit,numLayers);
560

  
561
              switch(edge)
562
                {
563
                case  0: return face==3 ? 3 : 5;
564
                case  1: return face==3 ? 4 : 3;
565
                case  2: return face==3 ? 5 : 2;
566
                case  3: return face==3 ? 2 : 4;
567
                case  4: return face==3 ? 5 : 1;
568
                case  5: return face==3 ? 1 : 4;
569
                case  6: return face==3 ? 5 : 0;
570
                case  7: return face==3 ? 0 : 4;
571
                case  8: return face==3 ? 1 : 3;
572
                case  9: return face==3 ? 2 : 1;
573
                case 10: return face==3 ? 0 : 3;
574
                case 11: return face==3 ? 2 : 0;
575
                default: return 0;
576
                }
577

  
578
      case 2: return face==4 ? getCenterNum(cubit,numLayers) : -1;
461 579
      }
580

  
581
    return -1;
462 582
    }
463 583

  
464 584
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff