我如何获得鼠标位置与灯光
How can I get mouse position with irrlicht?
我编写了一个示例来获取按钮上的鼠标输入。我的意思是当用户点击屏幕时,我想看到鼠标位置x和鼠标位置Y,但x和Y总是有垃圾值。这是我的代码:
#include <irrlicht.h>
#include <iostream>
using namespace std;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
// Declare a structure to hold some context for the event receiver so that it
// has it available inside its OnEvent() method.
struct SAppContext
{
IrrlichtDevice *device;
};
// Define some values that we'll use to identify individual GUI controls.
enum
{
GUI_ID_BUTTON = 101,
};
class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(SAppContext & context) : Context(context) { }
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
switch(id)
{
case GUI_ID_BUTTON:
cout << "X: "<< event.MouseInput.X << endl;
cout << "Y: "<< event.MouseInput.Y << endl << endl;
return true;
default:
return false;
}
break;
default:
break;
}
}
return false;
}
private:
SAppContext & Context;
};
int main(int argc, char** argv)
{
// create device and exit if creation failed
IrrlichtDevice * device = createDevice( video::EDT_SOFTWARE, core::dimension2d<u32>(1280, 720));
if (device == 0)
return 1; // could not create selected driver.
device->setWindowCaption(L"Irrlicht Engine - User Interface Demo");
device->setResizable(true);
video::IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();
// add button
env->addButton(rect<s32>(0,0,640,360), 0, GUI_ID_BUTTON,
L"Button", L"Button");
// Store the appropriate data in a context structure.
SAppContext context;
context.device = device;
// Then create the event receiver, giving it that context structure.
MyEventReceiver receiver(context);
// And tell the device to use our custom event receiver.
device->setEventReceiver(&receiver);
/*
That's all, we only have to draw everything.
*/
while(device->run() && driver)
if (device->isWindowActive())
{
driver->beginScene(true, true, SColor(0,200,200,200));
env->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
And result image:
https://i.stack.imgur.com/dQEMs.png我该如何解决这个问题?有没有其他的方法来采取鼠标输入位置?
irrlight文档有关于如何使用鼠标和操纵杆进行输入的教程。在这里阅读的。
您需要处理EMIE_MOUSE_MOVED
事件并将鼠标输入当前位置存储在某处。
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
switch(event.MouseInput.Event)
{
...
case EMIE_MOUSE_MOVED:
MouseState.Position.X = event.MouseInput.X;
MouseState.Position.Y = event.MouseInput.Y;
break;
...
}
}
相关文章:
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 如何在QML中设置鼠标光标位置
- SFML 鼠标获取位置无法正常工作
- 在小部件上获得绝对的鼠标点击位置(放大时也是如此)Qt
- 使用 dlib 记录鼠标位置
- 获取窗口中的鼠标位置
- 将文本添加到鼠标位置时,请单击“给出分割故障”
- 在鼠标位置移动精灵
- 如何在Mac OSX上的窗口客户端内获取真实的鼠标位置?
- 如何获取鼠标的位置
- 如何始终获得QT鼠标位置
- QT QgraphicView和Qgraphicscene鼠标位置
- 如何在Qwidget上获取当前的鼠标光标位置
- QT:QGraphicsScene鼠标位置始终(0,0)
- 如何检查鼠标单击位置是必需的应用程序
- C :使用全局鼠标钩的窗口重新位置
- SFML鼠标位置和碰撞从文件加载
- 根据鼠标位置缩小到窗口中
- 如何根据鼠标位置旋转精灵
- 为什么GET_X_LPARAM确实返回鼠标滚轮上的绝对位置