Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. internal static void HollowEllipsoidCallback ( Player player, Position[] marks, object tag ) {
  2.     byte drawBlock = (byte)tag;
  3.     if( drawBlock == (byte)Block.Undefined ) {
  4.         drawBlock = (byte)player.lastUsedBlockType;
  5.     }
  6.  
  7.     // find start/end coordinates
  8.     int sx = Math.Min( marks[0].x, marks[1].x );
  9.     int ex = Math.Max( marks[0].x, marks[1].x );
  10.     int sy = Math.Min( marks[0].y, marks[1].y );
  11.     int ey = Math.Max( marks[0].y, marks[1].y );
  12.     int sh = Math.Min( marks[0].h, marks[1].h );
  13.     int eh = Math.Max( marks[0].h, marks[1].h );
  14.  
  15.     // find axis lengths
  16.     double rx = (ex - sx + 1) / 2d;
  17.     double ry = (ey - sy + 1) / 2d;
  18.     double rh = (eh - sh + 1) / 2d;
  19.  
  20.     double rx2 = 1 / (rx * rx);
  21.     double ry2 = 1 / (ry * ry);
  22.     double rh2 = 1 / (rh * rh);
  23.  
  24.     // find center points
  25.     double cx = (ex + sx) / 2d;
  26.     double cy = (ey + sy) / 2d;
  27.     double ch = (eh + sh) / 2d;
  28.  
  29.     // rougher estimation than the non-hollow form, a voxelized surface is a bit funky
  30.     int volume = (int)(4 / 3d * Math.PI * ((rx+.5)*(ry+.5)*(rh+.5) - (rx-.5)*(ry-.5)*(rh-.5)) * 0.85);
  31.     if( !player.CanDraw( volume ) ) {
  32.         player.MessageNow( "You are only allowed to run draw commands that affect up to {0} blocks. This one would affect {1} blocks.",
  33.                            player.info.rank.DrawLimit,
  34.                            volume );
  35.         return;
  36.     }
  37.  
  38.     player.undoBuffer.Clear();
  39.  
  40.     int blocks = 0, blocksDenied = 0;
  41.     bool cannotUndo = false;
  42.  
  43.     for( int x = sx; x <= ex; x++ ) {
  44.         for( int y = sy; y <= ey; y ++ ) {
  45.             for( int h = sh; h <= eh; h++ ) {
  46.            
  47.                 double dx = (x - cx);
  48.                 double dy = (y - cy);
  49.                 double dh = (h - ch);
  50.  
  51.                 if( (dx*dx)*rx2 + (dy*dy)*ry2 + (dh*dh)*rh2 <= 1 ) {
  52.                     // we touched the surface
  53.                     // keep drilling until we hit an internal block
  54.                     do {
  55.                         DrawOneBlock( player, drawBlock, x, y, h, ref blocks, ref blocksDenied, ref cannotUndo );
  56.                         DrawOneBlock( player, drawBlock, x, y, (int)(ch - dh), ref blocks, ref blocksDenied, ref cannotUndo );
  57.                         dh = (++h - ch);
  58.                     } while( h <= (int)ch &&
  59.                             ((dx+1)*(dx+1) *rx2 + (dy*dy)       *ry2  + (dh*dh)       *rh2 > 1 ||
  60.                              (dx-1)*(dx-1) *rx2 + (dy*dy)       *ry2  + (dh*dh)       *rh2 > 1 ||
  61.                              (dx*dx)       *rx2 + (dy+1)*(dy+1) *ry2  + (dh*dh)       *rh2 > 1 ||
  62.                              (dx*dx)       *rx2 + (dy-1)*(dy-1) *ry2  + (dh*dh)       *rh2 > 1 ||
  63.                              (dx*dx)       *rx2 + (dy*dy)       *ry2  + (dh+1)*(dh+1) *rh2 > 1 ||
  64.                              (dx*dx)       *rx2 + (dy*dy)       *ry2  + (dh-1)*(dh-1) *rh2 > 1) );
  65.                     break;
  66.                 }
  67.             }
  68.         }
  69.     }
  70.     Logger.Log( "{0} drew a hollow ellipsoid containing {1} blocks of type {2} (on world {3})", LogType.UserActivity,
  71.                 player.name,
  72.                 blocks,
  73.                 (Block)drawBlock,
  74.                 player.world.name );
  75.     DrawingFinished( player, "drawn", blocks, blocksDenied );
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement