[SOLVED] Following tutorials, mouse stuck in 50x50 grid

hellaeon

10-02-2009 22:15:10

I hope the subject says enough...!

Goodaye all, I apologise if this is something totally silly but I cant figure out why using the default settings (eg the tutorials) I seem to have an ivisible mouse area that restricts the mouse moving anymore then in the area on screen of (0,0) x (50,50). Even if I create buttons anywhere else, the mouse pointer refuses to move outside this 'invisible' bordered region...

I know its some default setting im missing....help!

Here is my code

Initialize

// the main GUI root
QuickGUI::Root *mRoot = new QuickGUI::Root();

// load skin type
QuickGUI::SkinTypeManager::getSingleton().loadTypes();

// GUI Manager
QuickGUI::GUIManagerDesc d;

// initialise Manager
mGUIMgr = QuickGUI::Root::getSingletonPtr()->createGUIManager(d);

// set window size - trying this because of mouse restriction problem - does not make a difference
int x = Ogre::Root::getSingletonPtr()->getAutoCreatedWindow()->getWidth();
int y = Ogre::Root::getSingletonPtr()->getAutoCreatedWindow()->getHeight();
mGUIMgr->getDefaultSheet()->setSize(QuickGUI::Size(x,y));


my mouse movement grabbing function in the listener class

bool MainListener::mouseMoved(const OIS::MouseEvent &arg)
{
// gui takes abs values for x,y, relative for z
mGUI->InjectMouseMoved(arg.state.X.abs, arg.state.Y.abs, arg.state.Z.rel);

// continue
return true;
}


my calss that injects those mouse coords into quick gui

void MainGUI::InjectMouseMoved(float x, float y, float z)
{
mGUIMgr->injectMousePosition(x,y);
if(z != 0)
mGUIMgr->injectMouseWheelChange(z);
}



arggh!

If anyone can help - thanks
Cheers

kungfoomasta

10-02-2009 22:43:10

If you don't specify a viewport or scenemanager when creating the GUIManager, it will find and use the first ones found. I don't know if this affects you, but its something good to know.

Also, can you verify what x and y are, in the following lines of code?

int x = Ogre::Root::getSingletonPtr()->getAutoCreatedWindow()->getWidth();
int y = Ogre::Root::getSingletonPtr()->getAutoCreatedWindow()->getHeight();


I remember there was a "getActualWidth" function, where the normal getWidth returned 1.0 and getActualWidth would return 800, for example.

Also, are you doing any resizing of your window? I remember OIS capped my mouse x/y values unless I set it. I don't have the play pen in front of me, but I think I set the OIS max input values for the mouse when resizing the window. Are you able to run the PlayPen app without these issues?

[edit]
This might be obvious, but also check to make sure you've setup OIS correctly, so that your mouse callback functions are being called. If they don't get called, the cursor will not be updated.
[/edit]

hellaeon

10-02-2009 23:36:17

Thanks for the reply mate, ignore the PM on the same topic :)
Those values certainly go in at 640*480 for getWidth and getHeight.
I did some testing such as purposely setting the viewport, but it seemed to crash.

Im starting to think, that because I tried to set the viewport in the constructor, and that I call the GUI in the Listener constructor BEFORE OGRE:Start Render Loop kicks in, the viewport may not have been properly defined at that point - I got the same issue with betaGUI as well with an identical placement of code.

My code works like so

I have MainApplication and MainListener classes. Main application does all the ogre sequence code identical to basic tutorial 6.

In there I declare an instance of the gui class (mine, which then instatiates QuickGUI). MainGUI *mGUI. Just before loading resources I do a mGUI = new MainGUI() which sets the QuickGUI::registerScriptReader();

A number of other functions run next including createScene which at this point creates the camera and viewport (following tut 6)
Then in createFrameListener - I pass mGUI pointer to the Listener in the constructor. Same as tut 6, but with the extra parameter of *mGUI.
In the constructor of my listener I run the 'Initialize' code sequence posted in the first post of this thread.

This as you may tell now is done all before startRendering Loop - which is called last (see tut 6 again)

Is this going to be a problem?
Should I perhaps call the initialize function in framestarted, using a variable to check it only runs once? (eg: case 'GAME_STARTING':)
i can post all this relevant code if needs be, but I am at work so it will have to wait!
Cheers

kungfoomasta

11-02-2009 00:22:28

How big is your code base? If its near the size of tutorial 6 code, you can zip it up and I can try to run it and see what the problem is. I don't believe you have to start rendering before initializing QuickGUI. You can email me the zip at benjaminki at hotmail dot com. If you don't want to zip it up, you could always post it in this thread and I'll try to run it.

If all else fails I can add QuickGUI into tutorial 6 code and post that. :)

hellaeon

11-02-2009 00:34:05

I'll try the other fixes or checks. Specifically the mouse one.
I can get CEGUI to take over the whole viewport, just not QuickGUI or even BetaGUI.
I have not actually tried running the playpen, but have referred to the code.

I'll send or post the code later and go from there...cheers!

hellaeon

11-02-2009 07:32:00

Goodaye again

MainApplication.cpp

/*
Ogre startup sequence

Create the Root object.
Define the resources that Ogre will use.
Choose and setup the RenderSystem (that is, DirectX, OpenGL, etc).
Create the RenderWindow (the window which Ogre resides in).
Initialize the resources that you are going to use.
Create a scene using those resources.
Setup any third party libraries and plugins.
Create any number of frame listeners.
Start the render loop.

*/
#pragma once
#include "MainApplication.h"

void MainApplication::go(void)
{
CreateRoot();
DefineResources();
SetupRenderSystem();
CreateRenderWindow();
InitializeResourceGroups();
SetupScene();
SetupInputSystem();
CreateFrameListener();
StartRenderLoop();
}

// kill the app
MainApplication::~MainApplication(void)
{
// kill newton world
OgreNewt::Debugger::getSingleton().deInit();
delete mWorld;

// kill input
mInputManager->destroyInputObject(mKeyboard);
mInputManager->destroyInputObject(mMouse);
OIS::InputManager::destroyInputSystem(mInputManager);
if (mGUI) delete mGUI;

// kill the frame listener and our OGRE root object
if (mListener) delete mListener;
if (mRoot) delete mRoot;
}

// create root object
void MainApplication::CreateRoot()
{
// set up the ogre root
mRoot = new Ogre::Root();

// ogre newt world
mWorld = new OgreNewt::World();
Ogre::AxisAlignedBox physicsBox(Ogre::Vector3(-1000, -1000, -1000), Ogre::Vector3(1000, 1000, 1000));
mWorld->setWorldSize(physicsBox);
}

// defining all resources that our application will use
void MainApplication::DefineResources()
{
// parse the config file
Ogre::String secName, typeName, archName;
Ogre::ConfigFile cf;
cf.load("resources_nd.cfg");

// now add the sections to the ResourceGroupManager
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
Ogre::ResourceGroupManager::getSingleton()
.addResourceLocation(archName, typeName, secName);
}
}
}

// create the render system
void MainApplication::SetupRenderSystem()
{
if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
throw Ogre::Exception(52, "User canceled the config dialog!", "Application::setupRenderSystem()");
}

// create render window
void MainApplication::CreateRenderWindow()
{
mRoot->initialise(true, "Networking Demo");
}

// initialize the resource we need
void MainApplication::InitializeResourceGroups()
{
/*
To keep down memory requirements, we can load only the
resources that our application is using. We do this by
dividing the resources into sections and only initializing
them as we go. see :
http://www.ogre3d.org/wiki/index.php/Advanced_Tutorial_1
*/

// initialize gui
mGUI = new MainGUI();
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}

// setup the scene
void MainApplication::SetupScene()
{
// create a new scene manager
Ogre::SceneManager *mgr = mRoot->createSceneManager(Ogre::ST_GENERIC,
"MainSM");
// create a new camera
Ogre::Camera *cam = mgr->createCamera("MainCam");
cam->setNearClipDistance(1);
cam->setPosition(0,30,100);
cam->lookAt(0,0,0);

// add a viewport to it
Ogre::Viewport *mVP = mRoot->getAutoCreatedWindow()->addViewport(cam);

// Alter the camera aspect ratio to match the viewport
cam->setAspectRatio(Ogre::Real(mVP->getActualWidth()) / Ogre::Real(mVP->getActualHeight()));

// setAutoAspectRatio is needed so that if the screen is resized,
// the 3D elements inside buttonGUI can keep their size relative to the screen
cam->setAutoAspectRatio(true);
}

void MainApplication::SetupInputSystem()
{
size_t windowHnd = 0;
std::ostringstream windowHndStr;
OIS::ParamList pl;
Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow();

win->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
mInputManager = OIS::InputManager::createInputSystem(pl);
mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, true));
mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true));
}

// create our frame listener
void MainApplication::CreateFrameListener()
{
// create the frame listener
mListener = new MainListener(mKeyboard,mMouse,mWorld,mGUI);
mRoot->addFrameListener(mListener);

// newton frame listener
mOgreNewtListener = new OgreNewt::BasicFrameListener(
mRoot->getAutoCreatedWindow(),
mRoot->getSceneManager("MainSM"),
mWorld,
60 );
mRoot->addFrameListener( mOgreNewtListener );
}

// start the rendering loop
void MainApplication::StartRenderLoop()
{
mRoot->startRendering();
}




MainListener.cpp

#pragma once
#include "MainListener.h"

// constructor
MainListener::MainListener( OIS::Keyboard *keyboard = 0,
OIS::Mouse *mouse = 0,
OgreNewt::World *W = 0,
MainGUI *gui = 0) :
mKeyboard(keyboard),
mMouse(mouse),
mWorld(W),
mGUI(gui)

{
// setup input listeners
if (keyboard) mKeyboard->setEventCallback(this);
if (mouse) mMouse->setEventCallback(this);

// get our scene manager
mSceneMgr = Ogre::Root::getSingletonPtr()->getSceneManager("MainSM");

// background
mBackground = new Background("skybox", Ogre::SHADOWTYPE_STENCIL_MODULATIVE);

// GUI - set up the root object
mGUI->Initialize();
mGUI->TestButton();
// draw the scene
DrawScene *mDrawScene = new DrawScene(mWorld);

// continue rendering
m_bContinue = true;
}

MainListener::~MainListener()
{
//delete mDrawScene;
//delete mBackground;
}

// listen at frame start
bool MainListener::frameStarted(const Ogre::FrameEvent &evt)
{
// capture input
if(mMouse) mMouse->capture();
if(mKeyboard) mKeyboard->capture();

// continue
return m_bContinue;
}
bool MainListener::frameEnded(const Ogre::FrameEvent &evt)
{
// continue
return m_bContinue;
}

// KeyListener
bool MainListener::keyPressed(const OIS::KeyEvent &arg)
{

// handle keyboard input
switch (arg.key)
{
case OIS::KC_ESCAPE:
m_bContinue = false;
break;
default:
break;
}

// gui
mGUI->InjectChar(static_cast<Ogre::UTFString::unicode_char>(arg.text));
mGUI->InjectKeyPressed(static_cast<QuickGUI::KeyCode>(arg.key));

// continue
return true;
}

bool MainListener::keyReleased(const OIS::KeyEvent &arg)
{
// gui
mGUI->InjectKeyReleased(static_cast<QuickGUI::KeyCode>(arg.key));

// continue
return true;
}

// MouseListener
bool MainListener::mouseMoved(const OIS::MouseEvent &arg)
{
// gui takes abs values for x,y, relative for z
mGUI->InjectMouseMoved(arg.state.X.abs, arg.state.Y.abs, arg.state.Z.rel);

// grab values
Ogre::Real mx = arg.state.X.rel;
Ogre::Real my = arg.state.Y.rel;
Ogre::Real MoveFactor = 1;

//mSceneMgr->getCamera("MainCam")->yaw(Ogre::Degree(mx * MoveFactor * -0.1));
//mSceneMgr->getCamera("MainCam")->pitch(Ogre::Degree(my * MoveFactor * -0.1));

// continue
return true;
}
bool MainListener::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
// gui
mGUI->InjectMousePressed(static_cast<QuickGUI::MouseButtonID>(id));

// continue
return true;
}
bool MainListener::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
// gui
mGUI->InjectMouseReleased(static_cast<QuickGUI::MouseButtonID>(id));

// continue
return true;
}



Finally my MainGUI.cpp class which calls on your QuickGUI code...

#pragma once
#include "MainGUI.h"

MainGUI::MainGUI()
{
QuickGUI::registerScriptReader();
}

// cleanup
MainGUI::~MainGUI(void)
{
delete QuickGUI::Root::getSingletonPtr();
}

// initialise
void MainGUI::Initialize(void)
{
// the main GUI root
QuickGUI::Root *mRoot = new QuickGUI::Root();

// load skin type
QuickGUI::SkinTypeManager::getSingleton().loadTypes();

// GUI Manager
QuickGUI::GUIManagerDesc d;

// initialise Manager
mGUIMgr = QuickGUI::Root::getSingletonPtr()->createGUIManager(d);

// set window size
int x = Ogre::Root::getSingletonPtr()->getSceneManager("MainSM")->getCamera("MainCam")->getViewport()->getActualWidth();
int y = Ogre::Root::getSingletonPtr()->getSceneManager("MainSM")->getCamera("MainCam")->getViewport()->getActualHeight();
mGUIMgr->getDefaultSheet()->setSize(QuickGUI::Size(x,y));
}

// inject mouse movement
void MainGUI::InjectMouseMoved(float x, float y, float z)
{
mGUIMgr->injectMousePosition(x,y);
if(z != 0)
mGUIMgr->injectMouseWheelChange(z);
}

// inject mouse button
void MainGUI::InjectMousePressed(QuickGUI::MouseButtonID id)
{
mGUIMgr->injectMouseButtonDown(id);
}

// inject mouse button
void MainGUI::InjectMouseReleased(QuickGUI::MouseButtonID id)
{
mGUIMgr->injectMouseButtonUp(id);
}

// inject char
void MainGUI::InjectChar(Ogre::UTFString::unicode_char mChar)
{
mGUIMgr->injectChar(mChar);
}
// inject Keyboard
void MainGUI::InjectKeyPressed(QuickGUI::KeyCode key)
{
mGUIMgr->injectKeyDown(key);
}

// inject Keyboard
void MainGUI::InjectKeyReleased(QuickGUI::KeyCode key)
{
mGUIMgr->injectKeyUp(key);
}

// Test Button
void MainGUI::TestButton(void)
{
QuickGUI::Sheet* defaultSheet = mGUIMgr->getActiveSheet();
QuickGUI::Factory<QuickGUI::WidgetDesc>* descFactory = QuickGUI::FactoryManager::getSingleton().getWidgetDescFactory();
QuickGUI::ButtonDesc* bd = dynamic_cast<QuickGUI::ButtonDesc*>(QuickGUI::FactoryManager::getSingleton().getWidgetDescFactory()->getInstance("DefaultButtonDesc"));

// Using the desc object has many benefits. You can set button properties before creating the button,
// and also re-use the desc to create other buttons. All properties of the desc object have corresponding
// API calls, meaning the Button's properties can be changed after creation. Also note that all desc objects
// have a "resetToDefaults" function. At any time you can enforce all desc properties to be reverted to their default
// values. Lets give a few properties and create the button:

bd->widget_name = "MyButton";
bd->widget_dimensions.size = QuickGUI::Size(100,25);
bd->widget_dimensions.position = QuickGUI::Point(50,50);
QuickGUI::Button* myButton = defaultSheet->createButton(bd);
}

hellaeon

11-02-2009 10:48:21

using a bit of nouse and the debugger, I worked out it was because I needed to stick the viewport size into OIS!


//create local variables that will store the window width & height, colour depth, and top and left coordinates.
unsigned int width, height, depth;
int top, left;

//this line gets these values from an Ogre::RenderWindow (m_win is a pointer to an initialised RenderWindow).
win->getMetrics(width, height, depth, left, top);

//this line gets a mouse state object, and sets the width and height properties accordingly
const OIS::MouseState &mouseState = mMouse->getMouseState();
mouseState.width = width;
mouseState.height = height;


This is done at the end of my void MainApplication::SetupInputSystem() function.
Cheers

kungfoomasta

11-02-2009 19:14:29

Awesome, glad you figured it out! :)

From looking at your code snippits it seems you have a good handle on how Ogre works. Make sure and post any problems you have with QuickGUI, for example if you expected behavior X, but got something different. Or things to make the library easier to use, etc.