]> git.mxchange.org Git - flightgear.git/blob - src/Viewer/viewmgr.hxx
Kill off some globals.
[flightgear.git] / src / Viewer / viewmgr.hxx
1 // viewmgr.hxx -- class for managing all the views in the flightgear world.
2 //
3 // Written by Curtis Olson, started October 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _VIEWMGR_HXX
25 #define _VIEWMGR_HXX
26
27 #include <vector>
28
29 #include <simgear/compiler.h>
30 #include <simgear/structure/subsystem_mgr.hxx>
31 #include <simgear/props/props.hxx>
32 #include <simgear/props/tiedpropertylist.hxx>
33 #include <simgear/math/SGMath.hxx>
34
35 // forward decls
36 class FGViewer;
37 class SGSoundMgr;
38 typedef SGSharedPtr<FGViewer> FGViewerPtr;
39
40 // Define a structure containing view information
41 class FGViewMgr : public SGSubsystem
42 {
43
44 public:
45
46     // Constructor
47     FGViewMgr( void );
48
49     // Destructor
50     ~FGViewMgr( void );
51
52     virtual void init ();
53     virtual void bind ();
54     virtual void unbind ();
55     virtual void update (double dt);
56     virtual void reinit ();
57
58     // getters
59     inline int size() const { return views.size(); }
60     inline int get_current() const { return current; }
61     
62     FGViewer *get_current_view();
63     const FGViewer *get_current_view() const;
64     
65     FGViewer *get_view( int i ); 
66     const FGViewer *get_view( int i ) const;
67       
68     FGViewer *next_view();
69     FGViewer *prev_view();
70       
71     // setters
72     void clear();
73
74     void add_view( FGViewer * v );
75     
76 private:
77     void do_bind();
78
79     simgear::TiedPropertyList _tiedProperties;
80
81     double axis_long;
82     double axis_lat;
83
84     void do_axes ();
85
86     //  callbacks in manager to access viewer methods
87     double getViewHeadingOffset_deg () const;
88     void setViewHeadingOffset_deg (double offset);
89     double getViewGoalHeadingOffset_deg () const;
90     void setViewGoalHeadingOffset_deg (double offset);
91     double getViewPitchOffset_deg () const;
92     void setViewPitchOffset_deg (double tilt);
93     double getGoalViewPitchOffset_deg () const;
94     void setGoalViewRollOffset_deg (double tilt);
95     double getViewRollOffset_deg () const;
96     void setViewRollOffset_deg (double tilt);
97     double getGoalViewRollOffset_deg () const;
98     void setGoalViewPitchOffset_deg (double tilt);
99     double getViewXOffset_m () const;
100     void setViewXOffset_m (double x);
101     double getViewYOffset_m () const;
102     void setViewYOffset_m (double y);
103     double getViewZOffset_m () const;
104     void setViewZOffset_m (double z);
105     double getViewTargetXOffset_m () const;
106     void setViewTargetXOffset_m (double x);
107     double getViewTargetYOffset_m () const;
108     void setViewTargetYOffset_m (double y);
109     double getViewTargetZOffset_m () const;
110     void setViewTargetZOffset_m (double z);
111     double getFOV_deg () const;
112     void setFOV_deg (double fov);
113     double getARM_deg () const; // Aspect Ratio Multiplier
114     void setARM_deg (double fov);
115     double getNear_m () const;
116     void setNear_m (double near_m);
117     void setViewAxisLong (double axis);
118     void setViewAxisLat (double axis);
119     int getView () const;
120     void setView (int newview);
121
122 // quaternion accessors, for debugging:
123     double getCurrentViewOrientation_w() const;
124     double getCurrentViewOrientation_x() const;
125     double getCurrentViewOrientation_y() const;
126     double getCurrentViewOrientation_z() const;
127     double getCurrentViewOrOffset_w() const;
128     double getCurrentViewOrOffset_x() const;
129     double getCurrentViewOrOffset_y() const;
130     double getCurrentViewOrOffset_z() const;
131     double getCurrentViewFrame_w() const;
132     double getCurrentViewFrame_x() const;
133     double getCurrentViewFrame_y() const;
134     double getCurrentViewFrame_z() const;
135
136     bool stationary () const;
137
138     // copies current offset settings to current-view path...
139     void copyToCurrent ();
140     
141     bool inited;
142     SGPropertyNode_ptr view_number;
143     std::vector<SGPropertyNode_ptr> config_list;
144     typedef std::vector<FGViewerPtr> viewer_list;
145     viewer_list views;
146     SGVec3d abs_viewer_position;
147
148     int current;
149     SGQuatd current_view_orientation, current_view_or_offset;
150
151     SGSoundMgr *smgr;
152   
153     SGPropertyNode_ptr velocityNorthFPS, velocityEastFPS, velocityDownFPS;
154 };
155
156 // This takes the conventional aviation XYZ body system 
157 // i.e.  x=forward, y=starboard, z=bottom
158 // which is widely used in FGFS
159 // and rotates it into the OpenGL camera system 
160 // i.e. Xprime=starboard, Yprime=top, Zprime=aft.
161 inline const SGQuatd fsb2sta()
162 {
163     return SGQuatd(-0.5, -0.5, 0.5, 0.5);
164 }
165
166 #endif // _VIEWMGR_HXX