Project

General

Profile

« Previous | Next » 

Revision e5d9b235

Added by Leszek Koltunski almost 8 years ago

Further simplify and speed up the DistortedCubes target.

View differences:

src/main/java/org/distorted/library/DistortedCubesGrid.java
413 413
   
414 414
///////////////////////////////////////////////////////////////////////////////////////////////////
415 415

  
416
   private int addFrontVertex(int corner, int vertex, float vectZ, int col, int row, float[] position, float[] normal, float[] texture)
416
   private int addFrontVertex(int vertex, int index, float vectZ, int col, int row, float[] position, float[] normal, float[] texture)
417 417
     {
418 418
     remainingVert--;
419 419

  
420
     float x=0,y=0;
421
     int index=0;
422

  
423
     switch(corner)
424
       {
425
       case NW: x = (float)col/mCols;
426
                y = (float)row/mRows;
427
                index = 0;
428
                break;
429
       case SW: x = (float)col/mCols;
430
                y = (float)(row+1)/mRows;
431
                index = 1;
432
                break;
433
       case NE: x = (float)(col+1)/mCols;
434
                y = (float)row/mRows;
435
                index = 2;
436
                break;
437
       case SE: x = (float)(col+1)/mCols;
438
                y = (float)(row+1)/mRows;
439
                index = 3;
440
                break;
441
       }
420
     float x = (float)col/mCols;
421
     float y = (float)row/mRows;
442 422

  
443 423
     position[3*vertex  ] = x-0.5f;
444 424
     position[3*vertex+1] = 0.5f-y;
......
464 444

  
465 445
     //android.util.Log.d("CUBES", "buildFrontBack");
466 446

  
467
     for(int i=0; i<mRows; i++)
447
     for(int row=0; row<mRows; row++)
468 448
       {
469 449
       last =0;
470 450
         
471
       for(int j=0; j<mCols; j++)
451
       for(int col=0; col<mCols; col++)
472 452
         {
473
         current = mCubes[i][j];
453
         current = mCubes[row][col];
474 454

  
475 455
         if( current%2 == 1 )
476 456
           {
477
           currentBlockIsNE = isNE(i,j);
457
           currentBlockIsNE = isNE(row,col);
478 458

  
479 459
           if( !seenLand && !front && ((vertex%2==1)^currentBlockIsNE) )
480 460
             {
......
483 463
             vertex = repeatLast(vertex,position,normal,texture);
484 464
             }
485 465

  
486
           createNormals(front,i,j);
466
           createNormals(front,row,col);
487 467

  
488
           if( (last!=current) || (lastBlockIsNE^currentBlockIsNE) )
468
           if( currentBlockIsNE )
489 469
             {
490
             if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
491
             vertex= addFrontVertex( currentBlockIsNE ? NW:SW, vertex, vectZ, j, i, position, normal, texture);
492
             if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
493
             if( (lastBlockIsNE^currentBlockIsNE)
494
                 || (!front && !seenLand)       ) vertex = repeatLast(vertex,position,normal,texture);
495
             vertex= addFrontVertex( currentBlockIsNE ? SW:NW, vertex, vectZ, j, i, position, normal, texture);
470
             if( (last!=current) || !lastBlockIsNE )
471
               {
472
               if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
473
               vertex= addFrontVertex( vertex, 0, vectZ, col, row, position, normal, texture);
474
               if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
475
               if( !lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,position,normal,texture);
476
               vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, position, normal, texture);
477
               }
478
             vertex= addFrontVertex( vertex, 2, vectZ, col+1, row, position, normal, texture);
479
             vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, position, normal, texture);
480
             }
481
           else
482
             {
483
             if( (last!=current) || lastBlockIsNE )
484
               {
485
               if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
486
               vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, position, normal, texture);
487
               if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
488
               if( lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,position,normal,texture);
489
               vertex= addFrontVertex( vertex, 0, vectZ, col, row, position, normal, texture);
490
               }
491
             vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, position, normal, texture);
492
             vertex= addFrontVertex( vertex, 2, vectZ, col+1, row  , position, normal, texture);
496 493
             }
497
           vertex= addFrontVertex( currentBlockIsNE ? NE:SE, vertex, vectZ, j, i, position, normal, texture);
498
           vertex= addFrontVertex( currentBlockIsNE ? SE:NE, vertex, vectZ, j, i, position, normal, texture);
499 494

  
500 495
           seenLand = true;
501 496
           lastBlockIsNE = currentBlockIsNE;
......
512 507

  
513 508
   private int repeatLast(int vertex, float[] position, float[] normal, float[] texture)
514 509
     {
515
     remainingVert--;
516

  
517 510
     //android.util.Log.e("CUBES", "repeating last vertex!");
518 511

  
519 512
     if( vertex>0 )
520 513
       {
514
       remainingVert--;
515

  
521 516
       position[3*vertex  ] = position[3*vertex-3];
522 517
       position[3*vertex+1] = position[3*vertex-2];
523 518
       position[3*vertex+2] = position[3*vertex-1];
......
730 725
 */
731 726
   public DistortedCubesGrid(int cols, String desc, boolean frontOnly)
732 727
      {
728
      //android.util.Log.d("CUBES","calculating dataLength...");
729

  
733 730
      prepareDataStructures(cols,desc,frontOnly);
734 731
       
735 732
      int numVertices=0;
......
737 734
      float[] normalData  = new float[NORMAL_DATA_SIZE  *dataLength];
738 735
      float[] textureData = new float[TEX_DATA_SIZE     *dataLength];
739 736

  
737
      //android.util.Log.d("CUBES","building front grid...");
738

  
740 739
      numVertices = buildFrontBackGrid(true, numVertices,positionData,normalData,textureData);
741 740
      
742 741
      if( !frontOnly )
......
748 747

  
749 748
          numVertices = repeatLast(numVertices,positionData,normalData,textureData);
750 749
          }
750

  
751
        //android.util.Log.d("CUBES","building side grid...");
752

  
751 753
        numVertices = buildSideGrid (numVertices,positionData,normalData,textureData);
754

  
755
        //android.util.Log.d("CUBES","building back grid...");
756

  
752 757
        numVertices = buildFrontBackGrid (false,numVertices,positionData,normalData,textureData);
753 758
        }
754 759
      

Also available in: Unified diff