- OS: WIn7
driver mode: OpenGL
windowed mode
irrlicht 1.8.3
Basically if I use cursor control setPosition method to set my cursor to a specific position in windowed mode, the values I pass to the method are not going to be where the cursor is going to actually end up. Instead, the final position of the cursor seems to always be exactly 5 pixels to the left and 5 pixels up from the point I specify.
If I have a 800x600 window and I do device->getCursorControl()->setPosition(400, 300) (which would be the centre of the window in my logic) and then check the position of the cursor immediately after the cursor is positioned, it will be at x:395 y:295. I don't think this is a matter of my bad coding, because I can even see that the cursor is not perfectly centred by the eye, and my custom camera uses cursor delta from the screen centre to rotate, so it spins up and left non-stop. If setPosition would set the cursor dead in the middle of the screen then there would be no camera rotation.
However, if I change the code to device->getCursorControl()->setPosition(400+5, 300+5) everything works the way it should. For the sake of being thorough I tested various window resolutions and it always seems to be 5px.
Can anyone else confirm this behaviour in windowed mode? If this isn't a bug then this is definitely not how I expected the function to work. Why would it be this way?
Copy paste code that demonstrates the problem:
Code: Select all
int SCREEN_WIDTH, SCREEN_HEIGHT;
ICameraSceneNode*camera;
IrrlichtDevice *device;
IVideoDriver* driver;
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
if (event.MouseInput.Event == EMIE_MOUSE_MOVED)
{
device->getCursorControl()->setPosition(event.MouseInput.X, event.MouseInput.Y);
}
}
return false;
}
MyEventReceiver()
{
}
} eventReceiver;
void initSettings() {
SCREEN_WIDTH = 640;
SCREEN_HEIGHT = 480;
}
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show)
{
initSettings();
device = createDevice(video::EDT_OPENGL, dimension2d<u32>(SCREEN_WIDTH, SCREEN_HEIGHT), 32, false, false, false, &eventReceiver);
if (!device)
return 1;
device->setWindowCaption(L"Cursor Position Bug?");
driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
camera = smgr->addCameraSceneNode(0, vector3df(0, 30, -40), vector3df(0, 5, 0));
while (device->run())
{
if (!device->isWindowActive()) {
Sleep(1);
continue;
}
driver->beginScene(true, true, SColor(255, 100, 101, 140));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
I don't know If this happens on other systems though. What do you guys think?