Game Development Community

dev|Pro Game Development Curriculum

Joystick axis support in guiInputCtrl [T3DMIT]

by d0c · 10/08/2013 (1:39 pm) · 3 comments

Hello, i'm doc,is my first post here and my first resource.
Since i can not find anywhere how to do this,
here is how i added joystick axis mapping in options gui:
first we need to edit sourcecode.
open source/gui/utility/guiInputCtrl.cpp
copy a backup of the file(is always a good thing)
go around line 128, find GuiInputCtrl::onInputEvent
the original is:

bool GuiInputCtrl::onInputEvent( const InputEventInfo &event )
{
   // TODO - add POV support...
   if ( event.action == SI_MAKE )

change it to:

bool GuiInputCtrl::onInputEvent( const InputEventInfo &event )
{
   // TODO - add POV support...
   if ( event.action == SI_MAKE || event.action == SI_MOVE )

we have just added an or.
Now let's add the real thing:
go near line 145, you should see:

onInputEvent_callback(deviceString, actionString, 1);

         return( true );
      }
   }
   else if ( event.action == SI_BREAK )

we need to add an "else if" statement to read our axis data, so change as this:

onInputEvent_callback(deviceString, actionString, 1);

         return( true );
      }
	  else if (event.objType == SI_AXIS){
		  F32 value = event.fValue;
		  char deviceString[32];
         if ( !ActionMap::getDeviceName( event.deviceType, event.deviceInst, deviceString ) )
            return( false );

         const char* actionString = ActionMap::buildActionString( &event );

		 //here we see if joystick actually is moved, not completely shure about efficency of this
		 if(event.fValue == 1 || event.fValue == -1){ 
		 onInputEvent_callback(deviceString, actionString, 1);
		 
         return( true );
		 }
	  }
   }
   else if ( event.action == SI_BREAK )

now recompile.

Go to scripts/gui/optionsDlg.cs and find something like that:

$RemapCount = 0;
$RemapName[$RemapCount] = "Forward";
$RemapCmd[$RemapCount] = "moveforward";
$RemapCount++;

here you can add your own mappings, now usable with joystick.
here is a piece of mine:
$RemapName[$RemapCount] = "Yaw";
$RemapCmd[$RemapCount] = "JoystickYaw";
$RemapCount++;
$RemapName[$RemapCount] = "Pitch";
$RemapCmd[$RemapCount] = "JoystickPitch";
$RemapCount++;

last thing, is to find
error( "Unsupported Joystick input object passed to getDisplayMapName!" );

and change it to:
return(%action @ " joystick" @ ( %instance + 1 ));

NOTE: i don't know how much is safe to do this last thing.
as now, i had no problems.

i hope this could be useful.

sorry for my bad english.

About the author


#1
10/08/2013 (3:06 pm)
Useful stuff, doc. :)
#2
10/09/2013 (4:08 am)
Does this introduce issues with other input devices?
I guess this could make for a good pull reuqest!
#3
10/09/2013 (12:11 pm)
To be honest, i don't know if it could bring to problems with other input devices.

The only "issue" i found is at scripting level, when someone tries to assign a key (for example keyboard) to an axis, it obviously not work in game.

i'm using this by about three days, and no problems since now.
The only thing i'm not so shure is efficent is the

if(event.fValue == 1 || event.fValue == -1){   
         onInputEvent_callback(deviceString, actionString, 1);

I don't know why, but it sounds a bit "hacky" to me. There should be a better way.

If anyone can test it with other input devices, it would be cool :)

Thanks for feedback.