EventProcessor::getInputreader()::getMouseButton()-Problem

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany
Contact:

EventProcessor::getInputreader()::getMouseButton()-Problem

Post by Marc »

When I use

Code: Select all

        mEventProcessor = new EventProcessor();
	mEventProcessor->initialise(win);
	mEventProcessor->startProcessingEvents();
        mEventProcessor->addKeyListener(this);
        mEventProcessor->addMouseListener (this);
        mEventProcessor->addMouseMotionListener (this);
	mInputDevice = mEventProcessor->getInputReader();
like done in ExampleFrameListener.h and call mInputDevice->getMouseButton(0), I always get true as a result directly after application initialisation even if the mouse button is not pressed (same for button 1). After I press the button and release it, the function returns false, as it should when the button is not pressed.

When I create the inputReader directly, like it is done in ExampleFrameListener.h in the second case

Code: Select all

        mInputDevice = PlatformManager::getSingleton().createInputReader();
        mInputDevice->initialise(win, true, true);
mInputDevice->getMouseButton(0) works correctly from the beginning.

Did I forget to initialize something for using mInputDevice->getMouseButton() with an InputReader got from an EventProcessor? It pretty much looks like an initialization problem for me, like the memory is filled with random values !=0 and thus the memory holding the mousebutton state holds a value that corresponds to true even though the button is not pressed. But this is just a guess.
User avatar
Longstreet
Halfling
Posts: 94
Joined: Tue Jan 20, 2004 10:41 am

Post by Longstreet »

I'm pretty new, but do you have to do a mInputDevice->capture(); to update the information... maybe.
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany
Contact:

Post by Marc »

As far as I understand it, mInputDevice->capture has to get called if you use the 2nd option, creating the Inputreader yourself. If you use the Eventprocessor, it already captures the Input. However, I tried it with and without it and it made no difference.
Fredz
Greenskin
Posts: 122
Joined: Wed May 26, 2004 1:45 pm
Location: Perpignan, France

Post by Fredz »

I use an EventProcessor myself, I don't call capture() and it does work for the keyboard. Maybe it's only a problem with the mouse, did you try with the keyboard ?
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany
Contact:

Post by Marc »

Yes the keyboard input works. The eventhandlers for the keyboard like keyPressed/keyReleased as well as mInputDevice->isKeyDown() work correctly from the beginning. It's just the mousebuttons.
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Post by dermont »

Try adding mInputDevice->initialise(win, true, true);
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany
Contact:

Post by Marc »

dermont wrote:Try adding mInputDevice->initialise(win, true, true);
That didn't help. That's what EventProcesser::initialize calls too.

I had a look into the initialization of eventprocessor and figured that it's a problem with buffered mouse input initialization. In contrast to immediate mouse intpu initialization, the mMouseState of InputReader doesn't get initialized properly. I added the initialization code from the immediate mouse input and it works now correctly:

at line 303 in ogrewin32input8.cpp at the end of Win32Input8::initialiseBufferedMouse()

Code: Select all

		/* Get initial mouse data. We might as well fail this initial attempt, so no biggie. */
		captureMouse();

		/* Clear any relative mouse data. */
		mMouseState.Xrel = mMouseState.Yrel = mMouseState.Zrel = 0;
I don't post this as a patch now because I'm not sure if that's the way it should be done. As far as I can see, captureMouse doesn't get called with buffered mouse input in that class, only with immediate mouse input, so maybe this is not a nice solution, but it works.
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Post by dermont »

Sorry I should have read your original code more closely. I remember having the same problem. I think that adding the listeners before the mEventProcessor startProcessingEvents() method worked from me:
http://www.ogre3d.org/phpBB2/viewtopic. ... selistener
Anyway just a suggestion.
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany
Contact:

Post by Marc »

dermont wrote:Sorry I should have read your original code more closely. I remember having the same problem. I think that adding the listeners before the mEventProcessor startProcessingEvents() method worked from me:
http://www.ogre3d.org/phpBB2/viewtopic. ... selistener
Anyway just a suggestion.
I changed my code to

Code: Select all

	mEventProcessor = new EventProcessor();
	mEventProcessor->initialise(win);
	mEventProcessor->addMouseMotionListener(this);
	mEventProcessor->addMouseListener(this);
	mEventProcessor->addKeyListener(this);
	mInputDevice = mEventProcessor->getInputReader();
	mEventProcessor->startProcessingEvents();
but I still have the same problems without my modifications to ogrewin32input8.cpp .
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Post by dermont »

I use the above and to define the type of buffered input required:

Code: Select all

InputDevice->setBufferedInput (bool keys, bool mouse);
      (true,true)    - capturing  buffered mouse / key event details
     (false,false)  - processing unbuffered key/mouse input in frame started
I then use key checks / flags in the mouse/key events & frameStarted routine to switch between a combination of the above modes. I then check, in a similar manner to the ExampleFrameListener, whether I need to handle buffered mouse / key processing.
Post Reply