Project

General

Profile

« Previous | Next » 

Revision 15873844

Added by Leszek Koltunski almost 8 years ago

Simplify and spped 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 centerX, float centerY, float vectZ, int col, int row, float[] position, float[] normal, float[] texture)
416
   private int addFrontVertex(int corner, int vertex, 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

  
420 423
     switch(corner)
421 424
       {
422
       case NW: android.util.Log.e("CUBES", "adding NW vertex!");
425
       case NW: x = (float)col/mCols;
426
                y = (float)row/mRows;
427
                index = 0;
423 428
                break;
424
       case SW: android.util.Log.e("CUBES", "adding SW vertex!");
429
       case SW: x = (float)col/mCols;
430
                y = (float)(row+1)/mRows;
431
                index = 1;
425 432
                break;
426
       case SE: android.util.Log.e("CUBES", "adding SE vertex!");
433
       case NE: x = (float)(col+1)/mCols;
434
                y = (float)row/mRows;
435
                index = 2;
427 436
                break;
428
       case NE: android.util.Log.e("CUBES", "adding NE vertex!");
437
       case SE: x = (float)(col+1)/mCols;
438
                y = (float)(row+1)/mRows;
439
                index = 3;
429 440
                break;
430 441
       }
431
     */
432
     switch(corner)
433
       {
434
       case NW: position[3*vertex  ] = (centerX-0.5f)/mCols;
435
                position[3*vertex+1] = (centerY+0.5f)/mRows;
436
                position[3*vertex+2] = vectZ;
437
                normal[3*vertex  ]   = mNormalX[0];
438
                normal[3*vertex+1]   = mNormalY[0];
439
                normal[3*vertex+2]   = mNormalZ[0];
440
                texture[2*vertex  ]  = (float)col/mCols;
441
                texture[2*vertex+1]  = (float)row/mRows;
442
                return vertex+1;
443
       case SW: position[3*vertex  ] = (centerX-0.5f)/mCols;
444
                position[3*vertex+1] = (centerY-0.5f)/mRows;
445
                position[3*vertex+2] = vectZ;
446
                normal[3*vertex  ]   = mNormalX[1];
447
                normal[3*vertex+1]   = mNormalY[1];
448
                normal[3*vertex+2]   = mNormalZ[1];
449
                texture[2*vertex  ]  = (float)col/mCols;
450
                texture[2*vertex+1]  = (float)(row+1)/mRows;
451
                return vertex+1;
452
       case NE: position[3*vertex  ] = (centerX+0.5f)/mCols;
453
                position[3*vertex+1] = (centerY+0.5f)/mRows;
454
                position[3*vertex+2] = vectZ;
455
                normal[3*vertex  ]   = mNormalX[2];
456
                normal[3*vertex+1]   = mNormalY[2];
457
                normal[3*vertex+2]   = mNormalZ[2];
458
                texture[2*vertex  ]  = (float)(col+1)/mCols;
459
                texture[2*vertex+1]  = (float)row/mRows;
460
                return vertex+1;
461
       case SE: position[3*vertex  ] = (centerX+0.5f)/mCols;
462
                position[3*vertex+1] = (centerY-0.5f)/mRows;
463
                position[3*vertex+2] = vectZ;
464
                normal[3*vertex  ]   = mNormalX[3];
465
                normal[3*vertex+1]   = mNormalY[3];
466
                normal[3*vertex+2]   = mNormalZ[3];
467
                texture[2*vertex  ]  = (float)(col+1)/mCols;
468
                texture[2*vertex+1]  = (float)(row+1)/mRows;
469
                return vertex+1;
470
       }
471 442

  
472
     return vertex;
443
     position[3*vertex  ] = x-0.5f;
444
     position[3*vertex+1] = 0.5f-y;
445
     position[3*vertex+2] = vectZ;
446
     normal[3*vertex  ]   = mNormalX[index];
447
     normal[3*vertex+1]   = mNormalY[index];
448
     normal[3*vertex+2]   = mNormalZ[index];
449
     texture[2*vertex  ]  = x;
450
     texture[2*vertex+1]  = y;
451

  
452
     return vertex+1;
473 453
     }
474 454

  
475 455
///////////////////////////////////////////////////////////////////////////////////////////////////
......
480 460
     boolean seenLand=false;
481 461
     boolean lastBlockIsNE = false;
482 462
     boolean currentBlockIsNE;
483
     float centerX, centerY;
484 463
     float vectZ = front?FRONTZ:BACKZ;
485 464

  
486 465
     //android.util.Log.d("CUBES", "buildFrontBack");
......
496 475
         if( current%2 == 1 )
497 476
           {
498 477
           currentBlockIsNE = isNE(i,j);
499
           centerX = j-(mCols-1.0f)/2.0f;
500
           centerY = (mRows-1.0f)/2.0f-i;
501 478

  
502 479
           if( !seenLand && !front && ((vertex%2==1)^currentBlockIsNE) )
503 480
             {
......
511 488
           if( (last!=current) || (lastBlockIsNE^currentBlockIsNE) )
512 489
             {
513 490
             if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
514
             vertex= addFrontVertex( currentBlockIsNE ? NW:SW, vertex, centerX, centerY, vectZ, j, i, position, normal, texture);
491
             vertex= addFrontVertex( currentBlockIsNE ? NW:SW, vertex, vectZ, j, i, position, normal, texture);
515 492
             if( seenLand  && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
516 493
             if( (lastBlockIsNE^currentBlockIsNE)
517 494
                 || (!front && !seenLand)       ) vertex = repeatLast(vertex,position,normal,texture);
518
             vertex= addFrontVertex( currentBlockIsNE ? SW:NW, vertex, centerX, centerY, vectZ, j, i, position, normal, texture);
495
             vertex= addFrontVertex( currentBlockIsNE ? SW:NW, vertex, vectZ, j, i, position, normal, texture);
519 496
             }
520
           vertex= addFrontVertex( currentBlockIsNE ? NE:SE, vertex, centerX, centerY, vectZ, j, i, position, normal, texture);
521
           vertex= addFrontVertex( currentBlockIsNE ? SE:NE, vertex, centerX, centerY, vectZ, j, i, position, normal, texture);
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);
522 499

  
523 500
           seenLand = true;
524 501
           lastBlockIsNE = currentBlockIsNE;

Also available in: Unified diff