Wrecked Games
September 08, 2010, 03:10:26 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: We're just that awesome.
 
   Home   Help Search Members Login Register  
Pages: [1]
  Print  
Author Topic: Joystick problem  (Read 257 times)
Tikrou
Guest
« on: May 28, 2010, 07:47:27 AM »

Hello,

I'm trying to use a Wiimote as a joystick in Ogre, in order to create a kind of Monkey Ball. The problem is, everything works fine with keyboard (I don't use the mouse right now), by when I declare

Code:

        pWiimote = static_cast<OIS::JoyStick*>(pInputManager->createInputObject(OIS::OISJoyStick, true));

and launch the program, I get a Runtime Error, without any explanation (I get no errors when compiling)

I'm working under Visual Express 2008, using Bluesoleil as HID. Here's the full code.

Code:
#include "gestionentree.h"

void GestionEntree::InitOIS(Ogre::RenderWindow *pRenderWindow)
{
OIS::ParamList pl;size_t windowHnd = 0;
std::ostringstream windowHndStr;
pRenderWindow->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
pInputManager = OIS::InputManager::createInputSystem( pl );

// création d'objets OIS pour le clavier et la souris
pMouse = static_cast<OIS::Mouse*>(pInputManager->createInputObject(OIS::OISMouse, true));
pKeyboard = static_cast<OIS::Keyboard*>(pInputManager->createInputObject(OIS::OISKeyboard, false));
pWiimote = static_cast<OIS::JoyStick*>(pInputManager->createInputObject(OIS::OISJoyStick, true));

// définit la taille de la fenêtre de rendu (pRenderWindow)
unsigned int width, height, depth;
int top, left;
pRenderWindow->getMetrics(width, height, depth, left, top);
const OIS::MouseState &ms = pMouse->getMouseState();
ms.width = width;
ms.height = height;
}


Do you have any ideas of what is wrong? Thanks
Logged
pjcast
Administrator
Veteran
*****
Posts: 2546



View Profile WWW
« Reply #1 on: May 28, 2010, 05:32:54 PM »

1. Have you built OIS with wiimote enabled? By default it is disabled
2. Have you paired the wiimote?
3. You should always enumerate OIS Joysticks instead of assuming one is present.
4. You can surround OIS init methods with try/catch and handle OIS::Exceptions to see what the error is.
Logged
Tikrou
Guest
« Reply #2 on: May 29, 2010, 08:37:22 AM »

1. Yes, I have uncommented #define OIS_WIN32_WIIMOTE_SUPPORT in the OISConfig.h file.
2. By paired, I assume (as you might have guessed, English is not my mother tongue Smiley) you are meaning "connect as an HID device"? If so, I have done this.
3. I've added to the code

Code:
if (pInputManager->numJoySticks()>0)
{
pWiimote = static_cast<OIS::JoyStick*>(pInputManager->createInputObject(OIS::OISJoyStick, true));
}

and indeed the numJoySticks = 0... (note that the Wiimote is detected and works, I have tested this with GlovePie)
Logged
Tikrou
Guest
« Reply #3 on: May 30, 2010, 09:37:22 AM »

Ok, the problem was obvious, I guess my exams are driving me crazy...I forgot to add

Code:
pInputManager->enableAddOnFactory(InputManager::AddOn_All);

now it works perfectly. By the way, thanks for this great library  Smiley
Logged
Tikrou
Guest
« Reply #4 on: June 02, 2010, 10:38:08 AM »

Hello,

once again, I've got a problem with the wiimote. I have wrote this code :
Code:
bool GestionOgre::frameStarted(const Ogre::FrameEvent &evt)
{
    pGestionEntree->pKeyboard->capture();
    pGestionEntree->pWiimote->capture();
    pGestionEntree->pMouse->capture();

if (pGestionEntree->pKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false;
else if (pGestionEntree->isButtonDown(0))
pNode->yaw(Degree(1));
else if (pGestionEntree->isButtonDown(1))
pNode->roll(Degree(1));
else if (pGestionEntree->isButtonDown(2))
pNode->pitch(Degree(1));
else if (pGestionEntree->isButtonDown(3))
pNode->yaw(Degree(-1));
else if (pGestionEntree->isButtonDown(4))
pNode->roll(Degree(-1));
else if (pGestionEntree->isButtonDown(5))
pNode->pitch(Degree(-1));
return true;
}

The probleme is, whatever button of my joystick I press, the node keeps yawing, and nothing else. To be complete, my joystick is unbuffered. Another strange thing is that I once succeeded in rolling and pitching with separate buttons, but then the node keeps yawing in idle state.  The fonction isButtonDown is :
Code:
bool GestionEntree::isButtonDown(int button) const
{
const OIS::JoyStickState& state = pWiimote->getJoyStickState();
return state.mButtons[button];
}

I've another question : is the std::vector<bool> automaticaly converted to a bool in my condition? As far as I'm aware of, a bool is coded on 8 bits, and each element of the std::vector<bool> is only one bit... That is quite confusing for me Smiley
Logged
pjcast
Administrator
Veteran
*****
Posts: 2546



View Profile WWW
« Reply #5 on: June 02, 2010, 06:00:54 PM »

Yes, the bit vector (vector<bool>) will convert properly to regular boolean.

As for the joystick question, I really recommend you use buffered mode for joysticks, but I'm not sure that is part of your problem or not. You can still use the same get state method even when you turn on buffered mode. You could try setting some debug breakpoints in the OIS Wiimote class to see if the button releases are being captured.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!