Hi,
in my app I need to now if the mouse is moving or not, so I have a global flag "g_mousemoving".
In the OnMove() of the EventReceiver I set this flag to "true", if the event occurs.
But where should I set the flag to "false"? The OnMove() is not called when the mouse stops moving, so I tried several possibilities: at the beginning of my mainloop (where the moving and rendering is done), at the end of my mainloop... but nothing worked and I am just guessing. What I need to know is: when and how is the EventReceiver working? Is it running in an extra thread? Or is it called at specific times in the loop? I think that I have to set my flag to false exactly before the EventReceiver gets called, but I don't know when this happens.
Bye
Riky
EventReceiver, Flag for Mouse-Moving
Thanks for your answer. I tried with getting the mousepos in the main-loop and not in the eventreceiver like you suggested and now have a solution which does everything in the main loop in every frame. But the problem is the same. I think it is the high framerate. In my project its about 700 or so. You can't move the mouse so quickly, that in every frame a change of the position is measurable. So my flag gets set to false in some frames, wether i am moving the mouse or not.
Now I use kind of a idle-counter, in every frame without measurable mouse-move the idle-counter is incremented and when it reaches a limit, the program considers the mouse as not moving. This works, I think I the treshold could be calculated with the last fps from the driver. But is it a good way to do it?
What I want is that the following code produces a black screen while mouse it moving without flickering. It does now, but I am not sure if this is the best way to do it.
Now I use kind of a idle-counter, in every frame without measurable mouse-move the idle-counter is incremented and when it reaches a limit, the program considers the mouse as not moving. This works, I think I the treshold could be calculated with the last fps from the driver. But is it a good way to do it?
What I want is that the following code produces a black screen while mouse it moving without flickering. It does now, but I am not sure if this is the best way to do it.
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
int main()
{
int mouseidle;
int mouseidletime = 20;
position2d<s32> lastmousepos, mousepos;
int bggrey;
IrrlichtDevice *device =
createDevice(EDT_DIRECT3D9, dimension2d<s32>(1024, 768), 16, false, true, false);
IVideoDriver* driver = device->getVideoDriver();
while(device->run() )
{
mousepos = device->getCursorControl()->getPosition();
if (mousepos==lastmousepos)
mouseidle++;
else
{
mouseidle = 0;
lastmousepos = mousepos;
}
if (mouseidle<mouseidletime)
bggrey = 0;
else
bggrey = 128;
// Render
driver->beginScene(true, true, SColor(0,bggrey,bggrey,bggrey));
driver->endScene();
}
device->drop();
return 0;
}