我想在 OSG 中创建一个动态球体,通过鼠标左键单击该位置(中心)和鼠标指针当前位置到中心的距离的动态半径来创建(移动)......
我知道出于这个原因,我需要创建一个 osgGA::GUIEventHandler 对象并实现虚拟句柄功能,但我错过了其他细节,例如从场景中找到它自己的球体对象并更改其属性。
我还尝试更改A Picking 示例,但未能检测到 nodePath 中的球体或创建新球体
我想在 OSG 中创建一个动态球体,通过鼠标左键单击该位置(中心)和鼠标指针当前位置到中心的距离的动态半径来创建(移动)......
我知道出于这个原因,我需要创建一个 osgGA::GUIEventHandler 对象并实现虚拟句柄功能,但我错过了其他细节,例如从场景中找到它自己的球体对象并更改其属性。
我还尝试更改A Picking 示例,但未能检测到 nodePath 中的球体或创建新球体
我可能会首先创建一个从 osgGA Manipulator 类之一派生的自定义类。
你会想用这样的东西覆盖 handle() 方法:
bool CustomManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
using namespace osgGA;
if (ea.getEventType()==GUIEventAdapter::FRAME)
{
if (_thrown) aa.requestRedraw();
}
else if (ea.getEventType()==GUIEventAdapter::PUSH)
{
// check if your sphere is picked using LineSegmentIntersector
// (like in the picking example) and set a flag
}
else if (ea.getEventType()==GUIEventAdapter::DRAG)
{
// update the position and radius of your sphere if the flag was set
}
else if (ea.getEventType()==GUIEventAdapter::RELEASE)
{
// release the sphere, unset the flag
}
return false;
}
然后记得在查看器上使用 setCameraManipulator() 来添加它而不是默认的 TrackballManipulator。