This is for those of us that wanted to add gamepads to our games and programs but did not know how. This tutorial stems from the experience of getting a D-Pad (Directional Pad) and Analog Sticks recognized by TV3D. The listings we’re going to see in this small tutorial should work for both PSX (Playstation Game Paddles via the usb adapter), 12-buttons PC Game paddles and Dual Analog sticks. This is made using TV6.5 and VB.Net but the code can be ported easily to your desired language. TV initialization code is available elsewhere in this wiki. Enough talk!
First off in your Declarations were ever you are putting them:
Public GamePad As TV3D65.TVGameControllers
Next you need to initialize the gamepad(s):
GamePad = New TV3D65.TVGameControllers GamePad.Item(0).Initialize()
As you can see, it is only 2 lines of code. Line 1 is to set up the gamepad TVGameControllers engine. Line 2 is to initialize the gamepad.
Also take note that the gamepad has a index number of 0, depending on how many gamepads and what one you are using that index number will change.
Now comes to the part that you all like me wanted to know. How we can get the buttons, D-Pad and Analogs to be recognized.
In the game loop or in your input polling method:
Public Sub CheckGamePadInput() ' Game pad 1 (PSX/PC DUal Stick 12 button paddles) GamePad.Item(0).Poll() GamePad.Item(0).GetControllerState() If GamePad.Item(0).GetButtonState(0) = True Then ' this is 0 - 11 for button index numbers if it is pressed do this Else if not do this End If ' Directional Pad Select Case GamePad.Item(0).GetControllerStateAdvanced.PointOfView0 Case -1 No Press Case 0 up Case 9000 right Case 18000 down Case 27000 left Case 4500 up right Case 13500 right down Case 22500 down left Case 31500 left up End Select ' Left Analog Stick if GamePad.Item(0).GetControllerStateAdvanced.x < 5000 then If GamePad.Item(0).GetControllerStateAdvanced.x > 5000 then if GamePad.Item(0).GetControllerStateAdvanced.y > 5000 then if GamePad.Item(0).GetControllerStateAdvanced.y > 5000 then ' Right Analog Stick if GamePad.Item(0).GetControllerStateAdvanced.rotationz < 5000 then if GamePad.Item(0).GetControllerStateAdvanced.rotationz > 5000 then if GamePad.Item(0).GetControllerStateAdvanced.z > 5000 then if GamePad.Item(0).GetControllerStateAdvanced.z > 50000 then End Sub
D-Pad up = 0 down = 18000 left = 27000 right = 9000 up right = 4500 right down 13500 down left 22500 up left = 31500 no press = -1
Left Analog is X and Y center is 5000 and the range of motion ranges from 1 to 10000. Right Analog is Z and Rotation Z center is 5000 and the range of motion ranges from 1 to 10000.
Now you should be able to use this in your Truevision3D Applications and extend it so that users can configure the buttons or add game pads. This could also be a way for your program to have built in templates for all sorts of game pads.