Author Topic: remote controlled turrets revisited  (Read 8814 times)

0 Members and 1 Guest are viewing this topic.

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
remote controlled turrets revisited
i revamped the script to run on current builds. fly a ship with a turret01a (medusa works) while using this script. switch to outside view. now you can manipulate and fire the turret with the mouse. now there is a problem im just not figuring out. so long as your ship is in its default orientation (its position as placed in fred) it works fine. but you roll or turn into some funky position and your aim goes way off. anyone have any ideas?

Code: [Select]
#Global Hooks
$GameInit:
[

w = gr.getScreenWidth()
h = gr.getScreenHeight()
cx = w/2
cy = h/2

if w >= 1024 then
wf = w / 1024
hf = h / 768
awh = (wf + hf) / 2
hires = true
else
wf = w / 640
hf = h / 480
awh = ((wf + hf) / 2) * 0.625
hires = false
end

mousejoy = function(deadzone) --mousejoy function, returns a value from -1 to 1 depending on the mouse's position
local X = io.getMouseX()
local Y = io.getMouseY()

if hires then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end

local Mx = X --theese are for the menu, -1 to 1 without deadzone applied
local My = Y

local tweak = 1 / (1 - deadzone)

if X < deadzone and X > -deadzone then
X=0
else
if X > 0 then
X = (X - deadzone) * tweak
elseif X < 0 then
X = (X + deadzone) * tweak
end
end

if Y < deadzone and Y > -deadzone then
Y=0
else
if Y > 0 then
Y = (Y - deadzone) * tweak
elseif Y < 0 then
Y = (Y + deadzone) * tweak
end
end

return X, Y, Mx, My
end

mousegauge = function(eks,why) --just a bunch of loops to draw the various hashes for the gauges
gr.setColor(150,255,150,200) --big hashes

for i=cx-(54*awh), cx+(54*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (96*awh))
end
for i=cy-(54*awh), cy+(54*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (96*awh),i)
end

gr.setColor(50,255,50,150) --small hashes

for i=cx-(48*awh), cx+(48*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (100*awh))
end
for i=cy-(48*awh), cy+(48*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (100*awh),i)
end

gr.setColor(200,200,255,255) --indicators

gr.drawCircle(7.5*awh,cx+(eks*54*awh),cy-(104*awh))
gr.drawCircle(7.5*awh,cx-(104*awh),cy+(why*54*awh))
end

]
$Simulation:
[

player = mn.Ships["Alpha 1"]
X,Y,U,V = mousejoy(0.1)

if player:isValid() then
pgun = player["turret01a"]

ori = pgun.Orientation
ori.h = ori.h + X *2*ba.getFrametime()
pgun.Orientation = ori

ori = pgun.GunOrientation
ori.p = ori.p + Y *2*ba.getFrametime()

if ori.p > 0 then
ori.p = 0
elseif ori.p < -math.pi/2 then
ori.p = -math.pi/2
end

pgun.GunOrientation = ori

if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
pgun:fireWeapon(1, 1000)
end
end

]
$HUD:
[

mousegauge(X, Y)

]
#End
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Herra Tohtori

  • The Academic
  • 211
  • Bad command or file name
Re: remote controlled turrets revisited
i revamped the script to run on current builds. fly a ship with a turret01a (medusa works) while using this script. switch to outside view. now you can manipulate and fire the turret with the mouse. now there is a problem im just not figuring out. so long as your ship is in its default orientation (its position as placed in fred) it works fine. but you roll or turn into some funky position and your aim goes way off. anyone have any ideas?

Code: [Select]
#Global Hooks
$GameInit:
[

w = gr.getScreenWidth()
h = gr.getScreenHeight()
cx = w/2
cy = h/2

if w >= 1024 then
wf = w / 1024
hf = h / 768
awh = (wf + hf) / 2
hires = true
else
wf = w / 640
hf = h / 480
awh = ((wf + hf) / 2) * 0.625
hires = false
end

mousejoy = function(deadzone) --mousejoy function, returns a value from -1 to 1 depending on the mouse's position
local X = io.getMouseX()
local Y = io.getMouseY()

if hires then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end

local Mx = X --theese are for the menu, -1 to 1 without deadzone applied
local My = Y

local tweak = 1 / (1 - deadzone)

if X < deadzone and X > -deadzone then
X=0
else
if X > 0 then
X = (X - deadzone) * tweak
elseif X < 0 then
X = (X + deadzone) * tweak
end
end

if Y < deadzone and Y > -deadzone then
Y=0
else
if Y > 0 then
Y = (Y - deadzone) * tweak
elseif Y < 0 then
Y = (Y + deadzone) * tweak
end
end

return X, Y, Mx, My
end

mousegauge = function(eks,why) --just a bunch of loops to draw the various hashes for the gauges
gr.setColor(150,255,150,200) --big hashes

for i=cx-(54*awh), cx+(54*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (96*awh))
end
for i=cy-(54*awh), cy+(54*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (96*awh),i)
end

gr.setColor(50,255,50,150) --small hashes

for i=cx-(48*awh), cx+(48*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (100*awh))
end
for i=cy-(48*awh), cy+(48*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (100*awh),i)
end

gr.setColor(200,200,255,255) --indicators

gr.drawCircle(7.5*awh,cx+(eks*54*awh),cy-(104*awh))
gr.drawCircle(7.5*awh,cx-(104*awh),cy+(why*54*awh))
end

]
$Simulation:
[

player = mn.Ships["Alpha 1"]
X,Y,U,V = mousejoy(0.1)

if player:isValid() then
pgun = player["turret01a"]

ori = pgun.Orientation
ori.h = ori.h + X *2*ba.getFrametime()
pgun.Orientation = ori

ori = pgun.GunOrientation
ori.p = ori.p + Y *2*ba.getFrametime()

if ori.p > 0 then
ori.p = 0
elseif ori.p < -math.pi/2 then
ori.p = -math.pi/2
end

pgun.GunOrientation = ori

if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
pgun:fireWeapon(1, 1000)
end
end

]
$HUD:
[

mousegauge(X, Y)

]
#End

It sounds like you're missing a co-ordinate conversion from ship-relative to global XYZ co-ordinates in some point. It doesn't matter as long as ship's axes are aligned with global co-ordinate axes, but when they arent, it screws things up.

What does the turret orientation function do? Does it return turret's alignment vector in relation to global co-ordinates or in relation to ship-relative co-ordinates?
There are three things that last forever: Abort, Retry, Fail - and the greatest of these is Fail.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
ok, all the important stuff is in $Simulation: everything else is just my usual vars for multires and mouse functions, same from my mouse script. all they do is return mouse coords in a -1 to 1 format.

essentially it lets you move your turret, base with mouse x and gun with mouse y. pgun.Orientation is the orientation of the turret base in p,b,h. its read, stored in a var, which is modified then put back. this is for the turret base yaw. it does the same thing for the barrel object, pgun.GunOrientation, but it locks it to 90 degrees. what i dont understand is why the turret rotation can work fine, yet the firing normal is somehere else. as far as i know, GunOrientation is also supposed to affect the turret normal.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: remote controlled turrets revisited
Basically it looks like the problem is in aiturret.cpp

Code: [Select]
ship_get_global_turret_gun_info(&Objects[parent_objnum], ss, &gpos, &gvec, use_angles, &predicted_enemy_pos);

// Fire in the direction the turret is facing, not right at the target regardless of turret dir.
vm_vec_sub(&v2e, &predicted_enemy_pos, &gpos);

"gvec" appears to be the direction that the turret is actually facing. It's used for checks about whether the weapon can fire or not. However, the actual firing vector used is the vector from the turret to the enemy. Because the decision to fire is based on the actual turret position, it doesn't cause a gross inaccuracy (Like firing from the turret's ass), but if you're seeing a minor inaccuracy in your tests, that might just be it.

I think I might be able to fix this easily, but I have to proceed carefully, since this particular segment of code is used everytime a turret is fired, and the last time turrets were broken, nobody spoke up for months. :rolleyes:
-C

  

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
well when it all merges youl also have to shuffel in your turret changes with bobs. turrets will just need to be scrutinized more when code freeze time comes. if it helps i got a screenshot of the orientation matric being applies, the top 3 rows are for the base and the bottom 3 are for the gun. the first 3 rows are the matrix row 4 is the p'h'b and row 5 is row 4 converted to degrees. i was thinking that the matrix was merely incomplete, but if it was then why is the turret rotating properly, regaurdless of the ships orientation.



[attachment deleted by admin]
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: remote controlled turrets revisited
oh, my god you have no idea how ****ed up the turret\subobject rotation system is. the turrets have copys of matraceise made from the positions of there guns used to figure out were there target is but not to rotate the model there are like four seperate matraciese that are for diferent aspects of that (when all of this could be handled by one) and then I added another matrix into the mess fortunately I blocked it off whenever I could (and WOW was that ever a hack). and there is always the ever present issue of the agnles2matrix function being about as acurate as rolling a rock down a mountainside.

my code should be all in now, so he's going to have to deal with it post merge, wich is better for both of us realy.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
well im sorta thinking about what id need to do fully scripted turrets which dont even touch the internal c code. rc turrets are doable as is but the trickey part would be to interface a scripted turret with ai. i sorta want some functions that use orientations, like createWeapon() to have the option of using a normal instead. i really dont think anyone would notice if a prometheus shot is on its side, or a missile either. also cameras would be better if handeled by normals, then you can just set the normal to whatever you want to "film" and maybe another to say which end is up, sorta like a tripod axis. ive spent the last 3 or 4 days trying to understand the math behind matricies and i still dont get it.

anyway i was meaning to ask you bob if that thing in your turret build that lets us set the front, up and side axes is used to create an orientation matrix. if so id love to have that function in scripting. i dont need to understand matricies if i have a function that makes one for me.
« Last Edit: January 20, 2007, 09:49:22 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: remote controlled turrets revisited
well, it's a commonly used function within the code base, actualy it's such a minor thing I think the actual function doesn't get used that much.

if I knew how to make a function with optional parameters for LUA I'd have it done by the time it took ne to write this responce.

in the code getting/setting an fvec is literaly matrix.fvec,

there is a vm_vector_2_matrix(matrix *m,vec3d *fvec,vec3d *uvec,vec3d *rvec) function you'd probly like access too as well (the nice thing about that function is the last two parameters can be set to NULL and it'll fake them for you)
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
im not really sure if most of the built in functions im calling are written in c or in lua. anyway alot of stuff i want to do requires manupulatiion of spacial stuff, theese include:

ils carrier landing
atmospheric flight physics
battlemechs :D
freelancer style flight/turret control
blindfire weps
rtt panel gauges/working controls
ect.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: remote controlled turrets revisited
if I knew how to make a function with optional parameters for LUA I'd have it done by the time it took ne to write this responce.

You use a pipe (|) along with the normal format characters, so for a function like you're thinking, you'd do something like:

Code: [Select]
ade_get_args(L, "o|oo", l_Vector.Get(&fvec), l_Vector.Get(&uvec), l_Vector.Get(&rvec));
Everything after the pipe is considered as optional by Lua, and the variables are left alone unless they're set to something.
-C

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: remote controlled turrets revisited
so how do I tell how many parameters were passed
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: remote controlled turrets revisited
ade_get_args always returns the number of arguments gotten, or 0 in the case of a critical error (missing required argument or required argument with an invalid type).

However there is one bit of an oddity when using it. If the modder passes an argument of the wrong type to an optional argument, ade_get_args will act as if no argument was passed (besides passing an error as well). So it's a good idea to get in the habit of setting optional variables to something either obviously invalid or reasonable (if there is no invalid value), and checking for NULLity on all pointers. Besides doing something bizarre with an array to allow individual variables, I didn't see any better way to handle optional variables of the wrong type. I can certainly implement that functionality if it's needed, but I'd like to see a case first.

In this case:
0 (something seriously wrong, "." probably used instead of ":")
1 (fvector object was valid)
2 (fvector object && (u vector object was valid and specified OR r vector object was valid and specified))
3 (fvector, u vector, and r vector object were valid and specified)

However Lua will throw an error if the fvector object and the rvector object were specified, but the uvector object was set to nil. This is changeable, of course, but would require adding additional syntax to ade_get_args and complexity to the function definition. It's something I thought about, but never finished, but I figured you could in theory do something like this:
Code: [Select]
ade_get_args(L, "o|[ol]o", l_Vector.Get(&fvec), l_Vector.Get(&uvec), NULL, l_Vector.Get(&rvec));
But again, I'd want to see a (in this case compelling) need for the functionality.
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
heh, they work!

remember fly with a medusa and aim with the mouse and use this build

its not perfect, it will fire a maxim no matter what, it doesnt actually fire the turret but rather creates a weapon paralell to its bore. the sight could stand for some work and the controls are abit touchey.

Code: [Select]
#Global Hooks
$GameInit:
[

w = gr.getScreenWidth()
h = gr.getScreenHeight()
cx = w/2
cy = h/2

if w >= 1024 then
wf = w / 1024
hf = h / 768
awh = (wf + hf) / 2
hires = true
else
wf = w / 640
hf = h / 480
awh = ((wf + hf) / 2) * 0.625
hires = false
end

mousejoy = function(deadzone) --mousejoy function, returns a value from -1 to 1 depending on the mouse's position
local X = io.getMouseX()
local Y = io.getMouseY()

if hires then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end

local Mx = X --theese are for the menu, -1 to 1 without deadzone applied
local My = Y

local tweak = 1 / (1 - deadzone)

if X < deadzone and X > -deadzone then
X=0
else
if X > 0 then
X = (X - deadzone) * tweak
elseif X < 0 then
X = (X + deadzone) * tweak
end
end

if Y < deadzone and Y > -deadzone then
Y=0
else
if Y > 0 then
Y = (Y - deadzone) * tweak
elseif Y < 0 then
Y = (Y + deadzone) * tweak
end
end

return X, Y, Mx, My
end

mousegauge = function(eks,why) --just a bunch of loops to draw the various hashes for the gauges
gr.setColor(150,255,150,200) --big hashes

for i=cx-(54*awh), cx+(54*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (96*awh))
end
for i=cy-(54*awh), cy+(54*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (96*awh),i)
end

gr.setColor(50,255,50,150) --small hashes

for i=cx-(48*awh), cx+(48*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (100*awh))
end
for i=cy-(48*awh), cy+(48*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (100*awh),i)
end

gr.setColor(200,200,255,255) --indicators

gr.drawCircle(7.5*awh,cx+(eks*54*awh),cy-(104*awh))
gr.drawCircle(7.5*awh,cx-(104*awh),cy+(why*54*awh))
end

printmatrix = function(ori,v) --function to help understand the mystyries of the orientation matrix
gr.setColor(200,200,200,200)
gr.drawString(ori[1],150,100+v)
gr.drawString(ori[2],300,100+v)
gr.drawString(ori[3],450,100+v)
gr.drawString(ori.p, 600,100+v)
gr.drawString(ori.p*180/math.pi,800,100+v)
gr.drawString(ori[4],150,115+v)
gr.drawString(ori[5],300,115+v)
gr.drawString(ori[6],450,115+v)
gr.drawString(ori.h, 600,115+v)
gr.drawString(ori.h*180/math.pi,800,115+v)
gr.drawString(ori[7],150,130+v)
gr.drawString(ori[8],300,130+v)
gr.drawString(ori[9],450,130+v)
gr.drawString(ori.b, 600,130+v)
gr.drawString(ori.b*180/math.pi,800,130+v)
end

]
$Simulation:
[

player = mn.Ships["Alpha 1"]
X,Y,U,V = mousejoy(0.15)

if player:isValid() then
pgun = player["turret01a"]

thing0 = player.Position + player.Orientation:unrotateVector(pgun.Position)

bori = pgun.Orientation
thing1 = bori:unrotateVector(ba.createVector(0,0,-100))

bori.h = bori.h + X * ba.getFrametime()
pgun.Orientation = bori

gori = pgun.GunOrientation
gori.p = gori.p + Y * ba.getFrametime()

if gori.p > 0 then
gori.p = 0
elseif gori.p < -math.pi/2 then
gori.p = -math.pi/2
end

pgun.GunOrientation = gori

thing2 = gori:unrotateVector(ba.createVector(0,100,0))
thing2 = bori:unrotateVector(thing2)

thing1 = player.Orientation:unrotateVector(thing1) + thing0
thing2 = player.Orientation:unrotateVector(thing2) + thing0

thing3 = (player.Orientation:unrotateVector(ba.createVector(0,0,1)) - thing0) + thing2

if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
mn.createWeapon(tb.WeaponClasses["Maxim"],thing3:getOrientation(),thing0,player,-1)
end
end

]
$HUD:
[

mousegauge(X, Y)

if thing2:getScreenCoords() then
local b,e = thing2:getScreenCoords()
gr.setColor(0,100,200,74)
gr.drawCircle(9,b*wf,e*hf)
end

--testfuncs
--printmatrix(bori,0)
--printmatrix(gori,75)
--printmatrix(player.Orientation,150)

]
#End


i also got blindfire working, even though its a total bastardization of the above code, full of atrocities which would frighten even dave b himself i dare not post it :D
« Last Edit: January 25, 2007, 09:39:58 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 
Re: remote controlled turrets revisited
Nuke, you are crazy, but awesomely so. Soon in the not so distant future we will have Starlancer running on the FS2_Open engine. :drevil:

<3 scripting.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
i can also do freelancer style flight. but im gonna need to come up with a better way to convert 2d screen coords to a 3d vector.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 
Re: remote controlled turrets revisited
heh, they work!

remember fly with a medusa and aim with the mouse and use this build

its not perfect, it will fire a maxim no matter what, it doesnt actually fire the turret but rather creates a weapon paralell to its bore. the sight could stand for some work and the controls are abit touchey.

Code: [Select]
#Global Hooks
$GameInit:
[

w = gr.getScreenWidth()
h = gr.getScreenHeight()
cx = w/2
cy = h/2

if w >= 1024 then
wf = w / 1024
hf = h / 768
awh = (wf + hf) / 2
hires = true
else
wf = w / 640
hf = h / 480
awh = ((wf + hf) / 2) * 0.625
hires = false
end

mousejoy = function(deadzone) --mousejoy function, returns a value from -1 to 1 depending on the mouse's position
local X = io.getMouseX()
local Y = io.getMouseY()

if hires then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end

local Mx = X --theese are for the menu, -1 to 1 without deadzone applied
local My = Y

local tweak = 1 / (1 - deadzone)

if X < deadzone and X > -deadzone then
X=0
else
if X > 0 then
X = (X - deadzone) * tweak
elseif X < 0 then
X = (X + deadzone) * tweak
end
end

if Y < deadzone and Y > -deadzone then
Y=0
else
if Y > 0 then
Y = (Y - deadzone) * tweak
elseif Y < 0 then
Y = (Y + deadzone) * tweak
end
end

return X, Y, Mx, My
end

mousegauge = function(eks,why) --just a bunch of loops to draw the various hashes for the gauges
gr.setColor(150,255,150,200) --big hashes

for i=cx-(54*awh), cx+(54*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (96*awh))
end
for i=cy-(54*awh), cy+(54*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (96*awh),i)
end

gr.setColor(50,255,50,150) --small hashes

for i=cx-(48*awh), cx+(48*awh), 12*awh do
gr.drawLine(i,cy - (108*awh),i,cy - (100*awh))
end
for i=cy-(48*awh), cy+(48*awh), 12*awh do
gr.drawLine(cx - (108*awh),i,cx - (100*awh),i)
end

gr.setColor(200,200,255,255) --indicators

gr.drawCircle(7.5*awh,cx+(eks*54*awh),cy-(104*awh))
gr.drawCircle(7.5*awh,cx-(104*awh),cy+(why*54*awh))
end

printmatrix = function(ori,v) --function to help understand the mystyries of the orientation matrix
gr.setColor(200,200,200,200)
gr.drawString(ori[1],150,100+v)
gr.drawString(ori[2],300,100+v)
gr.drawString(ori[3],450,100+v)
gr.drawString(ori.p, 600,100+v)
gr.drawString(ori.p*180/math.pi,800,100+v)
gr.drawString(ori[4],150,115+v)
gr.drawString(ori[5],300,115+v)
gr.drawString(ori[6],450,115+v)
gr.drawString(ori.h, 600,115+v)
gr.drawString(ori.h*180/math.pi,800,115+v)
gr.drawString(ori[7],150,130+v)
gr.drawString(ori[8],300,130+v)
gr.drawString(ori[9],450,130+v)
gr.drawString(ori.b, 600,130+v)
gr.drawString(ori.b*180/math.pi,800,130+v)
end

]
$Simulation:
[

player = mn.Ships["Alpha 1"]
X,Y,U,V = mousejoy(0.15)

if player:isValid() then
pgun = player["turret01a"]

thing0 = player.Position + player.Orientation:unrotateVector(pgun.Position)

bori = pgun.Orientation
thing1 = bori:unrotateVector(ba.createVector(0,0,-100))

bori.h = bori.h + X * ba.getFrametime()
pgun.Orientation = bori

gori = pgun.GunOrientation
gori.p = gori.p + Y * ba.getFrametime()

if gori.p > 0 then
gori.p = 0
elseif gori.p < -math.pi/2 then
gori.p = -math.pi/2
end

pgun.GunOrientation = gori

thing2 = gori:unrotateVector(ba.createVector(0,100,0))
thing2 = bori:unrotateVector(thing2)

thing1 = player.Orientation:unrotateVector(thing1) + thing0
thing2 = player.Orientation:unrotateVector(thing2) + thing0

thing3 = (player.Orientation:unrotateVector(ba.createVector(0,0,1)) - thing0) + thing2

if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
mn.createWeapon(tb.WeaponClasses["Maxim"],thing3:getOrientation(),thing0,player,-1)
end
end

]
$HUD:
[

mousegauge(X, Y)

if thing2:getScreenCoords() then
local b,e = thing2:getScreenCoords()
gr.setColor(0,100,200,74)
gr.drawCircle(9,b*wf,e*hf)
end

--testfuncs
--printmatrix(bori,0)
--printmatrix(gori,75)
--printmatrix(player.Orientation,150)

]
#End


i also got blindfire working, even though its a total bastardization of the above code, full of atrocities which would frighten even dave b himself i dare not post it :D

Keep working on the blindfire! I know I'll need and Saga will need it for their Excalibur  :)
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
im gonna have to rethink the blindfire mode. i need to find out if bobs turret stuff got compiled into one of wmcs scripting builds. im gonna set up blindfire so it has to run on a forward facing multi or single part turret. this makes the movement alot smoother cause its not undergoing a yx rotation. now i dont need to use turrets at all for blindfire. infact for your standard blindfire i could do it entirely with mn.createWeapon(). the reason i want to use turrets is so that i can do gimballed gatling guns. nothing like a big honking sixpack throwing its weight around. :D

also  i plan to do everything in an advanced weapons suite. which would support everything from blindfire (with and without turrets), freelacer mode (it will use parts of my mouse script), commandable turrets, and maybe even bolt on turret support. il have all my functions in a main script and a bunch of tbms for each feature. im also gonna use some config files for some of the features. that way it should make using the features in a mod alot easyer.

unfortunately for the next few days i gotta be at work. so im not really gonna do any scripting till like tuesday.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
i created a cool little function to turn mouse coords (from my joymouse function), into a normal.

Code: [Select]
mjtonormal = function(X,Y) --converts mousejoy coords into a 3d normal, i think
local Z = (1 - math.abs(X)) * (1 - math.abs(Y))
local N = ba.createVector(X,Y,Z)
local nf = 1 / (N:getMagnitude())

N = N * nf

return N
end

*fixed a bug


it can likewise also turn an objects screen coords to a normal, assuming theyre scaled on a -1 to 1 range. this is mainly for freelancer/rc turret mode. for blindfire i can do some vector math, subtract one ships position from the other to get a vector to it and thin normalize it. normalizing a vector is fairly easy devide 1 by the magnatude of your vector and multiply the result with the vector.

now i need to figure out how to interpolate normals. i can get the normals of where i want the gun to face, but i need to set up the turret so that it always tries to make itself point along that normal. it would be very easy to directly tie in the turret rotation with the given normal. but i want to intrepolate it so that it takes time for the turret to lign up. in other words it needs to animate.
« Last Edit: February 02, 2007, 06:26:42 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Mav

  • 28
  • location: Shivan fleet - closing in on GTVA space
Re: remote controlled turrets revisited
Looks like there's a lot of good developements happening here  8) :yes: .


But - just a short idea - :   For blindfire (as in the WC3 Excalibur) - couldn't one just FRED it? I mean, mounting the gun bank on a turret instead of as primary bank of the ship itself, and then setting the turret to locked by default, only unlocking it while the player presses the trigger... ?

That way the usual turret code would take care of directions and such (of course being only as accurate as usual turrets; well, then set the turret-ai to highest level if you wish a good-aiming blindfire :) ) .

(Actually, I think I already have a ship that could use it ;) - the model's only an alpha version right now, though.)


So, would this be an idea? Or would this make things too unwieldy?
For ai-ships one shouldn't need the FRED stuff, as they'll anyway fire at what they want.

Of course, the turret would need to aim at the players target - what I think it does in retail, but I seem to remember a discussion about that to be changed - which is of course a good idea for most other turret uses, but for this use, one would need to be able to specify the turret to use the old target-selection routines, should newer ones be implemented.
-__ o_O___O_o
I______O_O_______dragons
________o

-----------------------------------
capship shields DO WORK !!!
my models, now with pics
test mission for commanding capships
-----------------------------------
suffering from a late stage of BoE-infection - DON'T call a doctor, it's too late for that anyway ;o)

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: remote controlled turrets revisited
you could but it would feel less like a hack unless you scripted it in. this way i can not only have blindfire but also manually aimable guns for player flown capships and bombers, commandable turrets, i can even put a turret on a ship that doesnt have one. i also wouldnt trust freespac's artifitial stupidity and atrocious turret code to do my aiming for me. :D plus the added bonus is you dont have to crowd your level with sexps, especially difficult if you want the feature top be presistand throughout your entire campaign.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN