Unigine.ControlsXPad360 Class
Inherits from: | Controls |
This class handles XBox 360 game pads input. Right now these game pads are supported only on Windows. It provides access to the following controller properties:
- Buttons represent digital buttons on the controller and can be either pressed or unpressed. Just like in the case of mouse/keyboard controls, they can be mapped to the specific controls states, to bind input events and programmed actions. You can either bind buttons in the code via SetStateButton() or let the user assign the button for a control state via GetStateEvent().
- D-pad is represented as four directional buttons (left, right, up and down). They are handled in the same way as other buttons.
- Thumbsticks are left and right analog directional sticks on the controller. They are queried via LeftX and LeftY for the left thumbstick and RightX and RightY for the right one. Thumbsticks also act as two digital buttons when pressed (i.e. the stick is "clicked" in). In this case, they are handled in the same way as other buttons.
- Triggers are two analog controls that can be queried for their states via LeftTrigger and RightTrigger.
- Vibration motors allow to set vibration effects. The left motor is a low-frequency rumble motor, while the right motor is a high-frequency one. The amount of vibration for each of the motors can be set via SetLeftMotor() and SetRightMotor().
Input data from analog controls (thumbsticks and triggers) can be additionally filtered via Filter to provide smooth interpolation between frames and avoid jerks.
A controller should update the physical state of all its input controls (i.e. check whether the user has pressed the button, for example) each frame using
UpdateEvents().
See also#
A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/controls/ folder:
- xpad360_00
- xpad360_01
ControlsXPad360 Class
Properties
float Filter#
The A filter value used to correct the current state of the analog axis (thumbsticks and triggers) relative to the previous one:
- Filter value of 0 means there is no interpolation and the current value is not corrected.
- Filter value of 1 means the previous state is used instead of the current one.
string Name#
The name of the game pad.
bool IsAvailable#
The Checks if the game pad is available.
int Number#
The game pad number (up to four game pads are supported).
bool IsStateEvent#
The A value indicating if a game pad button is successfully assigned to a state.
float RightTrigger#
The An axis state value (the position) of the right trigger. zero means the trigger is not pressed; 1 means the trigger is pressed to the maximum.
float LeftTrigger#
The An axis state value (the position) of the left trigger. zero means the trigger is not pressed; 1 means the trigger is pressed to the maximum.
float RightY#
The A state value of the right thumbstick along the Y-axis. When a thumbstick is in the center position, this value is zero. Negative values indicate down; positive values indicate up.
float RightX#
The A state value of the right thumbstick along the X-axis. When a thumbstick is in the center position, this value is zero. Negative values indicate left; positive values indicate right.
float LeftY#
The A state value of the left thumbstick along the Y-axis. When a thumbstick is in the center position, this value is zero. Negative values indicate down; positive values indicate up.
float LeftX#
The A state value of the left thumbstick along the X-axis. When a thumbstick is in the center position, this value is zero. Negative values indicate left; positive values indicate right.
Members
ControlsXPad360 ( int num ) #
Constructor. Creates a new XBox 360 game pad.Arguments
- int num - Game pad number (up to four game pads are supported).
int GetButton ( int button ) #
Returns a button state (pressed or not pressed).Arguments
- int button - Button (one of the CONTROLS_XPAD360_BUTTON_* variables).
Return value
1 if the button is pressed; otherwise, 0.void SetLeftMotor ( float speed ) #
Sets the amount of vibration for the left motor (a low-frequency motor).Arguments
- float speed - Speed of motor rotation in range [0; 1].
void SetRightMotor ( float speed ) #
Sets the amount of vibration for the right motor (a high-frequency motor).Arguments
- float speed - Speed of motor rotation in range [0; 1].
void SetStateButton ( int state, int button ) #
Sets a game pad button that switches a given state on and off.Arguments
- int state - State (one of the CONTROLS_STATE_* variables).
- int button - Button that switches the state (one of the CONTROLS_XPAD360_BUTTON_* variables).
int GetStateButton ( int state ) #
Returns a game pad button that switches a given state on and off.Arguments
- int state - State (one of the CONTROLS_STATE_* variables).
Return value
Button that switches the state (one of the CONTROLS_XPAD360_BUTTON_* variables):- BUTTON_A = 0
- BUTTON_B
- BUTTON_X
- BUTTON_Y
- BUTTON_BACK
- BUTTON_START
- BUTTON_DPAD_UP
- BUTTON_DPAD_DOWN
- BUTTON_DPAD_LEFT
- BUTTON_DPAD_RIGHT
- BUTTON_THUMB_LEFT
- BUTTON_THUMB_RIGHT
- BUTTON_SHOULDER_LEFT
- BUTTON_SHOULDER_RIGHT
void GetStateEvent ( int state ) #
Lets the user assign a game pad button to a given state.Arguments
- int state - State (one of the CONTROLS_STATE_* variables), to which a button is going to be assigned.
int IsStateEvent ( ) #
Returns a value indicating if a game pad button is successfully assigned to a state.Return value
1 if a button is already assigned; otherwise, 0.string GetStateName ( int state ) #
Returns the name of a given state.Arguments
- int state - State (one of the CONTROLS_STATE_* variables).
Return value
State name.int ClearButton ( int button ) #
Returns a button state and clears it to 0 (not pressed).Arguments
- int button - Button (one of the CONTROLS_XPAD360_BUTTON_* variables).
Return value
1 if the button is pressed, and this function was not called previously in the current frame; otherwise, 0.bool SaveState ( Stream stream ) #
Saves XBox 360 game pad settings into the stream.Example using saveState() and restoreState() methods:
// initialize a node and set its state
ControlsXPad360 xpad = new ControlsXPad360(1);
xpad.SetStateButton(0,1);
// save state
Blob blob_state = new Blob();
xpad.SaveState(blob_state);
// change the node state
xpad.SetStateButton(2,1);
// restore state
blob_state.SeekSet(0); // returning the carriage to the start of the blob
xpad.RestoreState(blob_state);
Arguments
- Stream stream - The stream to save controls data.
Return value
true if the XBox 360 game pad settings are saved successfully; otherwise, false.bool RestoreState ( Stream stream ) #
Restores XBox 360 game pad settings from the stream.Example using saveState() and restoreState() methods:
// initialize a node and set its state
ControlsXPad360 xpad = new ControlsXPad360(1);
xpad.SetStateButton(0,1);
// save state
Blob blob_state = new Blob();
xpad.SaveState(blob_state);
// change the node state
xpad.SetStateButton(2,1);
// restore state
blob_state.SeekSet(0); // returning the carriage to the start of the blob
xpad.RestoreState(blob_state);
Arguments
- Stream stream - The stream to save controls data.
Return value
true if the XBox 360 game pad settings are restored successfully; otherwise, false.int UpdateEvents ( ) #
Scans a game pad (synchronizes states of game pad buttons and thumbsticks with the controller itself). Should be called each frame.Return value
0 if a game pad is not found or updateEvents() already has been called for the frame; otherwise 1.Last update:
2021-12-13
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)