OSG点击场景中的某个物体,如何判断点击的物体,及处理此模型相关变换

首先建立事件响应类,继承自

osgGA::GUIEventHandler

在handle()函数中做相关处理如下:

//创建一个线段交集检测对象

bool handle( const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa )
{

osgUtil::LineSegmentIntersector::Intersections intersections;

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)*/
osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();//找到第一个交接点即可

(*hitr).drawable->getBound().center()找到这个几何体的中心位置

/*若为双击事件,为避免响应两次,可添加如下代码:

//m_CB为类成员变量,初始化为NULL

 if (m_CB)
        {
            // 双击消息
            m_CB->pickCB(ostr.str().c_str(),88);
 
 //           qDebug()<<"DoubleClick"<<endl;
        }
*/
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值