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

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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())
{

View File

@@ -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)
{

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())
{
@@ -257,8 +257,8 @@ bool LineProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projected
// Project the objectLine onto the window.
osg::ref_ptr<osg::LineSegment> 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())
{

View File

@@ -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);
}
}
}

View File

@@ -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())