Advertisement
LPGhatguy

getCellsWithinRadius

Jun 10th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local center = cellsize / 2
  2.  
  3. function align(x)
  4.     return math.floor(x + 0.5) + center
  5. end
  6.  
  7. function getCellsWithinRadius(Point, Radius)
  8.     local Point = Point * cellsize
  9.     local HalfRadius = (Radius * cellsize) / 2
  10.     local near = {}
  11.  
  12.     for x = Point.X - HalfRadius, Point.X + HalfRadius do
  13.         local fx = align(x)
  14.         for y = Point.Y - HalfRadius, Point.Y + HalfRadius do
  15.             local fy = align(y)
  16.             for z = Point.Z - HalfRadius, Point.Z + HalfRadius do
  17.  
  18.                 local v3p = Vector3.new(fx, fy, align(z))
  19.                 if ((Point - v3p).magnitude < Radius) then
  20.                     table.insert(near, v3p)
  21.                 end
  22.             end
  23.         end
  24.     end
  25.  
  26.     return near
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement