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:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user