2006-08-22 10:06:46 +00:00
|
|
|
# Dynamic Cockpit View manager. Tries to simulate the pilot's most likely
|
|
|
|
# deliberate view direction. Doesn't consider forced view changes due to
|
|
|
|
# acceleration.
|
2007-02-10 23:47:02 +00:00
|
|
|
#
|
|
|
|
# To override the default recipes, put something like this into one of
|
|
|
|
# your aircraft's Nasal files:
|
|
|
|
#
|
|
|
|
# dynamic_view.register(func {
|
|
|
|
# # me.default_plane(); # uncomment one of these if you want
|
|
|
|
# # me.default_helicopter(); # to base your code on the defaults
|
|
|
|
#
|
|
|
|
# # positive values rotate (deg) or move (m)
|
|
|
|
# me.heading_offset = ... # left
|
|
|
|
# me.pitch_offset = ... # up
|
|
|
|
# me.roll_offset = ... # right
|
|
|
|
# me.x_offset = ... # right (transversal axis)
|
|
|
|
# me.y_offset = ... # up (vertical axis)
|
|
|
|
# me.z_offset = ... # back/aft (longitudinal axis)
|
|
|
|
# me.fov_offset = ... # zoom out (field of view)
|
|
|
|
# });
|
|
|
|
#
|
|
|
|
# All offsets are by default 0, and you only need to set them if they should
|
|
|
|
# be non-zero. The registered function is called for each frame and the respective
|
|
|
|
# view parameters are set accordingly. The function can access all internal
|
2007-05-11 18:59:34 +00:00
|
|
|
# variables of the view_manager class, such as me.roll, me.pitch, etc., and it
|
2007-02-10 23:47:02 +00:00
|
|
|
# can, of course, also use module variables from the file where it's defined.
|
|
|
|
#
|
|
|
|
# The following commands move smoothly to a fixed view position and back.
|
|
|
|
# All values are relative to aircraft origin (absolute), not relative to
|
2007-02-23 22:17:55 +00:00
|
|
|
# the default cockpit view position. The time and field-of-view argument
|
2007-02-11 16:56:15 +00:00
|
|
|
# is optional.
|
2007-02-10 23:47:02 +00:00
|
|
|
#
|
2007-02-23 22:17:55 +00:00
|
|
|
# dynamic_view.lookat(hdg, pitch, roll, x, y, z [, time=0.2 [, fov=55]]);
|
2007-02-10 23:47:02 +00:00
|
|
|
# dynamic_view.resume();
|
|
|
|
|
2006-08-17 15:59:44 +00:00
|
|
|
|
2007-02-23 22:17:55 +00:00
|
|
|
var FREEZE_DURATION = 2;
|
|
|
|
var BLEND_TIME = 0.2;
|
|
|
|
|
|
|
|
|
2008-11-20 20:18:39 +00:00
|
|
|
var sin = func(a) math.sin(a * D2R);
|
|
|
|
var cos = func(a) math.cos(a * D2R);
|
2007-02-06 14:33:59 +00:00
|
|
|
var sigmoid = func(x) { 1 / (1 + math.exp(-x)) }
|
|
|
|
var nsigmoid = func(x) { 2 / (1 + math.exp(-x)) - 1 }
|
2007-02-10 20:42:36 +00:00
|
|
|
var pow = func(v, w) { v < 0 ? nil : v == 0 ? 0 : math.exp(math.ln(v) * w) }
|
|
|
|
var npow = func(v, w) { v == 0 ? 0 : math.exp(math.ln(abs(v)) * w) * (v < 0 ? -1 : 1) }
|
2007-02-06 14:33:59 +00:00
|
|
|
var clamp = func(v, min, max) { v < min ? min : v > max ? max : v }
|
|
|
|
var normatan = func(x) { math.atan2(x, 1) * 2 / math.pi }
|
|
|
|
|
|
|
|
var normdeg = func(a) {
|
2007-05-11 18:59:34 +00:00
|
|
|
while (a >= 180)
|
2006-11-02 21:06:36 +00:00
|
|
|
a -= 360;
|
2007-05-11 18:59:34 +00:00
|
|
|
while (a < -180)
|
2006-11-02 21:06:36 +00:00
|
|
|
a += 360;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2006-08-19 22:24:24 +00:00
|
|
|
|
|
|
|
|
2006-08-17 15:59:44 +00:00
|
|
|
# Class that reads a property value, applies factor & offset, clamps to min & max,
|
2006-08-22 10:06:46 +00:00
|
|
|
# and optionally lowpass filters.
|
2006-08-17 15:59:44 +00:00
|
|
|
#
|
2007-02-06 14:33:59 +00:00
|
|
|
var Input = {
|
2006-08-22 10:06:46 +00:00
|
|
|
new : func(prop = "/null", factor = 1, offset = 0, filter = 0, min = nil, max = nil) {
|
2006-08-17 15:59:44 +00:00
|
|
|
var m = { parents : [Input] };
|
|
|
|
m.prop = isa(props.Node, prop) ? prop : props.globals.getNode(prop, 1);
|
|
|
|
m.factor = factor;
|
|
|
|
m.offset = offset;
|
|
|
|
m.min = min;
|
|
|
|
m.max = max;
|
2006-11-03 17:38:32 +00:00
|
|
|
m.lowpass = filter ? aircraft.lowpass.new(filter) : nil;
|
2006-08-17 15:59:44 +00:00
|
|
|
return m;
|
|
|
|
},
|
|
|
|
get : func {
|
|
|
|
var v = me.prop.getValue() * me.factor + me.offset;
|
2007-05-11 18:59:34 +00:00
|
|
|
if (me.min != nil and v < me.min)
|
2006-08-17 15:59:44 +00:00
|
|
|
v = me.min;
|
2007-05-11 18:59:34 +00:00
|
|
|
if (me.max != nil and v > me.max)
|
2006-08-17 15:59:44 +00:00
|
|
|
v = me.max;
|
|
|
|
|
2007-05-11 18:59:34 +00:00
|
|
|
return me.lowpass == nil ? v : me.lowpass.filter(v);
|
2006-08-17 15:59:44 +00:00
|
|
|
},
|
|
|
|
set : func(v) {
|
|
|
|
me.prop.setDoubleValue(v);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Class that maintains one sim/current-view/goal-*-offset-deg property.
|
|
|
|
#
|
2007-02-06 14:33:59 +00:00
|
|
|
var ViewAxis = {
|
2006-08-17 15:59:44 +00:00
|
|
|
new : func(prop) {
|
|
|
|
var m = { parents : [ViewAxis] };
|
2007-02-07 22:13:51 +00:00
|
|
|
m.prop = props.globals.getNode(prop, 1);
|
2007-05-11 18:59:34 +00:00
|
|
|
if (m.prop.getType() == "NONE")
|
2007-02-07 22:13:51 +00:00
|
|
|
m.prop.setDoubleValue(0);
|
2007-05-11 18:59:34 +00:00
|
|
|
|
2006-08-17 15:59:44 +00:00
|
|
|
m.reset();
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
reset : func {
|
|
|
|
me.applied_offset = 0;
|
|
|
|
},
|
|
|
|
add_offset : func {
|
|
|
|
me.prop.setValue(me.prop.getValue() + me.applied_offset);
|
|
|
|
},
|
2006-12-10 23:09:42 +00:00
|
|
|
sub_offset : func {
|
|
|
|
var raw = me.prop.getValue() - me.applied_offset;
|
|
|
|
me.prop.setValue(raw);
|
|
|
|
return raw;
|
|
|
|
},
|
2006-08-18 17:00:16 +00:00
|
|
|
apply : func(v) {
|
|
|
|
var raw = me.prop.getValue() - me.applied_offset;
|
|
|
|
me.applied_offset = v;
|
|
|
|
me.prop.setDoubleValue(raw + me.applied_offset);
|
|
|
|
},
|
2007-02-07 16:58:46 +00:00
|
|
|
static : func(v) {
|
|
|
|
normdeg(v - me.prop.getValue() + me.applied_offset);
|
|
|
|
},
|
2006-08-17 15:59:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-05-11 18:59:34 +00:00
|
|
|
# Singleton class that manages a dynamic cockpit view by manipulating
|
2006-08-17 15:59:44 +00:00
|
|
|
# sim/current-view/goal-*-offset-deg properties.
|
|
|
|
#
|
2007-05-11 18:59:34 +00:00
|
|
|
var view_manager = {
|
|
|
|
init : func {
|
|
|
|
me.elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
|
|
|
me.deltaN = props.globals.getNode("/sim/time/delta-realtime-sec", 1);
|
|
|
|
|
|
|
|
me.headingN = props.globals.getNode("/orientation/heading-deg", 1);
|
|
|
|
me.pitchN = props.globals.getNode("/orientation/pitch-deg", 1);
|
|
|
|
me.rollN = props.globals.getNode("/orientation/roll-deg", 1);
|
|
|
|
me.slipN = props.globals.getNode("/orientation/side-slip-deg", 1);
|
|
|
|
me.speedN = props.globals.getNode("velocities/airspeed-kt", 1);
|
|
|
|
|
|
|
|
me.wind_dirN = props.globals.getNode("/environment/wind-from-heading-deg", 1);
|
|
|
|
me.wind_speedN = props.globals.getNode("/environment/wind-speed-kt", 1);
|
|
|
|
|
|
|
|
me.axes = [
|
|
|
|
me.heading_axis = ViewAxis.new("/sim/current-view/goal-heading-offset-deg"),
|
|
|
|
me.pitch_axis = ViewAxis.new("/sim/current-view/goal-pitch-offset-deg"),
|
|
|
|
me.roll_axis = ViewAxis.new("/sim/current-view/goal-roll-offset-deg"),
|
|
|
|
me.x_axis = ViewAxis.new("/sim/current-view/x-offset-m"),
|
|
|
|
me.y_axis = ViewAxis.new("/sim/current-view/y-offset-m"),
|
|
|
|
me.z_axis = ViewAxis.new("/sim/current-view/z-offset-m"),
|
|
|
|
me.fov_axis = ViewAxis.new("/sim/current-view/field-of-view"),
|
2007-02-08 22:16:10 +00:00
|
|
|
];
|
2007-02-07 22:13:51 +00:00
|
|
|
|
2007-02-06 16:25:44 +00:00
|
|
|
# accelerations are converted to G (Earth gravitation is omitted)
|
2007-05-11 18:59:34 +00:00
|
|
|
me.ax = Input.new("/accelerations/pilot/x-accel-fps_sec", 0.03108095, 0, 0.58, 0);
|
|
|
|
me.ay = Input.new("/accelerations/pilot/y-accel-fps_sec", 0.03108095, 0, 0.95);
|
|
|
|
me.az = Input.new("/accelerations/pilot/z-accel-fps_sec", -0.03108095, -1, 0.46);
|
2006-08-17 15:59:44 +00:00
|
|
|
|
|
|
|
# velocities are converted to knots
|
2007-05-11 18:59:34 +00:00
|
|
|
me.vx = Input.new("/velocities/uBody-fps", 0.5924838, 0, 0.45);
|
|
|
|
me.vy = Input.new("/velocities/vBody-fps", 0.5924838, 0);
|
|
|
|
me.vz = Input.new("/velocities/wBody-fps", 0.5924838, 0);
|
2006-08-17 15:59:44 +00:00
|
|
|
|
2006-08-24 20:55:18 +00:00
|
|
|
# turn WoW bool into smooth values ranging from 0 to 1
|
2007-05-11 18:59:34 +00:00
|
|
|
me.wow = Input.new("/gear/gear/wow", 1, 0, 0.74);
|
|
|
|
me.hdg_change = aircraft.lowpass.new(0.95);
|
|
|
|
me.ubody = aircraft.lowpass.new(0.95);
|
|
|
|
me.last_heading = me.headingN.getValue();
|
|
|
|
me.size_factor = getprop("/sim/chase-distance-m") / -25;
|
2006-12-09 22:42:13 +00:00
|
|
|
|
2007-02-08 22:16:10 +00:00
|
|
|
# "lookat" blending
|
2007-05-11 18:59:34 +00:00
|
|
|
me.blendN = props.globals.getNode("/sim/view/dynamic/blend", 1);
|
|
|
|
me.blendN.setDoubleValue(0);
|
|
|
|
me.blendtime = BLEND_TIME;
|
|
|
|
me.frozen = 0;
|
|
|
|
|
|
|
|
if (props.globals.getNode("rotors", 0) != nil)
|
|
|
|
me.calculate = me.default_helicopter;
|
|
|
|
else
|
|
|
|
me.calculate = me.default_plane;
|
|
|
|
me.reset();
|
2006-08-17 15:59:44 +00:00
|
|
|
},
|
|
|
|
reset : func {
|
2007-02-10 23:47:02 +00:00
|
|
|
me.heading_offset = me.heading = me.target_heading = 0;
|
|
|
|
me.pitch_offset = me.pitch = me.target_pitch = 0;
|
|
|
|
me.roll_offset = me.roll = me.target_roll = 0;
|
|
|
|
me.x_offset = me.x = me.target_x = 0;
|
|
|
|
me.y_offset = me.y = me.target_y = 0;
|
|
|
|
me.z_offset = me.z = me.target_z = 0;
|
|
|
|
me.fov_offset = me.fov = me.target_fov = 0;
|
|
|
|
|
2007-02-06 16:25:44 +00:00
|
|
|
interpolate(me.blendN);
|
|
|
|
me.blendN.setDoubleValue(0);
|
2007-05-11 18:59:34 +00:00
|
|
|
foreach (var a; me.axes)
|
2007-02-08 22:16:10 +00:00
|
|
|
a.reset();
|
2007-05-11 18:59:34 +00:00
|
|
|
|
2006-12-03 23:59:50 +00:00
|
|
|
me.add_offset();
|
2006-08-17 15:59:44 +00:00
|
|
|
},
|
2006-08-18 17:00:16 +00:00
|
|
|
add_offset : func {
|
|
|
|
me.heading_axis.add_offset();
|
|
|
|
me.pitch_axis.add_offset();
|
|
|
|
me.roll_axis.add_offset();
|
2007-02-08 22:16:10 +00:00
|
|
|
me.fov_axis.add_offset();
|
2006-08-18 17:00:16 +00:00
|
|
|
},
|
2006-08-17 15:59:44 +00:00
|
|
|
apply : func {
|
2007-05-11 18:59:34 +00:00
|
|
|
if (me.elapsedN.getValue() < me.frozen)
|
2007-02-06 16:25:44 +00:00
|
|
|
return;
|
2007-05-11 18:59:34 +00:00
|
|
|
elsif (me.frozen)
|
2007-02-06 16:25:44 +00:00
|
|
|
me.unfreeze();
|
|
|
|
|
2006-12-09 22:42:13 +00:00
|
|
|
me.pitch = me.pitchN.getValue();
|
|
|
|
me.roll = me.rollN.getValue();
|
|
|
|
|
2006-12-10 21:50:59 +00:00
|
|
|
me.calculate();
|
2007-02-06 16:25:44 +00:00
|
|
|
|
|
|
|
var b = me.blendN.getValue();
|
|
|
|
var B = 1 - b;
|
|
|
|
me.heading = me.target_heading * b + me.heading_offset * B;
|
|
|
|
me.pitch = me.target_pitch * b + me.pitch_offset * B;
|
|
|
|
me.roll = me.target_roll * b + me.roll_offset * B;
|
2007-02-08 22:16:10 +00:00
|
|
|
me.x = me.target_x * b + me.x_offset * B;
|
|
|
|
me.y = me.target_y * b + me.y_offset * B;
|
|
|
|
me.z = me.target_z * b + me.z_offset * B;
|
|
|
|
me.fov = me.target_fov * b + me.fov_offset * B;
|
2007-02-06 16:25:44 +00:00
|
|
|
|
|
|
|
me.heading_axis.apply(me.heading);
|
|
|
|
me.pitch_axis.apply(me.pitch);
|
|
|
|
me.roll_axis.apply(me.roll);
|
2007-02-08 22:16:10 +00:00
|
|
|
me.x_axis.apply(me.x);
|
|
|
|
me.y_axis.apply(me.y);
|
|
|
|
me.z_axis.apply(me.z);
|
|
|
|
me.fov_axis.apply(me.fov);
|
2006-12-09 22:42:13 +00:00
|
|
|
},
|
2007-02-23 22:17:55 +00:00
|
|
|
lookat : func(heading, pitch, roll, x, y, z, time, fov) {
|
2007-02-08 22:16:10 +00:00
|
|
|
me.target_heading = me.heading_axis.static(heading);
|
|
|
|
me.target_pitch = me.pitch_axis.static(pitch);
|
|
|
|
me.target_roll = me.roll_axis.static(roll);
|
|
|
|
me.target_x = me.x_axis.static(x);
|
|
|
|
me.target_y = me.y_axis.static(y);
|
|
|
|
me.target_z = me.z_axis.static(z);
|
|
|
|
me.target_fov = me.fov_axis.static(fov);
|
2007-02-11 16:56:15 +00:00
|
|
|
|
2007-02-23 22:17:55 +00:00
|
|
|
me.blendtime = time;
|
2007-02-11 16:56:15 +00:00
|
|
|
me.blendN.setValue(0);
|
2007-02-23 22:17:55 +00:00
|
|
|
interpolate(me.blendN, 1, me.blendtime);
|
2007-02-08 22:16:10 +00:00
|
|
|
},
|
|
|
|
resume : func {
|
2007-02-23 22:17:55 +00:00
|
|
|
interpolate(me.blendN, 0, me.blendtime);
|
|
|
|
me.blendtime = BLEND_TIME;
|
2007-02-06 16:25:44 +00:00
|
|
|
},
|
|
|
|
freeze : func {
|
|
|
|
if (!me.frozen) {
|
|
|
|
me.target_heading = me.heading;
|
|
|
|
me.target_pitch = me.pitch;
|
|
|
|
me.target_roll = me.roll;
|
2007-02-08 22:16:10 +00:00
|
|
|
me.target_x = me.x;
|
|
|
|
me.target_y = me.y;
|
|
|
|
me.target_z = me.z;
|
|
|
|
me.target_fov = me.fov;
|
2007-02-06 16:25:44 +00:00
|
|
|
me.blendN.setDoubleValue(1);
|
2006-12-09 22:42:13 +00:00
|
|
|
}
|
2007-02-11 16:56:15 +00:00
|
|
|
me.frozen = me.elapsedN.getValue() + FREEZE_DURATION;
|
2007-02-06 16:25:44 +00:00
|
|
|
},
|
|
|
|
unfreeze : func {
|
2007-02-23 22:17:55 +00:00
|
|
|
if (me.frozen) {
|
|
|
|
me.frozen = 0;
|
|
|
|
me.resume();
|
|
|
|
}
|
2006-12-09 22:42:13 +00:00
|
|
|
},
|
|
|
|
};
|
2006-08-19 22:24:24 +00:00
|
|
|
|
2006-12-09 22:42:13 +00:00
|
|
|
|
|
|
|
|
2006-12-10 21:50:59 +00:00
|
|
|
# default calculations for a plane
|
|
|
|
#
|
2007-05-11 18:59:34 +00:00
|
|
|
view_manager.default_plane = func {
|
2006-12-10 21:50:59 +00:00
|
|
|
var wow = me.wow.get();
|
2006-12-09 22:42:13 +00:00
|
|
|
|
2006-12-10 21:50:59 +00:00
|
|
|
# calculate steering factor
|
|
|
|
var hdg = me.headingN.getValue();
|
|
|
|
var hdiff = normdeg(me.last_heading - hdg);
|
|
|
|
me.last_heading = hdg;
|
2008-02-07 15:07:09 +00:00
|
|
|
var steering = 0; # normatan(me.hdg_change.filter(hdiff)) * me.size_factor;
|
2006-12-10 21:50:59 +00:00
|
|
|
|
|
|
|
var az = me.az.get();
|
|
|
|
var vx = me.vx.get();
|
|
|
|
|
|
|
|
# calculate sideslip factor (zeroed when no forward ground speed)
|
|
|
|
var wspd = me.wind_speedN.getValue();
|
|
|
|
var wdir = me.headingN.getValue() - me.wind_dirN.getValue();
|
|
|
|
var u = vx - wspd * cos(wdir);
|
|
|
|
var slip = sin(me.slipN.getValue()) * me.ubody.filter(normatan(u / 10));
|
|
|
|
|
2006-12-11 18:37:10 +00:00
|
|
|
me.heading_offset = # view heading
|
2006-12-09 22:42:13 +00:00
|
|
|
-15 * sin(me.roll) * cos(me.pitch) # due to roll
|
2006-12-10 21:50:59 +00:00
|
|
|
+ 40 * steering * wow # due to ground steering
|
|
|
|
+ 10 * slip * (1 - wow); # due to sideslip (in air)
|
2006-12-09 22:42:13 +00:00
|
|
|
|
2006-12-11 18:37:10 +00:00
|
|
|
me.pitch_offset = # view pitch
|
2006-12-09 22:42:13 +00:00
|
|
|
10 * sin(me.roll) * sin(me.roll) # due to roll
|
2006-12-10 21:50:59 +00:00
|
|
|
+ 30 * (1 / (1 + math.exp(2 - az)) # due to G load
|
|
|
|
- 0.119202922); # [move to origin; 1/(1+exp(2)) ]
|
2006-12-09 22:42:13 +00:00
|
|
|
|
2006-12-10 21:50:59 +00:00
|
|
|
me.roll_offset = 0;
|
2006-12-09 22:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-12-10 21:50:59 +00:00
|
|
|
# default calculations for a helicopter
|
|
|
|
#
|
2007-05-11 18:59:34 +00:00
|
|
|
view_manager.default_helicopter = func {
|
2006-12-10 21:50:59 +00:00
|
|
|
var lowspeed = 1 - normatan(me.speedN.getValue() / 20);
|
2006-12-09 22:42:13 +00:00
|
|
|
|
2006-12-10 21:50:59 +00:00
|
|
|
me.heading_offset = # view heading due to
|
|
|
|
-50 * npow(sin(me.roll) * cos(me.pitch), 2); # roll
|
2006-12-09 22:42:13 +00:00
|
|
|
|
2006-12-10 21:50:59 +00:00
|
|
|
me.pitch_offset = # view pitch due to
|
|
|
|
(me.pitch < 0 ? -35 : -40) * sin(me.pitch) * lowspeed # pitch
|
|
|
|
+ 15 * sin(me.roll) * sin(me.roll); # roll
|
2006-12-09 22:42:13 +00:00
|
|
|
|
2006-12-10 21:50:59 +00:00
|
|
|
me.roll_offset = # view roll due to
|
|
|
|
-15 * sin(me.roll) * cos(me.pitch) * lowspeed; # roll
|
2006-12-09 22:42:13 +00:00
|
|
|
}
|
2006-08-17 15:59:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-17 22:58:06 +00:00
|
|
|
# Update loop for the whole dynamic view manager. It only runs if
|
2007-11-03 14:08:39 +00:00
|
|
|
# /sim/current-view/dynamic-view is true.
|
2006-08-17 15:59:44 +00:00
|
|
|
#
|
2007-02-06 14:33:59 +00:00
|
|
|
var main_loop = func(id) {
|
2007-05-11 18:59:34 +00:00
|
|
|
id == loop_id or return;
|
2007-02-05 22:59:51 +00:00
|
|
|
if (cockpit_view and !panel_visible) {
|
2007-05-11 18:59:34 +00:00
|
|
|
if (mouse_button)
|
2007-02-05 22:59:51 +00:00
|
|
|
freeze();
|
2007-05-11 18:59:34 +00:00
|
|
|
else
|
2007-02-05 20:57:19 +00:00
|
|
|
view_manager.apply();
|
2006-08-17 15:59:44 +00:00
|
|
|
}
|
|
|
|
settimer(func { main_loop(id) }, 0);
|
|
|
|
}
|
|
|
|
|
2007-02-08 22:16:10 +00:00
|
|
|
|
|
|
|
|
2007-02-06 14:33:59 +00:00
|
|
|
var freeze = func {
|
2007-05-11 18:59:34 +00:00
|
|
|
if (mouse_mode == 0)
|
2007-02-06 16:25:44 +00:00
|
|
|
view_manager.freeze();
|
2007-02-05 20:36:29 +00:00
|
|
|
}
|
2006-08-17 15:59:44 +00:00
|
|
|
|
2007-02-06 14:33:59 +00:00
|
|
|
var register = func(f) {
|
2007-01-22 00:03:07 +00:00
|
|
|
view_manager.calculate = f;
|
2006-12-10 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
2007-02-06 14:33:59 +00:00
|
|
|
var reset = func {
|
2006-12-10 21:50:59 +00:00
|
|
|
view_manager.reset();
|
|
|
|
}
|
|
|
|
|
2007-05-11 18:59:34 +00:00
|
|
|
var lookat = func {
|
|
|
|
call(view_manager.lookat, arg, view_manager);
|
2007-02-08 22:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var resume = func {
|
|
|
|
view_manager.resume();
|
2006-12-10 21:50:59 +00:00
|
|
|
}
|
2006-08-17 15:59:44 +00:00
|
|
|
|
2007-02-05 16:14:51 +00:00
|
|
|
|
2006-08-17 15:59:44 +00:00
|
|
|
var original_resetView = nil;
|
|
|
|
var panel_visibilityN = nil;
|
2006-08-22 10:06:46 +00:00
|
|
|
var dynamic_view = nil;
|
2006-08-17 15:59:44 +00:00
|
|
|
|
2006-08-17 18:53:44 +00:00
|
|
|
var cockpit_view = nil;
|
2007-02-06 14:33:59 +00:00
|
|
|
var panel_visible = nil; # whether 2D panel is visible
|
2007-02-05 20:36:29 +00:00
|
|
|
var elapsedN = nil;
|
2007-02-05 22:59:51 +00:00
|
|
|
var mouse_mode = nil;
|
2007-02-05 20:57:19 +00:00
|
|
|
var mouse_button = nil;
|
2007-10-03 19:14:04 +00:00
|
|
|
var enabled = nil;
|
2006-08-17 15:59:44 +00:00
|
|
|
|
2006-08-18 17:00:16 +00:00
|
|
|
var loop_id = 0;
|
|
|
|
|
2006-08-17 15:59:44 +00:00
|
|
|
|
2020-05-30 19:55:28 +00:00
|
|
|
# disable menu entry and return for inappropriate FDMs (see Main/fg_init.cxx)
|
|
|
|
var fdms = {
|
|
|
|
acms:0, ada:0, balloon:0, external:0,
|
|
|
|
jsb:1, larcsim:1, magic:0, network:0,
|
|
|
|
null:0, pipe:0, ufo:0, yasim:1,
|
|
|
|
};
|
|
|
|
var fdm = getprop("/sim/flight-model");
|
|
|
|
if (!contains(fdms, fdm) or !fdms[fdm])
|
|
|
|
return;
|
|
|
|
|
|
|
|
enabled = props.globals.getNode("/sim").getChildren("view");
|
|
|
|
forindex (var i; enabled)
|
|
|
|
enabled[i] = ((var n = enabled[i].getNode("config/dynamic-view")) != nil) and n.getBoolValue();
|
|
|
|
|
|
|
|
# some properties may still be unavailable or nil
|
|
|
|
props.globals.initNode("/accelerations/pilot/x-accel-fps_sec", 0);
|
|
|
|
props.globals.initNode("/accelerations/pilot/y-accel-fps_sec", 0);
|
|
|
|
props.globals.initNode("/accelerations/pilot/z-accel-fps_sec", -32);
|
|
|
|
props.globals.initNode("/orientation/side-slip-deg", 0);
|
|
|
|
props.globals.initNode("/gear/gear/wow", 1, "BOOL");
|
|
|
|
elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
|
|
|
|
|
|
|
# let listeners keep some variables up-to-date, so that they do not have
|
|
|
|
# to be queried in the loop
|
|
|
|
setlistener("/sim/panel/visibility", func(n) { panel_visible = n.getValue() }, 1);
|
|
|
|
setlistener("/sim/current-view/view-number", func(n) { cockpit_view = enabled[n.getValue()] }, 1);
|
|
|
|
setlistener("/devices/status/mice/mouse/button", func(n) { mouse_button = n.getValue() }, 1);
|
|
|
|
setlistener("/devices/status/mice/mouse/x", freeze);
|
|
|
|
setlistener("/devices/status/mice/mouse/y", freeze);
|
|
|
|
setlistener("/devices/status/mice/mouse/mode", func(n) {
|
|
|
|
if (mouse_mode = n.getValue())
|
|
|
|
view_manager.unfreeze();
|
|
|
|
}, 1);
|
|
|
|
|
|
|
|
setlistener("/sim/signals/reinit", func(n) {
|
|
|
|
n.getValue() and return;
|
|
|
|
cockpit_view = enabled[getprop("/sim/current-view/view-number")];
|
|
|
|
view_manager.reset();
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
view_manager.init();
|
|
|
|
|
|
|
|
original_resetView = view.resetView;
|
|
|
|
view.resetView = func {
|
|
|
|
original_resetView();
|
|
|
|
if (cockpit_view and dynamic_view)
|
|
|
|
view_manager.add_offset();
|
|
|
|
}
|
|
|
|
|
|
|
|
settimer(func {
|
|
|
|
setlistener("/sim/current-view/dynamic-view", func(n) {
|
|
|
|
dynamic_view = n.getBoolValue();
|
|
|
|
loop_id += 1;
|
|
|
|
view.resetView();
|
|
|
|
if (dynamic_view)
|
|
|
|
main_loop(loop_id);
|
|
|
|
}, 1);
|
|
|
|
}, 0);
|
2006-08-17 15:59:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|