Hi all

The default Field of View has been choosen a long time ago and discussed several times on the devel list.

AFAIK this 55 deg FOV had been settled for two main reasons:

1) There is a need to have a standard FOV across different aircrafts so the user keeps its space and distance perception when being in different aircrafts cockpits. 2) We "determined [55 degree] as an acceptable compromise between seeing enough of the instrument panel and the outside world" quoting Curt's email in september 2008.

Today we all are throwing our old 4:3 CRTs through the windows and most of us already enjoy the 16:9 or 16:10 ratio. This changes the rules.

The idea is NOT to change anything to this standard. Instead, I've just added a tiny option in the Display Options dialog:

[ ] Compensate Field of View for wider screens (Disabled by default)



When you check this option, a new function in /Nasal/view.nas checks FG window size and changes the default FOV for each view so the vertical FOV keeps in line with what ought to be a 55 deg on a 4:3 screen. Actually it computes a 4:3 central part of the screen and change the overall FOV so the FOV on this central part keeps being 55 deg.

The result is that when you resize and change the height/width of your window you still see the same instruments than in a standard 4:3 screen with 55 deg FOV. This should work out of the box for any aircraft. Unchecking the option resets the FOV for any view to the initial settings.

Patch attached, Tests and comments welcome.

Alexis

diff --git a/Aircraft/E-2C/E-2C-set.xml b/Aircraft/E-2C/E-2C-set.xml
index 9d6730a..3d16688 100644
--- a/Aircraft/E-2C/E-2C-set.xml
+++ b/Aircraft/E-2C/E-2C-set.xml
@@ -63,8 +63,8 @@ Grumman E-2C simulation config.
 			<config>
 				<x-offset-m>-0.45</x-offset-m>
 				<y-offset-m>-0.072</y-offset-m>
-				<z-offset-m>-6.9</z-offset-m>
-				<pitch-offset-deg>-16.5</pitch-offset-deg>
+				<z-offset-m>-6.85</z-offset-m>
+				<pitch-offset-deg>-17</pitch-offset-deg>
 				<default-field-of-view-deg>55</default-field-of-view-deg>
 				<!--<limits>
 					<enabled type="bool">true</enabled>
diff --git a/Nasal/view.nas b/Nasal/view.nas
index 6af58fa..09244dd 100644
--- a/Nasal/view.nas
+++ b/Nasal/view.nas
@@ -6,7 +6,7 @@
 var index = nil;    # current view index
 var views = nil;    # list of all view branches (/sim/view[n]) as props.Node
 var current = nil;  # current view branch (e.g. /sim/view[1]) as props.Node
-
+var fovProp = nil;
 
 var hasmember = func(class, member) {
 	if (contains(class, member))
@@ -235,6 +235,7 @@ var manager = {
 			me.current.handler.start();
 		if (hasmember(me.current.handler, "update"))
 			me._loop_(me.loopid += 1);
+		resetFOV();
 	},
 	reset : func {
 		if (hasmember(me.current.handler, "reset"))
@@ -638,7 +639,61 @@ var point = {
 
 
 
-var fovProp = nil;
+##
+# view.ScreenWidthCompens: optional FOV compensation for wider screens.
+# It keeps an equivalent of 55° FOV on a 4:3 zone centered on the screen
+# whichever is the screen width/height ratio. Works only if width >= height.
+#
+# status: 0=Init, 1=toggle option, 2=waiting for the window size to change. 
+
+var defaultFov = nil;
+var oldW = 0;
+var oldH = 0;
+var fovStore = {};
+
+var screenWidthCompens = func(status) {
+	var opt = getprop("/sim/current-view/field-of-view-compensation");
+	if (status == 0) {
+		defaultFov = getprop("/sim/current-view/config/default-field-of-view-deg");
+		forindex (var i; views) {
+			var defaultFovNode = views[i].getNode("config/default-field-of-view-deg", 1);
+			fovStore[i] = defaultFovNode.getValue();
+		}
+	} elsif (status == 1) {
+		opt = ! opt;
+		setprop("/sim/current-view/field-of-view-compensation", opt);
+		if (! opt) {
+			forindex (var i; views) {
+				var defaultFovNode = views[i].getNode("config/default-field-of-view-deg", 1);
+				defaultFovNode.setValue(fovStore[i]);
+			}
+			var vn = getprop("/sim/current-view/view-number");
+			setprop("/sim/current-view/field-of-view", fovStore[vn]);
+		}
+	} elsif (status == 2 and ! opt) {
+		return;
+	}
+	var w = getprop("/sim/rendering/camera-group/camera/viewport/width");
+	var h = getprop("/sim/rendering/camera-group/camera/viewport/height");
+	if (! opt) {
+		setprop("/sim/current-view/config/default-field-of-view-deg", defaultFov);
+		return;
+	}
+	if ( w != oldW or h != oldH or status == 1) {
+		oldW = w;
+		oldH = h;
+		d = 1.28066 * h; # 1.28066 = 4/3 (width/height ratio) / 2 / tan(55°)
+		newFov = 2 * math.atan2( w / h * h / 2, d) * R2D;
+		setprop("/sim/current-view/config/default-field-of-view-deg", newFov);
+		forindex (var i; views) {
+			var defaultFovNode = views[i].getNode("config/default-field-of-view-deg", 1);
+			defaultFovNode.setValue(newFov);
+		}
+		fovProp.setValue(newFov);
+	}
+	settimer(func { screenWidthCompens(2); }, 1);
+}
+
 
 
 _setlistener("/sim/signals/nasal-dir-initialized", func {
@@ -654,6 +709,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
 	manager.init();
 	manager.register("Fly-By View", fly_by_view_handler);
 	manager.register("Model View", model_view_handler);
+	screenWidthCompens(0);
 });
 
 
diff --git a/gui/dialogs/view.xml b/gui/dialogs/view.xml
index 1bd235b..7ef301c 100644
--- a/gui/dialogs/view.xml
+++ b/gui/dialogs/view.xml
@@ -88,6 +88,25 @@
 	</group>
 
 	<hrule/>
+	<group>
+		<layout>hbox</layout>
+		<checkbox>
+			<property>sim/current-view/field-of-view-compensation</property>
+			<live>false</live>
+					<binding>
+						<command>nasal</command>
+						<script>view.screenWidthCompens(1)</script>
+					</binding>
+		</checkbox>
+		<text>
+			<label>Compensate Field of View for wider screens</label>
+		</text>
+	</group>
+
+
+
+
+	<hrule/>
 
 	<button>
 		<legend>Close</legend>
diff --git a/preferences.xml b/preferences.xml
index 80b324d..ef7d593 100644
--- a/preferences.xml
+++ b/preferences.xml
@@ -346,6 +346,7 @@ Started September 2000 by David Megginson, da...@megginson.com
 		<speed-up type="double">1.0</speed-up>
 		<current-view>
 			<field-of-view type="double">55.0</field-of-view>
+			<field-of-view-compensation type="bool" userarchive="y">false</field-of-view-compensation>
 			<aspect-ratio-multiplier type="double">1.0</aspect-ratio-multiplier>
 			<dynamic-view type="bool" userarchive="y">false</dynamic-view>
 		</current-view>
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to