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:
@@ -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)\
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
#include "ProducerEventAdapter.h"
|
||||
|
||||
// default to no mouse buttons being pressed.
|
||||
unsigned int ProducerEventAdapter::_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;
|
||||
|
||||
ProducerEventAdapter::ProducerEventAdapter()
|
||||
{
|
||||
_eventType = NONE; // adaptor does not encapsulate any events.
|
||||
_key = -1; // set to 'invalid' key value.
|
||||
_button = -1; // set to 'invalid' button value.
|
||||
_mx = -1; // set to 'invalid' position value.
|
||||
_my = -1; // set to 'invalid' position value.
|
||||
_buttonMask = 0; // default to no mouse buttons being pressed.
|
||||
_modKeyMask = 0; // default to no mouse buttons being pressed.
|
||||
_time = 0.0f; // default to no time has been set.
|
||||
|
||||
copyStaticVariables();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ProducerEventAdapter::copyStaticVariables()
|
||||
{
|
||||
_buttonMask = _s_accumulatedButtonMask;
|
||||
_modKeyMask = _s_modKeyMask;
|
||||
_button = _s_button;
|
||||
_Xmin = _s_Xmin;
|
||||
_Xmax = _s_Xmax;
|
||||
_Ymin = _s_Ymin;
|
||||
_Ymax = _s_Ymax;
|
||||
_mx = _s_mx;
|
||||
_my = _s_my;
|
||||
}
|
||||
|
||||
|
||||
void ProducerEventAdapter::setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax)
|
||||
{
|
||||
_s_Xmin = Xmin;
|
||||
_s_Xmax = Xmax;
|
||||
_s_Ymin = Ymin;
|
||||
_s_Ymax = Ymax;
|
||||
}
|
||||
|
||||
|
||||
void ProducerEventAdapter::setButtonMask(unsigned int buttonMask)
|
||||
{
|
||||
_s_accumulatedButtonMask = buttonMask;
|
||||
}
|
||||
|
||||
|
||||
void ProducerEventAdapter::adaptResize(double time, int Xmin, int Ymin, int Xmax, int Ymax)
|
||||
{
|
||||
setWindowSize(Xmin,Ymin,Xmax,Ymax);
|
||||
_eventType = RESIZE;
|
||||
_time = time;
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
void ProducerEventAdapter::adaptButtonPress(double time,float x, float y, unsigned int button)
|
||||
{
|
||||
_time = time;
|
||||
|
||||
_eventType = PUSH;
|
||||
_button = button-1;
|
||||
|
||||
switch(_button)
|
||||
{
|
||||
case(0):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask | LEFT_MOUSE_BUTTON;
|
||||
_s_button = LEFT_MOUSE_BUTTON;
|
||||
break;
|
||||
case(1):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask | MIDDLE_MOUSE_BUTTON;
|
||||
_s_button = MIDDLE_MOUSE_BUTTON;
|
||||
break;
|
||||
case(2):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask | RIGHT_MOUSE_BUTTON;
|
||||
_s_button = RIGHT_MOUSE_BUTTON;
|
||||
break;
|
||||
}
|
||||
|
||||
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
|
||||
_s_my = (int)(y*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
void ProducerEventAdapter::adaptButtonRelease(double time,float x, float y, unsigned int button)
|
||||
{
|
||||
_time = time;
|
||||
|
||||
_eventType = RELEASE;
|
||||
_button = button-1;
|
||||
|
||||
switch(_button)
|
||||
{
|
||||
case(0):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask & ~LEFT_MOUSE_BUTTON;
|
||||
_s_button = LEFT_MOUSE_BUTTON;
|
||||
break;
|
||||
case(1):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask & ~MIDDLE_MOUSE_BUTTON;
|
||||
_s_button = MIDDLE_MOUSE_BUTTON;
|
||||
break;
|
||||
case(2):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask & ~RIGHT_MOUSE_BUTTON;
|
||||
_s_button = RIGHT_MOUSE_BUTTON;
|
||||
break;
|
||||
}
|
||||
|
||||
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
|
||||
_s_my = (int)(y*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
/** method for adapting mouse motion events whilst mouse buttons are pressed.*/
|
||||
void ProducerEventAdapter::adaptMouseMotion(double time, float x, float y)
|
||||
{
|
||||
_eventType = DRAG;
|
||||
_time = time;
|
||||
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
|
||||
_s_my = (int)(y*(float)(_s_Ymin-_s_Ymax))+_s_Ymax;
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
|
||||
/** method for adapting keyboard events.*/
|
||||
void ProducerEventAdapter::adaptKeyPress( double time, Producer::KeySymbol key)
|
||||
{
|
||||
_eventType = KEYDOWN;
|
||||
_time = time;
|
||||
_key = key;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
void ProducerEventAdapter::adaptKeyRelease( double time, Producer::KeySymbol key)
|
||||
{
|
||||
// we won't handle this correctly right now.. GUIEventAdapter isn't up to it
|
||||
_eventType = KEYUP;
|
||||
_time = time;
|
||||
_key = key;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** method for adapting frame events, i.e. iddle/display callback.*/
|
||||
void ProducerEventAdapter::adaptFrame(double time)
|
||||
{
|
||||
_eventType = FRAME;
|
||||
_time = time;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
@@ -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
|
||||
@@ -1,98 +0,0 @@
|
||||
#include "ProducerEventCallback.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <X11/keysym.h>
|
||||
#endif
|
||||
|
||||
|
||||
void ProducerEventCallback::keyPress( Producer::KeySymbol key )
|
||||
{
|
||||
|
||||
switch( key )
|
||||
{
|
||||
#ifdef XK_MISCELLANY // XWindows keydefs
|
||||
case XK_Escape:
|
||||
_done = true;
|
||||
break;
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
case VK_ESCAPE:
|
||||
_done = true;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptKeyPress(getTime(),key);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void ProducerEventCallback::keyRelease( Producer::KeySymbol key )
|
||||
{
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptKeyRelease(getTime(),key);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void ProducerEventCallback::mouseMotion( float mx, float my)
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptMouseMotion(getTime(),mx,my);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
|
||||
}
|
||||
|
||||
void ProducerEventCallback::buttonPress( float mx, float my, unsigned int mbutton )
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
_mbutton |= (1<<(mbutton-1));
|
||||
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptButtonPress(getTime(),mx,my,mbutton);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void ProducerEventCallback::buttonRelease( float mx, float my, unsigned int mbutton )
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
_mbutton &= ~(1<<(mbutton-1));
|
||||
|
||||
|
||||
osg::ref_ptr<ProducerEventAdapter> event = new ProducerEventAdapter;
|
||||
event->adaptButtonRelease(getTime(),mx,my,mbutton);
|
||||
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.push_back(event);
|
||||
_eventQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void ProducerEventCallback::getEventQueue(EventQueue& queue)
|
||||
{
|
||||
queue.clear();
|
||||
_eventQueueMutex.lock();
|
||||
_eventQueue.swap(queue);
|
||||
_eventQueueMutex.unlock();
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user