2006-09-26 00:25:53 +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.
*/
2006-11-02 20:27:15 +08:00
#ifndef OSGVIEWER_SimpleViewer
#define OSGVIEWER_SimpleViewer 1
2006-09-26 00:25:53 +08:00
#include <osgGA/EventVisitor>
#include <osgGA/MatrixManipulator>
2006-11-02 20:27:15 +08:00
#include <osgViewer/GraphicsWindow>
2006-09-26 00:25:53 +08:00
#include <osgDB/DatabasePager>
#include <list>
2006-11-02 20:27:15 +08:00
namespace osgViewer{
2006-09-26 00:25:53 +08:00
/** SimpleViewer provide a simple interface for setting up rendering of an scene graph, using a single camera view within a single window.*/
2006-11-02 20:27:15 +08:00
class OSGVIEWER_EXPORT SimpleViewer : public virtual osgViewer::GraphicsWindow
2006-09-26 00:25:53 +08:00
{
public:
SimpleViewer();
virtual ~SimpleViewer();
void setSceneData(osg::Node* node);
osg::Node* getSceneData();
const osg::Node* getSceneData() const;
2006-11-22 00:15:42 +08:00
void setDatabasePager(osgDB::DatabasePager* dp);
osgDB::DatabasePager* getDatabasePager() { return _databasePager.get(); }
const osgDB::DatabasePager* getDatabasePager() const { return _databasePager.get(); }
2006-11-27 22:52:07 +08:00
osg::Camera* getCamera();
const osg::Camera* getCamera() const;
2006-09-26 00:25:53 +08:00
2006-11-02 20:27:15 +08:00
void setCameraManipulator(osgGA::MatrixManipulator* manipulator);
osgGA::MatrixManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
const osgGA::MatrixManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
2006-09-26 00:25:53 +08:00
2006-11-02 20:27:15 +08:00
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
2006-09-26 00:25:53 +08:00
2006-11-02 20:27:15 +08:00
void addEventHandler(osgGA::GUIEventHandler* eventHandler);
2006-09-26 00:25:53 +08:00
EventHandlers& getEventHandlers() { return _eventHandlers; }
const EventHandlers& getEventHandlers() const { return _eventHandlers; }
/** Render a complete new frame.
* Calls frameAdvance(), frameEventTraversal(), frameUpateTraversal(), frameCullTraversal() and frameDrawTraversal().
* Note, no internal makeCurrent() is issued before, or swap buffers called after frame(), these operations are the responsibility of the calling code.*/
2007-01-25 20:02:51 +08:00
virtual void frame(double simulationTime=USE_REFERENCE_TIME);
2006-09-26 00:25:53 +08:00
2007-01-25 20:02:51 +08:00
virtual void advance(double simulationTime=USE_REFERENCE_TIME);
2007-01-06 00:48:04 +08:00
virtual void eventTraversal();
virtual void updateTraversal();
virtual void renderingTraversal();
2006-09-26 00:25:53 +08:00
2006-10-02 23:38:31 +08:00
/** Release all OpenGL objects associated with this viewer's scenegraph. Note, does not deleted the actual OpenGL objects, it just releases them to the pending GL object delete lists which will need flushing once a valid graphics context is obtained.*/
virtual void releaseAllGLObjects();
/** Clean up all OpenGL objects associated with this viewer's scenegraph. Note, must only be called from the graphics context associated with this viewer.*/
2006-09-26 00:25:53 +08:00
virtual void cleanup();
public:
osgUtil::SceneView* getSceneView() { return _sceneView.get(); }
const osgUtil::SceneView* getSceneView() const { return _sceneView.get(); }
void init();
protected:
bool _firstFrame;
osg::ref_ptr<osg::FrameStamp> _frameStamp;
osg::ref_ptr<osgUtil::SceneView> _sceneView;
osg::ref_ptr<osgGA::MatrixManipulator> _cameraManipulator;
EventHandlers _eventHandlers;
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
osg::ref_ptr<osgDB::DatabasePager> _databasePager;
};
}
#endif