view_limiter:
- new parameter naming (left/right instead of min/max; signs are ignored) - fix wrap-around skips - use regular constructor so as not to confuse people ;-)
This commit is contained in:
parent
c4ebd9a0f2
commit
7fbeb50695
2 changed files with 43 additions and 29 deletions
|
@ -323,42 +323,51 @@ var fly_by_view_handler = {
|
||||||
|
|
||||||
|
|
||||||
var pilot_view_limiter = {
|
var pilot_view_limiter = {
|
||||||
|
new : func {
|
||||||
|
return { parents: [pilot_view_limiter] };
|
||||||
|
},
|
||||||
init : func {
|
init : func {
|
||||||
me.hdgN = props.globals.getNode("/sim/current-view/heading-offset-deg");
|
me.hdgN = props.globals.getNode("/sim/current-view/heading-offset-deg");
|
||||||
me.xoffsetN = props.globals.getNode("/sim/current-view/x-offset-m");
|
me.xoffsetN = props.globals.getNode("/sim/current-view/x-offset-m");
|
||||||
me.xoffset_lowpass = aircraft.lowpass.new(0.1);
|
me.xoffset_lowpass = aircraft.lowpass.new(0.05);
|
||||||
me.old_offset = 0;
|
me.old_offset = 0;
|
||||||
},
|
},
|
||||||
start : func {
|
start : func {
|
||||||
var limits = current.getNode("config/limits", 1);
|
var limits = current.getNode("config/limits", 1);
|
||||||
me.heading_min = limits.getNode("heading-min-deg", 1).getValue();
|
me.left = {
|
||||||
me.heading_max = limits.getNode("heading-max-deg", 1).getValue();
|
heading_max : abs(limits.getNode("left/heading-max-deg", 1).getValue() or 1000),
|
||||||
me.max_xoffset = limits.getNode("x-offset-max-m", 1).getValue() or 0;
|
xoffset_max : abs(limits.getNode("left/x-offset-max-m", 1).getValue() or 0),
|
||||||
me.threshold_min = limits.getNode("x-offset-heading-min-deg", 1).getValue() or 0;
|
threshold : -abs(limits.getNode("left/x-offset-threshold-deg", 1).getValue() or 0),
|
||||||
me.threshold_max = limits.getNode("x-offset-heading-max-deg", 1).getValue() or 0;
|
};
|
||||||
|
me.right = {
|
||||||
if (me.heading_max == nil)
|
heading_max : -abs(limits.getNode("right/heading-max-deg", 1).getValue() or 1000),
|
||||||
me.heading_max = 1000;
|
xoffset_max : -abs(limits.getNode("right/x-offset-max-m", 1).getValue() or 0),
|
||||||
if (me.heading_min == nil)
|
threshold : abs(limits.getNode("right/x-offset-threshold-deg", 1).getValue() or 0),
|
||||||
me.heading_min = -1000;
|
};
|
||||||
|
me.left.range = me.left.threshold - me.left.heading_max;
|
||||||
|
me.right.range = me.right.threshold - me.right.heading_max;
|
||||||
|
me.last_hdg = normdeg(me.hdgN.getValue());
|
||||||
|
me.enable_xoffset = me.right.xoffset_max > 0.001 or me.left.xoffset_max > 0.001;
|
||||||
},
|
},
|
||||||
update : func {
|
update : func {
|
||||||
var hdg = normdeg(me.hdgN.getValue());
|
var hdg = normdeg(me.hdgN.getValue());
|
||||||
|
if (abs(me.last_hdg - hdg) > 180) # avoid wrap-around skips
|
||||||
if (hdg > me.heading_max)
|
me.hdgN.setDoubleValue(hdg = me.last_hdg);
|
||||||
me.hdgN.setDoubleValue(hdg = me.heading_max);
|
elsif (hdg > me.left.heading_max)
|
||||||
elsif (hdg < me.heading_min)
|
me.hdgN.setDoubleValue(hdg = me.left.heading_max);
|
||||||
me.hdgN.setDoubleValue(hdg = me.heading_min);
|
elsif (hdg < me.right.heading_max)
|
||||||
|
me.hdgN.setDoubleValue(hdg = me.right.heading_max);
|
||||||
|
me.last_hdg = hdg;
|
||||||
|
|
||||||
# translate view on X axis to look far right or far left
|
# translate view on X axis to look far right or far left
|
||||||
if (me.max_xoffset > 0.001) {
|
if (me.enable_xoffset) {
|
||||||
var norm = 0;
|
var offset = 0;
|
||||||
if (hdg <= me.threshold_min)
|
if (hdg >= me.left.threshold)
|
||||||
norm = (hdg - me.threshold_min) / (me.heading_min - me.threshold_min);
|
offset = me.left.xoffset_max * (hdg - me.left.threshold) / me.left.range;
|
||||||
elsif (hdg >= me.threshold_max)
|
elsif (hdg <= me.right.threshold)
|
||||||
norm = -(hdg - me.threshold_max) / (me.heading_max - me.threshold_max);
|
offset = me.right.xoffset_max * (hdg - me.right.threshold) / me.right.range;
|
||||||
|
|
||||||
var new_offset = me.xoffset_lowpass.filter(norm * me.max_xoffset);
|
var new_offset = me.xoffset_lowpass.filter(offset);
|
||||||
me.xoffsetN.setDoubleValue(me.xoffsetN.getValue() - me.old_offset + new_offset);
|
me.xoffsetN.setDoubleValue(me.xoffsetN.getValue() - me.old_offset + new_offset);
|
||||||
me.old_offset = new_offset;
|
me.old_offset = new_offset;
|
||||||
}
|
}
|
||||||
|
@ -560,7 +569,7 @@ _setlistener("/sim/signals/fdm-initialized", func {
|
||||||
var limits = views[i].getNode("config/limits/enabled");
|
var limits = views[i].getNode("config/limits/enabled");
|
||||||
if (limits != nil) {
|
if (limits != nil) {
|
||||||
func (i) {
|
func (i) {
|
||||||
var limiter = { parents: [ pilot_view_limiter ] };
|
var limiter = pilot_view_limiter.new();
|
||||||
setlistener(limits, func(n) {
|
setlistener(limits, func(n) {
|
||||||
manager.register(i, n.getBoolValue() ? limiter : nil);
|
manager.register(i, n.getBoolValue() ? limiter : nil);
|
||||||
manager.set_view();
|
manager.set_view();
|
||||||
|
|
|
@ -284,11 +284,16 @@ Started September 2000 by David Megginson, david@megginson.com
|
||||||
<dynamic-view type="bool">true</dynamic-view>
|
<dynamic-view type="bool">true</dynamic-view>
|
||||||
<limits>
|
<limits>
|
||||||
<enabled type="bool">false</enabled>
|
<enabled type="bool">false</enabled>
|
||||||
<heading-min-deg type="double">-140</heading-min-deg>
|
<left>
|
||||||
<heading-max-deg type="double">140</heading-max-deg>
|
<heading-max-deg type="double">140</heading-max-deg>
|
||||||
<x-offset-max-m type="double">0.15</x-offset-max-m>
|
<x-offset-max-m type="double">0.15</x-offset-max-m>
|
||||||
<x-offset-heading-min-deg type="double">-65</x-offset-heading-min-deg>
|
<x-offset-threshold-deg type="double">65</x-offset-threshold-deg>
|
||||||
<x-offset-heading-max-deg type="double">65</x-offset-heading-max-deg>
|
</left>
|
||||||
|
<right>
|
||||||
|
<heading-max-deg type="double">140</heading-max-deg>
|
||||||
|
<x-offset-max-m type="double">0.15</x-offset-max-m>
|
||||||
|
<x-offset-threshold-deg type="double">65</x-offset-threshold-deg>
|
||||||
|
</right>
|
||||||
</limits>
|
</limits>
|
||||||
</config>
|
</config>
|
||||||
</view>
|
</view>
|
||||||
|
|
Loading…
Reference in a new issue