了解OSG节点选择

本文介绍如何利用osgGA::GUIEventHandler处理OSG程序中的节点选择交互。通过鼠标点击,节点会变得透明。文章探讨了osg的类结构,特别是osgGA::GUIEventHandler,包括它的构造函数、事件处理方法以及与用户交互的功能。重点关注handle函数及其变体,这些函数控制事件类型的处理,并与osg::NodeVisitor协同工作以遍历场景。
摘要由CSDN通过智能技术生成
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/GUIEventHandler>

class nodePick :public osgGA::GUIEventHandler
{
	virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
	{
		osgViewer::Viewer *viewer = dynamic_cast<osgViewer::Viewer*> (&aa);
		switch (ea.getEventType())
		{
		case osgGA::GUIEventAdapter::PUSH:
		{
			osgUtil::LineSegmentIntersector::Intersections intersections;
			osg::ref_ptr<osg::Node> node = new osg::Node;
			if (viewer->computeIntersections(ea.getX(), ea.getY(), intersections))
			{
				//得到选择的节点
				osgUtil::LineSegmentIntersector::Intersection intersection = *intersections.begin();
				osg::NodePath& nodePath = intersection.nodePath;
				node
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值