Hard Light Productions Forums
FreeSpace Releases => Scripting Releases => Topic started by: Wanderer on September 19, 2009, 07:32:02 am
-
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
-
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.
-
If the Turret you have targeted is not in and of itself targeting anything, then there is nothing for this script to show.
-
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.
-
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
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.
-
So yeah, I can't tell what I'm looking at. There's some lines... rotating?
-
Yeah.. That's it. It is more of a dev tool - for setting turret FOVs and fvecs and uvecs properly - than anything else
-
Really, if there can only ever be the one indicator at a time, I don't think it would be too bad to draw a ring instead of the weird spinning lines. Especially if it's only as a dev tool anyway.
-
Uh, there is only one indicator at a time, because you can only ever target one at a time.
Unless you want to code us up a multi-targeting function.....
And a "draw_sector" too while you are at it.
-
Yeah.. ATM drawing a sector (as the firing is always anymore limited to simple rings) would require drawing every pixel (if you wanted smooth) separately. And before that calculating every single pixels position first in 3D and then converted into 2D... And how many pixels you wanted to use? Or then using short lines.. but there is the same dilemma again.. how many is enough?
Of course the data could first be drawn to a texture and then via drawPolygon drawn to the desired position but most of what was written above would still apply (not to mention that then you would need to considered the viewing angles against the newly drawn planes as well).