2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2001-10-04 23:12:57 +08:00
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSGGLUT_VIEWER
|
|
|
|
#define OSGGLUT_VIEWER 1
|
|
|
|
|
|
|
|
#include <osg/Light>
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/Timer>
|
2001-12-22 06:48:19 +08:00
|
|
|
#include <osg/DisplaySettings>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-06-09 21:10:09 +08:00
|
|
|
#include <osgGA/GUIEventAdapter>
|
|
|
|
#include <osgGA/CameraManipulator>
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <osgUtil/SceneView>
|
|
|
|
|
2001-12-25 03:06:49 +08:00
|
|
|
#include <osgGLUT/Window>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2001-12-25 03:06:49 +08:00
|
|
|
namespace osgGLUT
|
|
|
|
{
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** A basic viewer base class which provides a window, simple keyboard and mouse interaction.
|
2001-09-20 05:08:56 +08:00
|
|
|
* Please note, this viewer class has been developed via a rather haphazard
|
2001-09-28 20:36:40 +08:00
|
|
|
* path and <i>needs</i> a total rewrite. It currently suffices for osg demos
|
2001-09-20 05:08:56 +08:00
|
|
|
* but shouldn't be viewed as the be all and end of osg viewer classes.
|
2001-01-11 00:32:10 +08:00
|
|
|
* Someone please rewrite it :-)
|
|
|
|
*/
|
2002-06-09 21:10:09 +08:00
|
|
|
class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Viewer();
|
|
|
|
virtual ~Viewer();
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** init is deprecated, you should use addViewport instead. init is
|
|
|
|
* only available for backwards compatibility.*/
|
|
|
|
virtual void init(osg::Node* rootnode);
|
|
|
|
|
|
|
|
virtual void addViewport(osgUtil::SceneView* sv,
|
|
|
|
float x = 0.0, float y = 0.0,
|
|
|
|
float width = 1.0, float height = 1.0);
|
|
|
|
|
|
|
|
virtual void addViewport(osg::Node*,
|
|
|
|
float x = 0.0, float y = 0.0,
|
|
|
|
float width = 1.0, float height = 1.0);
|
|
|
|
|
|
|
|
const int getNumViewports() const { return _viewportList.size(); }
|
|
|
|
|
|
|
|
osgUtil::SceneView* getViewportSceneView(unsigned int pos)
|
|
|
|
{ return _viewportList[pos].sceneView.get(); }
|
|
|
|
|
|
|
|
virtual bool open();
|
2001-01-11 00:32:10 +08:00
|
|
|
virtual bool run();
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// called on each frame redraw..return the time in ms for each operation.
|
|
|
|
virtual float app(unsigned int viewport);
|
|
|
|
virtual float cull(unsigned int viewport);
|
|
|
|
virtual float draw(unsigned int viewport);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
// initialize the clock.
|
|
|
|
long initClock();
|
|
|
|
// time since initClock() in seconds.
|
2001-09-22 10:42:08 +08:00
|
|
|
double clockSeconds() { return _timer.delta_s(_initialTick,clockTick()); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
// update the number of ticks since the last frame update.
|
|
|
|
osg::Timer_t updateFrameTick();
|
|
|
|
|
|
|
|
// time from the current frame update and the previous one in seconds.
|
2001-09-22 10:42:08 +08:00
|
|
|
double frameSeconds() { return _timer.delta_s(_lastFrameTick,_frameTick); }
|
|
|
|
double frameRate() { return 1.0/frameSeconds(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-12-15 07:18:28 +08:00
|
|
|
void help(std::ostream& fout);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-28 20:36:40 +08:00
|
|
|
// handle multiple camera.
|
2002-06-09 21:10:09 +08:00
|
|
|
unsigned int registerCameraManipulator(osgGA::CameraManipulator* cm,
|
2001-09-20 05:08:56 +08:00
|
|
|
unsigned int viewport = 0);
|
|
|
|
void selectCameraManipulator(unsigned int pos,
|
|
|
|
unsigned int viewport = 0);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-07-17 18:00:50 +08:00
|
|
|
void setEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport = 0);
|
|
|
|
|
2002-06-09 21:10:09 +08:00
|
|
|
// derived from osgGA::GUIActionAdapter
|
2001-09-28 20:36:40 +08:00
|
|
|
virtual void requestRedraw() {} // redraw always by idle callback done.
|
|
|
|
virtual void requestContinuousUpdate(bool /*needed*/) {} // continuous update always
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual void requestWarpPointer(int x,int y);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-12-19 08:38:23 +08:00
|
|
|
/** read the command line string list, removing any matched control sequences.*/
|
|
|
|
void readCommandLine(std::vector<std::string>& commandLine);
|
|
|
|
|
2002-03-15 01:34:08 +08:00
|
|
|
void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
|
|
|
|
osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
|
|
|
|
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
|
|
|
|
|
2002-07-13 10:46:06 +08:00
|
|
|
typedef std::vector<osg::ref_ptr<osgGA::CameraManipulator> > CameraManipList;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected:
|
|
|
|
|
2002-03-24 05:28:25 +08:00
|
|
|
virtual void clear();
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
virtual void display();
|
|
|
|
virtual void reshape(GLint w, GLint h);
|
|
|
|
virtual void mouseMotion(int x, int y);
|
|
|
|
virtual void mousePassiveMotion(int x, int y);
|
|
|
|
virtual void mouse(int button, int state, int x, int y);
|
|
|
|
virtual void keyboard(unsigned char key, int x, int y);
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
void setFocusedViewport(unsigned int pos);
|
|
|
|
int mapWindowXYToSceneView(int x, int y);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-10-23 06:02:47 +08:00
|
|
|
void showStats(const unsigned int i); // gwm 24.09.01 pass the viewport to collect sta for each viewport
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
static Viewer* s_theViewer;
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
struct ViewportDef
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osgUtil::SceneView> sceneView;
|
|
|
|
float viewport[4]; // Win-size-relative [0,1]
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-07-17 18:00:50 +08:00
|
|
|
osg::ref_ptr<osgGA::CameraManipulator> _cameraManipulator;
|
2001-09-20 05:08:56 +08:00
|
|
|
CameraManipList _cameraManipList;
|
2002-07-17 18:00:50 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osgGA::GUIEventHandler> _eventHandler;
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<ViewportDef> ViewportList;
|
|
|
|
ViewportList _viewportList;
|
|
|
|
unsigned int _focusedViewport;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
std::string _saveFileName;
|
|
|
|
|
|
|
|
bool _viewFrustumCullingActive;
|
|
|
|
bool _smallFeatureCullingActive;
|
|
|
|
|
|
|
|
int polymode;
|
|
|
|
int texture;
|
|
|
|
int backface;
|
|
|
|
int lighting;
|
|
|
|
int flat_shade;
|
2001-09-20 05:08:56 +08:00
|
|
|
float frRate; // gwm Jul 2001 added convolved ('averaged') frame rate
|
|
|
|
int _printStats; // gwm Jul 2001 change from bool
|
|
|
|
struct { // gwm Jul 2001, added for display of statistics
|
|
|
|
float timeApp, timeCull, timeDraw, timeFrame;
|
|
|
|
osg::Timer_t frameend;
|
|
|
|
} times[3]; // store up to 3 frames worth of times
|
2001-01-11 00:32:10 +08:00
|
|
|
bool _useDisplayLists;
|
|
|
|
|
|
|
|
osg::Timer _timer;
|
|
|
|
osg::Timer_t _tickRatePerSecond;
|
|
|
|
osg::Timer_t _initialTick;
|
|
|
|
osg::Timer_t _lastFrameTick;
|
|
|
|
osg::Timer_t _frameTick;
|
|
|
|
|
|
|
|
// system tick.
|
|
|
|
osg::Timer_t clockTick();
|
|
|
|
osg::Timer_t frameTick();
|
|
|
|
|
|
|
|
|
2001-12-19 08:38:23 +08:00
|
|
|
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
2001-12-22 06:48:19 +08:00
|
|
|
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
|
2001-09-22 10:42:08 +08:00
|
|
|
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SG_VIEWIER_H
|