From cac6642de5da2b6dedefe263656e82e4a2d317fe Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 5 Apr 2003 07:19:40 +0000 Subject: [PATCH] Improvements to the handling of warp pointer call on start up. --- examples/osghangglide/GliderManipulator.cpp | 18 +++++++++--------- include/osgProducer/KeyboardMouseCallback | 3 ++- src/osgProducer/Viewer.cpp | 19 +++---------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/examples/osghangglide/GliderManipulator.cpp b/examples/osghangglide/GliderManipulator.cpp index e15f5734d..ec1b77e35 100644 --- a/examples/osghangglide/GliderManipulator.cpp +++ b/examples/osghangglide/GliderManipulator.cpp @@ -52,7 +52,7 @@ void GliderManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) us.requestRedraw(); - us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2); + us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f); flushMouseEventStack(); @@ -70,7 +70,10 @@ void GliderManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) const osg::BoundingSphere& boundingSphere=_node->getBound(); _velocity = boundingSphere._radius*0.01f; - us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2); + if (ea.getEventType()!=GUIEventAdapter::RESIZE) + { + us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f); + } } @@ -207,18 +210,15 @@ bool GliderManipulator::calcMovement() } - float mx = (_ga_t0->getXmin()+_ga_t0->getXmax())/2.0f; - float my = (_ga_t0->getYmin()+_ga_t0->getYmax())/2.0f; - - float dx = _ga_t0->getX()-mx; - float dy = _ga_t0->getY()-my; + float dx = _ga_t0->getXnormalized(); + float dy = _ga_t0->getYnormalized(); osg::Vec3 center = _camera->getEyePoint(); osg::Vec3 sv = _camera->getSideVector(); osg::Vec3 lv = _camera->getLookVector(); - float pitch = inDegrees(dy*0.15f*dt); - float roll = inDegrees(dx*0.1f*dt); + float pitch = inDegrees(dy*70.0f*dt); + float roll = inDegrees(dx*60.0f*dt); osg::Matrix mat; mat.makeTranslate(-center); diff --git a/include/osgProducer/KeyboardMouseCallback b/include/osgProducer/KeyboardMouseCallback index 3a2fb3eef..310315548 100644 --- a/include/osgProducer/KeyboardMouseCallback +++ b/include/osgProducer/KeyboardMouseCallback @@ -76,9 +76,10 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC Producer::KeyboardMouse* getKeyboardMouse() { return _keyboardMouse; } const Producer::KeyboardMouse* getKeyboardMouse() const { return _keyboardMouse; } + EventAdapter* createEventAdapter(); + protected: - EventAdapter* createEventAdapter(); Producer::KeyboardMouse* _keyboardMouse; float _mx, _my; diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 94f3d9d91..e93d8cd62 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -132,8 +132,8 @@ void Viewer::setUpViewer(unsigned int options) _old_style_osg_camera = new osg::Camera; if (options&TRACKBALL_MANIPULATOR) addCameraManipulator(new osgGA::TrackballManipulator); - if (options&FLIGHT_MANIPULATOR) addCameraManipulator(new osgGA::FlightManipulator); if (options&DRIVE_MANIPULATOR) addCameraManipulator(new osgGA::DriveManipulator); + if (options&FLIGHT_MANIPULATOR) addCameraManipulator(new osgGA::FlightManipulator); if (options&STATE_MANIPULATOR) { @@ -141,20 +141,7 @@ void Viewer::setUpViewer(unsigned int options) statesetManipulator->setStateSet(getGlobalStateSet()); _eventHandlerList.push_back(statesetManipulator.get()); } - -// if (options&STATS_MANIPULATOR) -// { -// // register the drawing of stats to pipe 0. -// FrameStatsHandler* fsh = new FrameStatsHandler; -// setStatsHandler(fsh); -// getCamera(0)->addPostDrawCallback(fsh); -// -// // register the event handler for stats. -// getEventHandlerList().push_back(new StatsEventHandler(this)); -// -// -// } - + if (options&VIEWER_MANIPULATOR) { getEventHandlerList().push_back(new ViewerEventHandler(this)); @@ -192,7 +179,7 @@ void Viewer::realize( ThreadingModel thread_model) if (_keyswitchManipulator.valid() && _keyswitchManipulator->getCurrentCameraManipulator()) { - osg::ref_ptr init_event = new osgProducer::EventAdapter; + osg::ref_ptr init_event = _kbmcb->createEventAdapter(); init_event->adaptFrame(0.0); _keyswitchManipulator->setCamera(_old_style_osg_camera.get());