Debian Codegraph @

src/Viewer/sview.hxx

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