Board index FlightGear Development New features

Got Compass?

Discussion and requests for new features. Please note that FlightGear developers are volunteers and may or may not be able to consider these requests.

Got Compass?

Postby CaptainJohnThomas » Wed Feb 19, 2014 8:00 pm

I like to free fly but I get lost. Anyone got a compass? Like a global compass HUD widget for any and all craft.
CaptainJohnThomas
 
Posts: 24
Joined: Wed Feb 19, 2014 7:38 pm

Re: Got Compass?

Postby Hooray » Wed Feb 19, 2014 8:05 pm

a compass is part of most HUDs actually:
http://wiki.flightgear.org/Hud
Image

Or just use this:
http://wiki.flightgear.org/Map
Image


You could also use the Canvas/MapStructure framework to create arbitrary displays/maps and show them on a Canvas: http://wiki.flightgear.org/MapStructure
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: 11469
Joined: Tue Mar 25, 2008 8:40 am

Re: Got Compass?

Postby CaptainJohnThomas » Wed Feb 19, 2014 8:31 pm

Clearly I need a better plane haha
I was just thinking a little widget that could be toggled on and off for like gliders and such
Thanks for your help!
CaptainJohnThomas
 
Posts: 24
Joined: Wed Feb 19, 2014 7:38 pm

Re: Got Compass?

Postby Hooray » Wed Feb 19, 2014 9:19 pm

CaptainJohnThomas wrote in Wed Feb 19, 2014 8:31 pm:I was just thinking a little widget that could be toggled on and off for like gliders and such


That should be a neat little project for someone interested in learning a bit more about Nasal and Canvas coding, this should be possible to accomplish with less than 50 lines of code actually - there's a ton of stuff that you could reuse (SVG compass rose or an existing 2D panel texture), we have quite a few tutorials on Nasal, Canvas and Image processing (check the wiki).

EDIT: What the heck, here's a working prototype (paste this into your Nasal console):
Code: Select all
var CanvasApplication = {
 ##
 # constructor
 new: func(x=300,y=200) {
  var m = { parents: [CanvasApplication] };
  m.dlg = canvas.Window.new([x,y],"dialog");
  m.canvas = m.dlg.createCanvas().setColorBackground(1,1,1,0.5);
  m.root = m.canvas.createGroup();
  m.timer = maketimer(0.1, func m.update() );
  m.init();
  return m;
 },

del: func me.timer.stop(),

update: func() {
 var hdg=getprop("/orientation/heading-deg");
 me.compass.setRotation(-hdg*D2R);
 
},

init: func() {
 var filename = "/Aircraft/Instruments/gyro.xml";
 var temp= io.read_properties(getprop("/sim/fg-root") ~ filename);
 var layers = temp.getValues().layers.layer;

var z=100;
foreach(var layer; layers ) {
 print("new layer:", layer.name);
 
 # if it's  not a texture, skip
 if (!contains(layer, "texture")) continue;
 
 # get a handle to the texture of the layer
 var texture = layer.texture;
 
 # create an image child for the texture
 var child=me.root.createChild("image")
                    .setFile( texture.path )
               .setSourceRect( texture.x1, texture.x2, texture.y1, texture.y2 )
                                   .setSize(layer.w,layer.h)
                                   .setTranslation(20,20)
               .set("z-index", z +=1 )
               .setScale(2.5);
 
if (layer.w != nil and layer.h!=nil)
  child.setCenter(layer.w/2, layer.h/2);

 if (layer.name=="compass rose") {
  print("Found compass layer");
  # child.setCenter(55,55);
  me.compass = child;
 }
} # foreach


 
 me.timer.start();
 },
}; # end of CanvasApplication


var InstrumentWidget = {
 new: func(x,y) {
  var m = CanvasApplication.new(x:x,y:y);
 },

};

var compass = InstrumentWidget.new(x:300, y:300);

print("Compass Loaded...!");

Image

Note, this didn't involve any real programming, it's 100% copy&paste, all based on wiki tutorials
You can easily change the apperance of the widget/instrument within seconds, no programming involved ...
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: 11469
Joined: Tue Mar 25, 2008 8:40 am


Return to New features

Who is online

Users browsing this forum: No registered users and 1 guest