Board index FlightGear Development

Improved view angle for keyboard pilots

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Improved view angle for keyboard pilots

Postby PH-JAKE » Thu May 28, 2020 9:11 pm

As an, dare I say, avid keyboard pilot (I'm too cheap to get a yoke I guess) I've found my way around the numeric keypad controls nicely. Most planes handle well from the keyboard, so I'm fine with that. Please bear with me on this one and hold back on your suggestions for mouse, yoke, VR goggles and what not. I know these exist, this is not about that. This is about improving keyboard flying even more.

TLDR: Get a better view out of the cockpit while flying keyboard, especially with fighters.

Background
So when I'm flying, especially bubble canopy planes, e.g., fighters, I tend to struggle with the views they present me when looking around from the keyboard (Shift-1 through Shift-9 with the exception of Shift-5). The view is angled down towards the instruments in the cockpit, but that's too low for looking outside. Especially in a bubble canopy plane you want to use the unobstructed view towards the horizon. But also in tranditional cockpits, when looking outside you want to look up from your instruments and get a glance of the runway when turning final, for instance.

What this does
For this I've created an XML file to amend the operation of the keypad keys, so they update not only the view heading but also the view pitch. The update of the pitch depends on the mode the improvement is in. In full mode, suitable for bubble canopy airplanes, the pitch is updated so to give the best view towards the horizon, while in simple mode the pitch is lifted half way up from the instruments.

How to install
In the launcher go to the settings panel and scroll down to 'Additional Settings'. There you can define parameters for Flightgear to use. Add this line to it:

--config=<path>improved_view.xml

where <path> is the path on your file system where you stored the XML file.

How to activate
When loaded this XML file will try to guess the kind of model you're flying. In case of the precense of a 'figther' tag, the full view angle improvement is enabled. Otherwise the simple view angle improvement, suitable for 'normal' cockpits, is enabled. If you want to switch modes you can do so from the View menu.

I don't see a difference
It may be subtle to spot when flying level, but once the bank angle increases, the difference becomes noticable. Go make a 45 degrees level turn in a fighter and look left and right. The result in both modes differ considerably. For a 'normal' cockpit the change will indeed be limited, but that is more due to the model than the pitch angle.

Exactly what is different
A picture may be helpful here. Although busy, the lines help to point things out.

Image

Black: Horizon
Red: View X-axis
Blue: View Y-axis
Green: View Z-axis

The white lines illustrate the views forward towards the cockpit instruments, and the view turned outside. Before the downward angle of the view was retained when looking around, so in this case looking left points to the ground too much and looking right looks into the sky too much.

The blue arcs show where the 'ideal' view should be, and the yellow lines form the center of that. This is what the full mode does, determine that angle and adjust the view pitch according to it.

Even though this is a gross simplification of things, it aims to get the point across.

Can you show the difference
Here's a demo flight with an F-16. Be sure to enable the subtitles for the commentary.



Was this tested
I've tried various airplanes with and without bubble canopies to see how this change affected the
views of these models: F-16, F-15, C172, A-10, B777, B757 and Seneca II.

I don't like it
You're free to not use it, that is your choice. Just remove the config line added during install and everything is back to normal.

I like it
You're free to use it as you please. I've attached to GPLv2 license to it, as the rest of the project, so you know what to do.
PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

The code

Postby PH-JAKE » Thu May 28, 2020 9:12 pm

Code: Select all
<?xml version="1.0"?>
<!--
 Improved view

 Copyright 2020  PH-JAKE
 SPDX-License-Identifier: GPL-2.0-or-later

 This configuration file aims to improve the cockpit viewing pitch angles when flying with
 keyboard controls, thereby removing the need to reach for the mouse to adjust view pitch
 angles especially in high bank turns. This becomes apparent when flying bubble canopy aircraft,
 typically fighter aircraft. But also the normal cockpit view pitch is improved by not looking
 down at instrument level when looking in other directions.

 To install this configuration add a 'config' option to the fgfs command line, e.g., in the
 launcher Settings page under Additional settings.

 The configuration operates in two modes: simple and full.
 Simple mode is suitable for normal cockpits where the roof limits view upwards.
 Full mode is suitable for bubble canopy aircraft with an unobstructed view around.
 Aircraft tagged as 'fighter' enable full mode automatically, otherwise simple mode is engaged.
 The View menu provides an option to toggle the mode from simple to full and back.

 Background information
 The configuration works by adding a binding to the existing keyboard bindings for cockpit view
 control, i.e., Shift-1 through Shift-9, except Shift-5 on the numeric keypad. In full mode they
 use the current bank angle and view direction to calculate a compromise between looking at the
 horizon and looking down, in order to create an optimum view. In simple mode in all but forward
 view the pitch of the forward view is simply halved, so to get a slightly better look outside.

 During loading the aircraft model is interrogated to see if the 'fighther' tag is present.
 If so a bubble canopy is assumed and full mode engaged. Otherwise the simple mode is active.

 The keyboard bindings are numbered to stay out of the way of other additional bindings, but
 it's not impossible for them to overlap. This may interfere with the operation. The same is
 true for the View menu item.

 First posted on https://forum.flightgear.org/viewtopic.php?f=18&t=37513

 Release 1.0    2020-05-18 - Initial release

-->
<PropertyList>

<nasal>
  <load>
    <script><![CDATA[
      foreach (var tag; props.globals.getNode("/sim/tags", 1).getChildren("tag")) {
        if (tag.getValue() == "fighter") {
          setprop("/sim/current-view/improved-view-mode", 1);
        }
      }
    ]]></script>
  </load>
</nasal>

<sim>
  <current-view>
    <improved-view-mode type="bool">false</improved-view-mode>
  </current-view>

  <menubar>
    <default>
      <menu n="1">
        <enabled type="bool">true</enabled>
        <item n="19">
          <label>Toggle Improved View Mode</label>
          <binding>
            <command>nasal</command>
            <script><![CDATA[
              var mode = getprop("/sim/current-view/improved-view-mode");
              mode = !mode;
              setprop("/sim/current-view/improved-view-mode", mode);
              gui.popupTip(mode?"Improved view mode full":"Improved view mode simple", 3);
              var hdg = getprop("/sim/current-view/goal-heading-offset-deg");
              var front = getprop("/sim/view/config/front-direction-deg");
              # hdg becomes 360 when resetting view with Shift-Q while looking right...
              if ((hdg != front) and (hdg != 360)) {
                __kbd.setViewPitch();
              }             
            ]]></script>
          </binding>
        </item>
      </menu>
    </default>
  </menubar>
</sim>

<input>
  <keyboard>

    <nasal>
      <script><![CDATA[
        var setViewPitch = func() {
          var mode = getprop("/sim/current-view/improved-view-mode");
          var pitch = 0;
          if (mode) {
            var hdg = getprop("/sim/current-view/goal-heading-offset-deg");
            var roll = getprop("/orientation/roll-deg");
            pitch = -(roll*math.sin(hdg*D2R))/2;
          } else {
            pitch = getprop("/sim/current-view/config/pitch-offset-deg")/2;
          }
          setprop("/sim/current-view/goal-pitch-offset-deg", pitch);
        }
      ]]></script>
    </nasal>

    <!-- The number keys -->

    <key n="49">
      <!-- 1 -->
      <mod-shift>
        <!-- Look back left -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="50">
      <!-- 2 -->
      <mod-shift>
        <!-- Look back-->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="51">
      <!-- 3 -->
      <mod-shift>
        <!-- Look back right -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="52">
      <!-- 4 -->
      <mod-shift>
        <!-- Look left -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <!-- Key 5 is not related to a view -->

    <key n="54">
      <!-- 6 -->
      <mod-shift>
        <!-- Look right -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="55">
      <!-- 7 -->
      <mod-shift>
        <!-- Look front-left -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="56">
      <!-- 8 -->
      <mod-shift>
        <!-- Look front -->
        <binding n="9">
          <command>property-assign</command>
          <property>/sim/current-view/goal-pitch-offset-deg</property>
          <property>/sim/current-view/config/pitch-offset-deg</property>
        </binding>
      </mod-shift>
    </key>

    <key n="57">
      <!-- 9 -->
      <mod-shift>
        <!-- Look front right -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <!-- The numeric keypad keys -->

    <key n="356">
      <!-- Left -->
      <mod-shift>
        <!-- Look left -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="357">
      <!-- Up -->
      <mod-shift>
        <!-- Look front -->
        <binding n="9">
          <command>property-assign</command>
          <property>/sim/current-view/goal-pitch-offset-deg</property>
          <property>/sim/current-view/config/pitch-offset-deg</property>
        </binding>
      </mod-shift>
    </key>

    <key n="358">
      <!-- Right -->
      <mod-shift>
        <!-- Look right -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="359">
      <!-- Down -->
      <mod-shift>
        <!-- Look back -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="360">
      <!-- PageUp -->
      <mod-shift>
        <!-- Look front right -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="361">
      <!-- PageDn -->
      <mod-shift>
        <!-- Look back right -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

    <key n="362">
      <!-- Home -->
      <mod-shift>
        <!-- Look front left -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>
   
    <key n="363">
      <!-- End -->
      <mod-shift>
        <!-- Look back left -->
        <binding n="9">
          <command>nasal</command>
          <script>
            setViewPitch();
          </script>
        </binding>
      </mod-shift>
    </key>

  </keyboard>
</input>

</PropertyList>
PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

Re: Improved view angle for keyboard pilots

Postby danielHL » Fri May 29, 2020 10:18 am

Wow, I love it! One issue though: when returning from a side/back view to front, the script will adjust that too to the current pitch. During climb this will make fg show the cockpit floor and not the panel. Can this view be returned to the state it was before looking away? I usually adjust my view position a bit to have good view outside and the panel. With the normal look-around keys I return to that configuration.

In fact, I find this so useful I would vote to integrate this into fgdata and make it available by default.

Cheers,
Daniel
danielHL / D-FMPW
danielHL
 
Posts: 280
Joined: Fri May 02, 2014 7:23 pm
Callsign: D-FMPW
Version: next
OS: Linux

Re: Improved view angle for keyboard pilots

Postby wkitty42 » Fri May 29, 2020 4:20 pm

PH-JAKE wrote in Thu May 28, 2020 9:11 pm:TLDR: Get a better view out of the cockpit while flying keyboard, especially with fighters.

very noice! it would be nice for this to be included in FG so that all craft could use it... the current demo is certainly great!

perhaps you might also post this on the dev's mailing list? ;)
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9123
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Improved view angle for keyboard pilots

Postby PH-JAKE » Fri May 29, 2020 7:33 pm

danielHL wrote in Fri May 29, 2020 10:18 am:Wow, I love it! One issue though: when returning from a side/back view to front, the script will adjust that too to the current pitch. During climb this will make fg show the cockpit floor and not the panel. Can this view be returned to the state it was before looking away? I usually adjust my view position a bit to have good view outside and the panel. With the normal look-around keys I return to that configuration.


HI,

Glad you like it.

I've tried to replicate your observations, but so far haven't been able to. All the time the view stays level relative to the pitch of the plane. Maybe I'll do another demo flight for this.
Can you tell me what plane you experience this with? and what the (relevant) view options are, if that makes sense?

Thanks.
PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

Re: Improved view angle for keyboard pilots

Postby PH-JAKE » Sat May 30, 2020 9:20 am

wkitty42 wrote in Fri May 29, 2020 4:20 pm:
PH-JAKE wrote in Thu May 28, 2020 9:11 pm:TLDR: Get a better view out of the cockpit while flying keyboard, especially with fighters.

very noice! it would be nice for this to be included in FG so that all craft could use it... the current demo is certainly great!

perhaps you might also post this on the dev's mailing list? ;)


Hi,
Also glad you like it.

I hope to get a proper shakedown of this code first, to get rid of any bugs in there.
So, to any keyboard pilots out there please give it a try and post feedback.
Once enough support is gathered who knows if and how it's picked up.

Thanks
PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

Improved View second demo flight

Postby PH-JAKE » Sat May 30, 2020 12:50 pm

The first demo flight showed the Improved View performance on a level flight with large roll angle. Although this demonstrates the change with respect to the current handling of the keyboard control of view direction when confronted with aircraft roll, it does leave out the aircraft pitch angle. This video was made to add that aspect to the evaluation of performance of the Improved View configuration.
Be sure to enable the subtitles for the commentary.

PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

Re: Improved view angle for keyboard pilots

Postby wkitty42 » Sat May 30, 2020 3:22 pm

PH-JAKE wrote in Sat May 30, 2020 9:20 am:I hope to get a proper shakedown of this code first, to get rid of any bugs in there.
So, to any keyboard pilots out there please give it a try and post feedback.

i plan to try it but i'll need to try to modify it first to support the UFO :mrgreen:
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9123
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Improved view angle for keyboard pilots

Postby PH-JAKE » Sat May 30, 2020 3:45 pm

wkitty42 wrote in Sat May 30, 2020 3:22 pm:
PH-JAKE wrote in Sat May 30, 2020 9:20 am:I hope to get a proper shakedown of this code first, to get rid of any bugs in there.
So, to any keyboard pilots out there please give it a try and post feedback.

i plan to try it but i'll need to try to modify it first to support the UFO :mrgreen:

I doubt it is compatible with alien technology, but who knows? :?
PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

Re: Improved view angle for keyboard pilots

Postby stuart » Sat May 30, 2020 7:07 pm

I think this is just great.

I think it's equally applicable to those using a joystick, and indeed non-bubble aircraft as well. So rather than an optional add-on I think it should just be part of fgdata and both the standard keyboard and view.panViewDIr() function.

If you're on the -devel list, I'd encourage you to raise it as an idea. I'd be happy to support it and review any code changes.

Best regards,

-Stuart
G-MWLX
User avatar
stuart
Moderator
 
Posts: 1629
Joined: Wed Nov 29, 2006 10:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: Improved view angle for keyboard pilots

Postby PH-JAKE » Sun May 31, 2020 1:17 pm

stuart wrote in Sat May 30, 2020 7:07 pm:I think this is just great.

I think it's equally applicable to those using a joystick, and indeed non-bubble aircraft as well. So rather than an optional add-on I think it should just be part of fgdata and both the standard keyboard and view.panViewDIr() function.

If you're on the -devel list, I'd encourage you to raise it as an idea. I'd be happy to support it and review any code changes.


Glad you like it. Now you know where all these questions were for. :wink: And good to hear it's even useful outside the realm of keyboard pilots.

As for elevating this into a standard feature I'm not sure I'm the right person to do that. This proof-of-concept hooks into various parts of the system of which I'm not even sure it is appropriate and/or generic enough to work in all cases, let alone not being familiar with the code base as such. I'm not on a developer list, so I welcome anyone who would rework this POC into generic real world code.

Thanks
PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

Re: Improved view angle for keyboard pilots

Postby PH-JAKE » Tue Jun 02, 2020 10:00 am

This improved View configuration is especially useful for bubble canopy type of aircraft. Currently this is automatically assumed to be the case for aircraft tagged as 'fighter'.
But come to think of it, Improved View full mode might as well be set automatically for 'glider' and 'aerobatic' tagged aircraft.
PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

Re: Improved view angle for keyboard pilots

Postby wkitty42 » Tue Jun 02, 2020 3:51 pm

and the UFO ;)

but also it would likely be good for GA craft with low wings... maybe not so much for those with high wings like the c172p but it could be worth looking into...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9123
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Improved view angle for keyboard pilots

Postby PH-JAKE » Tue Jun 02, 2020 6:44 pm

wkitty42 wrote in Tue Jun 02, 2020 3:51 pm:and the UFO ;)

but also it would likely be good for GA craft with low wings... maybe not so much for those with high wings like the c172p but it could be worth looking into...


The UFO? Yes, obviously. But it already had it, we just don't know how to use the technology :shock:

As for low wing GA aircraft, it's not so much the wing mounting, but the kind of cockpit. Only a bubble canopy allows for unrestricted view in all upward (relative to the aircraft's plane) directions. For normal cockpits there's the roof, which becomes an obstacle rather quickly I found out testing the Seneca. That's were the simple mode of the Improved View comes in. You do look up from the instruments, but not so far that you can't look outside (especially in larger banking turns).

But then again the Improved View mode is switchable from the View menu, so if you want, or the aircraft lacks the proper tag, you can always switch over to the better mode.

Keep tagging those aircraft!
PH-JAKE
 
Posts: 156
Joined: Wed Mar 12, 2014 12:53 am
Callsign: PH-JAKE
Version: 2020.3.18
OS: Debian trixie

Re: Improved view angle for keyboard pilots

Postby Johan G » Fri Jul 03, 2020 8:10 am

I am a bit late, but this looks like a great addition, and, like Stuart said, not just for keyboard pilots. :D
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6625
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Next

Return to Development

Who is online

Users browsing this forum: No registered users and 6 guests