diff --git a/VisualStudio/OpenSceneGraph.dsw b/VisualStudio/OpenSceneGraph.dsw index 444b138b3..b06927ed1 100644 --- a/VisualStudio/OpenSceneGraph.dsw +++ b/VisualStudio/OpenSceneGraph.dsw @@ -1344,7 +1344,7 @@ Package=<4> Project_Dep_Name Core osgManipulator End Project Dependency Begin Project Dependency - Project_Dep_Name Core osgProducer + Project_Dep_Name Core osgViewer End Project Dependency Begin Project Dependency Project_Dep_Name Core osgText diff --git a/VisualStudio/examples/osgmanipulator/osgmanipulatordemo.dsp b/VisualStudio/examples/osgmanipulator/osgmanipulatordemo.dsp index 2e9e59d7a..6ad1b8418 100644 --- a/VisualStudio/examples/osgmanipulator/osgmanipulatordemo.dsp +++ b/VisualStudio/examples/osgmanipulator/osgmanipulatordemo.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Target_Dir "" MTL=midl.exe # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /Zm200 /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /Zm200 /c # ADD BASE RSC /l 0x809 /d "NDEBUG" # ADD RSC /l 0x809 /d "NDEBUG" BSC32=bscmake.exe @@ -51,7 +51,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 OpenThreadsWin32.lib Producer.lib /nologo /subsystem:console /debug /machine:I386 /opt:ref /opt:icf /out:"$(OutDir)/osgmanipulator.exe" /libpath:"../../../lib/$(PlatformName)" /libpath:"../../../../OpenThreads/lib/$(PlatformName)" /libpath:"../../../../Producer/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib" +# ADD LINK32 OpenThreadsWin32.lib /nologo /subsystem:console /debug /machine:I386 /opt:ref /opt:icf /out:"$(OutDir)/osgmanipulator.exe" /libpath:"../../../lib/$(PlatformName)" /libpath:"../../../../OpenThreads/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib" !ELSEIF "$(CFG)" == "Example osgmanipulator - Win32 Debug" @@ -68,7 +68,7 @@ LINK32=link.exe # PROP Target_Dir "" MTL=midl.exe # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /FR /YX /FD /Zm200 /c +# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /FR /YX /FD /Zm200 /c # ADD BASE RSC /l 0x809 /d "_DEBUG" # ADD RSC /l 0x809 /d "_DEBUG" BSC32=bscmake.exe @@ -76,7 +76,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 OpenThreadsWin32d.lib Producerd.lib glu32.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"$(OutDir)/osgmanipulatord.exe" /pdbtype:sept /libpath:"../../../lib/$(PlatformName)" /libpath:"../../../../OpenThreads/lib/$(PlatformName)" /libpath:"../../../../Producer/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib" +# ADD LINK32 OpenThreadsWin32d.lib glu32.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"$(OutDir)/osgmanipulatord.exe" /pdbtype:sept /libpath:"../../../lib/$(PlatformName)" /libpath:"../../../../OpenThreads/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib" # SUBTRACT LINK32 /incremental:no !ENDIF diff --git a/examples/osgmanipulator/GNUmakefile b/examples/osgmanipulator/GNUmakefile index 045b385b8..131042f2e 100644 --- a/examples/osgmanipulator/GNUmakefile +++ b/examples/osgmanipulator/GNUmakefile @@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs CXXFILES =\ osgmanipulator.cpp\ -LIBS += -losgProducer -lProducer -losgManipulator -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) +LIBS += -losgViewer -losgManipulator -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) INSTFILES = \ $(CXXFILES)\ diff --git a/examples/osgmanipulator/GNUmakefile.inst b/examples/osgmanipulator/GNUmakefile.inst index d6d08a661..d710eeb1f 100644 --- a/examples/osgmanipulator/GNUmakefile.inst +++ b/examples/osgmanipulator/GNUmakefile.inst @@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs CXXFILES =\ osgmanipulator.cpp\ -LIBS += -losgProducer -lProducer -losgManipulator -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) +LIBS += -losgViewer -losgManipulator -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) EXEC = osgmanipulator diff --git a/examples/osgmanipulator/osgmanipulator.cpp b/examples/osgmanipulator/osgmanipulator.cpp index 507eb6d22..d2446682e 100644 --- a/examples/osgmanipulator/osgmanipulator.cpp +++ b/examples/osgmanipulator/osgmanipulator.cpp @@ -1,6 +1,7 @@ +// --c++-- #include #include -#include +#include #include #include @@ -13,6 +14,8 @@ #include #include +#include + osgManipulator::Dragger* createDragger(const std::string& name) { osgManipulator::Dragger* dragger = 0; @@ -99,7 +102,7 @@ osg::Node* createHUD() return camera; } - +#if 0 bool computePixelCoords(osgProducer::Viewer* viewer,float x,float y,unsigned int cameraNum,float& pixel_x,float& pixel_y) { Producer::KeyboardMouse* km = viewer->getKeyboardMouse(); @@ -150,6 +153,7 @@ bool computePixelCoords(osgProducer::Viewer* viewer,float x,float y,unsigned int } return true; } +#endif osg::Node* addDraggerToScene(osg::Node* scene, osgManipulator::CommandManager* cmdMgr, const std::string& name) { @@ -182,14 +186,18 @@ class PickModeHandler : public osgGA::GUIEventHandler PICK }; - PickModeHandler(osgProducer::Viewer *viewer) : osgGA::GUIEventHandler(), - _viewer(viewer), _mode(VIEW), _activeDragger(0) + PickModeHandler(): + _mode(VIEW), + _activeDragger(0) { } bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) { + osgViewer::View* view = dynamic_cast(&aa); + if (!view) return false; + if (ea.getKey() == osgGA::GUIEventAdapter::KEY_Tab && ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN && _activeDragger == 0) @@ -199,28 +207,27 @@ class PickModeHandler : public osgGA::GUIEventHandler if (VIEW == _mode) return false; - for(unsigned int i=0;i<_viewer->getNumberOfCameras();++i) + switch (ea.getEventType()) { - - if ((ea.getEventType() == osgGA::GUIEventAdapter::PUSH) && - _viewer->computeIntersections(ea.getX(), ea.getY(), i, _pointer.hitList)) + case osgGA::GUIEventAdapter::PUSH: { - float pixel_x,pixel_y; - if (computePixelCoords(_viewer,ea.getX(),ea.getY(),i,pixel_x,pixel_y)) + osgUtil::LineSegmentIntersector::Intersections intersections; + + _pointer.reset(); + + if (view->computeIntersections(ea.getX(),ea.getY(),intersections)) { - Producer::Camera* camera=_viewer->getCamera(i); + _pointer.setCamera(view->getCamera()); + _pointer.setMousePosition(ea.getX(), ea.getY()); - osgProducer::OsgSceneHandler* sh = dynamic_cast(camera->getSceneHandler()); - osgUtil::SceneView* sv = sh ? sh->getSceneView() : 0; - if (! sv) continue; - - _pointer.pixel_x = int(pixel_x+0.5); - _pointer.pixel_y = int(pixel_y+0.5); - _pointer.sv = sv; - _pointer.hitIter = _pointer.hitList.begin(); - - for (osg::NodePath::iterator itr = _pointer.hitList.front().getNodePath().begin(); - itr != _pointer.hitList.front().getNodePath().end(); + for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); + hitr != intersections.end(); + ++hitr) + { + _pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint()); + } + for (osg::NodePath::iterator itr = _pointer._hitList.front().first.begin(); + itr != _pointer._hitList.front().first.end(); ++itr) { osgManipulator::Dragger* dragger = dynamic_cast(*itr); @@ -234,50 +241,36 @@ class PickModeHandler : public osgGA::GUIEventHandler } } } - - switch (ea.getEventType()) + case osgGA::GUIEventAdapter::DRAG: + case osgGA::GUIEventAdapter::RELEASE: { - case osgGA::GUIEventAdapter::DRAG: - case osgGA::GUIEventAdapter::RELEASE: - if (_activeDragger) - { - float pixel_x,pixel_y; - if (computePixelCoords(_viewer,ea.getX(),ea.getY(),i,pixel_x,pixel_y)) - { - Producer::Camera* camera=_viewer->getCamera(i); + if (_activeDragger) + { + _pointer._hitIter = _pointer._hitList.begin(); + _pointer.setCamera(view->getCamera()); + _pointer.setMousePosition(ea.getX(), ea.getY()); - osgProducer::OsgSceneHandler* sh = dynamic_cast(camera->getSceneHandler()); - osgUtil::SceneView* sv = sh ? sh->getSceneView() : 0; - if (_activeDragger && sv) - { - _pointer.pixel_x = int(pixel_x+0.5); - _pointer.pixel_y = int(pixel_y+0.5); - _pointer.sv = sv; - _pointer.hitIter = _pointer.hitList.begin(); - - _activeDragger->handle(_pointer, ea, aa); - } - } - } - break; - - default: - break; - } - if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE) - { - _activeDragger = 0; - _pointer.hitList.clear(); + _activeDragger->handle(_pointer, ea, aa); + } + break; } + default: + break; } + + if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE) + { + _activeDragger = 0; + _pointer.reset(); + } + return true; } private: - osgProducer::Viewer* _viewer; unsigned int _mode; osgManipulator::Dragger* _activeDragger; - osgManipulator::Dragger::PointerInfo _pointer; + osgManipulator::PointerInfo _pointer; }; int main( int argc, char **argv ) @@ -301,10 +294,7 @@ int main( int argc, char **argv ) // construct the viewer. - osgProducer::Viewer viewer(arguments); - - // set up the value with sensible default event handlers. - viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); + osgViewer::Viewer viewer; // get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(*arguments.getApplicationUsage()); @@ -371,34 +361,8 @@ int main( int argc, char **argv ) // pass the loaded scene graph to the viewer. viewer.setSceneData(addDraggerToScene(loadedModel.get(), cmdMgr.get(), dragger_name)); - viewer.getEventHandlerList().push_front(new PickModeHandler(&viewer)); + viewer.addEventHandler(new PickModeHandler()); - // create the windows and run the threads. - viewer.realize(); - - while( !viewer.done() ) - { - // wait for all cull and draw threads to complete. - viewer.sync(); - - // update the scene by traversing it with the the update visitor which will - // call all node update callbacks and animations. - viewer.update(); - - // fire off the cull and draw traversals of the scene. - viewer.frame(); - - } - - // wait for all cull and draw threads to complete. - viewer.sync(); - - // run a clean up frame to delete all OpenGL objects. - viewer.cleanup_frame(); - - // wait for all the clean up frame to complete. - viewer.sync(); - - return 0; + return viewer.run(); } diff --git a/include/osgManipulator/Dragger b/include/osgManipulator/Dragger index c0266a452..98143aec2 100644 --- a/include/osgManipulator/Dragger +++ b/include/osgManipulator/Dragger @@ -29,6 +29,99 @@ namespace osgManipulator class CommandManager; class CompositeDragger; +class OSGMANIPULATOR_EXPORT PointerInfo +{ + public: + + PointerInfo(); + + PointerInfo(const PointerInfo& rhs): + _pixel_x(rhs._pixel_x), + _pixel_y(rhs._pixel_y), + _camera(rhs._camera), + _hitList(rhs._hitList) + { + _hitIter = _hitList.begin(); + } + + void reset() + { + _hitList.clear(); + _hitIter = _hitList.begin(); + setCamera(0); + } + + + bool completed() const { return _hitIter==_hitList.end(); } + + void next() + { + if (!completed()) ++_hitIter; + } + + typedef std::pair NodePathIntersectionPair; + typedef std::list< NodePathIntersectionPair> IntersectionList; + + + osg::Vec2 pointToProject() const { return osg::Vec2(_pixel_x, _pixel_y); } + osg::Vec3 getLocalIntersectPoint() const { return _hitIter->second; } + + bool projectWindowXYIntoObject(const osg::Vec2& windowCoord, osg::Vec3& nearPoint, osg::Vec3& farPoint) const; + + bool projectWindowXYIntoObject(osg::Vec3& nearPoint, osg::Vec3& farPoint) const + { + return projectWindowXYIntoObject(pointToProject(), nearPoint, farPoint); + } + + bool projectObjectIntoWindow(const osg::Vec3& object,osg::Vec3& window) const; + + const osg::Matrix& getViewMatrix() const { return _camera->getViewMatrix(); } + + bool contains(const osg::Node* node) const; + + void setCamera(osg::Camera* camera) + { + _camera = camera; + if (_camera) + { + _MVPW = _camera->getViewMatrix() * _camera->getProjectionMatrix(); + if (_camera->getViewport()) _MVPW.postMult(_camera->getViewport()->computeWindowMatrix()); + _inverseMVPW.invert(_MVPW); + } + else + { + _MVPW.makeIdentity(); + _inverseMVPW.makeIdentity(); + } + + } + + void addIntersection(const osg::NodePath& nodePath, osg::Vec3 intersectionPoint) + { + bool needToResetHitIter = _hitList.empty(); + _hitList.push_back(NodePathIntersectionPair(nodePath, intersectionPoint)); + if (needToResetHitIter) _hitIter = _hitList.begin(); + } + + void setMousePosition(int pixel_x, int pixel_y) + { + _pixel_x = pixel_x; + _pixel_y = pixel_y; + } + + public: + + int _pixel_x, _pixel_y; + osg::Camera* _camera; + + IntersectionList _hitList; + IntersectionList::iterator _hitIter; + + osg::Matrix _MVPW; + osg::Matrix _inverseMVPW; + +}; + /** * Base class for draggers. Concrete draggers implement the pick event handler * and generate motion commands (translate, rotate, ...) and sends these @@ -59,45 +152,7 @@ class OSGMANIPULATOR_EXPORT Dragger : public Selection /** Returns 0 if this Dragger is not a CompositeDragger. */ virtual CompositeDragger* getComposite() { return 0; } - - struct OSGMANIPULATOR_EXPORT PointerInfo - { - PointerInfo(); - PointerInfo(const PointerInfo& rhs): - pixel_x(rhs.pixel_x), - pixel_y(rhs.pixel_y), - sv(rhs.sv), - hitList(rhs.hitList) - { - hitIter = hitList.begin(); - } - - - bool completed() const { return hitIter==hitList.end(); } - - void next() - { - if (!completed()) ++hitIter; - } - - int pixel_x, pixel_y; - osgUtil::SceneView* sv; - osgUtil::IntersectVisitor::HitList hitList; - osgUtil::IntersectVisitor::HitList::iterator hitIter; - - osg::Vec2 pointToProject() const { return osg::Vec2(pixel_x, pixel_y); } - osg::Vec3 getLocalIntersectPoint() const { return hitIter->getLocalIntersectPoint(); } - - bool projectWindowXYIntoObject(const osg::Vec2& windowCoord, osg::Vec3& nearPoint, osg::Vec3& farPoint) const { return sv->projectWindowXYIntoObject(static_cast(windowCoord.x()), static_cast(windowCoord.y()), nearPoint, farPoint); } - bool projectWindowXYIntoObject(osg::Vec3& nearPoint, osg::Vec3& farPoint) const { return sv->projectWindowXYIntoObject(pixel_x, pixel_y, nearPoint, farPoint); } - - const osg::Matrix& getViewMatrix() const { return sv->getViewMatrix(); } - - - bool contains(const osg::Node* node) const; - - }; virtual bool handle(const PointerInfo&, const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) { return false; } diff --git a/include/osgManipulator/Projector b/include/osgManipulator/Projector index 92456ff7f..15a0d1c14 100644 --- a/include/osgManipulator/Projector +++ b/include/osgManipulator/Projector @@ -40,7 +40,7 @@ class OSGMANIPULATOR_EXPORT Projector : public osg::Referenced * projecting window coordinates into object coordinates and vice versa. * Returns true on successful projection. */ - virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const = 0; + virtual bool project(const PointerInfo& pi, osg::Vec3& projectedPoint) const = 0; /** * Sets the matrix for transforming the projector's local coordinate @@ -105,7 +105,7 @@ class OSGMANIPULATOR_EXPORT LineProjector : public Projector * coordinate (pointToProject) when projected onto the given line. * Returns true on successful projection. */ - virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const; + virtual bool project(const PointerInfo& pi, osg::Vec3& projectedPoint) const; protected: @@ -133,7 +133,7 @@ class OSGMANIPULATOR_EXPORT PlaneProjector : public Projector * coordinate (pointToProject) when projected onto the given plane. * Returns true on successful projection. */ - virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const; + virtual bool project(const PointerInfo& pi, osg::Vec3& projectedPoint) const; protected: @@ -161,13 +161,13 @@ class OSGMANIPULATOR_EXPORT SphereProjector : public Projector * coordinate (pointToProject) when projected onto the given sphere. * Returns true on successful projection. */ - virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const; + virtual bool project(const PointerInfo& pi, osg::Vec3& projectedPoint) const; /** * Returns true is the point is in front of the cylinder given the eye * direction. */ - bool isPointInFront(const Dragger::PointerInfo& pi, const osg::Matrix& localToWorld) const; + bool isPointInFront(const PointerInfo& pi, const osg::Matrix& localToWorld) const; void setFront(bool front) { _front = front; } @@ -196,7 +196,7 @@ class OSGMANIPULATOR_EXPORT SpherePlaneProjector : public SphereProjector * coordinate (pointToProject) when projected onto the given sphere. * Returns true on successful projection. */ - virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const; + virtual bool project(const PointerInfo& pi, osg::Vec3& projectedPoint) const; /** * Returns true if the previous projection was on the sphere and false @@ -240,14 +240,14 @@ class OSGMANIPULATOR_EXPORT CylinderProjector : public Projector * coordinate (pointToProject) when projected onto the given plane. * Returns true on successful projection. */ - virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const; + virtual bool project(const PointerInfo& pi, osg::Vec3& projectedPoint) const; /** * Returns true is the point is in front of the cylinder given the eye * direction. */ - bool isPointInFront(const Dragger::PointerInfo& pi, const osg::Matrix& localToWorld) const; + bool isPointInFront(const PointerInfo& pi, const osg::Matrix& localToWorld) const; void setFront(bool front) { _front = front; } @@ -276,7 +276,7 @@ class OSGMANIPULATOR_EXPORT CylinderPlaneProjector : public CylinderProjector * coordinate (pointToProject) when projected onto the given plane. * Returns true on successful projection. */ - virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const; + virtual bool project(const PointerInfo& pi, osg::Vec3& projectedPoint) const; /** * Returns true if the previous projection was on the cylinder and diff --git a/src/osgGA/DriveManipulator.cpp b/src/osgGA/DriveManipulator.cpp index 5c51096c9..d33ca6f75 100644 --- a/src/osgGA/DriveManipulator.cpp +++ b/src/osgGA/DriveManipulator.cpp @@ -301,6 +301,23 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) { + switch(ea.getEventType()) + { + case(GUIEventAdapter::FRAME): + addMouseEvent(ea); + if (calcMovement()) us.requestRedraw(); + return false; + + case(GUIEventAdapter::RESIZE): + init(ea,us); + us.requestRedraw(); + return true; + default: + break; + } + + if (ea.getHandled()) return false; + switch(ea.getEventType()) { case(GUIEventAdapter::PUSH): @@ -399,22 +416,6 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) return false; } - _pitchDownKeyPressed = false; - - case(GUIEventAdapter::FRAME): - { - addMouseEvent(ea); - if (calcMovement()) us.requestRedraw(); - return false; - } - - case(GUIEventAdapter::RESIZE): - { - init(ea,us); - us.requestRedraw(); - return true; - } - default: return false; } diff --git a/src/osgGA/FlightManipulator.cpp b/src/osgGA/FlightManipulator.cpp index 4e9b496b1..530633cd2 100644 --- a/src/osgGA/FlightManipulator.cpp +++ b/src/osgGA/FlightManipulator.cpp @@ -91,6 +91,23 @@ void FlightManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) { + switch(ea.getEventType()) + { + case(GUIEventAdapter::FRAME): + addMouseEvent(ea); + if (calcMovement()) us.requestRedraw(); + return false; + + case(GUIEventAdapter::RESIZE): + init(ea,us); + us.requestRedraw(); + return true; + default: + break; + } + + if (ea.getHandled()) return false; + switch(ea.getEventType()) { case(GUIEventAdapter::PUSH): @@ -152,15 +169,6 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) } return false; } - case(GUIEventAdapter::FRAME): - addMouseEvent(ea); - if (calcMovement()) us.requestRedraw(); - return false; - - case(GUIEventAdapter::RESIZE): - init(ea,us); - us.requestRedraw(); - return true; default: return false; diff --git a/src/osgGA/TrackballManipulator.cpp b/src/osgGA/TrackballManipulator.cpp index 0f7850455..dae602374 100644 --- a/src/osgGA/TrackballManipulator.cpp +++ b/src/osgGA/TrackballManipulator.cpp @@ -74,6 +74,20 @@ void TrackballManipulator::getUsage(osg::ApplicationUsage& usage) const bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) { + switch(ea.getEventType()) + { + case(GUIEventAdapter::FRAME): + if (_thrown) + { + if (calcMovement()) us.requestRedraw(); + } + return false; + default: + break; + } + + if (ea.getHandled()) return false; + switch(ea.getEventType()) { case(GUIEventAdapter::PUSH): @@ -155,6 +169,7 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us default: return false; } + return false; } diff --git a/src/osgGA/UFOManipulator.cpp b/src/osgGA/UFOManipulator.cpp index 9e5ffc0e2..4364f8765 100644 --- a/src/osgGA/UFOManipulator.cpp +++ b/src/osgGA/UFOManipulator.cpp @@ -189,6 +189,16 @@ void UFOManipulator::home(double) bool UFOManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter &aa) { + switch(ea.getEventType()) + { + case(osgGA::GUIEventAdapter::FRAME): + _frame(ea,aa); + return false; + default: + break; + } + + if (ea.getHandled()) return false; switch(ea.getEventType()) { diff --git a/src/osgManipulator/Dragger.cpp b/src/osgManipulator/Dragger.cpp index d1d907829..cd4c21374 100644 --- a/src/osgManipulator/Dragger.cpp +++ b/src/osgManipulator/Dragger.cpp @@ -17,6 +17,34 @@ using namespace osgManipulator; +PointerInfo::PointerInfo(): + _pixel_x(0), + _pixel_y(0), + _camera(0) +{ + _hitIter = _hitList.begin(); +} + +bool PointerInfo::contains(const osg::Node* node) const +{ + if (node && _hitIter!=_hitList.end()) return std::find((*_hitIter).first.begin(), (*_hitIter).first.end(), node) != (*_hitIter).first.end(); + else return false; +} + +bool PointerInfo::projectWindowXYIntoObject(const osg::Vec2& windowCoord, osg::Vec3& nearPoint, osg::Vec3& farPoint) const +{ + nearPoint = osg::Vec3(windowCoord.x(),windowCoord.y(),0.0f)*_inverseMVPW; + farPoint = osg::Vec3(windowCoord.x(),windowCoord.y(),1.0f)*_inverseMVPW; + + return true; +} + +bool PointerInfo::projectObjectIntoWindow(const osg::Vec3& object,osg::Vec3& window) const +{ + window = object * _MVPW; + return true; +} + Dragger::Dragger() : _commandManager(0) { _parentDragger = this; @@ -26,20 +54,6 @@ Dragger::~Dragger() { } -Dragger::PointerInfo::PointerInfo(): - pixel_x(0), - pixel_y(0), - sv(0) -{ - hitIter = hitList.begin(); -} - -bool Dragger::PointerInfo::contains(const osg::Node* node) const -{ - if (node) return std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), node) != (*hitIter)._nodePath.end(); - else return false; -} - bool CompositeDragger::handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { diff --git a/src/osgManipulator/Projector.cpp b/src/osgManipulator/Projector.cpp index 37a135721..c7f1513ad 100644 --- a/src/osgManipulator/Projector.cpp +++ b/src/osgManipulator/Projector.cpp @@ -243,7 +243,7 @@ LineProjector::~LineProjector() { } -bool LineProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const +bool LineProjector::project(const PointerInfo& pi, osg::Vec3& projectedPoint) const { if (!_line->valid()) { @@ -257,8 +257,8 @@ bool LineProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projected // Project the objectLine onto the window. osg::ref_ptr windowLine = new osg::LineSegment; - pi.sv->projectObjectIntoWindow(objectLine->start(), windowLine->start()); - pi.sv->projectObjectIntoWindow(objectLine->end(), windowLine->end()); + pi.projectObjectIntoWindow(objectLine->start(), windowLine->start()); + pi.projectObjectIntoWindow(objectLine->end(), windowLine->end()); windowLine->start().z() = windowLine->end().z() = 0.0f; @@ -305,7 +305,7 @@ PlaneProjector::~PlaneProjector() { } -bool PlaneProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const +bool PlaneProjector::project(const PointerInfo& pi, osg::Vec3& projectedPoint) const { if (!_plane.valid()) { @@ -340,7 +340,7 @@ SphereProjector::~SphereProjector() { } -bool SphereProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const +bool SphereProjector::project(const PointerInfo& pi, osg::Vec3& projectedPoint) const { if (!_sphere->valid()) { @@ -364,10 +364,10 @@ bool SphereProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& project return getSphereLineIntersection(*_sphere, objectNearPoint, objectFarPoint, dontCare, projectedPoint); } -bool SphereProjector::isPointInFront(const Dragger::PointerInfo& pi, const osg::Matrix& localToWorld) const +bool SphereProjector::isPointInFront(const PointerInfo& pi, const osg::Matrix& localToWorld) const { osg::Vec3 centerToPoint = getSphere()->getCenter() - pi.getLocalIntersectPoint(); - if (centerToPoint * getEyeDirection(pi.sv->getViewMatrix(), localToWorld) < 0.0) + if (centerToPoint * getEyeDirection(pi.getViewMatrix(), localToWorld) < 0.0) return false; return true; } @@ -449,7 +449,7 @@ osg::Quat SpherePlaneProjector::getRotation(const osg::Vec3& p1, bool p1OnSphere } } -bool SpherePlaneProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const +bool SpherePlaneProjector::project(const PointerInfo& pi, osg::Vec3& projectedPoint) const { if (!_sphere->valid()) { @@ -524,7 +524,7 @@ CylinderProjector::~CylinderProjector() { } -bool CylinderProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const +bool CylinderProjector::project(const PointerInfo& pi, osg::Vec3& projectedPoint) const { if (!_cylinder.valid()) { @@ -547,7 +547,7 @@ bool CylinderProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& proje return getCylinderLineIntersection(*_cylinder, objectNearPoint, objectFarPoint, projectedPoint, dontCare); } -bool CylinderProjector::isPointInFront(const Dragger::PointerInfo& pi, const osg::Matrix& localToWorld) const +bool CylinderProjector::isPointInFront(const PointerInfo& pi, const osg::Matrix& localToWorld) const { osg::Vec3 closestPointOnAxis; computeClosestPointOnLine(getCylinder()->getCenter(), getCylinder()->getCenter() + _cylinderAxis, @@ -571,7 +571,7 @@ CylinderPlaneProjector::~CylinderPlaneProjector() { } -bool CylinderPlaneProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const +bool CylinderPlaneProjector::project(const PointerInfo& pi, osg::Vec3& projectedPoint) const { if (!_cylinder.valid()) { diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index 63cae213d..696a76923 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -1052,17 +1052,17 @@ void CompositeViewer::eventTraversal() { osgGA::GUIEventAdapter* event = itr->get(); - if (view->getCameraManipulator()) - { - if (view->getCameraManipulator()->handle( *event, *view)) event->setHandled(true); - } - for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin(); hitr != view->getEventHandlers().end(); ++hitr) { if ((*hitr)->handle( *event, *view, 0, 0)) event->setHandled(true); } + + if (view->getCameraManipulator()) + { + if (view->getCameraManipulator()->handle( *event, *view)) event->setHandled(true); + } } } diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 4d1e28c81..055726c03 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -1956,17 +1956,18 @@ void Viewer::eventTraversal() { osgGA::GUIEventAdapter* event = itr->get(); - if (_cameraManipulator.valid()) - { - if (_cameraManipulator->handle( *event, *this)) event->setHandled(true); - } - for(EventHandlers::iterator hitr = _eventHandlers.begin(); hitr != _eventHandlers.end(); ++hitr) { if ((*hitr)->handle( *event, *this, 0, 0)) event->setHandled(true); } + + if (_cameraManipulator.valid()) + { + if (_cameraManipulator->handle( *event, *this)) event->setHandled(true); + } + } if (_eventVisitor.valid() && _scene.valid())