2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2006-11-27 22:52:07 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2006-11-27 22:52:07 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2006-11-27 22:52:07 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-11-27 22:52:07 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGVIEWER_Viewer
|
|
|
|
#define OSGVIEWER_Viewer 1
|
|
|
|
|
2007-06-06 18:57:02 +08:00
|
|
|
#include <osg/ArgumentParser>
|
|
|
|
#include <osgGA/EventVisitor>
|
2007-08-10 18:52:35 +08:00
|
|
|
#include <osgUtil/UpdateVisitor>
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osgViewer/GraphicsWindow>
|
|
|
|
#include <osgViewer/View>
|
2007-06-06 18:57:02 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2006-11-29 04:35:31 +08:00
|
|
|
namespace osgViewer {
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-05-15 00:14:40 +08:00
|
|
|
/** Viewer holds a single view on to a single scene.*/
|
2007-09-30 00:46:08 +08:00
|
|
|
class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
|
2006-11-27 22:52:07 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Viewer();
|
2007-06-06 18:57:02 +08:00
|
|
|
|
|
|
|
Viewer(osg::ArgumentParser& arguments);
|
|
|
|
|
2007-09-21 21:30:33 +08:00
|
|
|
Viewer(const osgViewer::Viewer& viewer, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
virtual ~Viewer();
|
2009-04-25 00:20:50 +08:00
|
|
|
|
2007-09-21 21:30:33 +08:00
|
|
|
META_Object(osgViewer,Viewer);
|
|
|
|
|
2007-09-21 23:34:25 +08:00
|
|
|
/** Take all the settings, Camera and Slaves from the passed in view(er), leaving it empty. */
|
2011-06-24 00:36:36 +08:00
|
|
|
virtual void take(osg::View& rhs);
|
2007-09-21 23:34:25 +08:00
|
|
|
|
2009-01-27 21:23:20 +08:00
|
|
|
|
|
|
|
/** Set the Stats object used for collect various frame related timing and scene graph stats.*/
|
|
|
|
virtual void setViewerStats(osg::Stats* stats) { setStats(stats); }
|
|
|
|
|
|
|
|
/** Get the Viewers Stats object.*/
|
|
|
|
virtual osg::Stats* getViewerStats() { return getStats(); }
|
|
|
|
|
|
|
|
/** Get the Viewers Stats object.*/
|
|
|
|
virtual const osg::Stats* getViewerStats() const { return getStats(); }
|
|
|
|
|
|
|
|
|
2007-09-21 21:30:33 +08:00
|
|
|
/** read the viewer configuration from a configuration file.*/
|
2007-09-30 00:46:08 +08:00
|
|
|
virtual bool readConfiguration(const std::string& filename);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-01-05 18:59:23 +08:00
|
|
|
/** Get whether at least of one of this viewers windows are realized.*/
|
2007-09-30 00:46:08 +08:00
|
|
|
virtual bool isRealized() const;
|
2007-01-05 18:59:23 +08:00
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
/** set up windows and associated threads.*/
|
2007-09-30 00:46:08 +08:00
|
|
|
virtual void realize();
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
virtual void setStartTick(osg::Timer_t tick);
|
2007-01-15 22:46:16 +08:00
|
|
|
void setReferenceTime(double time=0.0);
|
|
|
|
|
2007-06-03 17:34:28 +08:00
|
|
|
/** Set the sene graph data that viewer with view.*/
|
2007-01-15 22:46:16 +08:00
|
|
|
virtual void setSceneData(osg::Node* node);
|
2007-01-06 05:19:01 +08:00
|
|
|
|
2007-06-03 17:34:28 +08:00
|
|
|
|
2007-06-03 18:00:09 +08:00
|
|
|
/** Convenience method for setting up the viewer so it can be used embedded in an external managed window.
|
2007-06-03 17:34:28 +08:00
|
|
|
* Returns the GraphicsWindowEmbedded that can be used by applications to pass in events to the viewer. */
|
|
|
|
virtual GraphicsWindowEmbedded* setUpViewerAsEmbeddedInWindow(int x, int y, int width, int height);
|
|
|
|
|
2007-01-30 06:44:29 +08:00
|
|
|
|
2007-10-03 05:23:58 +08:00
|
|
|
virtual double elapsedTime();
|
2007-01-13 05:05:39 +08:00
|
|
|
|
2009-04-25 00:20:50 +08:00
|
|
|
virtual osg::FrameStamp* getViewerFrameStamp() { return getFrameStamp(); }
|
2007-08-11 18:28:14 +08:00
|
|
|
|
2007-01-05 18:59:23 +08:00
|
|
|
/** Execute a main frame loop.
|
2007-12-11 01:30:18 +08:00
|
|
|
* Equivalent to while (!viewer.done()) viewer.frame();
|
2007-01-05 18:59:23 +08:00
|
|
|
* Also calls realize() if the viewer is not already realized,
|
|
|
|
* and installs trackball manipulator if one is not already assigned.
|
|
|
|
*/
|
2007-01-05 21:16:24 +08:00
|
|
|
virtual int run();
|
2007-01-05 18:59:23 +08:00
|
|
|
|
2009-04-25 00:20:50 +08:00
|
|
|
/** check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.*/
|
|
|
|
virtual bool checkNeedToDoFrame();
|
|
|
|
|
2007-01-25 20:02:51 +08:00
|
|
|
virtual void advance(double simulationTime=USE_REFERENCE_TIME);
|
2006-12-22 00:56:20 +08:00
|
|
|
|
2007-01-06 00:48:04 +08:00
|
|
|
virtual void eventTraversal();
|
2006-12-22 00:56:20 +08:00
|
|
|
|
2007-01-06 00:48:04 +08:00
|
|
|
virtual void updateTraversal();
|
2009-04-25 00:20:50 +08:00
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
virtual void getCameras(Cameras& cameras, bool onlyActive=true);
|
2009-04-25 00:20:50 +08:00
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
virtual void getContexts(Contexts& contexts, bool onlyValid=true);
|
2007-01-02 20:50:57 +08:00
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
virtual void getAllThreads(Threads& threads, bool onlyActive=true);
|
2007-02-06 19:03:13 +08:00
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
|
2007-01-29 01:11:21 +08:00
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
virtual void getScenes(Scenes& scenes, bool onlyValid=true);
|
2007-01-29 01:11:21 +08:00
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
virtual void getViews(Views& views, bool onlyValid=true);
|
|
|
|
|
2007-02-12 21:39:18 +08:00
|
|
|
/** Get the keyboard and mouse usage of this viewer.*/
|
|
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
|
2007-01-04 19:49:15 +08:00
|
|
|
protected:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-06-06 18:57:02 +08:00
|
|
|
void constructorInit();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-10-03 05:23:58 +08:00
|
|
|
virtual void viewerInit() { init(); }
|
2007-01-13 05:05:39 +08:00
|
|
|
|
2013-05-04 03:26:27 +08:00
|
|
|
void generateSlavePointerData(osg::Camera* camera, osgGA::GUIEventAdapter& event);
|
|
|
|
void generatePointerData(osgGA::GUIEventAdapter& event);
|
|
|
|
void reprojectPointerData(osgGA::GUIEventAdapter& source_event, osgGA::GUIEventAdapter& dest_event);
|
2007-08-10 18:52:35 +08:00
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|