How to get mouse and keyboard working?

v3n0w

13-05-2008 06:00:12

Well, I followed the sample to set up my application...

Here´s the .h code:

#ifndef C_GUI_H
#define C_GUI_H

#include <OIS/OIS.h>
#include "Ogre.h"
#include "QuickGUI.h"

using namespace OIS;

class cGUI : public MouseListener, public KeyListener
{
Keyboard* oisKeyboard;
Mouse* oisMouse;
QuickGUI::GUIManager* GUIManager;
QuickGUI::Sheet* sheet;
QuickGUI::TextBox* mouseOverTB;
QuickGUI::Window* CBTestWindow;
QuickGUI::ComboBox* colorCB;

public:

cGUI(Mouse*, Ogre::SceneManager*, OIS::Keyboard*);
~cGUI();
void init();
void update(const Ogre::FrameEvent &evt);
void selectionMade(const QuickGUI::EventArgs& args);
bool mouseMoved( const OIS::MouseEvent &e );
bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id );
bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id );
bool keyPressed( const OIS::KeyEvent &arg );
bool keyReleased( const OIS::KeyEvent &arg );
};

#endif


So I set the callbacks with oisMouse and keyboard setEventCallback method...

And the callback functions like the demo.

Also the update with GUIManager->injectTime();

What more I need to do to get it working?

I have this and no interation at all:

Thanks in advance.

kungfoomasta

13-05-2008 18:30:45

Assuming you've registered your callbacks with OIS, they will be called when you have keyboard/mouse input. In order to apply this input to the GUI, you have to inject it. (mGUIManager->inject...)

Examples of how to inject mouse/keyboard events can be found here:

http://www.ogre3d.org/wiki/index.php/QuickGUI_Beginner_Tutorial_2

v3n0w

13-05-2008 20:41:32

I did it...


cGUI::cGUI(Mouse* m, Ogre::SceneManager *sceneMgr, OIS::Keyboard* kB) : oisMouse(m), oisKeyboard(kB)
{
new QuickGUI::Root();
QuickGUI::SkinSetManager::getSingleton().loadSkin("qgui",QuickGUI::SkinSet::IMAGE_TYPE_PNG);
GUIManager = QuickGUI::Root::getSingleton().createGUIManager(sceneMgr->getCamera("MainCamera")->getViewport(),"qgui");
GUIManager->setSceneManager(sceneMgr);
oisMouse->setEventCallback(this);
oisKeyboard->setEventCallback(this);

this->init();
}

void cGUI::update(const Ogre::FrameEvent &evt)
{
GUIManager->injectTime(evt.timeSinceLastFrame);
mouseOverTB->setText(GUIManager->getMouseOverWidget()->getInstanceName());
}

bool cGUI::mouseMoved( const OIS::MouseEvent &arg ){

GUIManager->injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
return true;
}
bool cGUI::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id ){

GUIManager->injectMouseButtonDown(static_cast<QuickGUI::MouseButtonID>(id));
return true;
}
bool cGUI::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ){

GUIManager->injectMouseButtonUp(static_cast<QuickGUI::MouseButtonID>(id));
return true;
}

bool cGUI::keyReleased( const OIS::KeyEvent &arg )
{
GUIManager->injectKeyUp(static_cast<QuickGUI::KeyCode>(arg.key));
return true;
}

bool cGUI::keyPressed( const OIS::KeyEvent &arg )
{
GUIManager->injectKeyDown(static_cast<QuickGUI::KeyCode>(arg.key));
GUIManager->injectChar( arg.text );
return true;
}


QuickGUI::registerScriptParser(); is called in other place, but before resources like you saied in the tutorial...

v3n0w

13-05-2008 21:11:32

As I see on Debug, mouseMoved and etc are never called :cry:

kungfoomasta

13-05-2008 23:16:34

Thats an OIS issue you're having. I'm not sure what the problem is, since you're setting your keyboard and mouse eventCallback functions. Whats your code for initializing OIS? Are you following the example framework code? Make sure you're calling "capture" on your keyboard and mouse to capture events.

v3n0w

14-05-2008 01:26:46

Now its OK, The mouse and keyboard need to be buffered...

In fact I tried it once, but I didnt see the mouse because it was hiding...

So, my other problem is the clipping... How can I fix that?

Thanks!

kungfoomasta

14-05-2008 05:41:36

Is the Platform a 3d overlay? In your first screenshot it looks like the platform is blocking the UI, and I've only seen issues with Overlays. (Is this what you mean by clipping?)

v3n0w

15-05-2008 03:04:42

Is the Platform a 3d overlay? In your first screenshot it looks like the platform is blocking the UI, and I've only seen issues with Overlays. (Is this what you mean by clipping?)

Yes, I guessed that clipping was that :oops:

kungfoomasta

15-05-2008 08:33:32

You can try setting the Render Queue to the last one, which is RENDER_QUEUE_MAX. Make sure you call

RenderQueue::getQueueGroup( RENDER_QUEUE_MAX )

to ensure the QueueGroup is created.

The function is GUIManager::setRenderQueueID