![](/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.