Joker(Div)
Always Here..
- Reaction score
- 86
How would you check if someone entered an octagonal area? I'm trying to avoid a high-frequency terrain check.
library RegionFunctions
globals
private constant real CELL = 32.
private constant real HALF_CELL = 16.
endglobals
private function RegionAddGon takes region whichRegion, real x1, real y1, real apothem, real angle, real side returns nothing
local real length = HALF_CELL
local real width
local real offset
local real dx = Cos(angle)
local real dy = Sin(angle)
local real x
local real y
loop
set width = side * length / apothem
set offset = -.5 * width + HALF_CELL
loop
set x = x1 + length * dx - offset * dy
set y = y1 + length * dy + offset * dx
call RegionAddCell(whichRegion, x, y)
exitwhen(offset >= .5 * width)
set offset = offset + CELL
endloop
exitwhen(length >= apothem)
set length = length + CELL
endloop
endfunction
function RegionAddPolygon takes region whichRegion, real x, real y, real radius, integer polygons, real angle returns nothing
local real apothem = radius * Cos(bj_PI / polygons)
local real side = 2. * radius * Sin(bj_PI / polygons)
local real arc = 2. * bj_PI / polygons
loop
exitwhen(polygons <= 0)
call RegionAddGon(whichRegion, x, y, apothem, angle + arc / 2., side)
set angle = angle + arc
set polygons = polygons - 1
endloop
endfunction
endlibrary