From f87dc60dddff1e09428d36acc32a698cf8e1e5d0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 17 Jan 2003 14:12:46 +0000 Subject: [PATCH] Further improvements to the osgproducer demo. --- src/Demos/osgproducer/ProducerEventCallback.h | 7 ++- src/Demos/osgproducer/osgproducer.cpp | 55 +++++++++++-------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/Demos/osgproducer/ProducerEventCallback.h b/src/Demos/osgproducer/ProducerEventCallback.h index adb00a930..665f07640 100644 --- a/src/Demos/osgproducer/ProducerEventCallback.h +++ b/src/Demos/osgproducer/ProducerEventCallback.h @@ -41,7 +41,9 @@ class ProducerEventCallback : public Producer::KeyboardMouseCallback float my() { return _my; } unsigned int mbutton() { return _mbutton; } - double getTime() { return 0.0f; } + void setStartTick(osg::Timer_t tick) { _startTick = tick; } + + double getTime() { return _timer.delta_s(_startTick,_timer.tick()); } private: @@ -49,7 +51,8 @@ class ProducerEventCallback : public Producer::KeyboardMouseCallback unsigned int _mbutton; bool &_done; - osg::Timer _timer; + osg::Timer_t _startTick; + osg::Timer _timer; Producer::Mutex _eventQueueMutex; EventQueue _eventQueue; diff --git a/src/Demos/osgproducer/osgproducer.cpp b/src/Demos/osgproducer/osgproducer.cpp index 1d819c4ba..a6ba735fb 100644 --- a/src/Demos/osgproducer/osgproducer.cpp +++ b/src/Demos/osgproducer/osgproducer.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include @@ -23,6 +22,9 @@ #include #include +#include +#include +#include #include #if USE_MY_KEYBOARD_MOUSE_CALLBACK @@ -123,23 +125,19 @@ int main( int argc, char **argv ) (new Producer::KeyboardMouse(ia)) : (new Producer::KeyboardMouse(cg->getCamera(0)->getRenderSurface())); -#if USE_MY_KEYBOARD_MOUSE_CALLBACK - bool done = false; - MyKeyboardMouseCallback kbmcb(done); - kbm->setCallback( &kbmcb ); - kbm->startThread(); -#else + // set up the time and frame counter. + unsigned int frameNumber = 0; + osg::Timer timer; + osg::Timer_t start_tick = timer.tick(); + // set the keyboard mouse callback to catch the events from the windows. bool done = false; ProducerEventCallback kbmcb(done); + kbmcb.setStartTick(start_tick); + + // register the callback with the keyboard mouse manger. kbm->setCallback( &kbmcb ); kbm->startThread(); - -#endif - - Producer::Trackball tb; - tb.setOrientation( Producer::Trackball::Y_UP ); - // set the globa state @@ -152,7 +150,7 @@ int main( int argc, char **argv ) osg::LightSource* lightsource = new osg::LightSource; osg::Light* light = new osg::Light; lightsource->setLight(light); - lightsource->setReferenceFrame(osg::LightSource::RELATIVE_TO_ABSOLUTE); + lightsource->setReferenceFrame(osg::LightSource::RELATIVE_TO_ABSOLUTE); // headlight. lightsource->setLocalStateSetModes(osg::StateAttribute::ON); lightsource->addChild(loadedModel.get()); @@ -173,10 +171,6 @@ int main( int argc, char **argv ) osgUtil::UpdateVisitor update; update.setFrameStamp(frameStamp.get()); - // set up the time and frame counter. - unsigned int frameNumber = 0; - osg::Timer timer; - osg::Timer_t start_tick = timer.tick(); // create a camera to use with the manipulators. @@ -186,18 +180,37 @@ int main( int argc, char **argv ) trackballManipulator->setCamera(old_style_osg_camera.get()); trackballManipulator->setNode(loadedModel.get()); + osg::ref_ptr flightManipulator = new osgGA::FlightManipulator; + flightManipulator->setCamera(old_style_osg_camera.get()); + flightManipulator->setNode(loadedModel.get()); + + osg::ref_ptr driveManipulator = new osgGA::DriveManipulator; + driveManipulator->setCamera(old_style_osg_camera.get()); + driveManipulator->setNode(loadedModel.get()); + + + osg::ref_ptr keyswitchManipulator = new osgGA::KeySwitchCameraManipulator; + keyswitchManipulator->addNumberedCameraManipulator(trackballManipulator.get()); + keyswitchManipulator->addNumberedCameraManipulator(flightManipulator.get()); + keyswitchManipulator->addNumberedCameraManipulator(driveManipulator.get()); + + osg::ref_ptr statesetManipulator = new osgGA::StateSetManipulator; statesetManipulator->setStateSet(globalStateSet.get()); // create an event handler list, we'll dispatch our event to these.. typedef std::list< osg::ref_ptr > EventHandlerList; EventHandlerList eventHandlerList; - eventHandlerList.push_back(trackballManipulator.get()); + eventHandlerList.push_back(keyswitchManipulator.get()); eventHandlerList.push_back(statesetManipulator.get()); // create a dummy action adapter right now. ProducerActionAdapter actionAdapter; + osg::ref_ptr init_event = new ProducerEventAdapter; + init_event->adaptFrame(0.0); + keyswitchManipulator->getCurrentCameraManipulator()->home(*init_event,actionAdapter); + while( !done ) { // syncronize to screen refresh. @@ -208,10 +221,6 @@ int main( int argc, char **argv ) frameStamp->setFrameNumber(frameNumber); frameStamp->setReferenceTime(time_since_start); - // update the trackball - tb.input( kbmcb.mx(), kbmcb.my(), kbmcb.mbutton() ); - - // get the event since the last frame. ProducerEventCallback::EventQueue queue; kbmcb.getEventQueue(queue);