我想在OSG中创建一个动态球体,通过鼠标左键单击该位置(中心)并使用鼠标指针当前位置到中心的距离的动态半径来创建(移动).... BR />
据我所知,由于这个原因,我需要创建一个osgGA :: GUIEventHandler对象并实现虚拟句柄函数,但我想念其他细节,比如从场景中找到它自己的球体对象并更改其属性。
我还尝试更改A picking example,但未能在nodePath中检测到球体或创建新球体
答案 0 :(得分:1)
我可能首先创建一个从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。