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

@@ -2,11 +2,9 @@ TOPDIR = ../../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
ProducerEventCallback.cpp\
ProducerEventAdapter.cpp\
osgproducer.cpp\
LIBS += -lProducer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgProducer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\

View File

@@ -1,116 +0,0 @@
//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 <osgGA/GUIEventAdapter>
#include <Producer/KeyboardMouse>
/** Class for adapting GLUT events so that they can be used as input to osgGA::CameraManipulators.*/
class ProducerEventAdapter : public osgGA::GUIEventAdapter
{
public:
ProducerEventAdapter();
virtual ~ProducerEventAdapter() {}
/** 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

@@ -1,60 +0,0 @@
//C++
#ifndef PRODUCEREVENTCALLBACK
#define PRODUCEREVENTCALLBACK
#include <stdio.h>
#include <Producer/RenderSurface> // For definition of KeySymbol
#include <Producer/KeyboardMouse>
#include <Producer/Mutex>
#include "ProducerEventAdapter.h"
#include <osg/ref_ptr>
#include <osg/Timer>
class ProducerEventCallback : public Producer::KeyboardMouseCallback
{
public:
ProducerEventCallback(bool &done) :
Producer::KeyboardMouseCallback(),
_mx(0.0f),_my(0.0f),_mbutton(0),
_done(done)
{}
virtual ~ProducerEventCallback() {}
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<ProducerEventAdapter> > 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

@@ -9,8 +9,6 @@
#include <Producer/Camera>
#include <Producer/CameraConfig>
#include <Producer/OsgCameraGroup>
#include <Producer/OsgSceneHandler>
#include <Producer/InputArea>
#include <Producer/KeyboardMouse>
@@ -27,12 +25,10 @@
#include <osgGA/KeySwitchCameraManipulator>
#include <osgGA/StateSetManipulator>
#if USE_MY_KEYBOARD_MOUSE_CALLBACK
#include "MyKeyboardMouseCallback"
#else
#include "ProducerEventCallback.h"
#include "ProducerActionAdapter.h"
#endif
#include <osgProducer/CameraGroup>
#include <osgProducer/SceneHandler>
#include <osgProducer/KeyboardMouseCallback>
#include <osgProducer/ActionAdapter>
#include <list>
@@ -90,19 +86,19 @@ int main( int argc, char **argv )
// create the camera group.
Producer::OsgCameraGroup *cg = 0;
osgProducer::CameraGroup *cg = 0;
#define USE_BUILD_CONFIG
#ifdef USE_BUILD_CONFIG
Producer::CameraConfig *cfg = BuildConfig();
cg = new Producer::OsgCameraGroup(cfg);
cg = new osgProducer::CameraGroup(cfg);
#else
cg = configFile.empty() ?
(new Producer::OsgCameraGroup()):
(new Producer::OsgCameraGroup(configFile));
(new osgProducer::CameraGroup()):
(new osgProducer::CameraGroup(configFile));
#endif
@@ -132,7 +128,7 @@ int main( int argc, char **argv )
// set the keyboard mouse callback to catch the events from the windows.
bool done = false;
ProducerEventCallback kbmcb(done);
osgProducer::KeyboardMouseCallback kbmcb(done);
kbmcb.setStartTick(start_tick);
// register the callback with the keyboard mouse manger.
@@ -205,9 +201,9 @@ int main( int argc, char **argv )
eventHandlerList.push_back(statesetManipulator.get());
// create a dummy action adapter right now.
ProducerActionAdapter actionAdapter;
osgProducer::ActionAdapter actionAdapter;
osg::ref_ptr<ProducerEventAdapter> init_event = new ProducerEventAdapter;
osg::ref_ptr<osgProducer::EventAdapter> init_event = new osgProducer::EventAdapter;
init_event->adaptFrame(0.0);
keyswitchManipulator->getCurrentCameraManipulator()->home(*init_event,actionAdapter);
@@ -222,16 +218,16 @@ int main( int argc, char **argv )
frameStamp->setReferenceTime(time_since_start);
// get the event since the last frame.
ProducerEventCallback::EventQueue queue;
osgProducer::KeyboardMouseCallback::EventQueue queue;
kbmcb.getEventQueue(queue);
// create an event to signal the new frame.
osg::ref_ptr<ProducerEventAdapter> frame_event = new ProducerEventAdapter;
osg::ref_ptr<osgProducer::EventAdapter> frame_event = new osgProducer::EventAdapter;
frame_event->adaptFrame(frameStamp->getReferenceTime());
queue.push_back(frame_event);
// dispatch the events in order of arrival.
for(ProducerEventCallback::EventQueue::iterator event_itr=queue.begin();
for(osgProducer::KeyboardMouseCallback::EventQueue::iterator event_itr=queue.begin();
event_itr!=queue.end();
++event_itr)
{
@@ -250,11 +246,7 @@ int main( int argc, char **argv )
// update the main producer camera
#if USE_MY_KEYBOARD_MOUSE_CALLBACK
cg->setView(tb.getMatrix().ptr());
#else
cg->setView(old_style_osg_camera->getModelViewMatrix().ptr());
#endif
// fire off the cull and draw traversals of the scene.
cg->frame();

View File

@@ -1,18 +1,20 @@
#include "ProducerEventAdapter.h"
#include <osgProducer/EventAdapter>
using namespace osgProducer;
// default to no mouse buttons being pressed.
unsigned int ProducerEventAdapter::_s_accumulatedButtonMask = 0;
unsigned int EventAdapter::_s_accumulatedButtonMask = 0;
int ProducerEventAdapter::_s_button = 0;
int ProducerEventAdapter::_s_modKeyMask = 0;
int ProducerEventAdapter::_s_Xmin = 0;
int ProducerEventAdapter::_s_Xmax = 1280;
int ProducerEventAdapter::_s_Ymin = 0;
int ProducerEventAdapter::_s_Ymax = 1024;
int ProducerEventAdapter::_s_mx = 0;
int ProducerEventAdapter::_s_my = 0;
int EventAdapter::_s_button = 0;
int EventAdapter::_s_modKeyMask = 0;
int EventAdapter::_s_Xmin = 0;
int EventAdapter::_s_Xmax = 1280;
int EventAdapter::_s_Ymin = 0;
int EventAdapter::_s_Ymax = 1024;
int EventAdapter::_s_mx = 0;
int EventAdapter::_s_my = 0;
ProducerEventAdapter::ProducerEventAdapter()
EventAdapter::EventAdapter()
{
_eventType = NONE; // adaptor does not encapsulate any events.
_key = -1; // set to 'invalid' key value.
@@ -28,7 +30,7 @@ ProducerEventAdapter::ProducerEventAdapter()
}
void ProducerEventAdapter::copyStaticVariables()
void EventAdapter::copyStaticVariables()
{
_buttonMask = _s_accumulatedButtonMask;
_modKeyMask = _s_modKeyMask;
@@ -42,7 +44,7 @@ void ProducerEventAdapter::copyStaticVariables()
}
void ProducerEventAdapter::setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax)
void EventAdapter::setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax)
{
_s_Xmin = Xmin;
_s_Xmax = Xmax;
@@ -51,13 +53,13 @@ void ProducerEventAdapter::setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax)
}
void ProducerEventAdapter::setButtonMask(unsigned int buttonMask)
void EventAdapter::setButtonMask(unsigned int buttonMask)
{
_s_accumulatedButtonMask = buttonMask;
}
void ProducerEventAdapter::adaptResize(double time, int Xmin, int Ymin, int Xmax, int Ymax)
void EventAdapter::adaptResize(double time, int Xmin, int Ymin, int Xmax, int Ymax)
{
setWindowSize(Xmin,Ymin,Xmax,Ymax);
_eventType = RESIZE;
@@ -65,7 +67,7 @@ void ProducerEventAdapter::adaptResize(double time, int Xmin, int Ymin, int Xmax
copyStaticVariables();
}
void ProducerEventAdapter::adaptButtonPress(double time,float x, float y, unsigned int button)
void EventAdapter::adaptButtonPress(double time,float x, float y, unsigned int button)
{
_time = time;
@@ -97,7 +99,7 @@ void ProducerEventAdapter::adaptButtonPress(double time,float x, float y, unsign
copyStaticVariables();
}
void ProducerEventAdapter::adaptButtonRelease(double time,float x, float y, unsigned int button)
void EventAdapter::adaptButtonRelease(double time,float x, float y, unsigned int button)
{
_time = time;
@@ -130,7 +132,7 @@ void ProducerEventAdapter::adaptButtonRelease(double time,float x, float y, unsi
}
/** method for adapting mouse motion events whilst mouse buttons are pressed.*/
void ProducerEventAdapter::adaptMouseMotion(double time, float x, float y)
void EventAdapter::adaptMouseMotion(double time, float x, float y)
{
_eventType = DRAG;
_time = time;
@@ -141,7 +143,7 @@ void ProducerEventAdapter::adaptMouseMotion(double time, float x, float y)
/** method for adapting keyboard events.*/
void ProducerEventAdapter::adaptKeyPress( double time, Producer::KeySymbol key)
void EventAdapter::adaptKeyPress( double time, Producer::KeySymbol key)
{
_eventType = KEYDOWN;
_time = time;
@@ -150,7 +152,7 @@ void ProducerEventAdapter::adaptKeyPress( double time, Producer::KeySymbol key)
copyStaticVariables();
}
void ProducerEventAdapter::adaptKeyRelease( double time, Producer::KeySymbol key)
void EventAdapter::adaptKeyRelease( double time, Producer::KeySymbol key)
{
// we won't handle this correctly right now.. GUIEventAdapter isn't up to it
_eventType = KEYUP;
@@ -163,7 +165,7 @@ void ProducerEventAdapter::adaptKeyRelease( double time, Producer::KeySymbol key
/** method for adapting frame events, i.e. iddle/display callback.*/
void ProducerEventAdapter::adaptFrame(double time)
void EventAdapter::adaptFrame(double time)
{
_eventType = FRAME;
_time = time;

View File

@@ -1,4 +1,4 @@
#include "ProducerEventCallback.h"
#include <osgProducer/KeyboardMouseCallback>
#ifdef WIN32
#include <windows.h>
@@ -7,7 +7,9 @@
#endif
void ProducerEventCallback::keyPress( Producer::KeySymbol key )
using namespace osgProducer;
void KeyboardMouseCallback::keyPress( Producer::KeySymbol key )
{
switch( key )
@@ -24,7 +26,7 @@ void ProducerEventCallback::keyPress( Producer::KeySymbol key )
#endif
}
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptKeyPress(getTime(),key);
_eventQueueMutex.lock();
@@ -32,10 +34,10 @@ void ProducerEventCallback::keyPress( Producer::KeySymbol key )
_eventQueueMutex.unlock();
}
void ProducerEventCallback::keyRelease( Producer::KeySymbol key )
void KeyboardMouseCallback::keyRelease( Producer::KeySymbol key )
{
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptKeyRelease(getTime(),key);
_eventQueueMutex.lock();
@@ -43,13 +45,13 @@ void ProducerEventCallback::keyRelease( Producer::KeySymbol key )
_eventQueueMutex.unlock();
}
void ProducerEventCallback::mouseMotion( float mx, float my)
void KeyboardMouseCallback::mouseMotion( float mx, float my)
{
_mx = mx;
_my = my;
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptMouseMotion(getTime(),mx,my);
_eventQueueMutex.lock();
@@ -58,14 +60,14 @@ void ProducerEventCallback::mouseMotion( float mx, float my)
}
void ProducerEventCallback::buttonPress( float mx, float my, unsigned int mbutton )
void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutton )
{
_mx = mx;
_my = my;
_mbutton |= (1<<(mbutton-1));
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptButtonPress(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
@@ -73,14 +75,14 @@ void ProducerEventCallback::buttonPress( float mx, float my, unsigned int mbutto
_eventQueueMutex.unlock();
}
void ProducerEventCallback::buttonRelease( float mx, float my, unsigned int mbutton )
void KeyboardMouseCallback::buttonRelease( float mx, float my, unsigned int mbutton )
{
_mx = mx;
_my = my;
_mbutton &= ~(1<<(mbutton-1));
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
osg::ref_ptr<EventAdapter> event = new EventAdapter;
event->adaptButtonRelease(getTime(),mx,my,mbutton);
_eventQueueMutex.lock();
@@ -88,7 +90,7 @@ void ProducerEventCallback::buttonRelease( float mx, float my, unsigned int mbut
_eventQueueMutex.unlock();
}
void ProducerEventCallback::getEventQueue(EventQueue& queue)
void KeyboardMouseCallback::getEventQueue(EventQueue& queue)
{
queue.clear();
_eventQueueMutex.lock();

13
src/osgProducer/Makefile Normal file
View File

@@ -0,0 +1,13 @@
TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
EventAdapter.cpp\
KeyboardMouseCallback.cpp\
LIBS += -lProducer $(GL_LIBS) -losgGA -losgUtil -losgDB -losg $(OTHER_LIBS)
DEF += -DOSGPRODUCER_LIBRARY
TARGET_BASENAME = osgProducer
LIB = $(LIB_PREFIX)$(TARGET_BASENAME).$(LIB_EXT)
include $(TOPDIR)/Make/makerules

View File

@@ -0,0 +1,12 @@
#include <osgProducer/Version>
const char* osgProducerGetVersion()
{
return "0.9.2";
}
const char* osgProducerGetLibraryName()
{
return "Open Scene Graph Producer Library";
}