ExtraViewWindows

From FlightGear wiki
Jump to navigation Jump to search
Multiple top level windows in CompositeViewer

Overview

On next, there's support for Extra View windows. These are top-level windows that show views independently from the main window's view. These use a new view system called Sview (short for "Step View") along with CompositeViewer Support.

The simplest way to create an extra view window is from menu View/Add Clone View which, as the name implies, will create a new window that is a clone of the current view. Changing the main window's view will leave the new window's view unchanged.

Viewing pairs of aircraft

There is a slightly crude mechanism for creating views that work on pairs of aircraft: one uses menu View/Push Pair View to push the current main-window view onto a stack of views.

Once this has been done at two or more times, menu View/Add Pair View will open a new top-level window showing a view derived from the last two remembered viewpoints. So for example it can show the view of your aircraft from a particular multiplayer aircraft, or a view of the nearest tower from your aircraft.

Menu View/Add Pair Foreground View is similar but it keeps the first viewpoint at a fixed distance in the foreground and the second viewpoint in the background. This works well when flying in formation.

Limitations

As of 2021-10-25:

  • Extra View windows can be panned like the main window by dragging with the left mouse button.
  • Other UI interations is not supported:
    • Mouse clicks are ignord.
    • Key presses are ignored.

Specifying views in more detail

One can open new view windows explicitly with the view-new command, which accepts an Sview specification in the form of an accompanying XML tree.

For details of the XML format, see the comments in: flightgear/src/Viewer/sview.hxx

From Nasal, one can load the view specification from a specific file:

var spec = io.read_properties("sview.xml");
fgcommand("view-new", spec);

Alternatively a view can be specified in the main property tree, for example:

    <sim>
        ...
        <sview-tower>
            <window-width>300</window-width>
            <window-height>200</window-height>
            <window-x>200</window-x>
            <window-y>200</window-y>
            <step>  <!-- Move to aircraft. -->
                <type>aircraft</type>
                <callsign></callsign>
            </step>

            <step>  <!-- Move to centre of aircraft. -->
                <type>move</type>
                <right>0</right>
                <up>0.5</up>
                <forward>-3.85</forward>
            </step>

            <step>  <!-- Copy current position to target. -->
                <type>copy-to-target</type>
            </step>

            <step>  <!-- Move to nearest tower. -->
                <type>nearest-tower</type>
            </step>

            <step>  <!-- Look at target position we found earlier. -->
                <type>rotate-to-target</type>
            </step>
        </sview-tower>
            ...
    </sim>

And can be opened from Nasal:

fgcommand("view-new", props.globals.getNode("sim/sview-tower"));

Or from a menu item:

    <menu>
        ...
        <item>
            <name>Open extra tower view</name>
            <binding>
                <command>nasal</command>
                <script>
                    printf("running view-new");
                    fgcommand("view-new", props.globals.getNode("sim/sview-tower"));
                </script>
            </binding>
        </item>
        ...
    </menu>

How Sview works

Sview works by constructing camera's eye and target positions/directions using an arbitrary number of individual configurable steps. There are various step types defined which allow for various transformations such as moving to a particular user/multiplayer aircraft or nearest tower, move relative to the current position+direction, modify heading, pitch and roll according to particular property values, rotate view direction to point at a particular target etc.

These basic steps are enough to allow Sview to copy what conventional views do, allowing the View/Add clone view menu item to work.

It's also easy enough to add (C++) code to implement new steps to achieve more sophisticated behaviour. An example of this is the view step called double that keeps two aircraft visible at all times, with one in the foreground; this is used for View/Add Pair Foreground View.

For more details, see the C++ Sview code itself: flightgear/src/Viewer/sview.cxx

Example

This example will work with F-16. It will place a small window in lower-right corner of a 1920x1080 FG window.

<?xml version="1.0" encoding="UTF-8"?>

<PropertyList>
		<window-width>400</window-width>
		<window-height>400</window-height>
		<window-x>1520</window-x>
		<window-y>0</window-y>
		<type>sview</type>
		<name>step-dancer</name>

		<step n="0">  <!-- Move to own aircraft. -->
	        <type>aircraft</type>
	        <callsign></callsign>
	    </step>
  		
  		<!-- Move to place inside of aircraft. -->
	    <step n="1">
	        <type>move</type>
	        <right>0</right>
	        <up>-0.83</up>
	        <forward>4.40</forward>
	    </step>
</PropertyList>

Related content

Wiki articles