Completed changes to osgManipulator to make it more flexible w.r.t viewer usage, and

ported osgmanipulator example across of osgViewer
This commit is contained in:
Robert Osfield 2007-02-26 13:01:17 +00:00
parent 42689e83ef
commit 7f8f4e331a
15 changed files with 270 additions and 202 deletions

View File

@ -1344,7 +1344,7 @@ Package=<4>
Project_Dep_Name Core osgManipulator Project_Dep_Name Core osgManipulator
End Project Dependency End Project Dependency
Begin Project Dependency Begin Project Dependency
Project_Dep_Name Core osgProducer Project_Dep_Name Core osgViewer
End Project Dependency End Project Dependency
Begin Project Dependency Begin Project Dependency
Project_Dep_Name Core osgText Project_Dep_Name Core osgText

View File

@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Target_Dir "" # PROP Target_Dir ""
MTL=midl.exe MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # 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 BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG" # ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe BSC32=bscmake.exe
@ -51,7 +51,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo # ADD BSC32 /nologo
LINK32=link.exe 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 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" !ELSEIF "$(CFG)" == "Example osgmanipulator - Win32 Debug"
@ -68,7 +68,7 @@ LINK32=link.exe
# PROP Target_Dir "" # PROP Target_Dir ""
MTL=midl.exe MTL=midl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # 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 BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG" # ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe BSC32=bscmake.exe
@ -76,7 +76,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo # ADD BSC32 /nologo
LINK32=link.exe 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 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 # SUBTRACT LINK32 /incremental:no
!ENDIF !ENDIF

View File

@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\ CXXFILES =\
osgmanipulator.cpp\ 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 = \ INSTFILES = \
$(CXXFILES)\ $(CXXFILES)\

View File

@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\ CXXFILES =\
osgmanipulator.cpp\ 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 EXEC = osgmanipulator

View File

@ -1,6 +1,7 @@
// --c++--
#include <osgDB/ReadFile> #include <osgDB/ReadFile>
#include <osgUtil/Optimizer> #include <osgUtil/Optimizer>
#include <osgProducer/Viewer> #include <osgViewer/Viewer>
#include <osg/CoordinateSystemNode> #include <osg/CoordinateSystemNode>
#include <osgText/Text> #include <osgText/Text>
@ -13,6 +14,8 @@
#include <osgManipulator/Translate2DDragger> #include <osgManipulator/Translate2DDragger>
#include <osgManipulator/TranslateAxisDragger> #include <osgManipulator/TranslateAxisDragger>
#include <iostream>
osgManipulator::Dragger* createDragger(const std::string& name) osgManipulator::Dragger* createDragger(const std::string& name)
{ {
osgManipulator::Dragger* dragger = 0; osgManipulator::Dragger* dragger = 0;
@ -99,7 +102,7 @@ osg::Node* createHUD()
return camera; return camera;
} }
#if 0
bool computePixelCoords(osgProducer::Viewer* viewer,float x,float y,unsigned int cameraNum,float& pixel_x,float& pixel_y) bool computePixelCoords(osgProducer::Viewer* viewer,float x,float y,unsigned int cameraNum,float& pixel_x,float& pixel_y)
{ {
Producer::KeyboardMouse* km = viewer->getKeyboardMouse(); Producer::KeyboardMouse* km = viewer->getKeyboardMouse();
@ -150,6 +153,7 @@ bool computePixelCoords(osgProducer::Viewer* viewer,float x,float y,unsigned int
} }
return true; return true;
} }
#endif
osg::Node* addDraggerToScene(osg::Node* scene, osgManipulator::CommandManager* cmdMgr, const std::string& name) osg::Node* addDraggerToScene(osg::Node* scene, osgManipulator::CommandManager* cmdMgr, const std::string& name)
{ {
@ -182,14 +186,18 @@ class PickModeHandler : public osgGA::GUIEventHandler
PICK PICK
}; };
PickModeHandler(osgProducer::Viewer *viewer) : osgGA::GUIEventHandler(), PickModeHandler():
_viewer(viewer), _mode(VIEW), _activeDragger(0) _mode(VIEW),
_activeDragger(0)
{ {
} }
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa,
osg::Object*, osg::NodeVisitor*) osg::Object*, osg::NodeVisitor*)
{ {
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
if (!view) return false;
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_Tab && if (ea.getKey() == osgGA::GUIEventAdapter::KEY_Tab &&
ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN && ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN &&
_activeDragger == 0) _activeDragger == 0)
@ -199,28 +207,27 @@ class PickModeHandler : public osgGA::GUIEventHandler
if (VIEW == _mode) return false; if (VIEW == _mode) return false;
for(unsigned int i=0;i<_viewer->getNumberOfCameras();++i) switch (ea.getEventType())
{ {
case osgGA::GUIEventAdapter::PUSH:
if ((ea.getEventType() == osgGA::GUIEventAdapter::PUSH) &&
_viewer->computeIntersections(ea.getX(), ea.getY(), i, _pointer.hitList))
{ {
float pixel_x,pixel_y; osgUtil::LineSegmentIntersector::Intersections intersections;
if (computePixelCoords(_viewer,ea.getX(),ea.getY(),i,pixel_x,pixel_y))
_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<osgProducer::OsgSceneHandler*>(camera->getSceneHandler()); for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
osgUtil::SceneView* sv = sh ? sh->getSceneView() : 0; hitr != intersections.end();
if (! sv) continue; ++hitr)
{
_pointer.pixel_x = int(pixel_x+0.5); _pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint());
_pointer.pixel_y = int(pixel_y+0.5); }
_pointer.sv = sv; for (osg::NodePath::iterator itr = _pointer._hitList.front().first.begin();
_pointer.hitIter = _pointer.hitList.begin(); itr != _pointer._hitList.front().first.end();
for (osg::NodePath::iterator itr = _pointer.hitList.front().getNodePath().begin();
itr != _pointer.hitList.front().getNodePath().end();
++itr) ++itr)
{ {
osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr); osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr);
@ -234,50 +241,36 @@ class PickModeHandler : public osgGA::GUIEventHandler
} }
} }
} }
case osgGA::GUIEventAdapter::DRAG:
switch (ea.getEventType()) case osgGA::GUIEventAdapter::RELEASE:
{ {
case osgGA::GUIEventAdapter::DRAG: if (_activeDragger)
case osgGA::GUIEventAdapter::RELEASE: {
if (_activeDragger) _pointer._hitIter = _pointer._hitList.begin();
{ _pointer.setCamera(view->getCamera());
float pixel_x,pixel_y; _pointer.setMousePosition(ea.getX(), ea.getY());
if (computePixelCoords(_viewer,ea.getX(),ea.getY(),i,pixel_x,pixel_y))
{
Producer::Camera* camera=_viewer->getCamera(i);
osgProducer::OsgSceneHandler* sh = dynamic_cast<osgProducer::OsgSceneHandler*>(camera->getSceneHandler()); _activeDragger->handle(_pointer, ea, aa);
osgUtil::SceneView* sv = sh ? sh->getSceneView() : 0; }
if (_activeDragger && sv) break;
{
_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();
} }
default:
break;
} }
if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
{
_activeDragger = 0;
_pointer.reset();
}
return true; return true;
} }
private: private:
osgProducer::Viewer* _viewer;
unsigned int _mode; unsigned int _mode;
osgManipulator::Dragger* _activeDragger; osgManipulator::Dragger* _activeDragger;
osgManipulator::Dragger::PointerInfo _pointer; osgManipulator::PointerInfo _pointer;
}; };
int main( int argc, char **argv ) int main( int argc, char **argv )
@ -301,10 +294,7 @@ int main( int argc, char **argv )
// construct the viewer. // construct the viewer.
osgProducer::Viewer viewer(arguments); osgViewer::Viewer viewer;
// set up the value with sensible default event handlers.
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
// get details on keyboard and mouse bindings used by the viewer. // get details on keyboard and mouse bindings used by the viewer.
viewer.getUsage(*arguments.getApplicationUsage()); viewer.getUsage(*arguments.getApplicationUsage());
@ -371,34 +361,8 @@ int main( int argc, char **argv )
// pass the loaded scene graph to the viewer. // pass the loaded scene graph to the viewer.
viewer.setSceneData(addDraggerToScene(loadedModel.get(), cmdMgr.get(), dragger_name)); 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. return viewer.run();
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;
} }

View File

@ -29,6 +29,99 @@ namespace osgManipulator
class CommandManager; class CommandManager;
class CompositeDragger; 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<osg::NodePath, osg::Vec3> 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 * Base class for draggers. Concrete draggers implement the pick event handler
* and generate motion commands (translate, rotate, ...) and sends these * 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. */ /** Returns 0 if this Dragger is not a CompositeDragger. */
virtual CompositeDragger* getComposite() { return 0; } 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<int>(windowCoord.x()), static_cast<int>(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; } virtual bool handle(const PointerInfo&, const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) { return false; }

View File

@ -40,7 +40,7 @@ class OSGMANIPULATOR_EXPORT Projector : public osg::Referenced
* projecting window coordinates into object coordinates and vice versa. * projecting window coordinates into object coordinates and vice versa.
* Returns true on successful projection. * 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 * 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. * coordinate (pointToProject) when projected onto the given line.
* Returns true on successful projection. * 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: protected:
@ -133,7 +133,7 @@ class OSGMANIPULATOR_EXPORT PlaneProjector : public Projector
* coordinate (pointToProject) when projected onto the given plane. * coordinate (pointToProject) when projected onto the given plane.
* Returns true on successful projection. * 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: protected:
@ -161,13 +161,13 @@ class OSGMANIPULATOR_EXPORT SphereProjector : public Projector
* coordinate (pointToProject) when projected onto the given sphere. * coordinate (pointToProject) when projected onto the given sphere.
* Returns true on successful projection. * 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 * Returns true is the point is in front of the cylinder given the eye
* direction. * 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; } void setFront(bool front) { _front = front; }
@ -196,7 +196,7 @@ class OSGMANIPULATOR_EXPORT SpherePlaneProjector : public SphereProjector
* coordinate (pointToProject) when projected onto the given sphere. * coordinate (pointToProject) when projected onto the given sphere.
* Returns true on successful projection. * 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 * 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. * coordinate (pointToProject) when projected onto the given plane.
* Returns true on successful projection. * 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 * Returns true is the point is in front of the cylinder given the eye
* direction. * 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; } void setFront(bool front) { _front = front; }
@ -276,7 +276,7 @@ class OSGMANIPULATOR_EXPORT CylinderPlaneProjector : public CylinderProjector
* coordinate (pointToProject) when projected onto the given plane. * coordinate (pointToProject) when projected onto the given plane.
* Returns true on successful projection. * 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 * Returns true if the previous projection was on the cylinder and

View File

@ -301,6 +301,23 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
bool DriveManipulator::handle(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()) switch(ea.getEventType())
{ {
case(GUIEventAdapter::PUSH): case(GUIEventAdapter::PUSH):
@ -399,22 +416,6 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
return false; 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: default:
return false; return false;
} }

View File

@ -91,6 +91,23 @@ void FlightManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
bool FlightManipulator::handle(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()) switch(ea.getEventType())
{ {
case(GUIEventAdapter::PUSH): case(GUIEventAdapter::PUSH):
@ -152,15 +169,6 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
} }
return false; return false;
} }
case(GUIEventAdapter::FRAME):
addMouseEvent(ea);
if (calcMovement()) us.requestRedraw();
return false;
case(GUIEventAdapter::RESIZE):
init(ea,us);
us.requestRedraw();
return true;
default: default:
return false; return false;

View File

@ -74,6 +74,20 @@ void TrackballManipulator::getUsage(osg::ApplicationUsage& usage) const
bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) 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()) switch(ea.getEventType())
{ {
case(GUIEventAdapter::PUSH): case(GUIEventAdapter::PUSH):
@ -155,6 +169,7 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us
default: default:
return false; return false;
} }
return false;
} }

View File

@ -189,6 +189,16 @@ void UFOManipulator::home(double)
bool UFOManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter &aa) 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()) switch(ea.getEventType())
{ {

View File

@ -17,6 +17,34 @@
using namespace osgManipulator; 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) Dragger::Dragger() : _commandManager(0)
{ {
_parentDragger = this; _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) bool CompositeDragger::handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{ {

View File

@ -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()) if (!_line->valid())
{ {
@ -257,8 +257,8 @@ bool LineProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projected
// Project the objectLine onto the window. // Project the objectLine onto the window.
osg::ref_ptr<osg::LineSegment> windowLine = new osg::LineSegment; osg::ref_ptr<osg::LineSegment> windowLine = new osg::LineSegment;
pi.sv->projectObjectIntoWindow(objectLine->start(), windowLine->start()); pi.projectObjectIntoWindow(objectLine->start(), windowLine->start());
pi.sv->projectObjectIntoWindow(objectLine->end(), windowLine->end()); pi.projectObjectIntoWindow(objectLine->end(), windowLine->end());
windowLine->start().z() = windowLine->end().z() = 0.0f; 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()) 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()) if (!_sphere->valid())
{ {
@ -364,10 +364,10 @@ bool SphereProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& project
return getSphereLineIntersection(*_sphere, objectNearPoint, objectFarPoint, dontCare, projectedPoint); 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(); 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 false;
return true; 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()) 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()) if (!_cylinder.valid())
{ {
@ -547,7 +547,7 @@ bool CylinderProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& proje
return getCylinderLineIntersection(*_cylinder, objectNearPoint, objectFarPoint, projectedPoint, dontCare); 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; osg::Vec3 closestPointOnAxis;
computeClosestPointOnLine(getCylinder()->getCenter(), getCylinder()->getCenter() + _cylinderAxis, 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()) if (!_cylinder.valid())
{ {

View File

@ -1052,17 +1052,17 @@ void CompositeViewer::eventTraversal()
{ {
osgGA::GUIEventAdapter* event = itr->get(); 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(); for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin();
hitr != view->getEventHandlers().end(); hitr != view->getEventHandlers().end();
++hitr) ++hitr)
{ {
if ((*hitr)->handle( *event, *view, 0, 0)) event->setHandled(true); if ((*hitr)->handle( *event, *view, 0, 0)) event->setHandled(true);
} }
if (view->getCameraManipulator())
{
if (view->getCameraManipulator()->handle( *event, *view)) event->setHandled(true);
}
} }
} }

View File

@ -1956,17 +1956,18 @@ void Viewer::eventTraversal()
{ {
osgGA::GUIEventAdapter* event = itr->get(); osgGA::GUIEventAdapter* event = itr->get();
if (_cameraManipulator.valid())
{
if (_cameraManipulator->handle( *event, *this)) event->setHandled(true);
}
for(EventHandlers::iterator hitr = _eventHandlers.begin(); for(EventHandlers::iterator hitr = _eventHandlers.begin();
hitr != _eventHandlers.end(); hitr != _eventHandlers.end();
++hitr) ++hitr)
{ {
if ((*hitr)->handle( *event, *this, 0, 0)) event->setHandled(true); 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()) if (_eventVisitor.valid() && _scene.valid())