Works with r5602 or later.
Target a turret (and make sure it is targeting something as well or the turret matrix wont be properly set)
#Conditional Hooks
$State: GS_STATE_GAME_PLAY
$On Frame: [
if not_init == nil then
not_init = 1
vec_z = ba.createVector(0,0,100)
vec_y = ba.createVector(0,-100,0)
vec_draw = ba.createVector(0,0,0)
pi = math.pi
end
if missiontime_old == nil then
missiontime_old = mn.getMissionTime()
end
missiontime = mn.getMissionTime()
if missiontime ~= nil then
if missiontime ~= missiontime_old then
if hv.Player:isValid() then
player = hv.Player
if player:getBreedName() == "Ship" then
if player.Target ~= nil then
if player.TargetSubsystem:isValid() then
ship = player.Target
subsys = player.TargetSubsystem
matrix = subsys:getTurretMatrix()
fov, fov_e, fov_y = subsys:getFOVs()
if fov > -1 then
subsys_pos = ship.Orientation:unrotateVector(subsys.Position) + ship.Position
x_1,y_1 = subsys_pos:getScreenCoords()
gr.setColor(255,0,0,255)
for i = 1, 8 do
rot_mod = ((i/4) + ((missiontime/3) % 2))
cos = math.cos(rot_mod * pi)
sin = math.sin(rot_mod * pi)
vec_draw[1] = cos * math.sqrt(1-(fov * fov))
vec_draw[2] = sin * math.sqrt(1-(fov * fov))
vec_draw[3] = fov
vec_draw = 100 * vec_draw
pos_draw = subsys_pos + ship.Orientation:unrotateVector(matrix:unrotateVector(vec_draw))
x_i, y_i = pos_draw:getScreenCoords()
if x_1 ~= false and x_i ~= false then
if fov_y > -1 and fov_y < 1 then
if -sin >= fov_y then
gr.drawGradientLine(x_i,y_i,x_1,y_1)
end
else
gr.drawGradientLine(x_i,y_i,x_1,y_1)
end
end
end
if fov_e < 1 then
gr.setColor(255,128,0,255)
for i = 1, 8 do
rot_mod = ((i/4) + ((missiontime/3) % 4))
cos = math.cos(rot_mod * pi)
sin = math.sin(rot_mod * pi)
vec_draw[1] = cos * math.sqrt(1-(fov_e * fov_e))
vec_draw[2] = sin * math.sqrt(1-(fov_e * fov_e))
vec_draw[3] = fov_e
vec_draw = 100 * vec_draw
pos_draw = subsys_pos + ship.Orientation:unrotateVector(matrix:unrotateVector(vec_draw))
x_i, y_i = pos_draw:getScreenCoords()
if x_1 ~= false and x_i ~= false then
if fov_y > -1 and fov_y < 1 then
if -sin >= fov_y then
gr.drawGradientLine(x_i,y_i,x_1,y_1)
end
else
gr.drawGradientLine(x_i,y_i,x_1,y_1)
end
end
end
end
if fov_y > -1 and fov_y < 1 then
gr.setColor(255,0,128,255)
for i = 1, 8 do
rot_mod = ((i/4) + ((missiontime/3) % 4))
cos = math.cos(rot_mod * pi)
sin = math.sin(rot_mod * pi)
vec_draw[1] = fov_y * sin
if sin > 0 then
vec_draw[2] = math.sqrt(1-(fov_y*fov_y)) *sin
else
vec_draw[2] = -math.sqrt(1-(fov_y*fov_y)) *sin
end
vec_draw[3] = cos
vec_draw = 100 * vec_draw
pos_draw = subsys_pos + ship.Orientation:unrotateVector(matrix:unrotateVector(vec_draw))
x_i, y_i = pos_draw:getScreenCoords()
if x_1 ~= false and x_i ~= false then
if fov_e < 1 then
if cos < fov_e and cos > fov then
gr.drawGradientLine(x_i,y_i,x_1,y_1)
end
else
if cos > fov then
gr.drawGradientLine(x_i,y_i,x_1,y_1)
end
end
end
end
gr.setColor(128,128,255,255)
if fov_e < 1 then
for i = 0,1 do
vec_draw[2] = -fov_y * math.sqrt(1 - (fov_e*fov_e))
vec_draw[1] = (1 - (2*i)) * math.sqrt(1-(fov_y*fov_y)) *math.sqrt(1 - (fov_e*fov_e))
vec_draw[3] = fov_e
vec_draw = 100 * vec_draw
pos_draw = subsys_pos + ship.Orientation:unrotateVector(matrix:unrotateVector(vec_draw))
x_i, y_i = pos_draw:getScreenCoords()
if x_1 ~= false and x_i ~= false then
gr.drawLine(x_i,y_i,x_1,y_1)
end
end
end
for i = 0,1 do
vec_draw[2] = -fov_y * math.sqrt(1 - (fov*fov))
vec_draw[1] = (1 - (2*i)) * math.sqrt(1-(fov_y*fov_y)) *math.sqrt(1 - (fov*fov))
vec_draw[3] = fov
vec_draw = 100 * vec_draw
pos_draw = subsys_pos + ship.Orientation:unrotateVector(matrix:unrotateVector(vec_draw))
x_i, y_i = pos_draw:getScreenCoords()
if x_1 ~= false and x_i ~= false then
gr.drawLine(x_i,y_i,x_1,y_1)
end
end
end
z_pos = subsys_pos + ship.Orientation:unrotateVector(matrix:unrotateVector(vec_z))
y_pos = subsys_pos + ship.Orientation:unrotateVector(matrix:unrotateVector(vec_y))
x_2,y_2 = z_pos:getScreenCoords()
x_3,y_3 = y_pos:getScreenCoords()
if x_1 ~= false and x_2 ~= false then
gr.setColor(0,255,0,255)
gr.drawLine(x_1,y_1,x_2,y_2)
end
if x_1 ~= false and x_3 ~= false then
gr.setColor(255,0,0,255)
gr.drawLine(x_1,y_1,x_3,y_3)
end
end
end
end
end
end
end
missiontime_old = missiontime
end
]
#End