2013-11-28 47 views

回答

2

OSG使用事件處理程序移動它在屏幕上。只要創建一個這樣的:

// KeyboardEventHandler.h 
#pragma once 

#include <osgGA/GUIEventHandler> 

class KeyHandler : public osgGA::GUIEventHandler 
{ 
public: 
    KeyHandler() 
    {} 

public: 
    virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&) 
    { 
     switch(ea.getEventType()) 
     { 
      case(osgGA::GUIEventAdapter::KEYDOWN): 
      { 
       // Place your code here... 
      } 

      default: 
       return false; 
     } 
    } 

    virtual void accept(osgGA::GUIEventHandlerVisitor& v) 
    { 
     v.visit(*this); 
    } 
}; 

現在將它連接到您的視圖:

m_osgViewer->addEventHandler(new KeyHandler()); 

你可以通過「本」終場以KeyboardHandler並從內部調用瀏覽器的方法。