Jump to content
Sign in to follow this  
x-alberto

Drawing a HUD

Recommended Posts

Hi Lightner,

this version of the path indicator scripts works fine unless you have cross wind (we need to figure out what the path indicator shows, may be side accelerations?)

I see no more "lag" of sort...

You were almost there, you just did not compensate for fov as you (correctly) did for the horizon example...and a couple of math.tan went missing as well....


xpdr_alpha = xp.getDataref("sim/flightmodel/position/alpha")
xpdr_beta  = xp.getDataref("sim/flightmodel/position/beta")


function OnDraw_Windows()
   ----------------------------------------------------------------------------
   --[CONSTANTS]
   ----------------------------------------------------------------------------
   --[get screen resolution]
   local sw, sh = gfx.getScreenSize()
   --[set FPV circle radius]
   local m_radius = 14
   --[GET HORIZONTAL FOV IN DEG & RAD]
   local HFOV_deg = camera.getFOV()
   local HFOV_rad = math.rad(HFOV_deg)
   --[CALCULATE VERTICAL FOV IN DEG & RAD]
   local VFOV_rad = 2 * math.atan( math.tan(HFOV_rad/2) * (sh/sw) )
   local VFOV_deg = math.deg(VFOV_rad)


local vfov_factor = (sh/2) / math.tan((VFOV_rad/2))
local hfov_factor = (sw/2) / math.tan((HFOV_rad/2))


   ----------------------------------------------------------------------------
   --[DRAW FLIGHT PATH VECTOR]
   ----------------------------------------------------------------------------


   gfx.texOff()
       gl.PushMatrix();
           --move draw cursor to screen center
           gl.Translate( sw/2, sh/2, 0 )
               gl.PushMatrix()
                   ----------------------------------------------------------------------------
                   --[CALCULATE SCREEN POSITION TO DRAW FLIGHT PATH VECTOR]
                   ----------------------------------------------------------------------------
                   gl.Translate(- math.tan(math.rad(xp.getFloat(xpdr_beta))) * hfov_factor , -math.tan(math.rad(xp.getFloat(xpdr_alpha))) * vfov_factor , 0 )

                   --[set double line width and red color]
                   gl.LineWidth(2.0)
                   gfx.setColor(1,0,0,1)

                   --[DRAW FPV circle with m_radius made of 40 line segments]
                   gfx.drawCircle(m_radius,40)
                   --[draw left wing]
                   gl.Begin('LINES')
                     gl.Vertex(m_radius, 0)
                     gl.Vertex(m_radius + 10, 0)
                   gl.End()
                   --[draw right wing]
                   gl.Begin('LINES')
                     gl.Vertex(-m_radius,0)
                     gl.Vertex(-m_radius - 10, 0)
                   gl.End();
                   --[draw tailfin]
                   gl.Begin('LINES')
                     gl.Vertex(0, m_radius)
                     gl.Vertex(0, m_radius + 8)
                   gl.End();

               gl.PopMatrix()
       gl.PopMatrix()
   gfx.texOn()

end

ciao

alberto

EDIT: given how painful it had to be to cope with field of view compensation, I would suggest to have this script promoted in the tutorial section...

Share this post


Link to post
Share on other sites

Many thanks for figuring out my missing math.tan, x-alberto!!!  <salute>

Was right in front of my nose all the time, so close yet so far.

The horizonline also works as designed, jaggy drawing is exclusively an anti-aliasing thing..

Well, this shows what a wonderful and powerful tool Gizmo is.

One just has to be very careful and meticulous when scripting.

Time to finish off the rest of the HUD...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×