Game Development Community

RESOLVED: Joystick POV hat: How to make it work

by Jason Cahill · in Torque Game Builder · 06/12/2005 (11:18 pm) · 3 replies

I've been banging my head against the wall for a day trying to get the D-pad part of my joystick to work in Torque. Here's some background:

I've got a PS Dual Shock controller with drivers. In DirectX (the Joystick sample) I can see the D-pad working as a POV hat.

I've got T2D building and I enabled LOG_INPUT and I do, in fact, get input events for POV hat.

I've set breakpoints and traced my code through the debugger from when the POV event initiates to where it should fire the handler in my action map. I can't quite figure out why Torque is skipping past my registered handler for the POV stuff. Other handlers for buttons, and analog axes work fine, but none of the *pov events seem to work.

Here's the relevant snippets of my project:

$enableDirectInput = 1;
	activateDirectInput();
	enableJoystick();

	new ActionMap(playerMap);
	playerMap.bindCmd(joystick0, "xpov", xpovMake, xpovBreak);
	playerMap.bindCmd(joystick0, "lpov", lpovMake, lpovBreak);
	playerMap.bind(joystick0, "button0", button0);
	playerMap.push();

...

function xpovMake() { echo("xpov MAKE"); }
function xpovBreak() { echo("xpov BREAK"); }

function lpovMake() { echo("lpov MAKE"); }
function lpovBreak() { echo("lpov BREAK"); }

If anyone has a small sample showing how to make this work, I'd be really grateful!!!

#1
06/12/2005 (11:19 pm)
Also, there are no script errors in my source file, so it's not like I've just got a bug in my source code and that's what's hanging it all up.
#2
06/14/2005 (12:01 am)
OK, I've found the bug. It's two things in file /engine/PlatformWin32/winDInputDevice.cc:

1. Uncomment lines 1051 - 1088. I don't know why this was commented out, but that's how I got it.
2. Add the following line of code: newEvent.objType = newEvent.objInst; right before each call to Game->postEvent( newEvent );. In total, you should have 6 of these between lines 1050 - 1088. Recompile and voila!

For whatever reason, objType was set to "3" instead of 516 (for XPOV) or 517 (for YPOV). My gamepad uses XPOV & YPOV2, so make sure you hook everything to see how your gamepad works. YMMV. Also, POV stuff always fires an event for both X and Y, not just the one that changed. So, if the D-PAD is centered and you push UP, expect XPOV + YPOV back to back in that order.

Enjoy!
#3
06/22/2005 (12:33 pm)
Good job, thanks for posting the fix!