new version
#Global Hooks
$GameInit:
[
--all this stuff is for multires support, for getting true width and height, and for generating factors to scale coords by
w = gr.getScreenWidth()
h = gr.getScreenHeight()
if w >= 1024 then
wf = w / 1024
else
wf = w / 640
end
if h >= 768 then
hf = h / 768
else
hf = h / 480
end
--mousejoy function, returns a value from -1 to 1 depending on the mouse's position
dead = 0.05 --factor of how much range of motion is dead, 1 is max 0 is min
mX=0
mY=0
mZ=0
rolltoggle = false
mousejoy = function(deadzone)
local X = io.getX()
local Y = io.getY()
if w >= 1024 then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end
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
end
--mouse hud
mousegauge = function(eks,why,zee) --just a bunch of loops to draw the various hashes for the gauges
local cx = w/2
local cy = h/2
local rgx = cx+60
local rgy = cy+60
gr.setColor(150,255,150,200) --big hashes
for i=cx-67.5, cx+67.5, 15 do
gr.drawLine(i,cy - 140,i,cy - 125)
end
for i=cy-67.5, cy+67.5, 15 do
gr.drawLine(cx - 140,i,cx - 125,i)
end
for i=0, 90, 10 do --radial roll gauge
local x = math.sin(i*math.pi/180)
local y = math.cos(i*math.pi/180)
gr.drawLine(rgx+x*65,rgy+y*65,rgx+x*80,rgy+y*80)
end
gr.setColor(50,255,50,150) --small hashes
for i=cx-60, cx+60, 15 do
gr.drawLine(i,cy - 140,i,cy - 132)
end
for i=cy-60, cy+60, 15 do
gr.drawLine(cx - 140,i,cx - 132,i)
end
for i=5, 85, 10 do --radial roll gauge
local x = math.sin(i*math.pi/180)
local y = math.cos(i*math.pi/180)
gr.drawLine(rgx+x*70,rgy+y*70,rgx+x*80,rgy+y*80)
end
gr.setColor(200,200,255,255) --indicators
gr.drawCircle(8,cx+(eks*67.5),cy-135)
gr.drawCircle(8,cx-135,cy+(why*67.5))
zee = (-zee * 45) + 45
gr.drawCircle(8,rgx + (math.sin(zee*math.pi/180) * 75),rgy + (math.cos(zee*math.pi/180) * 75 ))
end
]
$HUD:
[
rolltoggle = io.isButtonDown(MOUSE_MIDDLE_BUTTON)
if rolltoggle then
mZ, mY = mousejoy(dead)
mX = 0
else
mX, mY = mousejoy(dead)
mZ = 0
end
cornholio = mn.Ships["Alpha 1"]
if cornholio:isValid() then
desrot = cornholio.Physics.RotationalVelocityMax
desrot['1'] = desrot['1'] * -mY
desrot['2'] = desrot['2'] * mX
desrot['3'] = desrot['3'] * -mZ
cornholio.Physics.RotationalVelocity = desrot
end
mousegauge(mX,mY,mZ)
]
#End
ive added some more astheticly pleasing gauges. ive also added deadzone support for the mouse, you may tweak the dead variable to your liking. bigger number means more deadzone, 1 is the full range of motion 0.5 is half. i find a low value like 0.05 works well, to give you a small snap to indicate you reached center. bigger deadzones can be harder to deal with, and if you have a steady hand you can just set it to zero to get a fluid range. no matter what setting you use it will always run a full smooth 0-1 gradient from the edge of the dead zone to the edge of the range max. to change the deadzone just change the number on this line to whatever you want:
dead = 0.05 --factor of how much range of motion is dead, 1 is max 0 is min
ive also added a roll mode, enabled by the middle button, if you dont have a middle button you can use your right (or left for that matter) my changing this line:
rolltoggle = io.isButtonDown(MOUSE_MIDDLE_BUTTON)
to
rolltoggle = io.isButtonDown(MOUSE_RIGHT_BUTTON)
i used middle so i could use my right for missiles.
now i still havent plugged in scale factors for different screen resolutions yet. it might be a little large cause i designed it for 1280*1024, but i intent to make it uniform, at any resolution. i also havent plugged damping values yet. not sure how yet, i might need to ask wmc about that. but theyre on my to do list.