osg对象拾取的问题 大佬来救救

老拆 2023-05-17 15:47:15

 我利用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函数 好像不能做到 ,请大神赐教一下

网上的资料太少了  谢谢  !!!!!!!!

...全文
616 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
老拆 2023-05-17
  • 打赏
  • 举报
回复
顶顶
老拆 2023-05-17
  • 打赏
  • 举报
回复
顶顶顶 求求救救!!
OhDurianMonkey 2023-05-17
  • 打赏
  • 举报
回复
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
        }
    }
}


老拆 2023-05-17
  • 举报
回复
@OhDurianMonkey 大佬 我是所有的 点 线 全部加在了一个全局的root节点里面 这个root是osg Group* 类型的 这个方法我貌似试过,只能得到root

1,451

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计/Flash/Silverlight 开发 图象工具使用
社区管理员
  • 图象工具使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧