]> git.mxchange.org Git - flightgear.git/blob - utils/fgviewer/SlaveCamera.hxx
commradio: improvements for atis speech
[flightgear.git] / utils / fgviewer / SlaveCamera.hxx
1 // Viewer.hxx -- alternative flightgear viewer application
2 //
3 // Copyright (C) 2009 - 2012  Mathias Froehlich
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19 #ifndef _fgviewer_SlaveCamera_hxx
20 #define _fgviewer_SlaveCamera_hxx
21
22 #include <string>
23 #include <osg/Camera>
24 #include <simgear/math/SGMath.hxx>
25 #include <simgear/structure/SGWeakReferenced.hxx>
26
27 #include "Frustum.hxx"
28
29 namespace fgviewer  {
30
31 class Viewer;
32
33 class SlaveCamera : public SGWeakReferenced {
34 public:
35     SlaveCamera(const std::string& name);
36     virtual ~SlaveCamera();
37     
38     const std::string& getName() const
39     { return _name; }
40
41     /// The drawable this camera renders to
42     bool setDrawableName(const std::string& drawableName);
43     const std::string& getDrawableName() const
44     { return _drawableName; }
45     
46     /// The viewport into the above drawable
47     virtual bool setViewport(const SGVec4i& viewport);
48     SGVec4i getViewport() const
49     { return SGVec4i(_viewport->x(), _viewport->y(), _viewport->width(), _viewport->height()); }
50     double getAspectRatio() const
51     { return _viewport->aspectRatio(); }
52     
53     /// The view offset, usually an orientation offset
54     virtual bool setViewOffset(const osg::Matrix& viewOffset);
55     const osg::Matrix& getViewOffset() const
56     { return _viewOffset; }
57     bool setViewOffsetDeg(double headingDeg, double pitchDeg, double rollDeg);
58     
59     /// The frustum for this camera
60     virtual bool setFrustum(const Frustum& frustum);
61     const Frustum& getFrustum() const
62     { return _frustum; }
63     void setFustumByFieldOfViewDeg(double fieldOfViewDeg);
64     bool setRelativeFrustum(const std::string names[2], const SlaveCamera& referenceCameraData,
65                             const std::string referenceNames[2]);
66
67     /// For relative cameras configure the reference points that should match
68     void setProjectionReferencePoint(const std::string& name, const osg::Vec2& point);
69     osg::Vec2 getProjectionReferencePoint(const std::string& name) const;
70     /// Set the reference points for a monitor configuration
71     void setMonitorProjectionReferences(double width, double height,
72                                         double bezelTop, double bezelBottom,
73                                         double bezelLeft, double bezelRight);
74
75     /// Access parameters of this view/camera
76     osg::Vec3 getLeftEyeOffset(const Viewer& viewer) const;
77     osg::Vec3 getRightEyeOffset(const Viewer& viewer) const;
78     double getZoomFactor(const Viewer& viewer) const;
79     osg::Matrix getEffectiveViewOffset(const Viewer& viewer) const;
80     Frustum getEffectiveFrustum(const Viewer& viewer) const;
81
82     /// The top level camera holding the context
83     osg::Camera* getCamera()
84     { return _camera.get(); }
85     
86     /// Top level entry points
87     bool realize(Viewer& viewer);
88     bool update(Viewer& viewer);
89     
90 protected:
91     virtual osg::Camera* _realizeImplementation(Viewer& viewer);
92     virtual bool _updateImplementation(Viewer& viewer);
93     
94 private:
95     SlaveCamera(const SlaveCamera&);
96     SlaveCamera& operator=(const SlaveCamera&);
97
98     /// The immutable name that is used to reference this slave camera.
99     const std::string _name;
100     std::string _drawableName;
101     osg::ref_ptr<osg::Viewport> _viewport;
102     osg::Matrix _viewOffset;
103     Frustum _frustum;
104     /// The camera that is attached to the slave and that has a context attached.
105     osg::ref_ptr<osg::Camera> _camera;
106
107     /// For relative views, the named reference points in the projection space
108     typedef std::map<std::string, osg::Vec2> NameReferencePointMap;
109     NameReferencePointMap _referencePointMap;
110 };
111
112 } // namespace fgviewer
113
114 #endif