Warcraft III resources & community, 2003–2006 · archived

IsPointInsidePara

not rated
Submitted by AltSubmitterVariable Change0 downloads
Determines if the given co-ordinates are inside a parallelogram/diamond, whose corners are defined as being the middle of each side of the rect ie:
_ _
| /\ |
/ \
\ /
|_\/_|

This is designed for diamond shape patches of terrain which cannot be defined easily be regions, village fields are a perfect example. Usually the enclosing rect will be a perfect square, but this is not a requirement for the function.
I'm not entirely happy with the function name or description, suggestions are welcome.

Source

function IsPointInsidePara takes rect r, real whichX, real whichY returns boolean
    local real width = GetRectMaxX(r) - GetRectMinX(r)
    local real height = GetRectMaxY(r) - GetRectMinY(r)
    local real x  = whichX - GetRectMinX(r)
    local real y  = whichY - GetRectMinY(r)
    set x = x / width - 0.5
    set y = y / height - 0.5
    return (RAbsBJ(x) + RAbsBJ(y) <= 0.5)
endfunction

Comments

0

No comments.