|
发表于 2010-11-8 00:07:41
|
显示全部楼层
[jass]function FixTheta takes real theta returns real
    loop
        exitwhen theta >= 0
        set theta = theta + bj_PI * 2
    endloop
    loop
        exitwhen theta < bi_PI * 2
        set theta = theta - bj_PI * 2
    endloop
    return theta
endfunction
function GetBound takes location l, real theta, real a, real b returns location
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local real x1
    local real y1
    local real tan
    local real sin
    local real cos
    set theta = FixTheta(theta)
    if (theta == bj_PI / 2) then
        set x1 = x
        set y1 = 0
    elseif (theta == bj_PI * 3 / 2) then
        set x1 = x
        set y1 = b
    elseif (theta == 0 then
        set x1 = 0
        set y1 = y
    elseif (theta == bj_PI) then
        set x1 = a
        set y1 = y
    else
        set tan = Tan(theta)
        set sin = Sin(theta)
        set cos = Cos(theta)
        set x1 = x - y / tan
        set y1 = 0
        if (not (x1 * (a - x1) >= 0 and (x - x1) * cos >= 0)) then
            set x1 = x + (b - y) / tan
            set y1 = b
            if (not (x1 * (a - x1) >= 0 and (x - x1) * cos >= 0)) then
                set x1 = 0
                set y1 = y - y * tan
                if (not (y1 * (b - y1) >= 0 and (y - y1) * sin >= 0)) then
                    set x1 = a
                    set y1 = y + (a - x) * tan
                    if (not (y1 * (b - y1) >= 0 and (y - y1) * sin >= 0)) then
                        return null
                    endif
                endif
            endif
        endif
    endif
    return Location(x1, y1)
endfunction[/jass]
乱写的,无验证,甚至语法都没检测过,那些变量啊函数名啊也不知道对不对,代码也写得十分丑陋……
参考意义不明 |
|