terrain-map.nas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ################################################################################
  2. #
  3. # Boeing 787-8 Dreamliner Terrain Map (also used in other aircraft)
  4. #
  5. # The idea about getting a terrain map without compromising much frame-rate is
  6. # to sweep the changes across the screen instead of getting the whole screen at
  7. # once. Another idea here is to interpolate between 2 points and 'assume' what
  8. # would be there. That way, say in a line of 32, instead of getting all 32
  9. # points, we could get just 16 and interpolate the rest to this and it would be
  10. # almost just as good.
  11. #
  12. # Licensed along with the 787-8 under GNU GPL v2
  13. #
  14. ################################################################################
  15. var row = 0;
  16. var RAD2DEG = 57.2957795;
  17. var DEG2RAD = 0.016774532925;
  18. var terrain = "/instrumentation/terrain-map/pixels/";
  19. var terrain_full = "/instrumentation/terrain-map[1]/pixels/";
  20. # Function to get Elevation at latitude and longitude
  21. var get_elevation = func (lat, lon) {
  22. var info = geodinfo(lat, lon);
  23. if (info != nil) {var elevation = info[0] * 3.2808399;}
  24. else {var elevation = -1.0; }
  25. return elevation;
  26. }
  27. var terrain_map = {
  28. init : func {
  29. me.UPDATE_INTERVAL = 0.025;
  30. me.loopid = 0;
  31. me.reset();
  32. },
  33. update : func {
  34. if (getprop("/instrumentation/efis/input/TERR")) {
  35. var pos_lon = getprop("/position/longitude-deg");
  36. var pos_lat = getprop("/position/latitude-deg");
  37. var heading = getprop("orientation/heading-magnetic-deg");
  38. #setprop("/controls/mfd/terrain-map/range", getprop("/instrumentation/ndfull/range"));
  39. var range = getprop("/instrumentation/efis/nd/display-range");
  40. var displaymode = getprop("instrumentation/efis[0]/nd/display-mode");
  41. ### Same calculations but for the fullscreen ND, that means RANGE matters
  42. # First get all the points (16x16)
  43. for (var col = 1; col <= 32; col += 2)
  44. {
  45. var proj_lon = pos_lon + ((-1 * (col-16) * (range/30) * math.sin(DEG2RAD * (heading - 90))) / 60);
  46. var proj_lat = pos_lat + ((-1 * (col-16) * (range/30) * math.cos(DEG2RAD * (heading - 90))) / 60);
  47. if (displaymode == 'ARC') { #just represent ahead
  48. var point_lon = proj_lon + ((row * (range/30) / 60) * math.sin(DEG2RAD * heading));
  49. var point_lat = proj_lat + ((row * (range/30) / 60) * math.cos(DEG2RAD * heading));
  50. } else { # Represent ahead and back
  51. var point_lon = proj_lon + (((row-16) * (range/30) / 60) * math.sin(DEG2RAD * heading));
  52. var point_lat = proj_lat + (((row-16) * (range/30) / 60) * math.cos(DEG2RAD * heading));
  53. }
  54. setprop(terrain ~ "row[" ~ row ~ "]/col[" ~ col ~ "]/elevation-ft", get_elevation(point_lat, point_lon));
  55. }
  56. # Interpolate the rest of the points in each column
  57. for (var col = 2; col <= 31; col += 2)
  58. {
  59. var elev_prev = getprop(terrain ~ "row[" ~ row ~ "]/col[" ~ (col - 1) ~ "]/elevation-ft");
  60. var elev_next = getprop(terrain ~ "row[" ~ row ~ "]/col[" ~ (col + 1) ~ "]/elevation-ft");
  61. var elevation = (elev_prev + elev_next) / 2;
  62. setprop(terrain ~ "row[" ~ row ~ "]/col[" ~ col ~ "]/elevation-ft", elevation);
  63. }
  64. row += 1;
  65. if (row == 32) row = 0;
  66. }
  67. },
  68. reset : func {
  69. me.loopid += 1;
  70. me._loop_(me.loopid);
  71. },
  72. _loop_ : func(id) {
  73. id == me.loopid or return;
  74. me.update();
  75. settimer(func { me._loop_(id); }, me.UPDATE_INTERVAL);
  76. }
  77. };
  78. setlistener("sim/signals/fdm-initialized", func {
  79. terrain_map.init();
  80. print("Terrain Map ......... Initialized");
  81. });