Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
Gondwana.Input.Gamepad.GamepadStickState Struct Reference

Represents the state of an analog stick on a gamepad, including both normalized floating-point values for convenient use in game logic and raw integer values from the underlying input system. This immutable struct provides methods for deadzone processing, direction detection, and magnitude calculation. More...

Public Member Functions

 GamepadStickState (float x, float y, int rawX=0, int rawY=0)
 Initializes a new instance of the GamepadStickState struct with the specified normalized and optional raw values.
bool IsEngaged (float threshold=0.15f)
 Returns true if the stick is pushed beyond the threshold.
StickDirection Direction (float threshold=0.15f)
 Returns the primary stick direction(s) based on angle and threshold.
GamepadStickState WithDeadzone (float threshold=0.15f)
 Returns a new stick state with a deadzone applied.
override string ToString ()
 Returns a string representation of the normalized stick position showing the X and Y values formatted to two decimal places in the format "(X, Y)".

Static Public Member Functions

static GamepadStickState FromRaw16 (int rawX, int rawY)
 Creates a GamepadStickState instance from raw 16-bit signed integer values.
static GamepadStickState FromRawUnsigned16 (ushort rawX, ushort rawY)
 Creates a GamepadStickState instance from raw 16-bit unsigned integer values.

Properties

float X [get]
 Gets the normalized horizontal position of the analog stick in the range [-1, 1], where -1 represents full left, 0 represents center, and 1 represents full right.
float Y [get]
 Gets the normalized vertical position of the analog stick in the range [-1, 1], where -1 represents full down, 0 represents center, and 1 represents full up.
int RawX [get]
 Raw horizontal value before normalization (e.g., from XInput or SDL2)
int RawY [get]
 Raw vertical value before normalization (e.g., from XInput or SDL2)
float Magnitude [get]
 Returns the magnitude (0 to 1) of the stick position.
float Angle [get]
 Returns the angle (in radians) relative to (1, 0).

Detailed Description

Represents the state of an analog stick on a gamepad, including both normalized floating-point values for convenient use in game logic and raw integer values from the underlying input system. This immutable struct provides methods for deadzone processing, direction detection, and magnitude calculation.

Definition at line 8 of file GamepadStickState.cs.

Constructor & Destructor Documentation

◆ GamepadStickState()

Gondwana.Input.Gamepad.GamepadStickState.GamepadStickState ( float x,
float y,
int rawX = 0,
int rawY = 0 )

Initializes a new instance of the GamepadStickState struct with the specified normalized and optional raw values.

Parameters
xThe normalized horizontal position in the range [-1, 1], where -1 is full left, 0 is center, and 1 is full right.
yThe normalized vertical position in the range [-1, 1], where -1 is full down, 0 is center, and 1 is full up.
rawXThe raw horizontal value from the underlying input system. Default is 0.
rawYThe raw vertical value from the underlying input system. Default is 0.

Definition at line 50 of file GamepadStickState.cs.

Member Function Documentation

◆ Direction()

StickDirection Gondwana.Input.Gamepad.GamepadStickState.Direction ( float threshold = 0::15f)

Returns the primary stick direction(s) based on angle and threshold.

Parameters
thresholdThe threshold used for the comparison.
Returns
The stick direction after applying the deadzone.

Definition at line 113 of file GamepadStickState.cs.

◆ FromRaw16()

GamepadStickState Gondwana.Input.Gamepad.GamepadStickState.FromRaw16 ( int rawX,
int rawY )
static

Creates a GamepadStickState instance from raw 16-bit signed integer values.

The method normalizes the raw input values to a floating-point range of [-1, 1] to represent the stick's position, while preserving the original raw values for reference.

Parameters
rawXThe raw X-axis value, ranging from -32768 to 32767.
rawYThe raw Y-axis value, ranging from -32768 to 32767.
Returns
A GamepadStickState representing the normalized stick position, with X and Y values clamped to the range [-1, 1], and the original raw values.

Definition at line 67 of file GamepadStickState.cs.

◆ FromRawUnsigned16()

GamepadStickState Gondwana.Input.Gamepad.GamepadStickState.FromRawUnsigned16 ( ushort rawX,
ushort rawY )
static

Creates a GamepadStickState instance from raw 16-bit unsigned integer values.

The raw input values are normalized to the range [-1, 1] based on the assumption that the midpoint (32768) represents the neutral position, and the range extends from 0 to 65535.

Parameters
rawXThe raw X-axis value, represented as an unsigned 16-bit integer.
rawYThe raw Y-axis value, represented as an unsigned 16-bit integer.
Returns
A GamepadStickState instance with normalized X and Y values in the range [-1, 1], along with the original raw input values.

Definition at line 84 of file GamepadStickState.cs.

◆ IsEngaged()

bool Gondwana.Input.Gamepad.GamepadStickState.IsEngaged ( float threshold = 0.15f)

Returns true if the stick is pushed beyond the threshold.

Parameters
thresholdThe threshold used for the comparison.
Returns
true if the control is currently engaged; otherwise, false.

◆ ToString()

override string Gondwana.Input.Gamepad.GamepadStickState.ToString ( )

Returns a string representation of the normalized stick position showing the X and Y values formatted to two decimal places in the format "(X, Y)".

Returns
A string in the format "(X, Y)" where X and Y are formatted to two decimal places.

◆ WithDeadzone()

GamepadStickState Gondwana.Input.Gamepad.GamepadStickState.WithDeadzone ( float threshold = 0::15f)

Returns a new stick state with a deadzone applied.

Parameters
thresholdThe threshold used for the comparison.
Returns
A stick state using the requested deadzone.

Definition at line 131 of file GamepadStickState.cs.

Property Documentation

◆ Angle

float Gondwana.Input.Gamepad.GamepadStickState.Angle
get

Returns the angle (in radians) relative to (1, 0).

Definition at line 99 of file GamepadStickState.cs.

◆ Magnitude

float Gondwana.Input.Gamepad.GamepadStickState.Magnitude
get

Returns the magnitude (0 to 1) of the stick position.

Definition at line 94 of file GamepadStickState.cs.

◆ RawX

int Gondwana.Input.Gamepad.GamepadStickState.RawX
get

Raw horizontal value before normalization (e.g., from XInput or SDL2)

Definition at line 25 of file GamepadStickState.cs.

◆ RawY

int Gondwana.Input.Gamepad.GamepadStickState.RawY
get

Raw vertical value before normalization (e.g., from XInput or SDL2)

Definition at line 30 of file GamepadStickState.cs.

◆ X

float Gondwana.Input.Gamepad.GamepadStickState.X
get

Gets the normalized horizontal position of the analog stick in the range [-1, 1], where -1 represents full left, 0 represents center, and 1 represents full right.

Definition at line 14 of file GamepadStickState.cs.

◆ Y

float Gondwana.Input.Gamepad.GamepadStickState.Y
get

Gets the normalized vertical position of the analog stick in the range [-1, 1], where -1 represents full down, 0 represents center, and 1 represents full up.

Definition at line 20 of file GamepadStickState.cs.