Added osgProducer library to the distribution.

Cleaned up the osgproducer demo, and made it work with the new osgProducer lib.
This commit is contained in:
Robert Osfield
2003-01-17 18:34:35 +00:00
parent 359e0d9c70
commit 619862f8d6
13 changed files with 476 additions and 71 deletions

View File

@@ -0,0 +1,26 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef PRODUCERACTIONADAPTER
#define PRODUCERGUIACTIONADAPTER 1
#include <osgGA/GUIActionAdapter>
namespace osgProducer {
class ActionAdapter : public osgGA::GUIActionAdapter
{
public:
void requestRedraw() {}
void requestContinuousUpdate(bool) {}
void requestWarpPointer(int,int) {}
};
}
#endif

View File

@@ -0,0 +1,208 @@
//C++ header - Open Producer - Copyright (C) 2002 Don Burns
//Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_CAMERA_GROUP_H
#define OSG_CAMERA_GROUP_H
#include <vector>
#include <Producer/CameraGroup>
#include <osg/Node>
#include <osg/StateSet>
#include <osg/FrameStamp>
#include <osg/DisplaySettings>
#include <osgProducer/SceneHandler>
namespace osgProducer {
class CameraGroup : public Producer::CameraGroup
{
public :
typedef std::vector <osgProducer::SceneHandler *> SceneHandlerList;
CameraGroup() : Producer::CameraGroup()
{ _init(); }
CameraGroup(Producer::CameraConfig *cfg) : Producer::CameraGroup(cfg)
{ _init(); }
CameraGroup(const std::string& configFile) : Producer::CameraGroup(configFile)
{ _init(); }
virtual ~CameraGroup() {}
void setSceneData( osg::Node *scene )
{
_scene_data = scene;
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setSceneData( _scene_data );
}
}
}
osg::Node *getSceneData() { return _scene_data; }
void setDisplaySettings( osg::DisplaySettings *ds ) { _ds = ds; }
osg::DisplaySettings *getDisplaySettings() { return _ds.get(); }
const osg::DisplaySettings *getDisplaySettings() const { return _ds.get(); }
void setFrameStamp( osg::FrameStamp* fs )
{
_frameStamp = fs;
for(SceneHandlerList::iterator p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setFrameStamp( fs );
}
}
osg::FrameStamp *getFrameStamp() { return _frameStamp.get(); }
const osg::FrameStamp *getFrameStamp() const { return _frameStamp.get(); }
void setGlobalStateSet( osg::StateSet *sset )
{
_global_stateset = sset;
for(SceneHandlerList::iterator p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setGlobalStateSet( _global_stateset );
}
}
void setBackgroundColor( const osg::Vec4& backgroundColor )
{
_background_color = backgroundColor;
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setBackgroundColor( _background_color );
}
}
}
void setLODScale( float bias )
{
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setLODScale( bias );
}
}
}
void setFusionDistance( osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f)
{
if( _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
for( p = _shvec.begin(); p != _shvec.end(); p++ )
{
(*p)->setFusionDistance( mode, value );
}
}
}
osg::Vec4& getBackgroundColor() { return _background_color; }
const osg::Vec4& getBackgroundColor() const { return _background_color; }
osg::StateSet *getGlobalStateSet() { return _global_stateset; }
const osg::StateSet *getGlobalStateSet() const { return _global_stateset; }
void advance()
{
if( !_initialized ) return;
CameraGroup::advance();
}
void realize( ThreadingModel thread_model= SingleThreaded )
{
if( _initialized ) return;
if (!_ds) _ds = osg::DisplaySettings::instance();
_ds->setMaxNumberOfGraphicsContexts( _cfg->getNumberOfCameras() );
for( unsigned int i = 0; i < _cfg->getNumberOfCameras(); i++ )
{
Producer::Camera *cam = _cfg->getCamera(i);
osgProducer::SceneHandler *sh = new osgProducer::SceneHandler(_ds.get());
sh->setDefaults();
if( _global_stateset != NULL )
sh->setGlobalStateSet( _global_stateset );
if( _scene_data != NULL )
sh->setSceneData( _scene_data );
sh->setBackgroundColor( _background_color);
sh->getState()->setContextID(i);
sh->setFrameStamp( _frameStamp.get() );
_shvec.push_back( sh );
cam->setSceneHandler( sh );
}
/// Make all statesets the same as the first.
if( _global_stateset == NULL && _shvec.size() > 0 )
{
SceneHandlerList::iterator p;
p = _shvec.begin();
_global_stateset = (*p)->getGlobalStateSet();
p++;
for( ; p != _shvec.end(); p++ )
(*p)->setGlobalStateSet( _global_stateset );
}
Producer::CameraGroup::realize( thread_model );
_initialized = true;
}
virtual void frame( )
{
Producer::CameraGroup::frame();
_frameStamp->setFrameNumber( _frameStamp->getFrameNumber() + 1 );
}
private :
osg::Node * _scene_data;
osg::StateSet * _global_stateset;
osg::Vec4 _background_color;
SceneHandlerList _shvec;
osg::ref_ptr<osg::DisplaySettings> _ds;
bool _initialized;
osg::ref_ptr<osg::FrameStamp> _frameStamp;
void _init()
{
_scene_data = NULL;
_global_stateset = NULL;
_background_color.set( 0.2f, 0.2f, 0.4f, 1.0f );
_initialized = false;
if (!_frameStamp) _frameStamp = new osg::FrameStamp;
}
};
}
#endif

View File

@@ -0,0 +1,123 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSGGLUT_ProducerEventAdapter
#define OSGGLUT_ProducerEventAdapter 1
#include <osgProducer/Export>
#include <osgGA/GUIEventAdapter>
#include <Producer/KeyboardMouse>
namespace osgProducer {
/** Class for adapting Producer events so that they can be used as input to osgGA::CameraManipulators.*/
class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter
{
public:
EventAdapter();
virtual ~EventAdapter() {}
/** Get the EventType of the GUI event.*/
virtual EventType getEventType() const { return _eventType; }
/** key pressed, return -1 if inappropriate for this event. */
virtual int getKey() const { return _key; }
/** button pressed/released, return -1 if inappropriate for this event.*/
virtual int getButton() const { return _button; }
/** window minimum x. */
virtual int getXmin() const { return _Xmin; }
/** window maximum x. */
virtual int getXmax() const { return _Xmax; }
/** window minimum y. */
virtual int getYmin() const { return _Ymin; }
/** window maximum y. */
virtual int getYmax() const { return _Ymax; }
/** current mouse x position.*/
virtual int getX() const { return _mx; }
/** current mouse y position.*/
virtual int getY() const { return _my; }
/** current mouse button state */
virtual unsigned int getButtonMask() const { return _buttonMask; }
/** time in seconds of event. */
virtual double time() const { return _time; }
virtual unsigned int getModKeyMask() const { return _modKeyMask; }
/** static method for setting window dimensions.*/
static void setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax);
/** static method for setting button state.*/
static void setButtonMask(unsigned int buttonMask);
/** method for adapting resize events. */
void adaptResize(double t, int Xmin, int Ymin, int Xmax, int Ymax);
/** method for adapting mouse motion events whilst mouse buttons are pressed.*/
void adaptMouseMotion(double t, float x, float y);
void adaptButtonPress(double t,float x, float y, unsigned int button);
void adaptButtonRelease(double t,float x, float y, unsigned int button);
/** method for adapting keyboard events.*/
void adaptKeyPress( double t, Producer::KeySymbol key);
void adaptKeyRelease( double t, Producer::KeySymbol key);
/** method for adapting frame events, i.e. idle/display callback.*/
void adaptFrame(double t);
void copyStaticVariables();
protected:
EventType _eventType;
int _key;
int _button;
int _Xmin,_Xmax;
int _Ymin,_Ymax;
int _mx;
int _my;
unsigned int _buttonMask;
unsigned int _modKeyMask;
double _time;
// used to accumulate the button mask state, it represents
// the current button mask state, which is modified by the
// adaptMouse() method which then copies it to value _buttonMask
// which required the mouse buttons state at the time of the event.
static unsigned int _s_accumulatedButtonMask;
// used to store current button value
static int _s_button;
// used to store window min and max values.
static int _s_Xmin;
static int _s_Xmax;
static int _s_Ymin;
static int _s_Ymax;
static int _s_mx;
static int _s_my;
static int _s_modKeyMask;
};
}
#endif

View File

@@ -0,0 +1,29 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
// The following symbol has a underscore suffix for compatibility.
#ifndef OSGPRODUCER_EXPORT_
#define OSGPRODUCER_EXPORT_ 1
#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
#pragma warning( disable : 4244 )
#pragma warning( disable : 4251 )
#pragma warning( disable : 4267 )
#pragma warning( disable : 4275 )
#pragma warning( disable : 4290 )
#pragma warning( disable : 4786 )
#endif
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# ifdef OSGPRODUCER_LIBRARY
# define OSGPRODUCER_EXPORT __declspec(dllexport)
# else
# define OSGPRODUCER_EXPORT __declspec(dllimport)
#endif /* OSGPRODUCER_LIBRARY */
#else
#define OSGPRODUCER_EXPORT
#endif
#endif

View File

@@ -0,0 +1,70 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSGPRODUCER_EVENTCALLBACK
#define OSGPRODUCER_EVENTCALLBACK 1
#include <Producer/RenderSurface> // For definition of KeySymbol
#include <Producer/KeyboardMouse>
#include <Producer/Mutex>
#include <osgProducer/EventAdapter>
#include <osg/ref_ptr>
#include <osg/Timer>
namespace osgProducer {
class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseCallback
{
public:
KeyboardMouseCallback(bool &done) :
Producer::KeyboardMouseCallback(),
_mx(0.0f),_my(0.0f),_mbutton(0),
_done(done)
{}
virtual ~KeyboardMouseCallback() {}
virtual void keyPress( Producer::KeySymbol key );
virtual void keyRelease( Producer::KeySymbol key );
virtual void mouseMotion( float mx, float my);
virtual void buttonPress( float mx, float my, unsigned int mbutton );
virtual void buttonRelease( float mx, float my, unsigned int mbutton );
typedef std::vector< osg::ref_ptr<EventAdapter> > EventQueue;
void getEventQueue(EventQueue& queue);
bool done() { return _done; }
float mx() { return _mx; }
float my() { return _my; }
unsigned int mbutton() { return _mbutton; }
void setStartTick(osg::Timer_t tick) { _startTick = tick; }
double getTime() { return _timer.delta_s(_startTick,_timer.tick()); }
private:
float _mx, _my;
unsigned int _mbutton;
bool &_done;
osg::Timer_t _startTick;
osg::Timer _timer;
Producer::Mutex _eventQueueMutex;
EventQueue _eventQueue;
};
}
#endif

View File

@@ -0,0 +1,67 @@
//C++ header - Open Producer - Copyright (C) 2002 Don Burns
//Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
//as published by the Free Software Foundation.
#ifndef OSGPRODUCER_SCENEHANDLER
#define OSGPRODUCER_SCENEHANDLER 1
#include <osgProducer/Export>
#include <Producer/Camera>
#include <osgUtil/SceneView>
#include <osg/Matrix>
#include <iostream>
namespace osgProducer {
class SceneHandler : public Producer::Camera::SceneHandler, public osgUtil::SceneView
{
public :
SceneHandler( osg::DisplaySettings *ds = NULL) : osgUtil::SceneView(ds)
{
mm = new osg::RefMatrix;
pm = new osg::RefMatrix;
}
void cull(Producer::Camera &cam)
{
pm->set(cam.getProjectionMatrix());
mm->set(cam.getPositionAndAttitudeMatrix());
setProjectionMatrix( pm.get() );
setModelViewMatrix( mm.get() );
int x, y;
unsigned int w, h;
cam.getProjectionRect( x, y, w, h );
setViewport( x, y, w, h );
#ifdef _windows_is_non_standard
SceneView::cull();
#else
osgUtil::SceneView::cull();
#endif
}
void draw(Producer::Camera &)
{
#ifdef _windows_is_non_standard
SceneView::draw();
#else
osgUtil::SceneView::draw();
#endif
}
void setContextID( int id )
{
getState()->setContextID( id );
}
private:
osg::ref_ptr<osg::RefMatrix> mm;
osg::ref_ptr<osg::RefMatrix> pm;
};
}
#endif

View File

@@ -0,0 +1,39 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSGPRODUCER_VERSION
#define OSGPRODUCER_VERSION 1
#include <osgProducer/Export>
extern "C" {
/**
* osgProducerGetVersion() returns the library version number.
* Numbering convention : osg_src-0.8.31 will return 0.8.31.
*
* This C function can be also used to check for the existence of the OpenSceneGraph
* library using autoconf and its m4 macro AC_CHECK_LIB.
*
* Here is the code to add to your configure.in:
\verbatim
#
# Check for the OpenSceneGraph (OSG) GLUT library
#
AC_CHECK_LIB(osg, osgProducerGetVersion, ,
[AC_MSG_ERROR(OpenSceneGraph GLUT library not found. See http://www.openscenegraph.org)],)
\endverbatim
*/
extern OSGPRODUCER_EXPORT const char* osgProducerGetVersion();
/**
* getLibraryName_osgProducer() returns the library name in human friendly form.
*/
extern OSGPRODUCER_EXPORT const char* osgProducerGetLibraryName();
}
#endif