FlightGear next
sview.hxx
Go to the documentation of this file.
1#pragma once
2
3/*
4Support for extra view windows using 'Step' views system.
5*/
6
7#include <simgear/scene/util/SGReaderWriterOptions.hxx>
8#include <simgear/props/props.hxx>
9
10#include <osgViewer/View>
11
12
13/* Should be called before the first call to SviewCreate() so that
14SviewCreate() can create new simgear::compositor::Compositor instances with the
15same parameters as were used for the main window.
16
17options
18compositor_path
19 Suitable for passing to simgear::compositor::Compositor().
20*/
22 osg::ref_ptr<simgear::SGReaderWriterOptions> options,
23 const std::string& compositor_path
24 );
25
26/* Pushes current main window view to internal circular list of two items used
27by SviewCreate() with 'last_pair' or 'last_pair_double'. */
28void SviewPush();
29
30/* Updates camera position/orientation/zoom of all sviews - should be called
31each frame. Will also handle closing of Sview windows. */
32void SviewUpdate(double dt);
33
34/* Deletes all internal views; e.g. used when restarting. */
35void SviewClear();
36
37/* A view, typically an extra view window. The definition of this is not
38public. */
39struct SviewView;
40
41
42/*
43Creates a new SviewView in a new top-level window. It will be updated as
44required by SviewUpdate() and can be dragged, resized
45and closed by the user.
46
47As of 2020-12-09, if not specified in *config, the new window will be half
48width and height of the main window, and will have top-left corner at (100,
49100).
50
51
52Returns:
53 Shared ptr to SviewView instance. As of 2020-11-18 there is little that
54 the caller can do with this. We handle closing of the SviewView's window
55 internally.
56
57As of 2020-11-17, extra views have various limitations including:
58
59 No key event handling, so no zooming with x/X.
60
61config:
62 width, height:
63 Size of new window. Defaults are half main window width and height.
64 x, y:
65 Position of new window.
66 type:
67 "sview" or not specified:
68 List of sview-step's - see below.
69 "current"
70 Clones the current view.
71 "last_pair"
72 Look from first pushed view's eye to second pushed view's
73 eye. Returns nullptr if SviewPush hasn't been called at least
74 twice.
75 "last_pair_double"
76 Keep first pushed view's aircraft in foreground and second pushed
77 view's aircraft in background. Returns nullptr if SviewPush hasn't
78 been called at least twice.
79 "legacy":
80 view:
81 A legacy <view>...</view> tree, e.g. deep copy of /sim/view[]
82 or /ai/models/multiplayer[]/set/sim/view[].
83
84 Note that agl damping_time is calculated as log(10) /
85 view/config/lookat-agl-damping, for backwards compatibility
86 with legacy view code.
87 callsign:
88 "" if user aircraft, else multiplayer aircraft's callsign.
89 view-number-raw:
90 From /sim/current-view/view-number-raw. Used to examine
91 /sim/view[]/config/eye-*-deg-path to decide which of aircraft's
92 heading, pitch and roll to preserve in helicopter and chase
93 views etc.
94 direction-delta: initial modifications to direction.
95 heading
96 pitch
97 roll
98 zoom-delta: modification to default zoom.
99
100 Chase view seems to be slightly different from the real legacy
101 view, possibly because the viewpoint correction config/y-offset-m
102 is applied after rotation instead of before.
103
104An sview-step is:
105 step:
106 type:
107 "aircraft"
108 callsign:
109 "": The user's aircraft.
110 Otherwise specifies a multiplayer aircraft.
111 "move":
112 forward
113 up
114 right
115 Fixed values defining the move relative to current
116 direction.
117 "direction-multiply":
118 heading, pitch, roll:
119 Values to multiply into direction. This can be used to
120 preserve/not preserve heading, pitch and roll, which allows
121 implementation of Helicopter and Chase views etc.
122 "copy-to-target":
123 Copy current position into target. This creates an implicit
124 final step that rotates the view to point at this target.
125 "mouse-drag":
126 Modify heading and pitch in response to mouse drags.
127 heading-scale:
128 pitch-scale:
129 Defaults to 1. For example use zero to disable or -1 to
130 reverse response.
131 "nearest-tower":
132 Move to position of the nearest tower to the aircraft.
133 "rotate":
134 heading, pitch, roll:
135 Values used to rotate direction.
136 damping-time-heading, damping-time-pitch, damping-time-roll:
137 Damping times for heading, pitch and roll; zero gives no
138 damping. See 'agl' below for details of damping.
139 "rotate-current-view":
140 Rotate view direction by current /sim/current-view/....
141 "double":
142 A double view, with eye in foreground and target in background.
143 chase-distance:
144 Distance to move from eye.
145 angle:
146 Angle to maintain between eye and target.
147 "agl":
148 Tilt and zoom to keep ground immediately below the aircraft
149 visible.
150 callsign:
151 Use chase distance of specified aircraft as a measure of
152 its size, to ensure entire aircraft is visible.
153 damping-time:
154 Ground level is damped as dx/dt =
155 (x_actual-x)/damping_time, and damping_time is the time in
156 seconds for the damped value to change by a factor of e
157 (2.71...).
158
159Examples:
160
161 Note that as of 2020-12-09 these examples are untested.
162
163 Tower view of user aircraft:
164
165 <window-width>300</window-width>
166 <window-height>200</window-height>
167 <window-x>100</window-x>
168 <window-y>100</window-y>
169 <step> <!-- Move to aircraft. -->
170 <type>aircraft</type>
171 <callsign></callsign>
172 </step>
173
174 <step> <!-- Move to centre of aircraft. -->
175 <type>move</type>
176 <right>0</right>
177 <up>0.5</up>
178 <forward>-3.85</forward>
179 </step>
180
181 <step> <!-- Copy current position to target. -->
182 <type>copy-to-target</type>
183 </step>
184
185 <step> <!-- Move to nearest tower. -->
186 <type>nearest-tower</type>
187 </step>
188
189 Helicopter view:
190
191 <step> <!-- Move to aircraft. -->
192 <type>aircraft</type>
193 <callsign>foobar</callsign>
194 </step>
195
196 <step> <!-- Move to centre of aircraft. -->
197 <type>move</type>
198 <right>0</right>
199 <up>0.5</up>
200 <forward>-3.85</forward>
201 </step>
202
203 <step> <!-- Force some direction values to zero. -->
204 <type>direction-multiply</type>
205 <heading>1</heading> <!-- Preserve aircraft heading. -->
206 <pitch>0</pitch> <!-- Don't follow aircraft pitch. -->
207 <roll>0</roll> <!-- Don't follow aircraft roll. -->
208 </step>
209
210 <step> <!-- Add constants to heading, pitch and roll. -->
211 <type>rotate</type>
212 <heading>123</heading> <!-- initial view heading -->
213 <pitch>-10</pitch> <!-- initial view pitch -->
214 </step>
215
216 <step> <!-- Move back from aircraft. -->
217 <type>move</type>
218 <forward>-25</forward>
219 </step>
220*/
221std::shared_ptr<SviewView> SviewCreate(const SGPropertyNode* config);
222
223
224#include <simgear/scene/viewer/Compositor.hxx>
225
226/* If event is for an Sview window, returns the window's Compositor; otherwise
227returns nullptr. */
228simgear::compositor::Compositor* SviewGetEventViewport(const osgGA::GUIEventAdapter& ea);
229
230/* If event is for an Sview window, handles it and returns true. Otherwise
231returns false. */
232bool SviewMouseMotion(int x, int y, const osgGA::GUIEventAdapter& ea);
233
bool options(int, char **)
Definition JSBSim.cpp:568
bool SviewMouseMotion(int x, int y, const osgGA::GUIEventAdapter &ea)
Definition sview.cxx:1849
void SViewSetCompositorParams(osg::ref_ptr< simgear::SGReaderWriterOptions > options, const std::string &compositor_path)
Definition sview.cxx:1840
void SviewClear()
Definition sview.cxx:1582
void SviewPush()
Definition sview.cxx:1522
void SviewUpdate(double dt)
Definition sview.cxx:1536
std::shared_ptr< SviewView > SviewCreate(const SGPropertyNode *config)
Definition sview.cxx:1824
simgear::compositor::Compositor * SviewGetEventViewport(const osgGA::GUIEventAdapter &ea)
Definition sview.cxx:1829