2006-03-22 20:25:58 +00:00
|
|
|
|
2007-10-15 18:59:34 +00:00
|
|
|
setlistener("/sim/panel/visibility", func(n) {
|
|
|
|
setprop("/instrumentation/radar/serviceable", n.getValue());
|
2007-06-24 22:45:10 +00:00
|
|
|
}, 1);
|
|
|
|
|
|
|
|
|
2008-05-04 21:16:48 +00:00
|
|
|
var gear_key_down = 0;
|
2008-05-05 13:22:01 +00:00
|
|
|
controls.gearDown = func(x) gear_key_down = x != 0;
|
2007-06-24 22:45:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-16 16:24:52 +00:00
|
|
|
# maximum speed -----------------------------------------------------------------------------------
|
2006-03-15 14:27:47 +00:00
|
|
|
|
2006-03-15 00:29:53 +00:00
|
|
|
var maxspeed = props.globals.getNode("engines/engine/speed-max-mps");
|
2007-02-26 17:57:55 +00:00
|
|
|
var speed = [10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000];
|
2006-03-15 00:29:53 +00:00
|
|
|
var current = 7;
|
|
|
|
|
|
|
|
|
|
|
|
controls.flapsDown = func(x) {
|
2008-05-05 13:22:01 +00:00
|
|
|
if (!x)
|
2006-03-15 00:29:53 +00:00
|
|
|
return;
|
2008-05-05 13:22:01 +00:00
|
|
|
elsif (x < 0 and current > 0)
|
2006-03-15 00:29:53 +00:00
|
|
|
current -= 1;
|
2008-05-05 13:22:01 +00:00
|
|
|
elsif (x > 0 and current < size(speed) - 1)
|
2006-03-15 00:29:53 +00:00
|
|
|
current += 1;
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2006-03-15 00:29:53 +00:00
|
|
|
var s = speed[current];
|
|
|
|
maxspeed.setDoubleValue(s);
|
2006-03-22 20:25:58 +00:00
|
|
|
gui.popupTip("Max. Speed " ~ s ~ " m/s");
|
2006-03-15 00:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-05 18:45:21 +00:00
|
|
|
# dialogs -----------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
var status_dialog = gui.Dialog.new("/sim/gui/dialogs/ufo/status/dialog", "Aircraft/ufo/Dialogs/status.xml");
|
|
|
|
var select_dialog = gui.Dialog.new("/sim/gui/dialogs/ufo/select/dialog", "Aircraft/ufo/Dialogs/select.xml");
|
|
|
|
var adjust_dialog = gui.Dialog.new("/sim/gui/dialogs/ufo/adjust/dialog", "Aircraft/ufo/Dialogs/adjust.xml");
|
|
|
|
|
|
|
|
adjust_dialog.center_sliders = func {
|
|
|
|
var ns = adjust_dialog.namespace();
|
|
|
|
if (ns != nil)
|
|
|
|
ns.center();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# hide status line in screenshots
|
|
|
|
#
|
|
|
|
var status_restore = nil;
|
|
|
|
setlistener("/sim/signals/screenshot", func(n) {
|
|
|
|
if (n.getBoolValue()) {
|
|
|
|
status_restore = status_dialog.is_open();
|
|
|
|
status_dialog.close();
|
|
|
|
} else {
|
|
|
|
status_restore and status_dialog.open();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-05 13:22:01 +00:00
|
|
|
# mouse walk --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
var lastelev = nil;
|
2008-05-08 10:23:19 +00:00
|
|
|
var mouse = { savex: nil, savey: nil };
|
2008-05-08 20:11:39 +00:00
|
|
|
setlistener("/sim/startup/xsize", func(n) mouse.centerx = int(n.getValue() / 2), 1);
|
|
|
|
setlistener("/sim/startup/ysize", func(n) mouse.centery = int(n.getValue() / 2), 1);
|
2008-05-08 10:23:19 +00:00
|
|
|
setlistener("/sim/mouse/hide-cursor", func(n) mouse.hide = n.getValue(), 1);
|
2008-05-05 13:22:01 +00:00
|
|
|
setlistener("/devices/status/mice/mouse/x", func(n) mouse.x = n.getValue(), 1);
|
|
|
|
setlistener("/devices/status/mice/mouse/y", func(n) mouse.y = n.getValue(), 1);
|
|
|
|
setlistener("/devices/status/mice/mouse/mode", func(n) mouse.mode = n.getValue(), 1);
|
2008-05-07 18:03:38 +00:00
|
|
|
setlistener("/devices/status/mice/mouse/button[0]", func(n) mouse.lmb = n.getValue(), 1);
|
2008-05-05 13:22:01 +00:00
|
|
|
setlistener("/devices/status/mice/mouse/button[1]", func(n) {
|
|
|
|
mouse.mmb = n.getValue();
|
2008-05-08 10:23:19 +00:00
|
|
|
if (mouse.mode)
|
|
|
|
return;
|
|
|
|
if (mouse.mmb) {
|
|
|
|
setprop("/controls/engines/engine/throttle", 0);
|
|
|
|
lastelev = getprop("/position/ground-elev-ft");
|
|
|
|
controls.centerFlightControls();
|
|
|
|
adjust_dialog.center_sliders();
|
|
|
|
mouse.savex = mouse.x;
|
|
|
|
mouse.savey = mouse.y;
|
|
|
|
gui.setCursor(mouse.centerx, mouse.centery, "none");
|
|
|
|
} else {
|
|
|
|
gui.setCursor(mouse.savex, mouse.savey, "pointer");
|
|
|
|
}
|
2008-05-05 13:22:01 +00:00
|
|
|
}, 1);
|
|
|
|
|
|
|
|
|
|
|
|
mouse.loop = func {
|
2008-05-08 20:11:39 +00:00
|
|
|
if (mouse.mode or !mouse.mmb)
|
|
|
|
return settimer(mouse.loop, 0);
|
|
|
|
|
|
|
|
var dx = mouse.x - mouse.centerx;
|
|
|
|
var dy = mouse.y - mouse.centery;
|
|
|
|
if (!dx and !dy)
|
|
|
|
return settimer(mouse.loop, 0);
|
|
|
|
|
|
|
|
var speed = KbdShift.getValue() ? 1 : 0.1;
|
|
|
|
var progress = 1.7;
|
|
|
|
var powx = npow(dx, progress) * speed;
|
|
|
|
var powy = -npow(dy, progress) * speed;
|
|
|
|
|
|
|
|
if (KbdCtrl.getValue()) { # operation
|
|
|
|
if (dx) {
|
|
|
|
if (mouse.lmb or gear_key_down)
|
|
|
|
modelmgr.adjust("bearing", dx * 0.2);
|
|
|
|
else
|
|
|
|
modelmgr.adjust("transversal", powx);
|
|
|
|
}
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2008-05-08 20:11:39 +00:00
|
|
|
if (dy) {
|
|
|
|
if (mouse.lmb or gear_key_down)
|
|
|
|
modelmgr.adjust("altitude", powy);
|
|
|
|
else
|
|
|
|
modelmgr.adjust("longitudinal", powy);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { # navigation
|
|
|
|
var pos = geo.aircraft_position();
|
|
|
|
var hdg = getprop("/orientation/heading-deg");
|
|
|
|
var elev = getprop("/position/ground-elev-ft");
|
|
|
|
var dalt = elev - lastelev;
|
|
|
|
lastelev = elev;
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2008-05-08 20:11:39 +00:00
|
|
|
if (dx) {
|
|
|
|
if (mouse.lmb or gear_key_down)
|
|
|
|
pos.apply_course_distance(hdg + 90, powx);
|
|
|
|
else
|
|
|
|
setprop("/orientation/heading-deg", hdg + dx * 0.2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dy) {
|
|
|
|
if (mouse.lmb or gear_key_down)
|
|
|
|
dalt += powy;
|
|
|
|
else
|
|
|
|
pos.apply_course_distance(hdg, powy);
|
2008-05-05 13:22:01 +00:00
|
|
|
}
|
2008-05-08 20:11:39 +00:00
|
|
|
setprop("/position/latitude-deg", pos.lat());
|
|
|
|
setprop("/position/longitude-deg", pos.lon());
|
|
|
|
setprop("/position/altitude-ft", getprop("/position/altitude-ft") + dalt);
|
2008-05-05 13:22:01 +00:00
|
|
|
}
|
2008-05-08 20:11:39 +00:00
|
|
|
|
|
|
|
gui.setCursor(mouse.centerx, mouse.centery);
|
2008-05-05 13:22:01 +00:00
|
|
|
settimer(mouse.loop, 0);
|
|
|
|
}
|
|
|
|
|
2008-05-05 18:45:21 +00:00
|
|
|
mouse.loop();
|
2006-03-16 16:24:52 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2008-05-08 10:23:19 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
# library stuff -----------------------------------------------------------------------------------
|
|
|
|
|
2008-05-05 13:22:01 +00:00
|
|
|
var ERAD = geo.ERAD; # Earth radius (m)
|
|
|
|
var FT2M = geo.FT2M;
|
|
|
|
var M2FT = geo.M2FT;
|
2006-03-16 16:24:52 +00:00
|
|
|
|
2007-03-20 20:57:58 +00:00
|
|
|
var normdeg = geo.normdeg;
|
2007-06-22 14:13:30 +00:00
|
|
|
var printf = func { print(call(sprintf, arg)) }
|
2008-05-05 13:22:01 +00:00
|
|
|
var npow = func(v, w) v == 0 ? 0 : math.exp(math.ln(abs(v)) * w) * (v < 0 ? -1 : 1);
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
|
|
|
|
var init_prop = func(prop, value) {
|
2007-06-19 21:21:14 +00:00
|
|
|
if (prop.getValue() != nil)
|
2007-02-26 17:57:55 +00:00
|
|
|
value = prop.getValue();
|
2007-06-19 21:21:14 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
prop.setDoubleValue(value);
|
|
|
|
return value;
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-24 00:20:22 +00:00
|
|
|
# binary search of string in sorted vector; returns index or -1 if not found
|
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var search = func(list, which) {
|
2006-03-24 00:20:22 +00:00
|
|
|
var left = 0;
|
|
|
|
var right = size(list);
|
|
|
|
var middle = nil;
|
|
|
|
while (1) {
|
|
|
|
middle = int((left + right) / 2);
|
|
|
|
var c = cmp(list[middle], which);
|
2007-06-19 21:21:14 +00:00
|
|
|
if (!c)
|
2006-03-24 00:20:22 +00:00
|
|
|
return middle;
|
2007-06-19 21:21:14 +00:00
|
|
|
elsif (left == middle)
|
2006-03-24 00:20:22 +00:00
|
|
|
return -1;
|
2007-06-19 21:21:14 +00:00
|
|
|
elsif (c > 0)
|
2006-03-24 00:20:22 +00:00
|
|
|
right = middle;
|
2007-06-19 21:21:14 +00:00
|
|
|
else
|
2006-03-24 00:20:22 +00:00
|
|
|
left = middle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-31 17:12:32 +00:00
|
|
|
# scan all objects in subdir of $FG_ROOT. (Prefer *.xml files to *.ac files
|
|
|
|
# if both exist)
|
2006-03-22 20:25:58 +00:00
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var scan_models = func(base) {
|
2006-03-22 20:25:58 +00:00
|
|
|
var result = [];
|
|
|
|
var list = directory(getprop("/sim/fg-root") ~ "/" ~ base);
|
2007-06-19 21:21:14 +00:00
|
|
|
if (list == nil)
|
2006-03-22 20:25:58 +00:00
|
|
|
return result;
|
2007-06-19 21:21:14 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
var xml = {};
|
|
|
|
var ac = {};
|
|
|
|
foreach (var d; list) {
|
|
|
|
if (d[0] != `.` and d != "CVS") {
|
2007-04-06 22:42:35 +00:00
|
|
|
if (substr(d, -4) == ".xml") {
|
2006-03-22 20:25:58 +00:00
|
|
|
xml[base ~ "/" ~ d] = 1;
|
2007-04-06 22:42:35 +00:00
|
|
|
} elsif (substr(d, -3) == ".ac") {
|
2006-03-22 20:25:58 +00:00
|
|
|
ac[base ~ "/" ~ d] = 1;
|
|
|
|
} else {
|
|
|
|
foreach (var s; scan_models(base ~ "/" ~ d)) {
|
|
|
|
append(result, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (var m; keys(xml)) {
|
|
|
|
append(result, m);
|
2006-04-24 20:34:59 +00:00
|
|
|
delete(ac, substr(m, 0, size(m) - 3) ~ "ac");
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
foreach (var m; keys(ac)) {
|
|
|
|
append(result, m);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2006-03-15 00:29:53 +00:00
|
|
|
|
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# -------------------------------------------------------------------------------------------------
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# loop that generates the model flashing pulse
|
2006-04-16 08:09:28 +00:00
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var clock = 0;
|
|
|
|
var clock_loop = func {
|
|
|
|
clock = !clock;
|
|
|
|
settimer(clock_loop, 0.3);
|
|
|
|
}
|
|
|
|
clock_loop();
|
2006-03-15 14:27:47 +00:00
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# class that maintains one adjustable model property (see src/Model/modelmgr.cxx)
|
|
|
|
#
|
|
|
|
var ModelValue = {
|
|
|
|
new : func(base, name, value) {
|
|
|
|
var m = { parents: [ModelValue] };
|
|
|
|
m.propN = base.getNode(name, 1);
|
|
|
|
m.propN.setDoubleValue(value);
|
|
|
|
base.getNode(name ~ "-prop", 1).setValue(m.propN.getPath());
|
2006-03-15 14:27:47 +00:00
|
|
|
return m;
|
|
|
|
},
|
|
|
|
set : func(v) {
|
2007-02-26 17:57:55 +00:00
|
|
|
me.propN.setDoubleValue(v);
|
2006-03-15 14:27:47 +00:00
|
|
|
},
|
|
|
|
get : func {
|
2007-02-26 17:57:55 +00:00
|
|
|
me.propN.getValue();
|
2006-03-15 14:27:47 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# class that maintains one scenery object (see src/Model/modelmgr.cxx)
|
2006-04-16 08:09:28 +00:00
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var Model = {
|
|
|
|
new : func(path, pos, data = nil) {
|
|
|
|
var m = { parents: [Model] };
|
|
|
|
m.pos = pos;
|
|
|
|
m.path = path;
|
|
|
|
m.selected = 1;
|
|
|
|
m.visible = 1;
|
|
|
|
m.flash_until = 0;
|
|
|
|
m.loopid = 0;
|
|
|
|
m.elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
|
|
|
|
|
|
|
var models = props.globals.getNode("/models", 1);
|
|
|
|
for (var i = 0; 1; i += 1) {
|
|
|
|
if (models.getChild("model", i, 0) == nil) {
|
|
|
|
m.node = models.getChild("model", i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m.node.getNode("legend", 1).setValue("");
|
2008-05-05 13:22:01 +00:00
|
|
|
if (data != nil and isa(data, props.Node))
|
2007-02-26 17:57:55 +00:00
|
|
|
props.copy(data, m.node); # import node
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var hdg = init_prop(m.node.getNode("heading-deg", 1), 0);
|
|
|
|
var pitch = init_prop(m.node.getNode("pitch-deg", 1), 0);
|
|
|
|
var roll = init_prop(m.node.getNode("roll-deg", 1), 0);
|
|
|
|
|
|
|
|
m.node.getNode("path", 1).setValue(path);
|
|
|
|
m.lat = ModelValue.new(m.node, "latitude-deg", pos.lat());
|
2007-06-18 10:23:14 +00:00
|
|
|
m.lon = ModelValue.new(m.node, "longitude-deg", pos.lon());
|
2007-02-26 17:57:55 +00:00
|
|
|
m.alt = ModelValue.new(m.node, "elevation-ft", pos.alt() * M2FT);
|
|
|
|
m.hdg = ModelValue.new(m.node, "heading-deg", hdg);
|
|
|
|
m.pitch = ModelValue.new(m.node, "pitch-deg", pitch);
|
|
|
|
m.roll = ModelValue.new(m.node, "roll-deg", roll);
|
|
|
|
|
|
|
|
m.node.getNode("load", 1).setValue(1);
|
|
|
|
m.node.removeChildren("load");
|
|
|
|
return m;
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
remove : func {
|
|
|
|
props.globals.getNode("/models", 1).removeChild("model", me.node.getIndex());
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
clone : func(path) {
|
|
|
|
Model.new(path, me.pos, me.node);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-27 15:39:49 +00:00
|
|
|
move : func(pos) {
|
|
|
|
var v = me.visible;
|
|
|
|
me.unhide();
|
|
|
|
me.pos.set(pos);
|
|
|
|
me.lat.set(me.pos.lat());
|
2007-06-18 10:23:14 +00:00
|
|
|
me.lon.set(me.pos.lon());
|
2007-02-27 15:39:49 +00:00
|
|
|
me.alt.set(me.pos.alt() * M2FT);
|
|
|
|
v or me.hide();
|
|
|
|
},
|
|
|
|
raise : func (dist) {
|
|
|
|
var v = me.visible;
|
|
|
|
me.unhide();
|
|
|
|
me.pos.set_alt(me.pos.alt() + dist);
|
|
|
|
me.alt.set(me.pos.alt() * M2FT);
|
|
|
|
v or me.hide();
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
apply_course_distance : func(course, dist) {
|
|
|
|
me.pos.apply_course_distance(course, dist);
|
|
|
|
me.lat.set(me.pos.lat());
|
2007-06-18 10:23:14 +00:00
|
|
|
me.lon.set(me.pos.lon());
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-27 15:39:49 +00:00
|
|
|
direct_distance_to : func(dest) {
|
|
|
|
me.pos.direct_distance_to(dest);
|
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
flash : func(v) {
|
|
|
|
me.loopid += 1;
|
|
|
|
if (v) {
|
|
|
|
me.flash_until = me.elapsedN.getValue() + 2;
|
|
|
|
me._flash_(me.loopid);
|
|
|
|
} else {
|
|
|
|
me.unhide();
|
2006-03-24 15:33:06 +00:00
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
_flash_ : func(id) {
|
|
|
|
id == me.loopid or return;
|
2008-05-05 13:22:01 +00:00
|
|
|
if (me.elapsedN.getValue() > me.flash_until)
|
2007-02-26 17:57:55 +00:00
|
|
|
return me.unhide();
|
2008-05-05 13:22:01 +00:00
|
|
|
elsif (clock)
|
2007-02-26 17:57:55 +00:00
|
|
|
me.hide();
|
2008-05-05 13:22:01 +00:00
|
|
|
else
|
2007-02-26 17:57:55 +00:00
|
|
|
me.unhide();
|
|
|
|
settimer(func { me._flash_(id) }, 0);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
hide : func {
|
|
|
|
me.visible or return;
|
|
|
|
me.alt.set(me.alt.get() - ERAD);
|
|
|
|
me.visible = 0;
|
2006-03-15 14:27:47 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
unhide : func {
|
|
|
|
me.visible and return;
|
|
|
|
me.alt.set(me.alt.get() + ERAD);
|
|
|
|
me.visible = 1;
|
2006-03-24 15:33:06 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
get_data : func {
|
|
|
|
var n = props.Node.new();
|
|
|
|
props.copy(me.node, n);
|
|
|
|
me.add_derived_data(n);
|
|
|
|
return n;
|
2006-03-15 14:27:47 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
add_derived_data : func(node) {
|
|
|
|
node.removeChildren("latitude-deg-prop");
|
2007-06-18 10:23:14 +00:00
|
|
|
node.removeChildren("longitude-deg-prop");
|
2007-02-26 17:57:55 +00:00
|
|
|
node.removeChildren("elevation-ft-prop");
|
|
|
|
node.removeChildren("heading-deg-prop");
|
|
|
|
node.removeChildren("pitch-deg-prop");
|
|
|
|
node.removeChildren("roll-deg-prop");
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
var path = node.getNode("path").getValue();
|
|
|
|
var lat = node.getNode("latitude-deg").getValue();
|
2007-06-18 10:23:14 +00:00
|
|
|
var lon = node.getNode("longitude-deg").getValue();
|
2006-03-22 20:25:58 +00:00
|
|
|
var elev = node.getNode("elevation-ft").getValue();
|
|
|
|
var hdg = node.getNode("heading-deg").getValue();
|
2007-02-26 17:57:55 +00:00
|
|
|
var legend = node.getNode("legend").getValue();
|
2006-04-14 14:58:08 +00:00
|
|
|
var type = nil;
|
|
|
|
var spec = "";
|
|
|
|
|
|
|
|
if (path == "Aircraft/ufo/Models/sign.ac") {
|
|
|
|
type = "OBJECT_SIGN";
|
2008-05-05 13:22:01 +00:00
|
|
|
if (legend == "")
|
2007-02-26 17:57:55 +00:00
|
|
|
legend = "{@size=10,@material=RedSign}NO_CONTENTS_" ~ int(10000 * rand());
|
2008-05-05 13:22:01 +00:00
|
|
|
|
|
|
|
foreach (var c; split('', legend))
|
|
|
|
if (c != ' ')
|
2006-04-16 22:05:59 +00:00
|
|
|
spec ~= c;
|
2006-04-14 14:58:08 +00:00
|
|
|
} else {
|
|
|
|
type = "OBJECT_SHARED";
|
|
|
|
spec = path;
|
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var elev_m = elev * FT2M;
|
2006-03-22 20:25:58 +00:00
|
|
|
var stg_hdg = normdeg(360 - hdg);
|
2007-06-18 10:23:14 +00:00
|
|
|
var stg_path = geo.tile_path(lat, lon);
|
2006-03-22 20:25:58 +00:00
|
|
|
var abs_path = getprop("/sim/fg-root") ~ "/" ~ path;
|
2006-04-24 20:34:59 +00:00
|
|
|
var obj_line = sprintf("%s %s %.8f %.8f %.4f %.1f", type, spec, lon, lat, elev_m, stg_hdg);
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
node.getNode("absolute-path", 1).setValue(abs_path);
|
2007-02-26 17:57:55 +00:00
|
|
|
node.getNode("legend", 1).setValue(legend);
|
2006-03-22 20:25:58 +00:00
|
|
|
node.getNode("stg-path", 1).setValue(stg_path);
|
|
|
|
node.getNode("stg-heading-deg", 1).setDoubleValue(stg_hdg);
|
2006-04-24 20:34:59 +00:00
|
|
|
node.getNode("elevation-m", 1).setDoubleValue(elev_m);
|
2007-02-26 17:57:55 +00:00
|
|
|
node.getNode("object-line", 1).setValue(obj_line);
|
|
|
|
return node;
|
2006-04-15 20:21:41 +00:00
|
|
|
},
|
2006-03-15 14:27:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var ModelMgr = {
|
2006-03-22 20:25:58 +00:00
|
|
|
new : func(path) {
|
|
|
|
var m = { parents: [ModelMgr] };
|
2007-02-26 17:57:55 +00:00
|
|
|
m.active = nil;
|
|
|
|
m.models = [];
|
|
|
|
m.legendN = props.globals.getNode("/sim/gui/dialogs/ufo-status/input", 1);
|
|
|
|
m.legendN.setValue("");
|
2007-03-20 20:57:58 +00:00
|
|
|
m.mouse_coord = geo.aircraft_position();
|
2007-02-26 17:57:55 +00:00
|
|
|
m.import();
|
2007-03-20 20:57:58 +00:00
|
|
|
m.marker = Model.new("Aircraft/ufo/Models/marker.ac", geo.Coord.new().set_xyz(0, 0, 0));
|
2007-02-27 22:56:22 +00:00
|
|
|
m.marker.hide();
|
2006-03-22 20:25:58 +00:00
|
|
|
m.modelpath = path;
|
2008-05-08 20:11:39 +00:00
|
|
|
if (m.active != nil)
|
|
|
|
m.marker.move(m.active.pos);
|
2006-03-15 14:27:47 +00:00
|
|
|
|
2008-05-05 13:22:01 +00:00
|
|
|
if (path != "Aircraft/ufo/Models/cursor.ac")
|
2007-02-26 17:57:55 +00:00
|
|
|
status_dialog.open();
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
return m;
|
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
click : func(mouse_coord) {
|
2008-05-04 21:56:34 +00:00
|
|
|
if (gear_key_down)
|
|
|
|
return teleport(mouse_coord, me.active);
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
me.mouse_coord = mouse_coord;
|
2007-02-24 19:48:02 +00:00
|
|
|
status_dialog.open();
|
2007-02-26 17:57:55 +00:00
|
|
|
adjust_dialog.center_sliders();
|
|
|
|
|
2008-05-05 13:22:01 +00:00
|
|
|
if (KbdAlt.getValue()) { # move active object here (and other selected ones along with it)
|
2007-02-26 17:57:55 +00:00
|
|
|
(me.active == nil) and return;
|
|
|
|
var course = me.active.pos.course_to(me.mouse_coord);
|
|
|
|
var distance = me.active.pos.distance_to(me.mouse_coord);
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.pos.set_alt(me.mouse_coord.alt());
|
|
|
|
m.selected and m.apply_course_distance(course, distance);
|
|
|
|
}
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(me.active.pos);
|
2007-02-26 17:57:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-06-05 16:33:39 +00:00
|
|
|
|
2008-05-05 13:22:01 +00:00
|
|
|
if (!KbdShift.getValue())
|
2007-02-26 17:57:55 +00:00
|
|
|
me.deselect_all();
|
2006-06-05 16:33:39 +00:00
|
|
|
|
2008-05-05 13:22:01 +00:00
|
|
|
if (KbdCtrl.getValue()) { # select existing object
|
2007-02-26 17:57:55 +00:00
|
|
|
me.select();
|
|
|
|
} else { # add one new object
|
|
|
|
me.active = Model.new(me.modelpath, mouse_coord, me.sticky_data());
|
|
|
|
append(me.models, me.active);
|
|
|
|
me.display_status(me.modelpath);
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(me.active.pos);
|
2007-02-26 17:57:55 +00:00
|
|
|
|
2008-05-05 13:22:01 +00:00
|
|
|
if (KbdShift.getValue())
|
|
|
|
foreach (var m; me.models)
|
2007-02-26 17:57:55 +00:00
|
|
|
m.flash(m.selected);
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
select : func() {
|
|
|
|
if (!size(me.models)) {
|
|
|
|
me.active = nil;
|
2008-05-08 20:11:39 +00:00
|
|
|
me.marker.hide();
|
2007-02-26 17:57:55 +00:00
|
|
|
return;
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
var min_dist = 10 * ERAD;
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
forindex (var i; me.models) {
|
|
|
|
var dist = me.models[i].direct_distance_to(me.mouse_coord);
|
2006-03-22 20:25:58 +00:00
|
|
|
if (dist < min_dist) {
|
|
|
|
min_dist = dist;
|
2007-02-26 17:57:55 +00:00
|
|
|
me.active = me.models[i];
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
me.active.selected = 1;
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(me.active.pos);
|
2008-03-18 22:58:42 +00:00
|
|
|
var selected = [];
|
2007-02-26 17:57:55 +00:00
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.flash(m.selected);
|
2008-03-18 22:58:42 +00:00
|
|
|
if (m.selected)
|
|
|
|
append(selected, m);
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
2008-03-18 22:58:42 +00:00
|
|
|
if (size(selected) == 2) {
|
|
|
|
var dist = selected[0].direct_distance_to(selected[1].pos);
|
|
|
|
screen.log.write(sprintf("%.3f m", dist));
|
|
|
|
}
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
me.display_status(me.modelpath = me.active.path);
|
|
|
|
},
|
|
|
|
deselect_all : func {
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var m; me.models)
|
2007-02-26 17:57:55 +00:00
|
|
|
m.flash(m.selected = 0);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
|
|
|
remove_selected : func {
|
2007-02-26 17:57:55 +00:00
|
|
|
var models = [];
|
|
|
|
foreach (var m; me.models) {
|
2008-05-05 13:22:01 +00:00
|
|
|
if (m.selected)
|
2007-02-26 17:57:55 +00:00
|
|
|
m.remove();
|
2008-05-05 13:22:01 +00:00
|
|
|
else
|
2007-02-26 17:57:55 +00:00
|
|
|
append(models, m);
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
me.models = models;
|
|
|
|
me.select();
|
|
|
|
me.display_status(me.modelpath);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
set_modelpath : func(path) {
|
2006-03-22 20:25:58 +00:00
|
|
|
me.modelpath = path;
|
2006-03-25 18:30:32 +00:00
|
|
|
me.display_status(path);
|
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
update_legend : func {
|
2008-05-05 13:22:01 +00:00
|
|
|
if (me.active != nil)
|
2007-02-26 17:57:55 +00:00
|
|
|
me.active.node.getNode("legend", 1).setValue(me.legendN.getValue());
|
|
|
|
},
|
|
|
|
display_status : func(path) {
|
|
|
|
var legend = me.active == nil ? "" : me.active.node.getNode("legend", 1).getValue();
|
|
|
|
me.legendN.setValue(legend);
|
|
|
|
setprop("/sim/model/ufo/status", "(" ~ size(me.models) ~ ") " ~ path);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
|
|
|
get_data : func {
|
|
|
|
var n = props.Node.new();
|
2008-05-05 13:22:01 +00:00
|
|
|
forindex (var i; me.models)
|
2007-02-26 17:57:55 +00:00
|
|
|
props.copy(me.models[i].get_data(), n.getChild("model", i, 1));
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
return n;
|
|
|
|
},
|
2006-03-24 00:20:22 +00:00
|
|
|
cycle : func(up) {
|
|
|
|
var i = search(modellist, me.modelpath) + up;
|
2008-05-05 13:22:01 +00:00
|
|
|
if (i < 0)
|
2006-03-24 00:20:22 +00:00
|
|
|
i = size(modellist) - 1;
|
2008-05-05 13:22:01 +00:00
|
|
|
elsif (i >= size(modellist))
|
2006-03-24 00:20:22 +00:00
|
|
|
i = 0;
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
me.set_modelpath(modellist[i]);
|
|
|
|
|
|
|
|
var models = [];
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
if (m.selected) {
|
|
|
|
append(models, m.clone(modellist[i]));
|
|
|
|
m.remove();
|
|
|
|
} else {
|
|
|
|
append(models, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
me.models = models;
|
|
|
|
},
|
|
|
|
sticky_data : func {
|
|
|
|
var n = props.Node.new();
|
2007-02-27 15:39:49 +00:00
|
|
|
if (me.active == nil) {
|
|
|
|
return n;
|
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
var hdg = n.getNode("heading-deg", 1);
|
|
|
|
var pitch = n.getNode("pitch-deg", 1);
|
|
|
|
var roll = n.getNode("roll-deg", 1);
|
2008-05-05 13:22:01 +00:00
|
|
|
if (getprop("/models/adjust/sticky-heading"))
|
2007-02-26 17:57:55 +00:00
|
|
|
hdg.setDoubleValue(me.active.node.getNode("heading-deg").getValue());
|
2008-05-05 13:22:01 +00:00
|
|
|
else
|
2007-02-26 17:57:55 +00:00
|
|
|
hdg.setDoubleValue(0);
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
if (getprop("/models/adjust/sticky-orientation")) {
|
|
|
|
pitch.setDoubleValue(me.active.node.getNode("pitch-deg").getValue());
|
|
|
|
roll.setDoubleValue(me.active.node.getNode("roll-deg").getValue());
|
|
|
|
} else {
|
|
|
|
pitch.setDoubleValue(0);
|
|
|
|
roll.setDoubleValue(0);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
},
|
|
|
|
reset_heading : func {
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var m; me.models)
|
|
|
|
if (m.selected)
|
2007-02-26 17:57:55 +00:00
|
|
|
m.hdg.set(0);
|
|
|
|
},
|
|
|
|
reset_orientation : func {
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
if (m.selected) {
|
|
|
|
m.pitch.set(0);
|
|
|
|
m.roll.set(0);
|
|
|
|
}
|
2006-03-24 00:20:22 +00:00
|
|
|
}
|
|
|
|
},
|
2006-04-13 22:01:53 +00:00
|
|
|
import : func {
|
2007-02-27 15:39:49 +00:00
|
|
|
me.active = nil;
|
2007-06-18 10:23:14 +00:00
|
|
|
var mandatory = ["path", "latitude-deg", "longitude-deg", "elevation-ft"];
|
2006-04-21 19:49:44 +00:00
|
|
|
foreach (var m; props.globals.getNode("models", 1).getChildren("model")) {
|
|
|
|
var ok = 1;
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var a; mandatory)
|
|
|
|
if (m.getNode(a) == nil or m.getNode(a).getType() == "NONE")
|
2006-04-21 19:49:44 +00:00
|
|
|
ok = 0;
|
|
|
|
if (ok) {
|
2007-02-27 15:39:49 +00:00
|
|
|
var tmp = props.Node.new({ legend:"", "heading-deg":0, "pitch-deg":0, "roll-deg":0 });
|
2006-04-21 19:59:51 +00:00
|
|
|
props.copy(m, tmp);
|
2006-04-21 19:49:44 +00:00
|
|
|
m.getParent().removeChild(m.getName(), m.getIndex());
|
2007-06-18 10:23:14 +00:00
|
|
|
var c = geo.Coord.new().set_latlon(
|
2007-02-26 17:57:55 +00:00
|
|
|
tmp.getNode("latitude-deg").getValue(),
|
2007-06-18 10:23:14 +00:00
|
|
|
tmp.getNode("longitude-deg").getValue(),
|
2007-02-26 17:57:55 +00:00
|
|
|
tmp.getNode("elevation-ft").getValue() * FT2M);
|
2007-02-27 15:39:49 +00:00
|
|
|
append(me.models, me.active = Model.new(tmp.getNode("path").getValue(), c, tmp));
|
2008-05-08 20:11:39 +00:00
|
|
|
#me.marker.move(me.active.pos);
|
2007-02-26 17:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
adjust : func(name, value, scale = 0) {
|
2008-05-05 13:22:01 +00:00
|
|
|
if (!size(me.models) or me.active == nil)
|
2007-02-26 17:57:55 +00:00
|
|
|
return;
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-03-20 20:57:58 +00:00
|
|
|
var ufo = geo.aircraft_position();
|
2007-02-26 17:57:55 +00:00
|
|
|
var dist = scale ? ufo.distance_to(me.active.pos) * 0.05 : 1;
|
|
|
|
if (name == "longitudinal") {
|
|
|
|
var dir = ufo.course_to(me.active.pos);
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var m; me.models)
|
2007-02-26 17:57:55 +00:00
|
|
|
m.selected and m.apply_course_distance(dir, value * dist);
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
} elsif (name == "transversal") {
|
|
|
|
var dir = ufo.course_to(me.active.pos) + 90;
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var m; me.models)
|
2007-02-26 17:57:55 +00:00
|
|
|
m.selected and m.apply_course_distance(dir, value * dist);
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
} elsif (name == "altitude") {
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var m; me.models)
|
2007-02-27 15:39:49 +00:00
|
|
|
m.selected and m.raise(value * dist * 0.4);
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
} elsif (name == "heading") {
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var m; me.models)
|
2007-02-26 19:15:26 +00:00
|
|
|
m.selected and m.hdg.set(m.hdg.get() + value * 4);
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
} elsif (name == "pitch") {
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var m; me.models)
|
2007-02-26 17:57:55 +00:00
|
|
|
m.selected and m.pitch.set(m.pitch.get() + value * 6);
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
} elsif (name == "roll") {
|
2008-05-05 13:22:01 +00:00
|
|
|
foreach (var m; me.models)
|
2007-02-26 17:57:55 +00:00
|
|
|
m.selected and m.roll.set(m.roll.get() + value * 6);
|
2008-05-05 13:22:01 +00:00
|
|
|
|
2008-05-08 20:11:39 +00:00
|
|
|
} elsif (name == "bearing") {
|
|
|
|
foreach (var m; me.models)
|
|
|
|
if (m.selected) {
|
|
|
|
var course = me.active.pos.course_to(m.pos);
|
|
|
|
var dist = me.active.pos.distance_to(m.pos);
|
|
|
|
m.apply_course_distance(course, -dist);
|
|
|
|
m.apply_course_distance(course + value * 4, dist);
|
|
|
|
m.hdg.set(m.hdg.get() + value * 4);
|
|
|
|
}
|
2006-04-13 22:01:53 +00:00
|
|
|
}
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(me.active.pos);
|
2007-02-27 15:39:49 +00:00
|
|
|
},
|
2007-02-27 22:56:22 +00:00
|
|
|
toggle_marker : func {
|
|
|
|
me.marker.visible ? me.marker.hide() : me.marker.unhide();
|
2006-04-13 22:01:53 +00:00
|
|
|
},
|
2006-03-22 20:25:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var scan_dirs = func(csv) {
|
2006-04-24 20:34:59 +00:00
|
|
|
var list = ["Aircraft/ufo/Models/sign.ac"];
|
2007-04-06 22:42:35 +00:00
|
|
|
foreach (var dir; split(",", csv))
|
|
|
|
foreach(var m; scan_models(dir))
|
2006-03-22 20:25:58 +00:00
|
|
|
append(list, m);
|
2007-04-06 22:42:35 +00:00
|
|
|
|
2007-05-12 18:40:09 +00:00
|
|
|
return sort(list, cmp);
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-23 16:16:44 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var print_ufo_data = func {
|
2006-03-27 13:13:57 +00:00
|
|
|
print("\n\n------------------------------ UFO -------------------------------\n");
|
|
|
|
|
|
|
|
var lat = getprop("/position/latitude-deg");
|
2007-06-18 10:23:14 +00:00
|
|
|
var lon = getprop("/position/longitude-deg");
|
2006-03-27 13:13:57 +00:00
|
|
|
var alt_ft = getprop("/position/altitude-ft");
|
|
|
|
var elev_m = getprop("/position/ground-elev-m");
|
|
|
|
var heading = getprop("/orientation/heading-deg");
|
2007-02-26 17:57:55 +00:00
|
|
|
var agl_ft = alt_ft - elev_m * M2FT;
|
2006-03-27 13:13:57 +00:00
|
|
|
|
2006-04-02 17:52:33 +00:00
|
|
|
printf("Latitude: %.8f deg", lat);
|
2007-06-18 10:23:14 +00:00
|
|
|
printf("Longitude: %.8f deg", lon);
|
2007-02-26 17:57:55 +00:00
|
|
|
printf("Altitude ASL: %.4f m (%.4f ft)", alt_ft * FT2M, alt_ft);
|
|
|
|
printf("Altitude AGL: %.4f m (%.4f ft)", agl_ft * FT2M, agl_ft);
|
2006-03-27 13:13:57 +00:00
|
|
|
printf("Heading: %.1f deg", normdeg(heading));
|
2007-02-26 17:57:55 +00:00
|
|
|
printf("Ground Elev: %.4f m (%.4f ft)", elev_m, elev_m * M2FT);
|
2006-03-27 13:13:57 +00:00
|
|
|
print();
|
2007-06-18 10:23:14 +00:00
|
|
|
print("# " ~ geo.tile_path(lat, lon));
|
2006-04-02 17:52:33 +00:00
|
|
|
printf("OBJECT_STATIC %.8f %.8f %.4f %.1f", lon, lat, elev_m, normdeg(360 - heading));
|
2006-03-27 13:13:57 +00:00
|
|
|
print();
|
|
|
|
|
|
|
|
var hdg = normdeg(heading + getprop("/sim/current-view/goal-pitch-offset-deg"));
|
2007-06-18 10:23:14 +00:00
|
|
|
var fgfs = sprintf("$ fgfs --aircraft=ufo --lat=%.6f --lon=%.6f --altitude=%.2f --heading=%.1f",
|
2008-03-12 20:47:53 +00:00
|
|
|
lat, lon, alt_ft, hdg);
|
2006-03-27 13:13:57 +00:00
|
|
|
print(fgfs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var print_model_data = func(prop) {
|
2006-03-27 13:13:57 +00:00
|
|
|
print("\n\n------------------------ Selected Object -------------------------\n");
|
|
|
|
var elev = prop.getNode("elevation-ft").getValue();
|
|
|
|
printf("Path: %s", prop.getNode("path").getValue());
|
2006-04-02 17:52:33 +00:00
|
|
|
printf("Latitude: %.8f deg", prop.getNode("latitude-deg").getValue());
|
2007-06-18 10:23:14 +00:00
|
|
|
printf("Longitude: %.8f deg", prop.getNode("longitude-deg").getValue());
|
2007-02-26 17:57:55 +00:00
|
|
|
printf("Altitude ASL: %.4f m (%.4f ft)", elev * FT2M, elev);
|
2006-03-27 13:13:57 +00:00
|
|
|
printf("Heading: %.1f deg", prop.getNode("heading-deg").getValue());
|
|
|
|
printf("Pitch: %.1f deg", prop.getNode("pitch-deg").getValue());
|
|
|
|
printf("Roll: %.1f deg", prop.getNode("roll-deg").getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-05 13:22:01 +00:00
|
|
|
var teleport = func(target, lookat = nil) {
|
2008-05-04 21:16:48 +00:00
|
|
|
setprop("/position/latitude-deg", target.lat());
|
|
|
|
setprop("/position/longitude-deg", target.lon());
|
2008-05-05 13:22:01 +00:00
|
|
|
setprop("/position/altitude-ft", target.alt() * M2FT + getprop("/position/altitude-agl-ft"));
|
2008-05-04 21:56:34 +00:00
|
|
|
|
|
|
|
var hdg = props.globals.getNode("/orientation/heading-deg");
|
2008-05-04 21:16:48 +00:00
|
|
|
if (lookat != nil)
|
2008-05-04 21:56:34 +00:00
|
|
|
hdg.setDoubleValue(target.course_to(lookat.pos));
|
|
|
|
else
|
|
|
|
hdg.setDoubleValue(hdg.getValue() - getprop("/sim/current-view/heading-offset-deg"));
|
|
|
|
view.resetView();
|
2008-05-04 21:16:48 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 13:13:57 +00:00
|
|
|
|
|
|
|
|
2006-03-23 16:16:44 +00:00
|
|
|
# interface functions -----------------------------------------------------------------------------
|
|
|
|
|
2008-03-12 20:47:53 +00:00
|
|
|
|
|
|
|
var vert_factor = 1;
|
|
|
|
var up = func(dir) {
|
|
|
|
if (!dir)
|
|
|
|
return vert_factor = 1;
|
|
|
|
var alt = "position/altitude-ft";
|
|
|
|
setprop(alt, getprop(alt) + 0.15 * vert_factor * dir);
|
|
|
|
vert_factor += 0.25;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var print_data = func {
|
2006-03-27 13:13:57 +00:00
|
|
|
var rule = "\n------------------------------------------------------------------\n";
|
|
|
|
print("\n\n");
|
2007-02-26 17:57:55 +00:00
|
|
|
print_ufo_data();
|
2006-03-27 13:13:57 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
var data = modelmgr.get_data();
|
2006-03-27 13:13:57 +00:00
|
|
|
|
|
|
|
var selected = data.getChild("model", 0);
|
2008-05-05 13:22:01 +00:00
|
|
|
if (selected == nil)
|
|
|
|
return print(rule);
|
2006-03-27 13:13:57 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
print_model_data(selected);
|
2006-03-27 13:13:57 +00:00
|
|
|
print(rule);
|
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
# group all objects of a bucket
|
2006-03-27 13:13:57 +00:00
|
|
|
var bucket = {};
|
2006-03-22 20:25:58 +00:00
|
|
|
foreach (var m; data.getChildren("model")) {
|
|
|
|
var stg = m.getNode("stg-path").getValue();
|
|
|
|
var obj = m.getNode("object-line").getValue();
|
2007-06-19 21:21:14 +00:00
|
|
|
if (contains(bucket, stg))
|
2006-03-22 20:25:58 +00:00
|
|
|
append(bucket[stg], obj);
|
2007-06-19 21:21:14 +00:00
|
|
|
else
|
2006-03-22 20:25:58 +00:00
|
|
|
bucket[stg] = [obj];
|
|
|
|
}
|
|
|
|
foreach (var key; keys(bucket)) {
|
|
|
|
print("\n# ", key);
|
2007-06-19 21:21:14 +00:00
|
|
|
foreach (var obj; bucket[key])
|
2006-03-22 20:25:58 +00:00
|
|
|
print(obj);
|
|
|
|
}
|
|
|
|
print(rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var export_data = func {
|
2006-04-02 17:35:47 +00:00
|
|
|
var path = getprop("/sim/fg-home") ~ "/ufo-model-export.xml";
|
2007-06-18 16:35:03 +00:00
|
|
|
var args = props.Node.new({ filename : path });
|
2007-07-01 13:07:08 +00:00
|
|
|
props.copy(modelmgr.get_data(), args.getNode("data/models", 1));
|
2007-06-18 16:35:03 +00:00
|
|
|
fgcommand("savexml", args);
|
2006-04-02 17:35:47 +00:00
|
|
|
print("model data exported to ", path);
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-18 21:20:39 +00:00
|
|
|
var export_flightplan = func {
|
|
|
|
var path = getprop("/sim/fg-home") ~ "/ufo-flightplan-export.xml";
|
|
|
|
var args = props.Node.new({ filename : path });
|
|
|
|
var export = args.getNode("data/flightplan", 1);
|
|
|
|
var waypoints = modelmgr.get_data().getChildren("model");
|
|
|
|
forindex (var i; waypoints) {
|
|
|
|
var from = waypoints[i];
|
|
|
|
var to = export.getChild("wpt", i, 1);
|
|
|
|
to.getNode("name", 1).setValue("#" ~ i);
|
|
|
|
to.getNode("lat", 1).setDoubleValue(from.getNode("latitude-deg").getValue());
|
|
|
|
to.getNode("lon", 1).setDoubleValue(from.getNode("longitude-deg").getValue());
|
|
|
|
to.getNode("crossat", 1).setDoubleValue(from.getNode("elevation-ft").getValue());
|
|
|
|
to.getNode("on-ground", 1).setBoolValue(1);
|
|
|
|
to.getNode("ktas", 1).setDoubleValue(100);
|
|
|
|
}
|
2007-10-18 21:31:29 +00:00
|
|
|
export.getChild("wpt", i + 1, 1).getNode("name", 1).setValue("END");
|
2007-10-18 21:20:39 +00:00
|
|
|
|
|
|
|
fgcommand("savexml", args);
|
|
|
|
print("flightplan exported to ", path);
|
|
|
|
}
|
|
|
|
|
2007-06-18 16:35:03 +00:00
|
|
|
|
|
|
|
var file_selector = nil;
|
|
|
|
|
|
|
|
# called via l-key (load object from disk)
|
|
|
|
var file_select_model = func {
|
|
|
|
if (file_selector == nil) {
|
|
|
|
file_selector = gui.FileSelector.new(fsel_callback,
|
2007-06-22 14:13:30 +00:00
|
|
|
"Select 3D model file", "Load Model",
|
|
|
|
["*.ac", "*.xml"], getprop("/sim/fg-root"));
|
2007-06-18 16:35:03 +00:00
|
|
|
}
|
|
|
|
file_selector.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
var fsel_callback = func {
|
|
|
|
var model = cmdarg().getValue();
|
2007-06-22 14:13:30 +00:00
|
|
|
var root = string.fixpath(getprop("/sim/fg-root")) ~ "/";
|
2007-06-18 16:35:03 +00:00
|
|
|
if (substr(model, 0, size(root)) == root)
|
|
|
|
model = substr(model, size(root));
|
|
|
|
|
|
|
|
append(modellist, model);
|
2007-06-19 21:21:14 +00:00
|
|
|
modellist = sort(modellist, cmp);
|
2007-06-18 16:35:03 +00:00
|
|
|
modelmgr.set_modelpath(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# init --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
var KbdShift = props.globals.getNode("/devices/status/keyboard/shift");
|
|
|
|
var KbdCtrl = props.globals.getNode("/devices/status/keyboard/ctrl");
|
|
|
|
var KbdAlt = props.globals.getNode("/devices/status/keyboard/alt");
|
|
|
|
|
|
|
|
var modellist = scan_dirs(getprop("/source"));
|
|
|
|
var modelmgr = ModelMgr.new(getprop("/cursor"));
|
|
|
|
|
|
|
|
setlistener("/sim/signals/click", func {
|
2008-05-07 18:03:38 +00:00
|
|
|
if (!mouse.mmb)
|
|
|
|
modelmgr.click(geo.click_position());
|
2007-02-26 17:57:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|