![](/img/trans.png)
[英]Creating a Sphere (using osg::Geometry) in OpenSceneGraph
[英]Creating a dynamic sphere in OSG
我想在OSG中创建一个动态球体,将通过鼠标左键单击该位置(中心)来创建(移动),并使用鼠标指针当前位置到中心的距离作为动态半径。
我知道出于这个原因,我需要创建一个osgGA :: GUIEventHandler对象并实现虚拟句柄功能,但是我错过了其他细节,例如从场景中找到它自己的球体对象并更改其属性。
我也尝试更改一个选择示例,但未能在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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.