Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Pages: 1 [2]

Author Topic: joystick axis problem  (Read 5095 times)

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
joystick axis problem
« Reply #15 on: November 16, 2006, 11:13:53 AM »

Here is the patch, I have also committed to cvs - not sure how long anonymous cvs is taking to update nowadays.

Code: [Select]

Index: includes/win32/Win32JoyStick.h
===================================================================
RCS file: /cvsroot/wgois/ois/includes/win32/Win32JoyStick.h,v
retrieving revision 1.7
diff -u -r1.7 Win32JoyStick.h
--- includes/win32/Win32JoyStick.h 31 Aug 2006 02:16:10 -0000 1.7
+++ includes/win32/Win32JoyStick.h 16 Nov 2006 18:35:49 -0000
@@ -74,7 +74,6 @@
 
  //! Mapping
  int _AxisNumber;
- std::map<int, int> mAxisMapping;
  };
 }
 
Index: src/win32/Win32JoyStick.cpp
===================================================================
RCS file: /cvsroot/wgois/ois/src/win32/Win32JoyStick.cpp,v
retrieving revision 1.19
diff -u -r1.19 Win32JoyStick.cpp
--- src/win32/Win32JoyStick.cpp 18 Sep 2006 01:31:12 -0000 1.19
+++ src/win32/Win32JoyStick.cpp 16 Nov 2006 19:14:55 -0000
@@ -27,7 +27,7 @@
 #include "OISEvents.h"
 #include "OISException.h"
 
-#include <iostream>
+#include <cassert>
 
 using namespace OIS;
 
@@ -115,9 +115,9 @@
  numAxes = (short)DIJoyCaps.dwAxes;
  numButtons = (short)DIJoyCaps.dwButtons;
  numHats = (short)DIJoyCaps.dwPOVs;
-
+
+ //Reset the axis mapping enumeration value
  _AxisNumber = 0;
- mAxisMapping.clear();
 
  //Enumerate Force Feedback (if any)
  mJoyStick->EnumEffects(DIEnumEffectsCallback, this, DIEFT_ALL);
@@ -129,11 +129,22 @@
 //--------------------------------------------------------------------------------------------------//
 BOOL CALLBACK Win32JoyStick::DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
 {
- DIPROPRANGE diprg;
  Win32JoyStick* _this = (Win32JoyStick*)pvRef;
 
- _this->mAxisMapping[lpddoi->dwOfs] = _this->_AxisNumber++;
+ //Setup mappings
+ DIPROPPOINTER diptr;
+ diptr.diph.dwSize       = sizeof(DIPROPPOINTER);
+ diptr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ diptr.diph.dwHow        = DIPH_BYID;
+ diptr.diph.dwObj        = lpddoi->dwType;
+ //Add the high bit in so that an axis value of zero does not mean a null userdata
+ diptr.uData             = 0x80000000 | _this->_AxisNumber++;
+
+ if (FAILED(_this->mJoyStick->SetProperty(DIPROP_APPDATA, &diptr.diph)))
+ OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set mapping ptr property" );
 
+ //Set range
+ DIPROPRANGE diprg;
  diprg.diph.dwSize       = sizeof(DIPROPRANGE);
  diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
  diprg.diph.dwHow        = DIPH_BYID;
@@ -142,7 +153,7 @@
  diprg.lMax              = MAX_AXIS;
 
  if (FAILED(_this->mJoyStick->SetProperty(DIPROP_RANGE, &diprg.diph)))
- OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set property" );
+ OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set min/max range property" );
 
  //Check if FF Axes
  if((lpddoi->dwFlags & DIDOI_FFACTUATOR) != 0 )
@@ -198,7 +209,8 @@
     mJoyStick->Poll();
  hr = mJoyStick->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 );
  //Perhaps the user just tabbed away
- if( FAILED(hr) ) return;
+ if( FAILED(hr) )
+ return;
  }
 
  bool axisMoved[24] = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,
@@ -208,12 +220,17 @@
  //Loop through all the events
  for(unsigned int i = 0; i < entries; ++i)
  {
- //First check to see if entry is a Axis as enumerated earlier:
- std::map<int, int>::iterator it = mAxisMapping.find( diBuff[i].dwOfs );
- if( it != mAxisMapping.end() )
+ //First check to see if event entry is a Axis we enumerated earlier
+ if( diBuff[i].uAppData > 0 )
  {
- int axis = it->second;
- mState.mAxes[axis].abs = (short)diBuff[i].dwData;
+ if( diBuff[i].uAppData == 0xFFFFFFFF )
+ {
+ assert( false && "If you hit this assertion, then your user pointer data got zapped too!" );
+ }
+
+ int axis = 0x7FFFFFFF & diBuff[i].uAppData; //Mask out the high bit
+ assert( axis > 0 && axis < mState.mAxes.size() && "Axis out of range!");
+ mState.mAxes[axis].abs = diBuff[i].dwData;
  axisMoved[axis] = true;
  }
  else

Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
joystick axis problem
« Reply #16 on: November 16, 2006, 12:48:30 PM »

Hmm, actually, I just noticed that this adversely affects buttons and hats now... I guess I have some more tweaking to do.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
joystick axis problem
« Reply #17 on: November 16, 2006, 12:55:50 PM »

Actually, this seems to work perfect here.. small modifaction after you apply first patch:

Code: [Select]

Index: src/win32/Win32JoyStick.cpp
===================================================================
RCS file: /cvsroot/wgois/ois/src/win32/Win32JoyStick.cpp,v
retrieving revision 1.20
diff -u -r1.20 Win32JoyStick.cpp
--- src/win32/Win32JoyStick.cpp 16 Nov 2006 19:12:51 -0000 1.20
+++ src/win32/Win32JoyStick.cpp 16 Nov 2006 20:57:52 -0000
@@ -221,13 +221,8 @@
  for(unsigned int i = 0; i < entries; ++i)
  {
  //First check to see if event entry is a Axis we enumerated earlier
- if( diBuff[i].uAppData > 0 )
+ if( diBuff[i].uAppData != 0xFFFFFFFF && diBuff[i].uAppData > 0 )
  {
- if( diBuff[i].uAppData == 0xFFFFFFFF )
- {
- assert( false && "If you hit this assertion, then your user pointer data got zapped too!" );
- }
-
  int axis = 0x7FFFFFFF & diBuff[i].uAppData; //Mask out the high bit
  assert( axis > 0 && axis < mState.mAxes.size() && "Axis out of range!");
  mState.mAxes[axis].abs = diBuff[i].dwData;
@@ -309,11 +304,6 @@
  if(!_doButtonClick((diBuff[i].dwOfs - DIJOFS_BUTTON0), diBuff[i]))
  return;
  }
- #ifdef _DEBUG
- else
- OIS_EXCEPT(E_General, "Debugging Information: JoyStick Action item not found!");
- #endif
-
  break;
  } //end case
  } //End else

Logged

gjaegy

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 29
    • View Profile
joystick axis problem
« Reply #18 on: November 17, 2006, 12:03:47 AM »

First thanks for the support, such a quick response is very valuable.

Secondly, thanks for the bug fix, I think the way you've solved the problem is quite elegant.

I still found something that need to be changed:

Code: [Select]
assert( axis > 0 && axis < mState.mAxes.size() && "Axis out of range!");

should be

Code: [Select]
assert( axis >= 0 && axis < mState.mAxes.size() && "Axis out of range!");

By the way, your library rocks ! I think there is definitively a need for an opensource cross-platform input library, so keep on the good work !
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
joystick axis problem
« Reply #19 on: November 17, 2006, 09:19:32 AM »

I got a PM from this on the Ogre forum, fixed now :D

For some reason, my controller has an extra reported axis (in 0) that is not really on the device.. So, I have 7 axes reported, but only 6 physical ones. So, I never actually could move axis 0 to trigger that, and overlooked the assertion.

Yup, I've always agreed that a pure input library was missing. Now, I think OIS has filled that void ;)
Logged

gjaegy

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 29
    • View Profile
joystick axis problem
« Reply #20 on: November 17, 2006, 09:32:41 AM »

I think so. I will try to make some advertisement here in Europe ;)
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
joystick axis problem
« Reply #21 on: November 17, 2006, 10:22:53 AM »

Quote from: "gjaegy"
I think so. I will try to make some advertisement here in Europe ;)


Sounds great :)

The only thing that I think is lacking as of now are:

* Joystick support under OSX (Keyboard and mouse work now)
* Additional Platform Support (Xbox 360, PS3, Wii, etc) - Even if I could only release the code to registered developers
* FreeBSD support
Logged
Pages: 1 [2]