2012-10-30 114 views
0

我想在OSG中創建一個動態球體,該球體將通過鼠標左鍵單擊在該位置(中心)創建(移動),並且鼠標指針的動態半徑與當前位置的距離中心....
在OSG中創建一個動態球體

我明白了這個原因,我需要創建一個osgGA :: GUIEventHandler對象和實現虛擬手柄的功能,但我錯過了其他細節,如從現場發現的領域對象時,它自身並改變其屬性。

我也試圖改變A picking example但未能檢測出的NodePath球體或創建一個新的領域

+0

現在,如果只有你有一個具體的編程問題。 – stark

回答

1

我可能會通過創建從osgGA機器人類之一派生的自定義類開始。

你會希望像這樣的東西覆蓋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這一點。

+1

我只是重新閱讀這個問題,並意識到你想在鼠標推動時「創造」球體。在這種情況下,忘記LineSegmentIntersector部分,只是在那個時候展示你的領域。我會提前創建它,然後使用節點掩碼來隱藏它。您也可能想要使用ea.getModKeyMask()僅在按下某個鍵盤按鈕(例如SHIFT)時執行您的操作。 – mikewoz

+0

所以它不可能在點擊時創建球體或將其添加到場景的節點路徑或從節點路徑中刪除一個? 或更改它的半徑? –