FlightGear next
CameraGroup.hxx
Go to the documentation of this file.
1// Copyright (C) 2008 Tim Moore
2//
3// This program is free software; you can redistribute it and/or
4// modify it under the terms of the GNU General Public License as
5// published by the Free Software Foundation; either version 2 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful, but
9// WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17#ifndef CAMERAGROUP_HXX
18#define CAMERAGROUP_HXX 1
19
20#include <map>
21#include <string>
22#include <vector>
23#include <memory>
24
25#include <osg/Matrix>
26#include <osg/ref_ptr>
27#include <osg/Referenced>
28#include <osg/Node>
29#include <osg/TextureRectangle>
30#include <osg/Texture2D>
31#include <osg/TexGen>
32#include <osgUtil/RenderBin>
33#include <osgViewer/View>
34
35#include <simgear/scene/viewer/Compositor.hxx>
36
37namespace osg
38{
39class Camera;
40}
41
42namespace osgViewer
43{
44class Viewer;
45}
46
47class SGPropertyNode;
48
49namespace flightgear
50{
51
53class GraphicsWindow;
54class CameraGroup;
55
58struct CameraInfo : public osg::Referenced
59{
62 enum Flags
63 {
67 ORTHO = 0x4,
68 GUI = 0x8,
74 VR_MIRROR = 0x80,
75 SPLASH = 0x100
76 };
77
78 CameraInfo(unsigned flags_) :
79 flags(flags_) { }
80
82 std::string name;
85 unsigned flags;
88 simgear::compositor::Compositor::MVRInfo mvr;
91 double physicalWidth = 0;
92 double physicalHeight = 0;
93 double bezelHeightTop = 0;
95 double bezelWidthLeft = 0;
96 double bezelWidthRight = 0;
103 osg::Vec2d parentReference[2];
106 osg::Vec2d thisReference[2];
109 osg::Matrix viewOffset;
112 osg::Matrix projOffset;
117 osg::Matrix viewMatrix, projMatrix;
120 std::unique_ptr<simgear::compositor::Compositor> compositor;
125 std::string compositor_path;
126
127 struct ReloadCompositorCallback : public virtual osg::Referenced
128 {
131 };
132 osg::ref_ptr<ReloadCompositorCallback> reloadCompositorCallback;
133
134};
135
136class CameraGroup : public osg::Referenced
137{
138public:
142 CameraGroup(osgViewer::View* viewer);
143 virtual ~CameraGroup();
144
149 static void buildDefaultGroup(osgViewer::View* view);
150 static void setDefault(CameraGroup* group) { _defaultGroup = group; }
154 static CameraGroup* getDefault() { return _defaultGroup.get(); }
158 osgViewer::View* getView() { return _viewer.get(); }
164 CameraInfo* buildCamera(SGPropertyNode* cameraNode);
168 void removeCamera(CameraInfo *info);
177 void buildSplashCamera(SGPropertyNode* cameraNode,
178 GraphicsWindow* window = 0);
187 void buildGUICamera(SGPropertyNode* cameraNode,
188 GraphicsWindow* window = 0);
193 void update(const osg::Vec3d& position,
194 const osg::Quat& orientation);
203 void setCameraParameters(float vfov, float aspectRatio);
206 void setCameraCullMasks(osg::Node::NodeMask nm);
209 void setLODScale(float scale);
212 void resized();
213
217 double getMasterAspectRatio() const;
218
219 CameraInfo *getGUICamera() const;
220
221 typedef std::vector<osg::ref_ptr<CameraInfo>> CameraList;
222 const CameraList& getCameras();
223
224protected:
226 friend bool computeIntersections(const CameraGroup* cgroup,
227 const osg::Vec2d& windowPos,
228 osgUtil::LineSegmentIntersector::Intersections&
229 intersections);
230 friend void reloadCompositors(CameraGroup *cgroup);
231
233 osg::ref_ptr<osgViewer::View> _viewer;
234 static osg::ref_ptr<CameraGroup> _defaultGroup;
235 std::unique_ptr<CameraGroupListener> _listener;
236
237 // Near, far for the master camera if used.
238 float _zNear;
239 float _zFar;
241
247 simgear::compositor::Compositor *buildVRMirrorCompositor(osg::GraphicsContext *gc,
248 osg::Viewport *viewport);
254 static CameraGroup* buildCameraGroup(osgViewer::View* viewer,
255 SGPropertyNode* node);
256};
257
263osg::Camera* getGUICamera(CameraGroup* cgroup);
273bool computeIntersections(const CameraGroup* cgroup,
274 const osg::Vec2d& windowPos,
275 osgUtil::LineSegmentIntersector::Intersections&
276 intersections);
282void warpGUIPointer(CameraGroup* cgroup, int x, int y);
283
287void reloadCompositors(CameraGroup *cgroup);
288
289}
290
291#endif
static double scale(int center, int deadband, int min, int max, int value)
static CameraGroup * getDefault()
Get the default CameraGroup.
const CameraList & getCameras()
void buildGUICamera(SGPropertyNode *cameraNode, GraphicsWindow *window=0)
Create a camera from properties that will draw the GUI and add it to the camera group.
friend bool computeIntersections(const CameraGroup *cgroup, const osg::Vec2d &windowPos, osgUtil::LineSegmentIntersector::Intersections &intersections)
Choose a camera using an event and do intersection testing on its view of the scene.
void buildSplashCamera(SGPropertyNode *cameraNode, GraphicsWindow *window=0)
Create a camera from properties that will draw the splash screen and add it to the camera group.
CameraInfo * getGUICamera() const
simgear::compositor::Compositor * buildVRMirrorCompositor(osg::GraphicsContext *gc, osg::Viewport *viewport)
Create a compositor for a VR mirror.
void removeCamera(CameraInfo *info)
Remove a camera from the camera group.
std::vector< osg::ref_ptr< CameraInfo > > CameraList
void resized()
Update camera properties after a resize event.
static osg::ref_ptr< CameraGroup > _defaultGroup
double getMasterAspectRatio() const
get aspect ratio of master camera's viewport
std::unique_ptr< CameraGroupListener > _listener
friend void reloadCompositors(CameraGroup *cgroup)
Force a reload of all Compositor instances in the CameraGroup, except the one used by the GUI camera.
static CameraGroup * buildCameraGroup(osgViewer::View *viewer, SGPropertyNode *node)
Build a complete CameraGroup from a property node.
static void buildDefaultGroup(osgViewer::View *view)
Set the default CameraGroup, which is the only one that matters at this time.
CameraInfo * buildCamera(SGPropertyNode *cameraNode)
Create an osg::Camera from a property node and add it to the camera group.
static void setDefault(CameraGroup *group)
osg::ref_ptr< osgViewer::View > _viewer
void setCameraCullMasks(osg::Node::NodeMask nm)
Set the cull mask on all non-GUI cameras.
void setCameraParameters(float vfov, float aspectRatio)
Set the parameters of the viewer's master camera.
void setLODScale(float scale)
Set the LOD scale on all non-GUI cameras.
CameraGroup(osgViewer::View *viewer)
Create a camera group associated with an osgViewer::Viewer.
osgViewer::View * getView()
Get the camera group's Viewer.
void update(const osg::Vec3d &position, const osg::Quat &orientation)
Update the view for the camera group.
A window with a graphics context and an integer ID.
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53
osg::Camera * getGUICamera(CameraGroup *cgroup)
Get the osg::Camera that draws the GUI, if any, from a camera group.
void reloadCompositors(CameraGroup *cgroup)
Force a reload of all Compositor instances in the CameraGroup, except the one used by the GUI camera.
void warpGUIPointer(CameraGroup *cgroup, int x, int y)
Warp the pointer to coordinates in the GUI camera of a camera group.
bool computeIntersections(const CameraGroup *cgroup, const osg::Vec2d &windowPos, osgUtil::LineSegmentIntersector::Intersections &intersections)
Choose a camera using an event and do intersection testing on its view of the scene.
Definition AIBase.hxx:25
virtual void preReloadCompositor(CameraGroup *, CameraInfo *)=0
virtual void postReloadCompositor(CameraGroup *, CameraInfo *)=0
A wrapper around osg::Camera that contains some extra information.
Flags
properties of a camera.
@ GUI
Camera draws the GUI.
@ VIEW_ABSOLUTE
The camera view is absolute, not relative to the master camera.
@ DO_INTERSECTION_TEST
scene intersection tests this camera.
@ SPLASH
For splash screen.
@ ENABLE_MASTER_ZOOM
Can apply the zoom algorithm.
@ ORTHO
The projection is orthographic.
@ VR_MIRROR
Switch to a mirror of VR.
@ PROJECTION_ABSOLUTE
The projection is absolute.
@ FIXED_NEAR_FAR
take the near far values in the projection for real.
simgear::compositor::Compositor::MVRInfo mvr
Multiview rendering properties.
const CameraInfo * relativeCameraParent
Non-owning reference to the parent camera for relative camera configurations.
unsigned flags
Properties of the camera.
std::string compositor_path
Compositor path.
osg::Vec2d thisReference[2]
The reference points in the current projection space.
osg::Matrix viewMatrix
Current view and projection matrices for this camera.
std::unique_ptr< simgear::compositor::Compositor > compositor
The Compositor used to manage the pipeline of this camera.
osg::Matrix viewOffset
View offset from the viewer master camera.
CameraInfo(unsigned flags_)
osg::Matrix projOffset
Projection offset from the viewer master camera.
osg::Vec2d parentReference[2]
The reference points in the parents projection space.
std::string name
The name as given in the config file.
osg::ref_ptr< ReloadCompositorCallback > reloadCompositorCallback
double physicalWidth
Physical size parameters.