Board index FlightGear Development Canvas

HUD

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

HUD

Postby 5H1N0B1 » Fri Mar 11, 2016 12:48 am

Hi all,
I want to make a very improved HUD on the mirage. And now the only way to achieve what I want to do is through canvas.
From now I find/read/saw 2 way of doing this.
- Via SVG (like the F20 hud canvas)
- Via re drawing each line. (like the Viggen, the C-130 etc...)
So I got 2 questions :
1- Which method is the less hungry in term of fps ?

2-A hud is a complex optical system that is not just a projection before your eyes : The horizon line will stay on the horizon, no matter if the pilot head position. Same for target, or for the trapezium around the runway.
Here is a little video to illustrate what I say. A man built a home hud.

I think that I have to recalculate the position of each hud projection, depending of the current view, the center of the hud and the object I want to project on the hud. So here come my question. Can someone help me with math ? this one is a bit complicated for me....

Thanks a lot in advance
5H1N0B1
5H1N0B1
"Each day, with every person you meet, there is something to learn"
5H1N0B1
 
Posts: 217
Joined: Thu Aug 30, 2012 9:36 am
Location: France
Callsign: 5H1N0B1
IRC name: _5H1N0B1
Version: GIT
OS: Ubuntu

Re: HUD

Postby Richard » Fri Mar 11, 2016 6:18 am

5H1N0B1 wrote in Fri Mar 11, 2016 12:48 am:I want to make a very improved HUD on the mirage. And now the only way to achieve what I want to do is through canvas.

- Via SVG (like the F20 hud canvas)
- Via re drawing each line. (like the Viggen, the C-130 etc...)

1- Which method is the less hungry in term of fps ?

2-A hud is a complex optical system that is not just a projection before your eyes : The horizon line will stay on the horizon, no matter if the pilot head position. Same for target, or for the trapezium around the runway.
Here is a little video to illustrate what I say. A man built a home hud.

I think that I have to recalculate the position of each hud projection, depending of the current view, the center of the hud and the object I want to project on the hud. So here come my question. Can someone help me with math ? this one is a bit complicated for me....



If the inline drawing method is used correctly the performance will be the same; SVG can take a little longer on startup but it does the same thing once loaded.

The SVG method I find preferable as it's a lot easier to draw.

Personally I'd recommend starting with the HUD from the F-15 as when I did this I looked at the other ones and they were too complex and intricate and I wanted something much simpler.

There are a few things that need to be explained if you use this one;

1. if you have an element ending with "_clip" it will apply a clipping window to the item that doesn't have the _clip; this is how it makes the tapes just appear on a portion of the screen.
2. The F-15 HUD models the combiner; so there are two images one for each piece of glass. This requires a bit of lining up. You don't have to do it this way you can just have a single drawing layer but this will look not right from the side. Doing it this way should achieve the same affect as the projection method used - so the images will remain constant with respect to the horizon regardless of the view point.
3. To model the combiner and improve performance there is a data provider class that should be used to get values (to save reading the tree multiple times)
4. The update frequency drops when FPS is low. This is managed outside of the HUD in aircraft-main.nas

If you want help adding this to the Mirage I'm happy to assist.
Richard
 
Posts: 785
Joined: Sun Nov 02, 2014 10:17 pm
Version: Git
OS: Win10

Re: HUD

Postby 5H1N0B1 » Fri Mar 11, 2016 8:50 pm

Cool. Thanks Richard. I'll look through it. Anyway about the calculation of the head displacement, do you have any idea ?
5H1N0B1
"Each day, with every person you meet, there is something to learn"
5H1N0B1
 
Posts: 217
Joined: Thu Aug 30, 2012 9:36 am
Location: France
Callsign: 5H1N0B1
IRC name: _5H1N0B1
Version: GIT
OS: Ubuntu

Re: HUD

Postby Johan G » Sat Mar 12, 2016 1:06 pm

A guess is that the head displacement is from the view related properties (probably found in /sim/current-view/, for details see $FG_ROOT/Nasal/view.nas). You would probably find them used in Richards code.
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Johan G
Moderator
 
Posts: 6036
Joined: Fri Aug 06, 2010 5:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.2
OS: Windows 10, 64 bit

Re: HUD

Postby Richard » Mon Mar 14, 2016 11:17 am

5H1N0B1 wrote in Fri Mar 11, 2016 8:50 pm:Cool. Thanks Richard. I'll look through it. Anyway about the calculation of the head displacement, do you have any idea ?


The F-15 HUD is actually modelled with two canvas drawables one for each piece of glass in the combiner.

Head displacement isn't taken into account in the F-15 for three reasons.

1. The glass combiner panes are fixed to the aircraft. Normally the head position is fixed and the rotation will work anyway as expected.
2. I'm not sure it's actually as pronounced as in the video when the horizon is further away;
3. I've only seen a few HUDs and what I recall is that actually you can't see much as you move out of the focus zone anyway. Not that you can actually move that much when you're strapped in.

After some experimentation and math I couldn't figure it out the right way to calculate this.

So overall (to me) it seems like a lot of extra code for something that would be hardly noticeable and may cause weird effects until it is perfect.
Richard
 
Posts: 785
Joined: Sun Nov 02, 2014 10:17 pm
Version: Git
OS: Win10

Re: HUD

Postby PINTO » Mon Mar 14, 2016 5:19 pm

Couldn't you do something like (in pseudo-nasal, not nasal):

Given the x,y,z of the viewer and the hud, calculate how much to offset the drawing using trigonometry?
My 3D trig is realllly rusty, so do this in two cycles to calculate x,y offset.

Code: Select all
var headpos_x;  # left/right
var headpos_y;  # up/down
var headpos_z;  # front/back

var hudpos_x;
var hudpos_y;
var hudpos_z;

var length_z = ( hudpos_z - headpos_z );
var reference_z = length_z + hudpos_z; # this is a point past the hud, to calculate a reference angle - this may need to be adjusted, but putting the hud in the middle seemed like a good idea (greater values here would result in less drastic hud display movement, and vis versa)

var length_x = headpos_x - hudpos_x; # how much higher/lower the head is in reference to the hud
var length_y = headpos_y - hudpos_y; # how much more left/right the head is in reference to the hud.

var angle_x = arctan(length_x / reference_z); # calculate x angle
var angle_y = arctan(length_y / reference_z); # calculate y angle

#now we know the angle to offset, we just need to find the length of the offset.

var offset_z = reference_z - length_z; # we want the distance past the hud to the reference point
var offset_x = tan(angle_x) * offset_z;
var offset_y = tan(angle_y) * offset_z;


Then you could add offset_x and offset_y to your canvas coordinates, and it should move with the person's head. If this doesn't work, then sorry for the waste of time. =] Haven't done much work in canvas, and I'm not sitting in front of FlightGear at the moment to test it out - but I'd love to try to implement this in the Viggen also.

EDIT: to add that my experience with this in real life is with holo gun sights, which need to have the red-dot remained centered no matter the viewing angle or the zero for the gun would be off. I'd imagine that HUD's would work based on the same principle.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 962
Joined: Wed Oct 21, 2015 6:28 pm
Callsign: pinto
Version: 2016.3.0
OS: Win10

Re: HUD

Postby Thorsten » Mon Mar 14, 2016 6:30 pm

Come on - you have the eye pos, you have some aim point far away, and you need to find the intersection point of that ray with a plane.

You can google it - it's a standard problem :-)
Thorsten
 
Posts: 11748
Joined: Mon Nov 02, 2009 8:33 am

Re: HUD

Postby 5H1N0B1 » Tue Mar 15, 2016 12:17 am

Thanks Pinto. I'll look what you've made. :)

Thanks Thorsten. That what I was looking for. I was searching in the wrong direction. this is a starting point :)
Ok I'll do the math :)
5H1N0B1
"Each day, with every person you meet, there is something to learn"
5H1N0B1
 
Posts: 217
Joined: Thu Aug 30, 2012 9:36 am
Location: France
Callsign: 5H1N0B1
IRC name: _5H1N0B1
Version: GIT
OS: Ubuntu

Re: HUD

Postby yanes » Tue Oct 11, 2016 1:54 pm

I can give some help ,
I already did the Su-27 svg hud (with some amount of success :) )
You can start creating the svg graphic , with all the needed symbols and I'll be happy to help with the future hud.nas , I love this Bird too ! :)
We need to use the same version of the aircraft which should be the latest, so make me know when the SVG is ready ,
User avatar
yanes
 
Posts: 135
Joined: Tue Sep 02, 2014 1:14 pm
Location: Tunisia
Callsign: YANES
Version: 2018.2.2
OS: Linux


Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest