1,451
社区成员




我利用osg自带的 函数 实现了 点击鼠标画点
osgUtil::LineSegmentIntersector::Intersections intersections;
if (mViewer->computeIntersections(x, y, intersections))
{
osgUtil::LineSegmentIntersector::Intersections::iterator hitr=intersections.begin();
osg::Vec3d vec3 = hitr->getLocalIntersectPoint();
然后得到这个点 就可以画了
但是我现在又画了线,我想实现鼠标点击 这个点,或线 能拾取到这个点或线的geode computeIntersections函数 好像不能做到 ,请大神赐教一下
网上的资料太少了 谢谢 !!!!!!!!
osgUtil::LineSegmentIntersector::Intersections intersections;
if (mViewer->computeIntersections(x, y, intersections))
{
osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
if(hitr != intersections.end()) {
osg::Vec3d vec3 = hitr->getLocalIntersectPoint();
// 获取拾取的Drawable和NodePath
osg::Drawable* drawable = hitr->drawable.get();
osg::NodePath& nodePath = hitr->nodePath;
// NodePath是一个节点数组,我们可以从中获取Geode
// 通常Geode是NodePath中的最后一个节点,但这也取决于你的场景图的结构
osg::Geode* geode = dynamic_cast<osg::Geode*>(nodePath.back());
if (geode)
{
// 执行你的代码,处理拾取到的Geode
}
}
}