| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGVIEWER_VIEW |
|---|
| 15 | #define OSGVIEWER_VIEW 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/View> |
|---|
| 18 | |
|---|
| 19 | #include <osgUtil/PolytopeIntersector> |
|---|
| 20 | #include <osgUtil/LineSegmentIntersector> |
|---|
| 21 | #include <osgUtil/UpdateVisitor> |
|---|
| 22 | #include <osgUtil/SceneView> |
|---|
| 23 | |
|---|
| 24 | #include <osgGA/MatrixManipulator> |
|---|
| 25 | #include <osgGA/EventVisitor> |
|---|
| 26 | #include <osgGA/EventQueue> |
|---|
| 27 | |
|---|
| 28 | #include <osgViewer/Scene> |
|---|
| 29 | #include <osgViewer/ViewerBase> |
|---|
| 30 | |
|---|
| 31 | namespace osgViewer { |
|---|
| 32 | |
|---|
| 33 | /** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/ |
|---|
| 34 | class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter |
|---|
| 35 | { |
|---|
| 36 | public: |
|---|
| 37 | |
|---|
| 38 | View(); |
|---|
| 39 | |
|---|
| 40 | View(const osgViewer::View& view, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 41 | |
|---|
| 42 | META_Object(osgViewer,View); |
|---|
| 43 | |
|---|
| 44 | /** Provide a mechanism for getting the osg::View associated from the GUIActionAdapter. |
|---|
| 45 | * One would use this to case view to osgViewer::View(er) if supported by the subclass.*/ |
|---|
| 46 | virtual osg::View* asView() { return this; } |
|---|
| 47 | |
|---|
| 48 | /** Provide a mechanism for getting the viewer object from this osgViewer::View. |
|---|
| 49 | * In the case of a osgViewer::Viewer the ViewerBase will effectively point to this object as Viewer subclasses from View. |
|---|
| 50 | * In the case of a osgViewer::CompsoiteViewer the ViewerBase will point to the CompositeViewer that owns this View. */ |
|---|
| 51 | ViewerBase* getViewerBase() { return _viewerBase.get(); } |
|---|
| 52 | |
|---|
| 53 | /** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */ |
|---|
| 54 | virtual void take(osg::View& rhs); |
|---|
| 55 | |
|---|
| 56 | virtual void setStartTick(osg::Timer_t tick); |
|---|
| 57 | osg::Timer_t getStartTick() const { return _startTick; } |
|---|
| 58 | |
|---|
| 59 | Scene* getScene() { return _scene.get(); } |
|---|
| 60 | const Scene* getScene() const { return _scene.get(); } |
|---|
| 61 | |
|---|
| 62 | /** Set the scene graph that the View will use.*/ |
|---|
| 63 | virtual void setSceneData(osg::Node* node); |
|---|
| 64 | |
|---|
| 65 | /** Get the View's scene graph.*/ |
|---|
| 66 | osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; } |
|---|
| 67 | |
|---|
| 68 | /** Get the const View's scene graph.*/ |
|---|
| 69 | const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; } |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | /** Set the View's database pager.*/ |
|---|
| 73 | void setDatabasePager(osgDB::DatabasePager* dp); |
|---|
| 74 | |
|---|
| 75 | /** Get the View's database pager.*/ |
|---|
| 76 | osgDB::DatabasePager* getDatabasePager(); |
|---|
| 77 | |
|---|
| 78 | /** Get the const View's database pager.*/ |
|---|
| 79 | const osgDB::DatabasePager* getDatabasePager() const; |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | /** Set the View's image pager.*/ |
|---|
| 83 | void setImagePager(osgDB::ImagePager* ip); |
|---|
| 84 | |
|---|
| 85 | /** Get the View's image pager.*/ |
|---|
| 86 | osgDB::ImagePager* getImagePager(); |
|---|
| 87 | |
|---|
| 88 | /** Get the const View's image pager.*/ |
|---|
| 89 | const osgDB::ImagePager* getImagePager() const; |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | /* Set the EventQueue that View uses to integrate external non window related events.*/ |
|---|
| 93 | void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; } |
|---|
| 94 | |
|---|
| 95 | /* Get the View's EventQueue.*/ |
|---|
| 96 | osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); } |
|---|
| 97 | |
|---|
| 98 | /* Get the const View's EventQueue.*/ |
|---|
| 99 | const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); } |
|---|
| 100 | |
|---|
| 101 | /** Set the CameraManipulator that moves the View's master Camera position in response to events.*/ |
|---|
| 102 | void setCameraManipulator(osgGA::MatrixManipulator* manipulator); |
|---|
| 103 | |
|---|
| 104 | /** Get the View's CameraManipulator.*/ |
|---|
| 105 | osgGA::MatrixManipulator* getCameraManipulator() { return _cameraManipulator.get(); } |
|---|
| 106 | |
|---|
| 107 | /** Get the const View's CameraManipulator.*/ |
|---|
| 108 | const osgGA::MatrixManipulator* getCameraManipulator() const { return _cameraManipulator.get(); } |
|---|
| 109 | |
|---|
| 110 | /** Set the view to the CameraManipulator's home position, if non is attached home() is does nothing. |
|---|
| 111 | * Note, to set the home position use getCamaraManipulator()->setHomePosition(...). */ |
|---|
| 112 | void home(); |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers; |
|---|
| 116 | |
|---|
| 117 | /** Add an EventHandler that adds handling of events to the View.*/ |
|---|
| 118 | void addEventHandler(osgGA::GUIEventHandler* eventHandler); |
|---|
| 119 | |
|---|
| 120 | /** Remove an EventHandler from View.*/ |
|---|
| 121 | void removeEventHandler(osgGA::GUIEventHandler* eventHandler); |
|---|
| 122 | |
|---|
| 123 | /** Get the View's list of EventHandlers.*/ |
|---|
| 124 | EventHandlers& getEventHandlers() { return _eventHandlers; } |
|---|
| 125 | |
|---|
| 126 | /** Get the const View's list of EventHandlers.*/ |
|---|
| 127 | const EventHandlers& getEventHandlers() const { return _eventHandlers; } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | /** Set the NodePath to any active CoordinateSystemNode present in the Scene. |
|---|
| 131 | * The CoordinateSystemNode path is used to help applications and CamaraManipualtors handle geocentric coordinates systems, |
|---|
| 132 | * such as known which way is the local up at any position on the a whole earth. */ |
|---|
| 133 | void setCoordinateSystemNodePath(const osg::NodePath& nodePath); |
|---|
| 134 | |
|---|
| 135 | /** Get the NodePath to any active CoordinateSystemNode present in the Scene.*/ |
|---|
| 136 | osg::NodePath getCoordinateSystemNodePath() const; |
|---|
| 137 | |
|---|
| 138 | /** Compute the NodePath to any active CoordinateSystemNode present in the Scene.*/ |
|---|
| 139 | void computeActiveCoordinateSystemNodePath(); |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | /** Set the DisplaySettings object associated with this view.*/ |
|---|
| 143 | void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; } |
|---|
| 144 | |
|---|
| 145 | /** Set the DisplaySettings object associated with this view.*/ |
|---|
| 146 | osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); } |
|---|
| 147 | |
|---|
| 148 | /** Set the DisplaySettings object associated with this view.*/ |
|---|
| 149 | const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); } |
|---|
| 150 | |
|---|
| 151 | /** Set the FusionDistanceMode and Value. Note, is used only when working in stereo.*/ |
|---|
| 152 | void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f) |
|---|
| 153 | { |
|---|
| 154 | _fusionDistanceMode = mode; |
|---|
| 155 | _fusionDistanceValue = value; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /** Get the FusionDistanceMode.*/ |
|---|
| 159 | osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; } |
|---|
| 160 | |
|---|
| 161 | /** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/ |
|---|
| 162 | float getFusionDistanceValue() const { return _fusionDistanceValue; } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | /** Convenience method for creating slave Cameras and associated GraphicsWindows across all screens.*/ |
|---|
| 166 | void setUpViewAcrossAllScreens(); |
|---|
| 167 | |
|---|
| 168 | /** Convenience method for a single camera on a single window.*/ |
|---|
| 169 | void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0); |
|---|
| 170 | |
|---|
| 171 | /** Convenience method for a single camera associated with a single full screen GraphicsWindow.*/ |
|---|
| 172 | void setUpViewOnSingleScreen(unsigned int screenNum=0); |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | /** Convenience method for spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ |
|---|
| 176 | void setUpViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()); |
|---|
| 177 | |
|---|
| 178 | /** Convenience method for spherical display by rendering main scene to as panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/ |
|---|
| 179 | void setUpViewForPanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()); |
|---|
| 180 | |
|---|
| 181 | /** Convenience method for autostereoscopic Philips WoWvx display.*/ |
|---|
| 182 | void setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C); |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | /** Return true if this view contains a specified camera.*/ |
|---|
| 186 | bool containsCamera(const osg::Camera* camera) const; |
|---|
| 187 | |
|---|
| 188 | /** Get the camera which contains the pointer position x,y specified master cameras window/eye coords. |
|---|
| 189 | * Also passes back the local window coords for the graphics context associated with the camera passed back. */ |
|---|
| 190 | const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const; |
|---|
| 191 | |
|---|
| 192 | /** Compute intersections between a ray through the specified master cameras window/eye coords and a specified node. |
|---|
| 193 | * Note, when a master cameras has slaves and no viewport itself its coordinate frame will be in clip space i.e. -1,-1 to 1,1, |
|---|
| 194 | * while if its has a viewport the coordintates will be relative to its viewport dimensions. |
|---|
| 195 | * Mouse events handled by the view will automatically be attached into the master camera window/clip coords so can be passed |
|---|
| 196 | * directly on to the computeIntersections method. */ |
|---|
| 197 | bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); |
|---|
| 198 | |
|---|
| 199 | /** Compute intersections between a ray through the specified master cameras window/eye coords and a specified nodePath's subgraph. */ |
|---|
| 200 | bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | virtual void requestRedraw(); |
|---|
| 204 | virtual void requestContinuousUpdate(bool needed=true); |
|---|
| 205 | virtual void requestWarpPointer(float x,float y); |
|---|
| 206 | |
|---|
| 207 | public: |
|---|
| 208 | |
|---|
| 209 | void assignSceneDataToCameras(); |
|---|
| 210 | void init(); |
|---|
| 211 | |
|---|
| 212 | protected: |
|---|
| 213 | |
|---|
| 214 | friend class CompositeViewer; |
|---|
| 215 | |
|---|
| 216 | virtual ~View(); |
|---|
| 217 | |
|---|
| 218 | virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera); |
|---|
| 219 | |
|---|
| 220 | osg::observer_ptr<ViewerBase> _viewerBase; |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | osg::Timer_t _startTick; |
|---|
| 224 | |
|---|
| 225 | osg::ref_ptr<osgViewer::Scene> _scene; |
|---|
| 226 | osg::ref_ptr<osgGA::EventQueue> _eventQueue; |
|---|
| 227 | osg::ref_ptr<osgGA::MatrixManipulator> _cameraManipulator; |
|---|
| 228 | EventHandlers _eventHandlers; |
|---|
| 229 | |
|---|
| 230 | typedef std::vector< osg::observer_ptr<osg::Node> > ObserverNodePath; |
|---|
| 231 | ObserverNodePath _coordinateSystemNodePath; |
|---|
| 232 | |
|---|
| 233 | osg::ref_ptr<osg::DisplaySettings> _displaySettings; |
|---|
| 234 | osgUtil::SceneView::FusionDistanceMode _fusionDistanceMode; |
|---|
| 235 | float _fusionDistanceValue; |
|---|
| 236 | }; |
|---|
| 237 | |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | #endif |
|---|