FreeSpace Releases > Scripting Releases
Turret fov visualisator
Wanderer:
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)
--- Code: ---#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
--- End code ---
Aardwolf:
Can you explain this stuff about it not working if the turret isn't targeting anything? Could this be easily fixed?
Also, I'm thinking if we could get something like this hard-coded (assuming it's what I think it is), it might be a very useful feature for the RTS mod. :D
No recent progress, FYI.
Zacam:
If the Turret you have targeted is not in and of itself targeting anything, then there is nothing for this script to show.
Aardwolf:
I'm not quite sure I get what it does, then. I'll try it out myself to see what it does, and maybe upload a screenshot.
Edit: Stupid pirate script is stupid.
Wanderer:
--- Quote from: Aardwolf on September 19, 2009, 04:04:06 pm ---Can you explain this stuff about it not working if the turret isn't targeting anything? Could this be easily fixed?
Also, I'm thinking if we could get something like this hard-coded (assuming it's what I think it is), it might be a very useful feature for the RTS mod. :D
--- End quote ---
Thing is turret needs to start tracking something (anything) just once or otherwise the turret may not be initialized properly and then its orientation matrices are not properly set.
EDIT: Fixed the crash upon restarting mission via mission quick start after dying bug.
Navigation
[0] Message Index
[#] Next page
Go to full version