2003-01-21 21:14:29 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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 OSG_VIEWER_H
|
|
|
|
#define OSG_VIEWER_H
|
|
|
|
|
|
|
|
#include <osg/Timer>
|
|
|
|
#include <osg/NodeVisitor>
|
2003-02-19 00:36:42 +08:00
|
|
|
#include <osg/ArgumentParser>
|
2003-02-21 22:05:39 +08:00
|
|
|
#include <osg/ApplicationUsage>
|
2003-04-06 06:24:48 +08:00
|
|
|
#include <osg/AnimationPath>
|
2003-01-21 21:14:29 +08:00
|
|
|
|
|
|
|
#include <osgGA/GUIActionAdapter>
|
|
|
|
#include <osgGA/GUIEventHandler>
|
|
|
|
#include <osgGA/KeySwitchCameraManipulator>
|
|
|
|
|
2003-02-25 20:28:16 +08:00
|
|
|
#include <osgProducer/OsgCameraGroup>
|
2003-01-21 21:14:29 +08:00
|
|
|
#include <osgProducer/KeyboardMouseCallback>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
namespace osgProducer {
|
|
|
|
|
2003-02-25 20:28:16 +08:00
|
|
|
class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIActionAdapter
|
2003-01-21 21:14:29 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
Viewer();
|
|
|
|
|
|
|
|
Viewer(Producer::CameraConfig *cfg);
|
|
|
|
|
|
|
|
Viewer(const std::string& configFile);
|
|
|
|
|
2003-02-19 00:36:42 +08:00
|
|
|
Viewer(osg::ArgumentParser& arguments);
|
|
|
|
|
2003-01-21 21:14:29 +08:00
|
|
|
virtual ~Viewer() {}
|
|
|
|
|
|
|
|
|
|
|
|
enum ViewerOptions
|
|
|
|
{
|
2003-03-19 22:27:05 +08:00
|
|
|
NO_EVENT_HANDLERS = 0,
|
2003-01-21 21:14:29 +08:00
|
|
|
TRACKBALL_MANIPULATOR = 1,
|
|
|
|
DRIVE_MANIPULATOR = 2,
|
|
|
|
FLIGHT_MANIPULATOR = 4,
|
|
|
|
STATE_MANIPULATOR = 8,
|
|
|
|
HEAD_LIGHT_SOURCE = 16,
|
|
|
|
SKY_LIGHT_SOURCE = 32,
|
2003-01-31 07:02:32 +08:00
|
|
|
STATS_MANIPULATOR = 64,
|
2003-03-25 23:13:20 +08:00
|
|
|
VIEWER_MANIPULATOR = 128,
|
2003-03-19 22:27:05 +08:00
|
|
|
ESCAPE_SETS_DONE = 256,
|
2003-01-21 21:14:29 +08:00
|
|
|
STANDARD_SETTINGS = TRACKBALL_MANIPULATOR|
|
|
|
|
DRIVE_MANIPULATOR |
|
|
|
|
FLIGHT_MANIPULATOR |
|
|
|
|
STATE_MANIPULATOR |
|
2003-01-31 07:02:32 +08:00
|
|
|
HEAD_LIGHT_SOURCE |
|
2003-03-19 22:27:05 +08:00
|
|
|
STATS_MANIPULATOR |
|
2003-03-25 23:13:20 +08:00
|
|
|
VIEWER_MANIPULATOR |
|
2003-03-19 22:27:05 +08:00
|
|
|
ESCAPE_SETS_DONE
|
2003-01-21 21:14:29 +08:00
|
|
|
};
|
|
|
|
|
2003-01-24 17:37:11 +08:00
|
|
|
void setUpViewer(unsigned int options=STANDARD_SETTINGS);
|
2003-01-21 21:14:29 +08:00
|
|
|
|
2003-04-08 23:47:45 +08:00
|
|
|
/** return true if the application is done and should exit.*/
|
2003-04-10 20:55:48 +08:00
|
|
|
virtual bool done() const;
|
2003-04-08 23:47:45 +08:00
|
|
|
|
2003-04-10 18:02:24 +08:00
|
|
|
/** Override the Producer::CameraGroup::setViewByMatrix to catch all changes to view.*/
|
|
|
|
virtual void setViewByMatrix( const Producer::Matrix & pm);
|
2003-01-21 21:14:29 +08:00
|
|
|
|
2003-04-08 23:18:45 +08:00
|
|
|
/** Set the threading model and then call realize().*/
|
|
|
|
virtual bool realize(ThreadingModel thread_model);
|
|
|
|
|
|
|
|
virtual bool realize();
|
2003-04-06 06:24:48 +08:00
|
|
|
|
2003-01-21 21:14:29 +08:00
|
|
|
virtual void sync();
|
|
|
|
|
|
|
|
virtual void update();
|
|
|
|
|
2003-04-06 06:24:48 +08:00
|
|
|
/** Dispatch the cull and draw for each of the Camera's for this frame.*/
|
|
|
|
virtual void frame();
|
2003-01-21 21:14:29 +08:00
|
|
|
|
|
|
|
virtual void requestRedraw() {}
|
|
|
|
virtual void requestContinuousUpdate(bool) {}
|
2003-04-05 03:10:37 +08:00
|
|
|
virtual void requestWarpPointer(float x,float y);
|
2003-01-21 21:14:29 +08:00
|
|
|
|
2003-01-22 23:30:17 +08:00
|
|
|
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlerList;
|
|
|
|
EventHandlerList& getEventHandlerList() { return _eventHandlerList; }
|
2003-04-06 06:24:48 +08:00
|
|
|
const EventHandlerList& getEventHandlerList() const { return _eventHandlerList; }
|
|
|
|
|
|
|
|
osgGA::KeySwitchCameraManipulator* getKeySwitchCameraManipulator() { return _keyswitchManipulator.get(); }
|
|
|
|
const osgGA::KeySwitchCameraManipulator* getKeySwitchCameraManipulator() const { return _keyswitchManipulator.get(); }
|
2003-01-22 23:30:17 +08:00
|
|
|
|
|
|
|
unsigned int addCameraManipulator(osgGA::CameraManipulator* cm);
|
|
|
|
void selectCameraManipulator(unsigned int no);
|
|
|
|
|
2003-04-06 06:24:48 +08:00
|
|
|
|
|
|
|
void setRecordingAnimationPath(bool on) { _recordingAnimationPath = on; }
|
|
|
|
bool getRecordingAnimationPath() const { return _recordingAnimationPath; }
|
|
|
|
|
|
|
|
void setAnimationPath(osg::AnimationPath* path) { _animationPath = path; }
|
|
|
|
osg::AnimationPath* getAnimationPath() { return _animationPath.get(); }
|
|
|
|
const osg::AnimationPath* getAnimationPath() const { return _animationPath.get(); }
|
|
|
|
|
|
|
|
|
2003-02-19 18:43:02 +08:00
|
|
|
/** Get the keyboard and mouse usage of this viewer.*/
|
|
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
2003-01-22 23:30:17 +08:00
|
|
|
|
2003-01-21 21:14:29 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
|
|
|
|
bool _done;
|
|
|
|
|
|
|
|
unsigned int _frameNumber;
|
|
|
|
osg::Timer _timer;
|
|
|
|
osg::Timer_t _start_tick;
|
|
|
|
|
|
|
|
osgProducer::KeyboardMouseCallback* _kbmcb;
|
|
|
|
|
|
|
|
EventHandlerList _eventHandlerList;
|
|
|
|
osg::ref_ptr<osgGA::KeySwitchCameraManipulator> _keyswitchManipulator;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> _old_style_osg_camera;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::NodeVisitor> _updateVisitor;
|
2003-04-06 06:24:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
bool _recordingAnimationPath;
|
|
|
|
osg::ref_ptr<osg::AnimationPath> _animationPath;
|
|
|
|
|
2003-01-21 21:14:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|