1
0
Fork 0
fgdata/Nasal/earthview.nas

271 lines
7.4 KiB
Text
Raw Normal View History

###########################################################
# Earthview orbital rendering
###########################################################
var start = func() {
if (earthview_running_flag ==1) {return;}
2014-04-25 06:40:32 +00:00
earthview_running_flag = 1;
var lat = getprop("/position/latitude-deg");
var lon = getprop("/position/longitude-deg");
# define the tile centers
center_N1 = geo.Coord.new();
center_N2 = geo.Coord.new();
center_N3 = geo.Coord.new();
center_N4 = geo.Coord.new();
center_S1 = geo.Coord.new();
center_S2 = geo.Coord.new();
center_S3 = geo.Coord.new();
center_S4 = geo.Coord.new();
center_N1.set_latlon(45.0, -135.0);
center_N2.set_latlon(45.0, -45.0);
center_N3.set_latlon(45.0, 45.0);
center_N4.set_latlon(45.0, 135.0);
center_S1.set_latlon(-45.0, -135.0);
center_S2.set_latlon(-45.0, -45.0);
center_S3.set_latlon(-45.0, 45.0);
center_S4.set_latlon(-45.0, 135.0);
# determine which tiles to show
var shuttle_pos = geo.aircraft_position();
#print(shuttle_pos.distance_to(center_N1));
#print(shuttle_pos.distance_to(center_N2));
#print(shuttle_pos.distance_to(center_N3));
#print(shuttle_pos.distance_to(center_N4));
#print(shuttle_pos.distance_to(center_S1));
#print(shuttle_pos.distance_to(center_S2));
#print(shuttle_pos.distance_to(center_S3));
#print(shuttle_pos.distance_to(center_S4));
if (shuttle_pos.distance_to(center_N1) > 8000000.0)
{setprop("/earthview/show-n1", 0);}
else {setprop("/earthview/show-n1", 1);}
if (shuttle_pos.distance_to(center_N2) > 8000000.0)
{setprop("/earthview/show-n2", 0);}
else {setprop("/earthview/show-n2", 1);}
if (shuttle_pos.distance_to(center_N3) > 8000000.0)
{setprop("/earthview/show-n3", 0);}
else {setprop("/earthview/show-n3", 1);}
if (shuttle_pos.distance_to(center_N4) > 8000000.0)
{setprop("/earthview/show-n4", 0);}
else {setprop("/earthview/show-n4", 1);}
if (shuttle_pos.distance_to(center_S1) > 8000000.0)
{setprop("/earthview/show-s1", 0);}
else {setprop("/earthview/show-s1", 1);}
if (shuttle_pos.distance_to(center_S2) > 8000000.0)
{setprop("/earthview/show-s2", 0);}
else {setprop("/earthview/show-s2", 1);}
if (shuttle_pos.distance_to(center_S3) > 8000000.0)
{setprop("/earthview/show-s3", 0);}
else {setprop("/earthview/show-s3", 1);}
if (shuttle_pos.distance_to(center_S4) > 8000000.0)
{setprop("/earthview/show-s4", 0);}
else {setprop("/earthview/show-s4", 1);}
earth_model.node = earthview.place_earth_model("Models/Astro/earth.xml",lat, lon, 0.0, 0.0, 0.0, 0.0);
cloudsphere_model.node = earthview.place_earth_model("Models/Astro/cloudsphere.xml",lat, lon, 0.0, 0.0, 0.0, 0.0);
# set Basic Weather off
props.globals.getNode("/environment/config/enabled").setBoolValue(0);
props.globals.getNode("/environment/params/metar-updates-environment").setBoolValue(0);
# set some reasonable defaults
setprop("/environment/visibility-m", 80000.0);
setprop("/sim/rendering/mie", 0.0);
setprop("/sim/rendering/rayleigh", 0.00002);
setprop("/sim/rendering/dome-density", 1.0);
control_loop();
}
var stop = func () {
earth_model.node.remove();
cloudsphere_model.node.remove();
setprop("/earthview/control_loop_flag",0);
2014-04-25 06:40:32 +00:00
earthview_running_flag = 0;
}
var place_earth_model = func(path, lat, lon, alt, heading, pitch, roll) {
var m = props.globals.getNode("models", 1);
for (var i = 0; 1; i += 1)
if (m.getChild("model", i, 0) == nil)
break;
var model = m.getChild("model", i, 1);
var R1 = 5800000.0;
var R2 = 58000.0;
var altitude1 = getprop("/position/altitude-ft");
var altitude2 = R2/R1 * altitude1;
var model_alt = altitude1 - altitude2 - R2 * m_to_ft;
setprop("/earthview/latitude-deg", lat);
setprop("/earthview/longitude-deg", lon);
setprop("/earthview/elevation-ft", model_alt);
setprop("/earthview/heading-deg", heading);
setprop("/earthview/pitch-deg", pitch);
setprop("/earthview/roll-deg", roll);
setprop("/earthview/yaw-deg", 0.0);
var eview = props.globals.getNode("earthview", 1);
var latN = eview.getNode("latitude-deg",1);
var lonN = eview.getNode("longitude-deg",1);
var altN = eview.getNode("elevation-ft",1);
var headN = eview.getNode("heading-deg",1);
var pitchN = eview.getNode("pitch-deg",1);
var rollN = eview.getNode("roll-deg",1);
model.getNode("path", 1).setValue(path);
model.getNode("latitude-deg-prop", 1).setValue(latN.getPath());
model.getNode("longitude-deg-prop", 1).setValue(lonN.getPath());
model.getNode("elevation-ft-prop", 1).setValue(altN.getPath());
model.getNode("heading-deg-prop", 1).setValue(headN.getPath());
model.getNode("pitch-deg-prop", 1).setValue(pitchN.getPath());
model.getNode("roll-deg-prop", 1).setValue(rollN.getPath());
model.getNode("load", 1).remove();
setprop("/earthview/heading-deg",90);
setprop("/earthview/control_loop_flag",1);
return model;
}
var control_loop = func {
var R1 = 5800000.0;
var R2 = 58000.0;
var altitude1 = getprop("/position/altitude-ft");
var altitude2 = R2/R1 * altitude1;
var model_alt = altitude1 - altitude2 - R2 * m_to_ft;
setprop("/earthview/elevation-ft", model_alt);
var lat = getprop("/position/latitude-deg");
var lon = getprop("/position/longitude-deg");
setprop("/earthview/latitude-deg", lat);
setprop("/earthview/longitude-deg", lon);
setprop("/earthview/roll-deg", -(90-lat));
setprop("/earthview/yaw-deg", -lon);
var shuttle_pos = geo.aircraft_position();
if (shuttle_pos.distance_to(center_N1) > 8000000.0)
{setprop("/earthview/show-n1", 0);}
else {setprop("/earthview/show-n1", 1);}
if (shuttle_pos.distance_to(center_N2) > 8000000.0)
{setprop("/earthview/show-n2", 0);}
else {setprop("/earthview/show-n2", 1);}
if (shuttle_pos.distance_to(center_N3) > 8000000.0)
{setprop("/earthview/show-n3", 0);}
else {setprop("/earthview/show-n3", 1);}
if (shuttle_pos.distance_to(center_N4) > 8000000.0)
{setprop("/earthview/show-n4", 0);}
else {setprop("/earthview/show-n4", 1);}
if (shuttle_pos.distance_to(center_S1) > 8000000.0)
{setprop("/earthview/show-s1", 0);}
else {setprop("/earthview/show-s1", 1);}
if (shuttle_pos.distance_to(center_S2) > 8000000.0)
{setprop("/earthview/show-s2", 0);}
else {setprop("/earthview/show-s2", 1);}
if (shuttle_pos.distance_to(center_S3) > 8000000.0)
{setprop("/earthview/show-s3", 0);}
else {setprop("/earthview/show-s3", 1);}
if (shuttle_pos.distance_to(center_S4) > 8000000.0)
{setprop("/earthview/show-s4", 0);}
else {setprop("/earthview/show-s4", 1);}
# now set scattering paramaters
if (getprop("/earthview/mrd-flag") == 1)
{
var rayleigh = 0.0002;
var mie = 0.001;
var density = 1.0;
if (altitude1 < 300000.0)
{
setprop("/sim/rendering/rayleigh",rayleigh);
setprop("/sim/rendering/mie",mie);
setprop("/sim/rendering/dome-density",density);
}
else if (altitude1 < 650000.0)
{
rayleigh = rayleigh - 0.00018 * (altitude1-300000.0)/350000.0;
mie = mie - 0.001 * (altitude1-300000.0)/350000.0;
density = 1.0;
setprop("/sim/rendering/rayleigh",rayleigh);
setprop("/sim/rendering/mie",mie);
setprop("/sim/rendering/dome-density",density);
}
else
{
rayleigh = 0.00002;
mie = 0.0;
density = 1.0;
setprop("/sim/rendering/rayleigh",rayleigh);
setprop("/sim/rendering/mie",mie);
setprop("/sim/rendering/dome-density",density);
}
}
if (getprop("/earthview/control_loop_flag") ==1) {settimer( func {control_loop(); },0);}
}
var ft_to_m = 0.30480;
var m_to_ft = 1.0/ft_to_m;
var earth_model = {};
var cloudsphere_model = {};
var earthview_running_flag = 0;
var center_N1 = {};
var center_N2 = {};
var center_N3 = {};
var center_N4 = {};
var center_S1 = {};
var center_S2 = {};
var center_S3 = {};
var center_S4 = {};