View Single Post
  #7   Spotlight this post!  
Unread 28-10-2002, 23:43
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
OK, I finally figured this out w/o DirectX or assembly! Here's the code you need:

Code:
#include <windows.h>
#include <mmsystem.h>
....

	JOYINFOEX joyInfo1;
	MMRESULT err;

	ZeroMemory(&joyInfo1, sizeof(JOYINFOEX));
	joyInfo1.dwSize=sizeof(JOYINFOEX);
	joyInfo1.dwFlags=JOY_RETURNALL;

	err=joyGetPosEx(JOYSTICKID1, &joyInfo1);
	if(err!=JOYERR_NOERROR){
		switch(err){
		case MMSYSERR_NODRIVER:
			//no driver installed
			break;
		case MMSYSERR_INVALPARAM:
			//invalid parameter passed
			break;
		case MMSYSERR_BADDEVICEID:
			//joystick ID is invalid
			break;
		case JOYERR_UNPLUGGED:
			//joystick is not pluged in
			break;
		}
	}
At this point, the joyInfo1 struct contains everything you could ever want. Here's a quick rundown of the important fields:

dwXpos: the x pos
dwYpos: the y pos
dwZpos: the z pos
dwButtons: All 32 buttons

In order to access an individual button, use the JOY_BUTTON1, JOY_BUTTON2, etc as a bit mask. I.e:

bool button1=(joyInfo1.dwButtons & JOY_BUTTON1 > 0 ? 1 : 0)

In order to use this stuff, you'll have to tell your compiler to link in the winmm.lib library.

Calibration comes from the Gaming Options control panel, but you'll probably want to check the values yourself just to make sure.

Finally, to access joystick #2, replace JOYSTICKID1 with JOYSTICKID2 in the joyGetPosEx function.


Anyway, I hope this helps. Let me know if something goes wrong or if you want some more detail/additional options. Alternatively, check out the MSDN library entry for JOYINFOEX.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php