Std::cout < < " \n\tERROR! PLAYER 1 - XBOX 360 Controller Not Found!\n" If(Player1- >GetState().Gamepad.wButtons & XINPUT_GAMEPAD_BACK) If(Player1- >GetState().Gamepad.wButtons & XINPUT_GAMEPAD_Y) If(Player1- >GetState().Gamepad.wButtons & XINPUT_GAMEPAD_X) If(Player1- >GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B) If(Player1- >GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A) This small bit will allow us to test the controller class: Due to our use of 0 as the default values for leftVal and rightVal, we can call controller->Vibrate() alone to stop all vibration on the controller. Just as a precaution, we zero-out this memory, then set the vibration speeds, and finally set the vibration state with XInputSetState. We first define an instance of the XINPUT_VIBRATION struct, which allows us to store the vibration speeds into one structure. Each of these can range from 0 to 65535, indicating the strength of the motor's vibration, 65535 being the strongest. We take this into account by allowing a value for the left motor and a value for the right motor. The Xbox 360 has two vibration motors in it one on the left, and one on the right. If the controller is connected and has no problems, XInputGetState() will return ERROR_SUCCESS, stating that everything is okay.Īnd finally, we implement a feature to allow for vibration. As in the GetState() function, we need to zero-out the memory and update the state, so that we can keep on top of the controller's state in case of a sudden disconnection. We then return the state of the controller.Īfter this, we implement IsConnected(), which returns true if the controller is connected and has no errors, or false if something is wrong. This will ensure that _controllerState is always up-to-date. We then make a call to XInputGetState, and pass the controller number and the address of the controller state variable to store the state of the controller into. First, we must zero-out the pointer to the game state, so that we can ensure no artifacts exist, by way of which the input is checked. Next, we flesh out the function that gets the state of the controller. This is where the CXBOXController class is fleshed out and given life.įirst, the CXBOXController constructor assigns the controller number based on the player number (player 1 = 0, player 2 = 1, player 3 = 2, player 4 = 3). XInputSetState(_controllerNum, &Vibration) ZeroMemory(&Vibration, sizeof(XINPUT_VIBRATION)) Void CXBOXController::Vibrate( int leftVal, int rightVal) XInputGetState(_controllerNum, &_controllerState) ĭWORD Result = XInputGetState(_controllerNum, &_controllerState) ZeroMemory(&_controllerState, sizeof(XINPUT_STATE)) Fleshing It OutĬXBOXController::CXBOXController( int playerNumber) The Vibrate() function simply provides us with a quick and easy method for vibrating the controller. IsConnected() checks to ensure that the controller is connected, and will return ERROR_SUCCESS if successful. GetState() updates the Controller's state and returns the state information to the caller so that checks can be made on the input (which will be done later when we flesh out the program). _controllerState holds the state of the Xbox 360 Controller, _controllerNum holds a reference to which controller (0-3) is being stored by the class. This defines a simple C++ class that manages an Xbox 360 Controller. Void Vibrate( int leftVal = 0, int rightVal = 0) A COMPILER THAT SUPPORTS THIS METHOD OF LINKING LIBRARIES NOTE: COMMENT THIS OUT IF YOU ARE NOT USING #include #include // Now, the XInput Library We need the Windows Header and the XInput Header
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |