1 // Viewer.hxx -- alternative flightgear viewer application
3 // Copyright (C) 2009 - 2012 Mathias Froehlich
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.
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.
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.
19 #ifndef _fgviewer_SlaveCamera_hxx
20 #define _fgviewer_SlaveCamera_hxx
24 #include <simgear/math/SGMath.hxx>
25 #include <simgear/structure/SGWeakReferenced.hxx>
27 #include "Frustum.hxx"
33 class SlaveCamera : public SGWeakReferenced {
35 SlaveCamera(const std::string& name);
36 virtual ~SlaveCamera();
38 const std::string& getName() const
41 /// The drawable this camera renders to
42 bool setDrawableName(const std::string& drawableName);
43 const std::string& getDrawableName() const
44 { return _drawableName; }
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(); }
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);
59 /// The frustum for this camera
60 virtual bool setFrustum(const Frustum& frustum);
61 const Frustum& getFrustum() const
63 void setFustumByFieldOfViewDeg(double fieldOfViewDeg);
64 bool setRelativeFrustum(const std::string names[2], const SlaveCamera& referenceCameraData,
65 const std::string referenceNames[2]);
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);
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;
82 /// The top level camera holding the context
83 osg::Camera* getCamera()
84 { return _camera.get(); }
86 /// Top level entry points
87 bool realize(Viewer& viewer);
88 bool update(Viewer& viewer);
91 virtual osg::Camera* _realizeImplementation(Viewer& viewer);
92 virtual bool _updateImplementation(Viewer& viewer);
95 SlaveCamera(const SlaveCamera&);
96 SlaveCamera& operator=(const SlaveCamera&);
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;
104 /// The camera that is attached to the slave and that has a context attached.
105 osg::ref_ptr<osg::Camera> _camera;
107 /// For relative views, the named reference points in the projection space
108 typedef std::map<std::string, osg::Vec2> NameReferencePointMap;
109 NameReferencePointMap _referencePointMap;
112 } // namespace fgviewer