Unigine.ControlsSixAxis Class
Inherits from: | Controls |
This class handles Sixaxis controller input. 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.
- Vibration motors allow to set vibration effects. The amount of vibration for each of the motors can be set via SetLargeMotor() and SetSmallMotor().
- Controller position/G-sensor data can be obtained via SensorX, SensorY, SensorZ and SensorG.
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().
ControlsSixAxis Class
Properties
float Filter#
The A filter value used to correct the current state of the analog axis of the sixaxis controller 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 sixaxis controller.
bool IsAvailable#
The Checks if the Sixaxis controller is available.
int Number#
The number of sixaxis controllers.
bool IsStateEvent#
The A value indicating if a sixaxis controller button is successfully assigned to a state.
float SensorG#
The A state value of the G-sensor.
float SensorZ#
The A state value of the controller position along the Z-axis.
float SensorY#
The A state value of the controller position along the Y-axis.
float SensorX#
The A state value of the controller position along the X-axis.
float PressSquare#
The A state value of the square button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressCross#
The A state value of the cross button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressCircle#
The A state value of the circle button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressTriangle#
The A state value of the triangle button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressRight#
The A state value of the right button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressLeft#
The A state value of the left button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressDown#
The A state value of the down button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressUp#
The A state value of the up button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressR2#
The A state value of the r2 button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressL2#
The A state value of the l2 button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressR1#
The A state value of the r1 button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float PressL1#
The A state value of the l1 button. 0 value means the button is not pressed; 1 means the button is pressed to the maximum.
float RightY#
The A state value of the right analog stick along the Y-axis. when the stick 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 analog stick along the X-axis. when the stick 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 analog stick along the Y-axis. when the stick 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 analog stick along the X-axis. when the stick is in the center position, this value is zero. negative values indicate left ; positive values indicate right.
Members
ControlsSixAxis ( int num ) #
Constructor. Creates a new Sixaxis controller.Arguments
- int num - Sixaxis controller number.
int GetButton ( int button ) #
Returns a button state (pressed or not pressed).Arguments
- int button - Button number.
Return value
1 if the button is pressed; otherwise, 0.void SetLargeMotor ( float speed ) #
Sets the amount of vibration for the large motor.Arguments
- float speed - Speed of motor rotation in range [0; 1]
void SetSmallMotor ( float speed ) #
Sets the amount of vibration for the small motor.Arguments
- float speed - Speed of motor rotation in range [0; 1]
void SetStateButton ( int state, int button ) #
Sets a Sixaxis controller 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 BUTTON_* variables).
int GetStateButton ( int state ) #
Returns a Sixaxis controller 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 BUTTON_* variables)void GetStateEvent ( int state ) #
Lets the user assign a Sixaxis controller button to a given state.Arguments
- int state - State (one of the CONTROLS_STATE_*) to which a button is going to be assigned.
string GetStateName ( int state ) #
Returns the name of a given state.Arguments
- int state - State (one of the CONTROLS_STATE_* variables).
int ClearButton ( int button ) #
Returns a button state and clears it to 0 (not pressed).Arguments
- int button - Button that switches the state (one of the 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 Sixaxis controller settings into the stream.Example using saveState() and restoreState() methods:
// initialize a node and set its state
ControlsSixAxis sixAxis = new ControlsSixAxis(1);
sixAxis.SetStateButton(0,1);
// save state
Blob blob_state = new Blob();
sixAxis.SaveState(blob_state);
// change the node state
sixAxis.SetStateButton(2,1);
// restore state
blob_state.SeekSet(0); // returning the carriage to the start of the blob
sixAxis.RestoreState(blob_state);
Arguments
- Stream stream - The stream to save controls data.
Return value
true if the Sixaxis controller settings are saved successfully; otherwise, false.bool RestoreState ( Stream stream ) #
Restores Sixaxis controller settings from the stream.Example using saveState() and restoreState() methods:
// initialize a node and set its state
ControlsSixAxis sixAxis = new ControlsSixAxis(1);
sixAxis.SetStateButton(0,1);
// save state
Blob blob_state = new Blob();
sixAxis.SaveState(blob_state);
// change the node state
sixAxis.SetStateButton(2,1);
// restore state
blob_state.SeekSet(0); // returning the carriage to the start of the blob
sixAxis.RestoreState(blob_state);
Arguments
- Stream stream - The stream to save controls data.
Return value
true if the Sixaxis controller settings are restored successfully; otherwise, false.int UpdateEvents ( ) #
Scans Sixaxis controller (synchronizes states of controller buttons with the controller). Should be called each frameReturn value
0 if a game pad is not found or updateEvents() already has been called for the frame; otherwise 1.Last update:
2022-03-10
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)