[英]Creating a dynamic sphere in OSG
I want to create a dynamic sphere in OSG which would be created(moved) by the mouse left click at that location (center) and with a dynamic radius of the mouse pointer current location's distance to the center.... 我想在OSG中创建一个动态球体,将通过鼠标左键单击该位置(中心)来创建(移动),并使用鼠标指针当前位置到中心的距离作为动态半径。
I understand that for this reason I need to create an osgGA::GUIEventHandler Object and implement the virtual handle function but I miss other details like finding the sphere object it self from the scene and changing its attributes. 我知道出于这个原因,我需要创建一个osgGA :: GUIEventHandler对象并实现虚拟句柄功能,但是我错过了其他细节,例如从场景中找到它自己的球体对象并更改其属性。
I also tried to change A picking example but failed to detect the sphere in the nodePath or creating a new sphere 我也尝试更改一个选择示例,但未能在nodePath中检测到球体或创建新球体
I would probably start by creating a custom class derived from one of the osgGA Manipulator classes. 我可能首先创建一个自osgGA Manipulator类之一派生的自定义类。
You'll want to override the handle() method with something like this: 您将需要使用以下方法覆盖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;
}
Then remember to use setCameraManipulator() on your viewer to add this instead of the default TrackballManipulator. 然后,请记住在查看器上使用setCameraManipulator()来添加它,而不是默认的TrackballManipulator。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.