Board index FlightGear Development Canvas

Canvas Mapstructure  Topic is solved

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.

Canvas Mapstructure

Postby ausdkunst » Tue Aug 09, 2016 3:50 am

Hi all,

I have been experimenting canvas and despite reading some documents, I still have no clue. I am trying to test out the following code

Code: Select all
var MapStructure_demo = func() {
  var temp = {};
  temp.dlg = canvas.Window.new([600,400],"dialog");
  temp.canvas = temp.dlg.createCanvas().setColorBackground(1,1,1,0.5);
  temp.root = temp.canvas.createGroup();
  var TestMap = temp.root.createChild("map");
  TestMap.setController("Aircraft position");
  TestMap.setRange(25);
 
  # this will center the map
  TestMap.setTranslation(
                           temp.canvas.get("view[0]")/2,
                           temp.canvas.get("view[1]")/2
                        );
 var r = func(name,vis=1,zindex=nil) return caller(0)[0];
 # TFC, APT and APS are the layer names as per $FG_ROOT/Nasal/canvas/map and the names used in each .lcontroller file
 # in this case, it will load the traffic layer (TFC), airports (APT) and render an airplane symbol (APS)
 foreach(var type; [r('TFC'),r('APT'), r('APS') ] )
        TestMap.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,);
}; # MapStructure_demo
MapStructure_demo();


Problem is I don't know how to assign it on a 3D model/how to get it to work.
BULLDOG RS (The No.1 place for Flightgear automobile): https://bulldogrs.wordpress.com/
User avatar
ausdkunst
 
Posts: 343
Joined: Fri Aug 28, 2015 9:47 am
Callsign: bulldog
Version: 2016.2.1
OS: Mac OS X

Re: Canvas Mapstructure  

Postby ausdkunst » Tue Aug 09, 2016 5:58 am

I have decided to test it on canvas-test model (found in Flightgear instrument 3d folder:

Code: Select all
      var my_canvas = canvas.new({
         "name": "Canvas-Test",
         "size": [1024, 1024],
         "view": [480, 512],
         "mipmapping": 1
      });
      my_canvas.addPlacement({"node": "PFD-Screen", "texture": "screen-test.png"});
      my_canvas.setColorBackground(0,0,0,1);
      var group = my_canvas.createGroup();
      var GMAP = group.createChild("map");
GMAP.setController("Aircraft position");
GMAP.setRange(15);
 
GMAP.setTranslation(    myCanvas.get("view[0]")/2,
                           myCanvas.get("view[1]")/2
                        );
var r = func(name,vis=1,zindex=nil) return caller(0)[0];

foreach(var type; [r('APT'), r('VOR') ] )
 GMAP.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,);


I am not sure what is the problem because the screen is black :(
BULLDOG RS (The No.1 place for Flightgear automobile): https://bulldogrs.wordpress.com/
User avatar
ausdkunst
 
Posts: 343
Joined: Fri Aug 28, 2015 9:47 am
Callsign: bulldog
Version: 2016.2.1
OS: Mac OS X

Re: Canvas Mapstructure

Postby ausdkunst » Tue Aug 09, 2016 8:09 am

Finally got it to work!!

Code: Select all
      var dashboard = canvas.new({
         "name": "Canvas-Test",
         "size": [1024, 1024],
         "view": [480, 512],
         "mipmapping": 1
      });
      dashboard.addPlacement({"node": "Dashboard", "texture": "dashboard.png"});
      dashboard.setColorBackground(0,0,0,1);
      var group = dashboard.createGroup();
      var GMAP = group.createChild("map");
GMAP.setController("Aircraft position");
GMAP.setRange(1);
 
GMAP.setTranslation(    dashboard.get("view[0]")/2,
                           dashboard.get("view[1]")/2
                        );
var r = func(name,vis=1,zindex=nil) return caller(0)[0];

foreach(var type; [r('TFC'),r('APT'), r('APS'), r('RTE') ] )
 GMAP.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,);
BULLDOG RS (The No.1 place for Flightgear automobile): https://bulldogrs.wordpress.com/
User avatar
ausdkunst
 
Posts: 343
Joined: Fri Aug 28, 2015 9:47 am
Callsign: bulldog
Version: 2016.2.1
OS: Mac OS X

Re: Canvas Mapstructure

Postby ausdkunst » Tue Aug 09, 2016 8:19 am

Image
I call this virtual cockpit (following Audi) :)
BULLDOG RS (The No.1 place for Flightgear automobile): https://bulldogrs.wordpress.com/
User avatar
ausdkunst
 
Posts: 343
Joined: Fri Aug 28, 2015 9:47 am
Callsign: bulldog
Version: 2016.2.1
OS: Mac OS X

Re: Canvas Mapstructure

Postby Hooray » Tue Aug 09, 2016 5:03 pm

nice, scaling looks a bit odd - besides, you can easily customize the whole thing to use other symbols, or to show other information - in fact, you could come up with all sorts of fancy (and experimental) gauges for cars, including modern HUDs or moving map stuff. Imagine having a Tesla vehicle in FG ;-)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11977
Joined: Tue Mar 25, 2008 8:40 am

Re: Canvas Mapstructure

Postby ausdkunst » Tue Aug 09, 2016 5:28 pm

HAHA thanks Hooray. I wish I know how to inset map. I am really bad at coding and even this layout took me hours to get it to work :(
BULLDOG RS (The No.1 place for Flightgear automobile): https://bulldogrs.wordpress.com/
User avatar
ausdkunst
 
Posts: 343
Joined: Fri Aug 28, 2015 9:47 am
Callsign: bulldog
Version: 2016.2.1
OS: Mac OS X

Re: Canvas Mapstructure

Postby Hooray » Tue Aug 09, 2016 6:19 pm

for starters, it may make more sense to use the Nasal Console to experiment a bit more, and a standalone GUI dialog instead of an actual aircraft panel/instrument - everything that you can get to work in a dialog, will also work on an actual aircraft


http://wiki.flightgear.org/Nasal_Console
http://wiki.flightgear.org/Canvas_Snippets

Image
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11977
Joined: Tue Mar 25, 2008 8:40 am


Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest