1
我想知道我怎麼可以輸入鍵盤事件來控制球?我想一個球,並與鍵盤事件鍵盤事件OSG(開放場景圖)
我想知道我怎麼可以輸入鍵盤事件來控制球?我想一個球,並與鍵盤事件鍵盤事件OSG(開放場景圖)
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並從內部調用瀏覽器的方法。