本文整理汇总了C++中osg::ref_ptr::computeIntersections方法的典型用法代码示例。如果您正苦于以下问题:C++ ref_ptr::computeIntersections方法的具体用法?C++ ref_ptr::computeIntersections怎么用?C++ ref_ptr::computeIntersections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::ref_ptr
的用法示例。
在下文中一共展示了ref_ptr::computeIntersections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pick
//PICK动作
void CPickHandler::pick(osg::ref_ptr<osgViewer::Viewer> viewer, const osgGA::GUIEventAdapter& ea)
{
//创建一个线段交集检测对象
osgUtil::LineSegmentIntersector::Intersections intersections;
std::string gdlist="";
//申请一个流
std::ostringstream os;
//得到鼠标的位置
float x = ea.getX();
float y = ea.getY();
//如果没有发生交集运算,及鼠标没有点中物体
if (viewer->computeIntersections(x,y,intersections))
{
//得到相交交集的交点
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end();
++hitr)
{
//输入流
os<<"Mouse in World X:"<< hitr->getWorldIntersectPoint().x()<<" Y: "<<
hitr->getWorldIntersectPoint().y()<<" Z: "<< hitr->getWorldIntersectPoint().z()<<std::endl ;
}
}
//输入流
os<<"Viewer Position X: "<<position[0]<<" Y: "<<position[1]<<" Z: "<<position[2]<<std::endl ;
gdlist += os.str();
//设置显示内容
setLabel(gdlist);
}
示例2: __pickNode
//***********************************************************
//FUNCTION:
bool CPickNode::__pickNode(osg::ref_ptr<osgViewer::View> vView, float vX, float vY)
{
osg::ref_ptr<osg::Node> SelectedNode;
osg::ref_ptr<osg::Group> ParentNode;
osgUtil::LineSegmentIntersector::Intersections intersections;
if (vView->computeIntersections(vX, vY, intersections))
{
osgUtil::LineSegmentIntersector::Intersection intersection = *intersections.begin();
osg::NodePath& nodePath = intersection.nodePath;
SelectedNode = (nodePath.size() > 1) ? nodePath[nodePath.size()-1] : 0;
ParentNode = (nodePath.size() >= 2) ? dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]) : nullptr;
}
if (SelectedNode.get() && ParentNode.get())
{
if (SelectedNode == m_PrevSelectedNode) return false;
if (SelectedNode != m_PrevSelectedNode && m_PrevSelectedNode)
{
m_PrevParentGroup->replaceChild(m_PrevMatrixTransform.get(), m_PrevSelectedNode.get());
}
m_PrevSelectedNode = SelectedNode;
m_PrevParentGroup = ParentNode;
const osg::BoundingSphere& NodeBoundingSphere = SelectedNode->getBound();
osg::ref_ptr<osg::Geode> LineNode = new osg::Geode;
osg::ref_ptr<osg::Geode> MaskNode = new osg::Geode;
__drawCoordinateSystem(NodeBoundingSphere.center(), NodeBoundingSphere.radius(), LineNode, MaskNode);
osg::ref_ptr<osg::MatrixTransform> CurMatrixTransform = new osg::MatrixTransform;
ParentNode->replaceChild(SelectedNode.get(), CurMatrixTransform.get());
CurMatrixTransform->addChild(SelectedNode.get());
CurMatrixTransform->addChild(LineNode.get());
CurMatrixTransform->addChild(MaskNode.get());
m_PrevMatrixTransform = CurMatrixTransform;
return true;
}
return false;
}