This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.ControlsJoystick Class

Inherits from: Controls

This class handles joystick input. Unlike XBox 360 controllers, generic joysticks cannot be hot-plugged. Therefore, a joystick should be already plugged before you create an instance of this class.

The ControlsJoystick class provides access to the following controller input:

  • Axes detect movement along X and Y axes (if a joystick is two-axis, which is the most typical case) and along Z axis (if it is three-axis one). Two-axis joysticks are configured in such a way that left-to-right movement of the stick is mapped to the movement along the X axis, while movement from backward to forward (down-up) indicates movement along the Y axis. In case of 3D joystick, twisting the stick to the left (counter-clockwise) or to the right (clockwise) corresponds to movement along the Z axis.
    Axes are quired for their states via getAxis(). To provide smooth interpolation between frames and avoid jerks, axis values can be filtered viasetFilter().
  • Buttons correspond to the each button on the controller and can be either pressed or unpressed. Just in case with 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().
  • POV (Point-Of-View) hat switches indicate the direction of view and support a number of positions such as left, right, up and down (similar to a D-pad).

A joystick 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 UnigineScript API sample <UnigineSDK>/data/samples/controls/joystick_00

ControlsJoystick Class

Properties

int NumButtons#

The number of buttons supported by the joystick.

int NumPovs#

The number of POV hat switches supported by the joystick.

int NumAxes#

The number of axes supported by the joystick.

float Filter#

A filter value used to correct the current state of the joystick axis 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.
set
Sets a filter value used to correct the current state of the joystick axis relative to the previous one.
set value - Filter value for interpolation between axis states. The provided value is clamped to a range [0;1].
  • 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 joystick.

bool IsAvailable#

Checks if the joystick is available.

int Number#

The joystick number.

string GuidInstance#

GUID of the joystick device. This can be very useful in case your application uses non-standard custom input devices to ensure proper configuration (dead zones, inverse flags, correction curves, etc.).

string GuidProduct#

GUID supplied by the device's manufacturer. This can be very useful in case your application uses non-standard custom input devices to ensure proper configuration (dead zones, inverse flags, correction curves, etc.).

Members


ControlsJoystick ( int num ) #

Constructor. Creates a new joystick.

Arguments

  • int num - Joystick number.

float GetAxis ( int axis ) #

Returns a state value of a given axis. It includes position of the joystick along the following axes: X, Y (two-axis joystick) and Z (three-axis joystick). When a joystick is in the center position, X and Y axes values are zero. Negative values indicate left or down; positive values indicate right or up.

Arguments

  • int axis - Axis number.

Return value

Value in range [-1; 1].

string GetAxisName ( int axis ) #

Returns the name of a given axis.

Arguments

  • int axis - Axis number.

Return value

Axis name.

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.

string GetButtonName ( int button ) #

Returns the name of a given button.

Arguments

  • int button - Button number.

Return value

Button name.

string GetGuidProduct ( ) #

Returns the GUID supplied by the device's manufacturer. This can be very useful in case your application uses non-standard custom input devices to ensure proper configuration (dead zones, inverse flags, correction curves, etc.).

Return value

GUID supplied by the device's manufacturer.

string GetGuidInstance ( ) #

Returns the GUID of the joystick device. This can be very useful in case your application uses non-standard custom input devices to ensure proper configuration (dead zones, inverse flags, correction curves, etc.).

Return value

GUID of the joystick device.

int GetPov ( int pov ) #

Returns a POV hat switch state. POV hats support the following positions: left, right, up and down.

Arguments

  • int pov - POV pad number.

Return value

One of the following:
  • -1  — not pressed
  • 0  — pressed "up"
  • 4500  — pressed "up" and "right"
  • 9000  — pressed "right"
  • 13500  — pressed "down" and "right"
  • 18000  — pressed "down"
  • 22500  — pressed "down" and "left"
  • 27000  — pressed "left"
  • 31500  — pressed "up" and "left"

string GetPovName ( int pov ) #

Returns the name of a given POV hat switch.

Arguments

  • int pov - POV hat number.

Return value

POV hat name.

void SetStateButton ( int state, int button ) #

Sets a joystick button that switches a given state on or off.

Arguments

  • int state - State (one of the CONTROLS_STATE_* variables).
  • int button - Button number.

int GetStateButton ( int state ) #

Returns a game pad button that switches a given state on and off.

Arguments

Return value

Button that switches the given state.

void GetStateEvent ( int state ) #

Lets the user assign a joystick 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 joystick 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, that was assigned to one of controls.

Arguments

Return value

State name.

int ClearButton ( int button ) #

Returns a button state and clears it to 0 (not pressed).

Arguments

  • int button - Button number.

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 ControlsJoystick settings into the stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// initialize a node and set its state
ControlsJoystick joystick = new ControlsJoystick(1);
joystick.SetStateButton(0,1);

// save state
Blob blob_state = new Blob();
joystick.SaveState(blob_state);

// change the node state
joystick.SetStateButton(2,1);

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
joystick.RestoreState(blob_state);

Arguments

  • Stream stream - The stream to save controls data.

Return value

true if the ControlsJoystick settings are saved successfully; otherwise, false.

bool RestoreState ( Stream stream ) #

Restores ControlsJoystick settings from the stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// initialize a node and set its state
ControlsJoystick joystick = new ControlsJoystick(1);
joystick.SetStateButton(0,1);

// save state
Blob blob_state = new Blob();
joystick.SaveState(blob_state);

// change the node state
joystick.SetStateButton(2,1);

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
joystick.RestoreState(blob_state);

Arguments

  • Stream stream - The stream to save controls data.

Return value

true if the ControlsJoystick settings are restored successfully; otherwise, false.

int UpdateEvents ( ) #

Scans the joystick controls (synchronizes joystick button states with the controller itself). Should be called each frame.
Notice
On Windows, in case a joystick is not connected, this function can substantially increase per-frame update time. (This happens due to calling IDirectInput8::EnumDevices() method.)

Return value

0 if a joystick is not found or updateEvents() already has been called for the frame; otherwise 1.
Last update: 2021-04-29
Build: ()