找回密码
 点一下
查看: 2251|回复: 4

定点投射物曲线模拟——小血要的东西

[复制链接]
发表于 2009-10-31 20:01:29 | 显示全部楼层 |阅读模式
用了hashtable的东西。bug修复完成

计算公式

计算公式

[jass]
    globals
    hashtable udg_ht
    constant real udg_steptime = 0.03
    constant real udg_stepspeed = 20
endglobals

function movemissile takes nothing returns nothing
    local integer i = GetHandleId(GetExpiredTimer())
    local unit missile = LoadUnitHandle(udg_ht,i,0)
    local real n = LoadReal(udg_ht,i,1)            
    local real m = LoadReal(udg_ht,i,2)
    local real a = LoadReal(udg_ht,i,3)
    local real l0 = LoadReal(udg_ht,i,4)
    local real x0 = LoadReal(udg_ht,i,5)  
    local real y0 = LoadReal(udg_ht,i,6)
    local real z0 = LoadReal(udg_ht,i,7)
    local real t = LoadReal(udg_ht,i,8)
    local real l = t * udg_stepspeed
    local real x = l * Cos(a) + x0
    local real y = l * Sin(a) + y0
    local real h = n * l * l / 1000000 + m * l / 10000 + z0
    local location loc = null
    if l > l0 then         
        call PauseTimer(GetExpiredTimer())
        call DestroyTimer(GetExpiredTimer())
        set missile = null
        call FlushChildHashtable(udg_ht,i)
        return
    endif     
    call SaveReal(udg_ht,i,8,t + 1)
    call SetUnitX(missile,x)   
    call SetUnitY(missile,y)
    set loc = Location(x,y)
    if GetLocationZ(loc) > h + 10 then
        call RemoveUnit(missile)   
        call PauseTimer(GetExpiredTimer())
        call DestroyTimer(GetExpiredTimer())
        call RemoveLocation(loc)
        set loc = null  
        set missile = null
        call FlushChildHashtable(udg_ht,i)
        return
    endif
    call SetUnitFlyHeight(missile,h - GetLocationZ(loc),0)   
endfunction

function aim takes unit missile ,real k ,real xs ,real ys ,real zs ,real xa ,real ya , real za returns nothing
    local real h = za - zs
    local real l = SquareRoot((xa - xs) * (xa - xs) + (ya - ys) * (ya - ys))
    local real a = Atan((ya - ys) / (xa - xs))         
    local real m = 2 * (k * l + SquareRoot(k * l * (k * l - h ))) * 10000 / l
    local real n = (h - m * l / 10000) * 1000000 / l / l
    local timer t = CreateTimer()
    local integer i = GetHandleId(t)
    if xa - xs < 0 then
        set a = a + 3.1415926
    endif
    call SaveUnitHandle(udg_ht,i,0,missile)  
    call SaveReal(udg_ht,i,1,n)      
    call SaveReal(udg_ht,i,2,m)  
    call SaveReal(udg_ht,i,3,a)      
    call SaveReal(udg_ht,i,4,l)
    call SaveReal(udg_ht,i,5,xs)   
    call SaveReal(udg_ht,i,6,ys)   
    call SaveReal(udg_ht,i,7,zs)  
    call SaveReal(udg_ht,i,8,0)   
    call TimerStart(t,udg_steptime,true,function movemissile)
    set t = null
endfunction

function aimlocation takes unit missile , real k ,location l0 , location l1 returns nothing
    call aim(missile,k,GetLocationX(l0),GetLocationY(l0),GetLocationZ(l0),GetLocationX(l1),GetLocationY(l1),GetLocationZ(l1))
endfunction
[/jass]

投射.w3x

35 KB, 下载次数: 83

评分

参与人数 1威望 +3 收起 理由
血戮魔动冰 + 3 ~

查看全部评分

发表于 2009-10-31 20:12:18 | 显示全部楼层
GetExpiredTimer 到底会不会存在干扰呢,一直有这个疑问...
回复

使用道具 举报

 楼主| 发表于 2009-10-31 20:20:39 | 显示全部楼层
不会
事件响应貌似都是局域变量
回复

使用道具 举报

发表于 2009-11-1 10:02:16 | 显示全部楼层
啊哈~刚刚学了双曲线
关于投射物。能不能写一个关于物理的呢,就是使投射物进行平抛运动,用上常量g。
回复

使用道具 举报

 楼主| 发表于 2009-11-1 11:01:19 | 显示全部楼层
这样没有意义
实质就是使用公式的差别
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-4-19 16:32 , Processed in 0.300732 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表