Jump to content

Lightner

Members
  • Posts

    9
  • Joined

  • Last visited

    Never

About Lightner

  • Birthday 01/01/1

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Lightner's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hi x-alberto, I have tried it using OnDraw_Gauges, but it still draws the box despite the MaskingTape. Lightner Update: drawing on the window with OnDraw_Windows() and gl.Scissor still works fine though: function OnDraw_Windows() sw, sh = gfx.getScreenSize() gfx.texOff() gl.Enable('SCISSOR_TEST') gl.Scissor( sw/2, sh/2, 100, 100 ) gfx.setColor(1,0,0,1) gfx.drawFilledBox( sw/2, sh/2, 200, 200 ) gl.Disable('SCISSOR_TEST') gfx.texOn() end
  2. Yes, Ben. I tried it out first thing after getting 11.4.24 with my previous code snippet. It still draws the box which is outside the MaskingTape bounds. Maybe I'm doing something terribly wrong?! Anybody else used this MaskingTape function succesfully in their code? function OnDraw_Windows() sw, sh = gfx.getScreenSize() gfx.texOff() gfx.setMaskingTape( sw/2, sh/2, 100, 100 ) gfx.setColor(1,0,0,1) gfx.drawFilledBox( sw/2, sh/2, 200, 200 ) gfx.clearMaskingTape() gfx.texOn() end
  3. I updated to the 11.4.24 release. Can you confirm the MaskingTape function has been implemented now?
  4. 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...
  5. Thanks for willing to look into this, x-alberto! Very much obliged having any expert feedback in this humble attempts at replicating the HUD. Regarding roll correction: I did initially implement this by having the following pseudocode. However, this resulted in worse offsets compared to the default HUD symbol. My previous code post enabled the closest matching of the default HUD symbol though apparently still not perfect. Pseudo-code: gl.Rotate(roll, 0, 0, 1) --roll camera with bank gl.Translate() --POSITION FPV ON SCREEN gl.Rotate(roll, 0, 0, -1) --reverse roll camera to get upright fpv symbol drawFPV() --draw symbology Here's another piece of code which is even simpler: replicate the Horizon Line on the HUD. Suffers from parallax effects (i.e. in a roll, right edge of drawn line has larger offset to default horizonline compared to left edge). init.lua (draw HorizonLine) function OnDraw_Windows() ---------------------------------------------------------------------------- --[CONSTANTS] ---------------------------------------------------------------------------- --[get screen resolution] local sw, sh = gfx.getScreenSize() --[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) --[SET DATAREFS] local phi = xp.getDataref("sim/flightmodel/position/phi") local theta = xp.getDataref("sim/flightmodel/position/theta") ---------------------------------------------------------------------------- --[DRAW HORIZON LINE] ---------------------------------------------------------------------------- gfx.texOff() gl.PushMatrix(); --[move draw cursor to screen center[ gl.Translate( sw/2, sh/2, 0 ) ---------------------------------------------------------------------------------------------------- --[draw HORIZON LINE]------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------------- gl.PushMatrix() gl.Rotate(xp.getFloat(phi),0,0,1) gl.PushMatrix() local h_distance = -math.tan(math.rad(xp.getFloat(theta))) * (sh/2) / math.tan((VFOV_rad/2)) gl.Translate(0, h_distance, 0) ---------------------------------------------------------------------------------------------------- --[set double line width and red color] gl.LineWidth(3.0) gfx.setColor(1,0,0,1) --[draw line] gl.Begin('LINES') gl.Vertex(-250, 0) gl.Vertex( 250, 0) gl.End() gl.PopMatrix() gl.PopMatrix() gl.PopMatrix() gfx.texOn() end
  6. Sincere apologies, Ben, for just tossing a chunk of code like that your way. I have condensed the laggy FPV symbology into the most basic code now with ample comments and the irky code line highlighted. Script is running on latest X-Plane demo with stock CirrusJet. Running with "flight models per frame" = 2 seems to be slightly better than 1 but still you can observe it lagging the default HUD symbol in steep banks. I run the X-Plane demo @1080p high settings over the ocean so I get 100+ fps in HUD view. init.lua 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) --[SET DATAREFS] local alpha = xp.getDataref("sim/flightmodel/position/alpha") local beta = xp.getDataref("sim/flightmodel/position/beta") ---------------------------------------------------------------------------- --[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(-xp.getFloat(beta)* sw / HFOV_deg , -xp.getFloat(alpha)* sh / VFOV_deg , 0 ) ---------------------------------------------------------------------------- --[^^ABOVE CODE LAGS COMPARED TO X-PLANE HUD FLIGHT PATH VECTOR IN STEEP BANKS] ---------------------------------------------------------------------------- --[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
  7. Ben, I have tried this but still no joy. HUD FPV lagging and data values show similar error differences under steep bank angles. Most of my first coding was done all in the drawing function, but then I resorted to using main() and seperate functions when more variables and complex maths were added. In the other thread, it was adviced to put any event drawing under the main() to ensure it was executed per frame. You state to not do any drawing under main(). Is there a way to guarantee calculation & drawings per frame with the same choice of where to draw that OnDraw_Gauges and OnDraw_Windows allow?
  8. Hi everybody, I'm currently replicating the default X-Plane HUD as seen on the forward HUD view mode by using Gizmo and OpenGL drawing. I have succeeded in drawing the flight path marker (FPM) but it is not fully in sync with the stock FPM symbol. There seems to be a slight misalignment especially at large bank angles. Examining raw dataref values, I am trying to check how actual Gizmo gets the Dataref and/if any lag might occur with calculations. From X-Plane DataRefs: Hence, vpath = theta-alpha and beta = psi-hpath This led to the following test script: - calculate climb angle (= theta - alpha) and compare with gamma (X-Plane dataref) - calculate beta angle (= heading - course) and compare with yaw (X-Plane dataref) Both the calculated values should theoretically match with the ones obtained directly from X-Plane. Calculations done in main function, so should occur every frame. However, load this script up and go fly and HIT PAUSE and observe the yellow (calculation) vs. blue (direct dataref) values. For the climb angle there is a small error creep, but the yaw value differences can be quite substantial! Is this anomaly caused by X-Plane dataref or is it Gizmo related? -Lightner- P.S. I haven't figured out LUA io operations yet so did not have gizmo output these values to a logfile to compare for lag. init.lua theta = xp.getDataref("sim/flightmodel/position/theta") alpha = xp.getDataref("sim/flightmodel/position/alpha") gamma = xp.getDataref("sim/flightmodel/position/vpath") roll = xp.getDataref("sim/flightmodel/position/phi") beta = xp.getDataref("sim/flightmodel/position/beta") heading = xp.getDataref("sim/flightmodel/position/psi") magheading = xp.getDataref("sim/flightmodel/position/magpsi") course = xp.getDataref("sim/flightmodel/position/hpath") HFOV_deg = camera.getFOV() HFOV_rad = math.rad(HFOV_deg) m_pixel_width,m_pixel_height = gfx.getScreenSize() VFOV_rad = 2.0 * math.atan( math.tan(HFOV_rad/2.0) * (m_pixel_height / m_pixel_width) ) VFOV_deg = math.deg(VFOV_rad) function main() theta_deg = xp.getFloat(theta) theta_rad = math.rad(theta_deg) alpha_deg = xp.getFloat(alpha) alpha_rad = math.rad(alpha_deg) gamma_deg = xp.getFloat(gamma) gamma_rad = math.rad(gamma_deg) climb_deg = theta_deg - alpha_deg --should be equal to gamma_deg climb_rad = math.rad(climb_deg) roll_deg = xp.getFloat(roll) roll_rad = math.rad(roll_deg) yaw_deg = xp.getFloat(beta) yaw_rad = math.rad(yaw_deg) heading_deg = xp.getFloat(heading) heading_rad = math.rad(heading_deg) magheading_deg = xp.getFloat(magheading) magheading_rad = math.rad(magheading_deg) course_deg = xp.getFloat(course) course_rad = math.rad(course_deg) beta_deg = heading_deg - course_deg --should be equal to yaw_deg beta_rad = math.rad(beta_deg) end function OnDraw_Windows() local HUDbox = 500 local offset = 15 --DRAW RAW DATAREF VALUES local pc ={width = HUDbox, height = HUDbox} gfx.texOff() gfx.setColor(0,0.5,0,0.5) gfx.drawFilledBox( 0.5 * (m_pixel_width + HUDbox), 0.5 * (m_pixel_height - HUDbox*1), HUDbox, HUDbox ) gl.PushMatrix() gl.Translate( 0.5 * (m_pixel_width + HUDbox), 0.5 * (m_pixel_height - 3*HUDbox), 0 ) local h_position = 5; local text_spacing = 15; gl.Scale(2,2,0) gfx.setColor( 1,1,1,1 ) local resolution = string.format("Resolution: %u/%u px", m_pixel_width, m_pixel_height) gfx.drawString( resolution, h_position, pc.height - offset ) local box = string.format("HUDbox size: %u/%u px", pc.width, pc.height) gfx.drawString( box, h_position, (pc.height - offset)- (1 * text_spacing) ) local FOV = string.format("HFOV: %0.2f deg / %0.5f rad", HFOV_deg, HFOV_rad) gfx.drawString( FOV, h_position, (pc.height - offset)- (2 * text_spacing) ) local VFOV = string.format("VFOV: %0.2f deg / %0.5f rad", VFOV_deg , VFOV_rad) gfx.drawString( VFOV, h_position, (pc.height - offset)- (3 * text_spacing) ) gfx.drawString("FLIGHT DATA", h_position, (pc.height - offset)- (4 * text_spacing) ) local pitch = string.format("Pitch: %0.5f deg / %0.5f rad", theta_deg , theta_rad) gfx.drawString( pitch, h_position, (pc.height - offset)- (5 * text_spacing) ) local aoa = string.format("Alpha: %0.5f deg / %0.5f rad", alpha_deg, alpha_rad) gfx.drawString( aoa, h_position, (pc.height - offset)- (6 * text_spacing) ) gfx.setColor( 1,1,0,1 ) local climb = string.format("Climb: %0.5f deg / %0.5f rad", climb_deg, climb_rad) gfx.drawString( climb, h_position, (pc.height - offset)- (7 * text_spacing) ) gfx.setColor( 0,0,1,1 ) local climb2 = string.format("Gamma: %0.5f deg / %0.5f rad", gamma_deg, gamma_rad) gfx.drawString( climb2, h_position, (pc.height - offset)- (8 * text_spacing) ) gfx.setColor( 1,1,1,1 ) local roll = string.format("Roll: %0.5f deg / %0.5f rad", roll_deg , roll_rad) gfx.drawString( roll, h_position, (pc.height - offset)- (9 * text_spacing) ) local magheading = string.format("MagPsi: %0.5f deg / %0.5f rad", magheading_deg, magheading_rad) gfx.drawString( magheading, h_position, (pc.height - offset)- (10 * text_spacing) ) local heading = string.format("Heading: %0.5f deg / %0.5f rad", heading_deg , heading_rad) gfx.drawString( heading, h_position, (pc.height - offset)- (11 * text_spacing) ) local course = string.format("Course: %0.5f deg / %0.5f rad", course_deg , course_rad) gfx.drawString( course, h_position, (pc.height - offset)- (12 * text_spacing) ) gfx.setColor( 1,1,0,1 ) local yaw = string.format("HDG-CRS: %0.5f deg / %0.5f rad", beta_deg , beta_rad) gfx.drawString( yaw, h_position, (pc.height - offset)- (13 * text_spacing) ) gfx.setColor( 0,0,1,1 ) local yaw2 = string.format("Yaw (Beta): %0.5f deg / %0.5f rad", yaw_deg, yaw_rad) gfx.drawString( yaw2, h_position, (pc.height - offset)- (14 * text_spacing) ) gl.PopMatrix() gfx.texOn() end
  9. Hi, I'm very new to all this Gizmo fun, big thanks to Ben for creating such an awesome API! I'm attempting utilize the MaskingTape function to keep the OpenGL drawing within boundaries. I've tried to use this function but seem unable to get in working: Attached below code, objective is to setup a Masking area of 100 by 100 px. Then draw a box of 200 by 200 px. If masking works then I should be only able to see the 100 by 100 section of this box, right? When I load this up in X-Plane it still draws my full 200x200 filled box. Another notable thing is gfx.texOff() placement, if this is placed inbetween the masking draw code, then the x-plane menu's and widgets will turn greyblack. Am I doing something wrong here? function OnDraw_Windows() sw, sh = gfx.getScreenSize() gfx.texOff() gfx.setMaskingTape( sw/2, sh/2, 100, 100 ) gfx.setColor(1,0,0,1) gfx.drawFilledBox( sw/2, sh/2, 200, 200 ) gfx.clearMaskingTape() end
×
×
  • Create New...