2006-11-27 22:52:07 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGVIEWER_VIEW
|
|
|
|
#define OSGVIEWER_VIEW 1
|
|
|
|
|
|
|
|
#include <osg/View>
|
|
|
|
|
2007-01-10 01:35:46 +08:00
|
|
|
#include <osgUtil/PolytopeIntersector>
|
|
|
|
#include <osgUtil/LineSegmentIntersector>
|
2006-12-23 01:46:21 +08:00
|
|
|
#include <osgUtil/SceneView>
|
|
|
|
|
2007-01-10 01:35:46 +08:00
|
|
|
#include <osgGA/MatrixManipulator>
|
|
|
|
#include <osgViewer/Scene>
|
|
|
|
|
2006-11-29 04:35:31 +08:00
|
|
|
namespace osgViewer {
|
|
|
|
|
2007-01-30 06:44:29 +08:00
|
|
|
class OSGVIEWER_EXPORT EndOfDynamicDrawBlock : public osg::State::DynamicObjectRenderingCompletedCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2007-02-01 06:24:20 +08:00
|
|
|
EndOfDynamicDrawBlock(unsigned int);
|
2007-01-30 06:44:29 +08:00
|
|
|
|
|
|
|
void completed(osg::State* state);
|
|
|
|
|
|
|
|
void block();
|
2007-02-01 06:24:20 +08:00
|
|
|
|
|
|
|
void reset();
|
2007-01-30 06:44:29 +08:00
|
|
|
|
|
|
|
void release();
|
|
|
|
|
2007-02-01 06:24:20 +08:00
|
|
|
void setNumOfBlocks(unsigned int blockCount);
|
2007-01-30 06:44:29 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
~EndOfDynamicDrawBlock();
|
|
|
|
|
|
|
|
OpenThreads::Mutex _mut;
|
|
|
|
OpenThreads::Condition _cond;
|
2007-02-01 06:24:20 +08:00
|
|
|
unsigned int _numberOfBlocks;
|
2007-01-30 06:44:29 +08:00
|
|
|
unsigned int _blockCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/
|
2007-01-02 02:20:10 +08:00
|
|
|
class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
2006-11-27 22:52:07 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
View();
|
|
|
|
|
2007-02-26 04:05:23 +08:00
|
|
|
View(const osgViewer::View& view, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Object(osgViewer,View);
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
Scene* getScene() { return _scene.get(); }
|
|
|
|
const Scene* getScene() const { return _scene.get(); }
|
|
|
|
|
2007-06-07 17:58:49 +08:00
|
|
|
/** Set the scene graph that the View will use.*/
|
2007-01-15 22:46:16 +08:00
|
|
|
virtual void setSceneData(osg::Node* node);
|
2007-06-07 17:58:49 +08:00
|
|
|
|
|
|
|
/** Get the View's scene graph.*/
|
2006-12-20 00:00:51 +08:00
|
|
|
osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; }
|
2007-06-07 17:58:49 +08:00
|
|
|
|
|
|
|
/** Get the const View's scene graph.*/
|
2006-12-20 00:00:51 +08:00
|
|
|
const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; }
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-06-07 17:58:49 +08:00
|
|
|
/* Set the EventQueue that View uses to intregrate external non window related events.*/
|
2006-12-21 05:13:29 +08:00
|
|
|
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
|
2007-06-07 17:58:49 +08:00
|
|
|
|
|
|
|
/* Get the View's EventQueue.*/
|
2006-12-21 05:13:29 +08:00
|
|
|
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
|
2007-06-07 17:58:49 +08:00
|
|
|
|
|
|
|
/* Get the const View's EventQueue.*/
|
2006-12-21 05:13:29 +08:00
|
|
|
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
|
|
|
|
|
2007-06-07 17:58:49 +08:00
|
|
|
/** Set the CameraManipulator that moves the View's master Camera position in response to events.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
void setCameraManipulator(osgGA::MatrixManipulator* manipulator);
|
2007-06-07 17:58:49 +08:00
|
|
|
|
|
|
|
/** Get the View's CameraManipulator.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
osgGA::MatrixManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
|
2007-06-07 17:58:49 +08:00
|
|
|
|
|
|
|
/** Get the const View's CameraManipulator.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
const osgGA::MatrixManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
|
|
|
|
|
2007-06-07 17:58:49 +08:00
|
|
|
/** Set the view to the CameraManipulator's home position, if non is attached home() is does nothing.
|
|
|
|
* Note, to set the home position use getCamaraManipulator()->setHomePosition(...). */
|
|
|
|
void home();
|
|
|
|
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
|
|
|
|
|
2007-06-07 17:58:49 +08:00
|
|
|
/** Add an EventHandler that adds handling of events to the View.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
void addEventHandler(osgGA::GUIEventHandler* eventHandler);
|
2007-06-07 17:58:49 +08:00
|
|
|
|
|
|
|
/** Get the View's list of EventHandlers.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
EventHandlers& getEventHandlers() { return _eventHandlers; }
|
2007-06-07 17:58:49 +08:00
|
|
|
|
|
|
|
/** Get the const View's list of EventHandlers.*/
|
2006-11-27 22:52:07 +08:00
|
|
|
const EventHandlers& getEventHandlers() const { return _eventHandlers; }
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2007-05-18 18:33:56 +08:00
|
|
|
|
2007-06-07 17:58:49 +08:00
|
|
|
/** Set the NodePath to any active CoordinateSystemNode present in the Scene.
|
|
|
|
* The CoordinateSystemNode path is used to help applications and CamaraManipualtors handle geocentric coordinates systems,
|
|
|
|
* such as known which way is the local up at any position on the a whole earth. */
|
2007-05-18 18:33:56 +08:00
|
|
|
void setCoordinateSystemNodePath(const osg::NodePath& nodePath);
|
|
|
|
|
|
|
|
/** Get the NodePath to any active CoordinateSystemNode present in the Scene.*/
|
|
|
|
osg::NodePath getCoordinateSystemNodePath() const;
|
|
|
|
|
|
|
|
/** Compute the NodePath to any active CoordinateSystemNode present in the Scene.*/
|
|
|
|
void computeActiveCoordinateSystemNodePath();
|
|
|
|
|
2007-01-11 20:06:24 +08:00
|
|
|
|
|
|
|
/** Set the DsplaySettings object associated with this view.*/
|
|
|
|
void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
|
|
|
|
|
|
|
|
/** Set the DsplaySettings object associated with this view.*/
|
|
|
|
osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
|
|
|
|
|
|
|
|
/** Set the DsplaySettings object associated with this view.*/
|
|
|
|
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
|
|
|
|
|
2007-05-18 03:58:57 +08:00
|
|
|
/** Set the FusionDistanceMode and Value. Note, is used only when working in stereo.*/
|
|
|
|
void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f)
|
|
|
|
{
|
|
|
|
_fusionDistanceMode = mode;
|
|
|
|
_fusionDistanceValue = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the FusionDistanceMode.*/
|
|
|
|
osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
|
|
|
|
|
|
|
|
/** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
|
|
|
|
float getFusionDistanceValue() const { return _fusionDistanceValue; }
|
|
|
|
|
2007-01-11 20:06:24 +08:00
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
/** Convinience method for creating slave Cameras and associated GraphicsWindows across all screens.*/
|
|
|
|
void setUpViewAcrossAllScreens();
|
2007-01-07 05:06:35 +08:00
|
|
|
|
2007-06-13 18:38:40 +08:00
|
|
|
/** Convinience method for a single Camara on a single window.*/
|
|
|
|
void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0);
|
|
|
|
|
2007-01-07 05:06:35 +08:00
|
|
|
/** Convinience method for a single Camara associated with a single full screen GraphicsWindow.*/
|
|
|
|
void setUpViewOnSingleScreen(unsigned int screenNum=0);
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2007-01-10 01:35:46 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
/** Return true if this view contains a specified camera.*/
|
|
|
|
bool containsCamera(const osg::Camera* camera) const;
|
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
/** Get the camera which contains the pointer position x,y specified master cameras window/eye coords.
|
|
|
|
* Also passes back the local window coords for the graphics context associated with the camera passed back. */
|
|
|
|
const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
|
|
|
|
|
2007-01-10 01:35:46 +08:00
|
|
|
/** Compute intersections between a ray through the specified master cameras window/eye coords and a specified node.
|
|
|
|
* 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,
|
|
|
|
* while if its has a viewport the coordintates will be relative to its viewport dimensions.
|
|
|
|
* Mouse events handled by the view will automatically be attached into the master camera window/clip coords so can be passed
|
|
|
|
* directly on to the computeIntersections method. */
|
|
|
|
bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
|
|
|
|
|
2007-01-10 18:09:05 +08:00
|
|
|
/** Compute intersections between a ray through the specified master cameras window/eye coords and a specified nodePath's subgraph. */
|
|
|
|
bool computeIntersections(float x,float y, osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
|
2007-01-10 01:35:46 +08:00
|
|
|
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
virtual void requestRedraw();
|
|
|
|
virtual void requestContinuousUpdate(bool needed=true);
|
|
|
|
virtual void requestWarpPointer(float x,float y);
|
2007-01-16 00:09:32 +08:00
|
|
|
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
|
|
|
|
public:
|
2006-12-20 00:00:51 +08:00
|
|
|
|
|
|
|
void assignSceneDataToCameras();
|
2007-01-17 00:01:01 +08:00
|
|
|
void init();
|
2006-11-27 22:52:07 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2007-01-17 00:01:01 +08:00
|
|
|
|
2006-11-29 04:35:31 +08:00
|
|
|
virtual ~View();
|
2006-11-27 22:52:07 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osgViewer::Scene> _scene;
|
2006-12-21 05:13:29 +08:00
|
|
|
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
|
2006-11-27 22:52:07 +08:00
|
|
|
osg::ref_ptr<osgGA::MatrixManipulator> _cameraManipulator;
|
|
|
|
EventHandlers _eventHandlers;
|
|
|
|
|
2007-07-12 00:06:04 +08:00
|
|
|
typedef std::vector< osg::observer_ptr<osg::Node> > ObserverNodePath;
|
|
|
|
ObserverNodePath _coordinateSystemNodePath;
|
2007-05-18 18:33:56 +08:00
|
|
|
|
2007-01-11 20:06:24 +08:00
|
|
|
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
|
2007-05-18 03:58:57 +08:00
|
|
|
osgUtil::SceneView::FusionDistanceMode _fusionDistanceMode;
|
|
|
|
float _fusionDistanceValue;
|
2006-11-27 22:52:07 +08:00
|
|
|
};
|
|
|
|
|
2006-11-29 04:35:31 +08:00
|
|
|
}
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
#endif
|