動画はこちら
コメントで動画との修正点が入れてあります
修正した場合、PIDの調節は必要です、Pを4あたりすると良いかも。
日本語はStormworksのLua内で使えないので必ず削除して下さい。
tracking radar
pi=math.pi
pi2=pi*2
function onTick()
local fov,Azimuth,Elevation,rotAzimuth,rotElevation
data={}
--camera fov
fov=input.getNumber(4)
fovRadian= -2.175*fov+2.2
--dcs angle
--動画ではpi2わすれてる1
Azimuth=input.getNumber(8)*pi2
Elevation=input.getNumber(12)*pi2
isLock=input.getBool(10)
for i=0,7 do
if input.getBool(i+1) then
local d,x,y
d=input.getNumber(i*4+1)
x=input.getNumber(i*4+2)*pi2
y=input.getNumber(i*4+3)*pi2
table.insert(data,{d=d,x=x,y=y})
end
end
if isLock and #data>=1 then
local bufferI
for i=1,#data do
--ここなんか微妙だったのでなおした
if i==1 then
bufferI=1
elseif data[bufferI].x^2+data[bufferI].y^2 > data[i].x^2+data[i].y^2 then
bufferI=i
end
end
rotAzimuth=Azimuth+data[bufferI].x
rotElevation=Elevation+data[bufferI].y
else
rotAzimuth=Azimuth
rotElevation=Elevation
end
--動画ではpi2わすれてる2
output.setNumber(1,rotAzimuth/pi2)
output.setNumber(2,rotElevation/pi2)
end
function onDraw()
local cw,ch,echoX,echoY,rad2pixel
w=screen.getWidth()
h=screen.getHeight()
--center
cw=w/2
ch=h/2
--draw radar echo
screen.setColor(0, 255, 0, 200)
rad2pixel=w/fovRadian
for i=1,#data do
echoX=cw+data[i].x*rad2pixel
echoY=ch-data[i].y*rad2pixel
screen.drawCircle(echoX,echoY,5)
end
--crosshair
screen.setColor(0, 255, 0, 100)
screen.drawLine(cw,0,cw,ch-5)
screen.drawLine(cw,ch+5,cw,h)
screen.drawLine(0,ch,cw-5,ch)
screen.drawLine(cw+5,ch,w,ch)
--display
if isLock then
screen.setColor(255, 0, 0)
screen.drawText(0,0,"Lock")
end
end