SDL3pp
A slim C++ wrapper for SDL3
|
The SDL haptic subsystem manages haptic (force feedback) devices. More...
Classes | |
struct | SDL::HapticParam |
Safely wrap Haptic for non owning parameters. More... | |
class | SDL::Haptic |
The haptic structure used to identify an SDL haptic. More... | |
struct | SDL::HapticRef |
Semi-safe reference for Haptic. More... | |
Typedefs | |
using | SDL::HapticRaw = SDL_Haptic * |
Alias to raw representation for Haptic. | |
using | SDL::HapticDirection = SDL_HapticDirection |
Structure that represents a haptic direction. More... | |
using | SDL::HapticConstant = SDL_HapticConstant |
A structure containing a template for a Constant effect. More... | |
using | SDL::HapticPeriodic = SDL_HapticPeriodic |
A structure containing a template for a Periodic effect. More... | |
using | SDL::HapticCondition = SDL_HapticCondition |
A structure containing a template for a Condition effect. More... | |
using | SDL::HapticRamp = SDL_HapticRamp |
A structure containing a template for a Ramp effect. More... | |
using | SDL::HapticLeftRight = SDL_HapticLeftRight |
A structure containing a template for a Left/Right effect. More... | |
using | SDL::HapticCustom = SDL_HapticCustom |
A structure containing a template for the HAPTIC_CUSTOM effect. More... | |
using | SDL::HapticEffect = SDL_HapticEffect |
The generic template for any haptic effect. More... | |
using | SDL::HapticID = SDL_HapticID |
This is a unique ID for a haptic device for the time it is connected to the system, and is never reused for the lifetime of the application. More... | |
Functions | |
OwnArray< HapticID > | SDL::GetHaptics () |
Get a list of currently connected haptic devices. More... | |
const char * | SDL::GetHapticNameForID (HapticID instance_id) |
Get the implementation dependent name of a haptic device. More... | |
Haptic | SDL::OpenHaptic (HapticID instance_id) |
Open a haptic device for use. More... | |
HapticRef | SDL::GetHapticFromID (HapticID instance_id) |
Get the Haptic associated with an instance ID, if it has been opened. More... | |
HapticID | SDL::GetHapticID (HapticParam haptic) |
Get the instance ID of an opened haptic device. More... | |
const char * | SDL::GetHapticName (HapticParam haptic) |
Get the implementation dependent name of a haptic device. More... | |
bool | SDL::IsMouseHaptic () |
Query whether or not the current mouse has haptic capabilities. More... | |
Haptic | SDL::OpenHapticFromMouse () |
Try to open a haptic device from the current mouse. More... | |
bool | SDL::IsJoystickHaptic (JoystickParam joystick) |
Query if a joystick has haptic features. More... | |
Haptic | SDL::OpenHapticFromJoystick (JoystickParam joystick) |
Open a haptic device for use from a joystick device. More... | |
void | SDL::CloseHaptic (HapticRaw haptic) |
Close a haptic device previously opened with Haptic.Haptic(). More... | |
int | SDL::GetMaxHapticEffects (HapticParam haptic) |
Get the number of effects a haptic device can store. More... | |
int | SDL::GetMaxHapticEffectsPlaying (HapticParam haptic) |
Get the number of effects a haptic device can play at the same time. More... | |
Uint32 | SDL::GetHapticFeatures (HapticParam haptic) |
Get the haptic device's supported features in bitwise manner. More... | |
int | SDL::GetNumHapticAxes (HapticParam haptic) |
Get the number of haptic axes the device has. More... | |
bool | SDL::HapticEffectSupported (HapticParam haptic, const HapticEffect &effect) |
Check to see if an effect is supported by a haptic device. More... | |
int | SDL::CreateHapticEffect (HapticParam haptic, const HapticEffect &effect) |
Create a new haptic effect on a specified device. More... | |
void | SDL::UpdateHapticEffect (HapticParam haptic, int effect, const HapticEffect &data) |
Update the properties of an effect. More... | |
void | SDL::RunHapticEffect (HapticParam haptic, int effect, Uint32 iterations) |
Run the haptic effect on its associated haptic device. More... | |
void | SDL::StopHapticEffect (HapticParam haptic, int effect) |
Stop the haptic effect on its associated haptic device. More... | |
void | SDL::DestroyHapticEffect (HapticParam haptic, int effect) |
Destroy a haptic effect on the device. More... | |
bool | SDL::GetHapticEffectStatus (HapticParam haptic, int effect) |
Get the status of the current effect on the specified haptic device. More... | |
void | SDL::SetHapticGain (HapticParam haptic, int gain) |
Set the global gain of the specified haptic device. More... | |
void | SDL::SetHapticAutocenter (HapticParam haptic, int autocenter) |
Set the global autocenter of the device. More... | |
void | SDL::PauseHaptic (HapticParam haptic) |
Pause a haptic device. More... | |
void | SDL::ResumeHaptic (HapticParam haptic) |
Resume a haptic device. More... | |
void | SDL::StopHapticEffects (HapticParam haptic) |
Stop all the currently playing effects on a haptic device. More... | |
bool | SDL::HapticRumbleSupported (HapticParam haptic) |
Check whether rumble is supported on a haptic device. More... | |
void | SDL::InitHapticRumble (HapticParam haptic) |
Initialize a haptic device for simple rumble playback. More... | |
void | SDL::PlayHapticRumble (HapticParam haptic, float strength, Uint32 length) |
Run a simple rumble effect on a haptic device. More... | |
void | SDL::StopHapticRumble (HapticParam haptic) |
Stop the simple rumble on a haptic device. More... | |
HapticID | SDL::Haptic::GetID () |
Get the instance ID of an opened haptic device. More... | |
const char * | SDL::Haptic::GetName () |
Get the implementation dependent name of a haptic device. More... | |
static Haptic | SDL::Haptic::OpenFromMouse () |
Try to open a haptic device from the current mouse. More... | |
void | SDL::Haptic::Close () |
Close a haptic device previously opened with Haptic.Haptic(). More... | |
int | SDL::Haptic::GetMaxEffects () |
Get the number of effects a haptic device can store. More... | |
int | SDL::Haptic::GetMaxEffectsPlaying () |
Get the number of effects a haptic device can play at the same time. More... | |
Uint32 | SDL::Haptic::GetFeatures () |
Get the haptic device's supported features in bitwise manner. More... | |
int | SDL::Haptic::GetNumAxes () |
Get the number of haptic axes the device has. More... | |
bool | SDL::Haptic::EffectSupported (const HapticEffect &effect) |
Check to see if an effect is supported by a haptic device. More... | |
int | SDL::Haptic::CreateEffect (const HapticEffect &effect) |
Create a new haptic effect on a specified device. More... | |
void | SDL::Haptic::UpdateEffect (int effect, const HapticEffect &data) |
Update the properties of an effect. More... | |
void | SDL::Haptic::RunEffect (int effect, Uint32 iterations) |
Run the haptic effect on its associated haptic device. More... | |
void | SDL::Haptic::StopEffect (int effect) |
Stop the haptic effect on its associated haptic device. More... | |
void | SDL::Haptic::DestroyEffect (int effect) |
Destroy a haptic effect on the device. More... | |
bool | SDL::Haptic::GetEffectStatus (int effect) |
Get the status of the current effect on the specified haptic device. More... | |
void | SDL::Haptic::SetGain (int gain) |
Set the global gain of the specified haptic device. More... | |
void | SDL::Haptic::SetAutocenter (int autocenter) |
Set the global autocenter of the device. More... | |
void | SDL::Haptic::Pause () |
Pause a haptic device. More... | |
void | SDL::Haptic::Resume () |
Resume a haptic device. More... | |
void | SDL::Haptic::StopEffects () |
Stop all the currently playing effects on a haptic device. More... | |
bool | SDL::Haptic::RumbleSupported () |
Check whether rumble is supported on a haptic device. More... | |
void | SDL::Haptic::InitRumble () |
Initialize a haptic device for simple rumble playback. More... | |
void | SDL::Haptic::PlayRumble (float strength, Uint32 length) |
Run a simple rumble effect on a haptic device. More... | |
void | SDL::Haptic::StopRumble () |
Stop the simple rumble on a haptic device. More... | |
Variables | |
constexpr Uint32 | SDL::HAPTIC_INFINITY = SDL_HAPTIC_INFINITY |
Used to play a device an infinite number of times. More... | |
Haptic effects | |
using | SDL::HapticEffectType = Uint32 |
Haptic effects flag constants. More... | |
constexpr HapticEffectType | SDL::HAPTIC_CONSTANT = SDL_HAPTIC_CONSTANT |
Constant effect supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_SINE = SDL_HAPTIC_SINE |
Sine wave effect supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_SQUARE = SDL_HAPTIC_SQUARE |
Square wave effect supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_TRIANGLE = SDL_HAPTIC_TRIANGLE |
Triangle wave effect supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_SAWTOOTHUP = SDL_HAPTIC_SAWTOOTHUP |
Sawtoothup wave effect supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_SAWTOOTHDOWN = SDL_HAPTIC_SAWTOOTHDOWN |
Sawtoothdown wave effect supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_RAMP = SDL_HAPTIC_RAMP |
Ramp effect supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_SPRING = SDL_HAPTIC_SPRING |
Spring effect supported - uses axes position. More... | |
constexpr HapticEffectType | SDL::HAPTIC_DAMPER = SDL_HAPTIC_DAMPER |
Damper effect supported - uses axes velocity. More... | |
constexpr HapticEffectType | SDL::HAPTIC_INERTIA = SDL_HAPTIC_INERTIA |
Inertia effect supported - uses axes acceleration. More... | |
constexpr HapticEffectType | SDL::HAPTIC_FRICTION = SDL_HAPTIC_FRICTION |
Friction effect supported - uses axes movement. More... | |
constexpr HapticEffectType | SDL::HAPTIC_LEFTRIGHT = SDL_HAPTIC_LEFTRIGHT |
Left/Right effect supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_RESERVED1 = SDL_HAPTIC_RESERVED1 |
Reserved for future use. More... | |
constexpr HapticEffectType | SDL::HAPTIC_RESERVED2 = SDL_HAPTIC_RESERVED2 |
Reserved for future use. More... | |
constexpr HapticEffectType | SDL::HAPTIC_RESERVED3 = SDL_HAPTIC_RESERVED3 |
Reserved for future use. More... | |
constexpr HapticEffectType | SDL::HAPTIC_CUSTOM = SDL_HAPTIC_CUSTOM |
Custom effect is supported. More... | |
constexpr HapticEffectType | SDL::HAPTIC_GAIN = SDL_HAPTIC_GAIN |
Device can set global gain. More... | |
constexpr HapticEffectType | SDL::HAPTIC_AUTOCENTER = SDL_HAPTIC_AUTOCENTER |
Device can set autocenter. More... | |
constexpr HapticEffectType | SDL::HAPTIC_STATUS = SDL_HAPTIC_STATUS |
Device can be queried for effect status. More... | |
constexpr HapticEffectType | SDL::HAPTIC_PAUSE = SDL_HAPTIC_PAUSE |
Device can be paused. More... | |
Direction encodings | |
using | SDL::HapticDirectionType = Uint8 |
Direction encoding. | |
constexpr HapticDirectionType | SDL::HAPTIC_POLAR = SDL_HAPTIC_POLAR |
Uses polar coordinates for the direction. More... | |
constexpr HapticDirectionType | SDL::HAPTIC_CARTESIAN = SDL_HAPTIC_CARTESIAN |
Uses cartesian coordinates for the direction. More... | |
constexpr HapticDirectionType | SDL::HAPTIC_SPHERICAL = SDL_HAPTIC_SPHERICAL |
Uses spherical coordinates for the direction. More... | |
constexpr HapticDirectionType | SDL::HAPTIC_STEERING_AXIS = SDL_HAPTIC_STEERING_AXIS |
Use this value to play an effect on the steering wheel axis. More... | |
The basic usage is as follows:
Simple rumble example:
Complete example:
Note that the SDL haptic subsystem is not thread-safe.
using SDL::HapticCondition = typedef SDL_HapticCondition |
The struct handles the following effects:
Direction is handled by condition internals instead of a direction member. The condition effect specific members have three parameters. The first refers to the X axis, the second refers to the Y axis and the third refers to the Z axis. The right terms refer to the positive side of the axis and the left terms refer to the negative side of the axis. Please refer to the HapticDirection diagram for which side is positive and which is negative.
using SDL::HapticConstant = typedef SDL_HapticConstant |
This struct is exclusively for the HAPTIC_CONSTANT effect.
A constant effect applies a constant force in the specified direction to the joystick.
using SDL::HapticCustom = typedef SDL_HapticCustom |
This struct is exclusively for the HAPTIC_CUSTOM effect.
A custom force feedback effect is much like a periodic effect, where the application can define its exact shape. You will have to allocate the data yourself. Data should consist of channels * samples Uint16 samples.
If channels is one, the effect is rotated using the defined direction. Otherwise it uses the samples in data for the different axes.
using SDL::HapticDirection = typedef SDL_HapticDirection |
This is the direction where the force comes from, instead of the direction in which the force is exerted.
Directions can be specified by:
Cardinal directions of the haptic device are relative to the positioning of the device. North is considered to be away from the user.
The following diagram represents the cardinal directions:
If type is HAPTIC_POLAR, direction is encoded by hundredths of a degree starting north and turning clockwise. HAPTIC_POLAR only uses the first dir
parameter. The cardinal directions would be:
If type is HAPTIC_CARTESIAN, direction is encoded by three positions (X axis, Y axis and Z axis (with 3 axes)). HAPTIC_CARTESIAN uses the first three dir
parameters. The cardinal directions would be:
The Z axis represents the height of the effect if supported, otherwise it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you can use any multiple you want, only the direction matters.
If type is HAPTIC_SPHERICAL, direction is encoded by two rotations. The first two dir
parameters are used. The dir
parameters are as follows (all values are in hundredths of degrees):
Example of force coming from the south with all encodings (force coming from the south means the user will have to pull the stick to counteract):
using SDL::HapticEffect = typedef SDL_HapticEffect |
All values max at 32767 (0x7FFF). Signed values also can be negative. Time values unless specified otherwise are in milliseconds.
You can also pass HAPTIC_INFINITY to length instead of a 0-32767 value. Neither delay, interval, attack_length nor fade_length support HAPTIC_INFINITY. Fade will also not be used since effect never ends.
Additionally, the HAPTIC_RAMP effect does not support a duration of HAPTIC_INFINITY.
Button triggers may not be supported on all devices, it is advised to not use them if possible. Buttons start at index 1 instead of index 0 like the joystick.
If both attack_length and fade_level are 0, the envelope is not used, otherwise both values are used.
Common parts:
Here we have an example of a constant effect evolution in time:
Note either the attack_level or the fade_level may be above the actual effect level.
using SDL::HapticEffectType = typedef Uint32 |
using SDL::HapticID = typedef SDL_HapticID |
If the haptic device is disconnected and reconnected, it will get a new ID.
The value 0 is an invalid ID.
using SDL::HapticLeftRight = typedef SDL_HapticLeftRight |
This struct is exclusively for the HAPTIC_LEFTRIGHT effect.
The Left/Right effect is used to explicitly control the large and small motors, commonly found in modern game controllers. The small (right) motor is high frequency, and the large (left) motor is low frequency.
using SDL::HapticPeriodic = typedef SDL_HapticPeriodic |
The struct handles the following effects:
A periodic effect consists in a wave-shaped effect that repeats itself over time. The type determines the shape of the wave and the parameters determine the dimensions of the wave.
Phase is given by hundredth of a degree meaning that giving the phase a value of 9000 will displace it 25% of its period. Here are sample values:
Examples:
using SDL::HapticRamp = typedef SDL_HapticRamp |
This struct is exclusively for the HAPTIC_RAMP effect.
The ramp effect starts at start strength and ends at end strength. It augments in linear fashion. If you use attack and fade with a ramp the effects get added to the ramp effect making the effect become quadratic instead of linear.
|
inline |
|
inline |
haptic | the Haptic device to close. |
|
inline |
|
inline |
|
inline |
This will stop the effect if it's running. Effects are automatically destroyed when the device is closed.
effect | the ID of the haptic effect to destroy. |
|
inline |
This will stop the effect if it's running. Effects are automatically destroyed when the device is closed.
haptic | the Haptic device to destroy the effect on. |
effect | the ID of the haptic effect to destroy. |
|
inline |
effect | the desired effect to query. |
|
inline |
Device must support the HAPTIC_STATUS feature.
effect | the ID of the haptic effect to query its status. |
|
inline |
|
inline |
Device must support the HAPTIC_STATUS feature.
haptic | the Haptic device to query for the effect status on. |
effect | the ID of the haptic effect to query its status. |
|
inline |
haptic | the Haptic device to query. |
|
inline |
|
inline |
haptic | the Haptic obtained from JoystickID.OpenJoystick(). |
|
inline |
This can be called before any haptic devices are opened.
instance_id | the haptic device instance ID. |
|
inline |
|
inline |
On some platforms this isn't fully supported, and therefore is an approximation. Always check to see if your created effect was actually created and do not rely solely on Haptic.GetMaxEffects().
|
inline |
This is not supported on all platforms, but will always return a value.
|
inline |
On some platforms this isn't fully supported, and therefore is an approximation. Always check to see if your created effect was actually created and do not rely solely on Haptic.GetMaxEffects().
haptic | the Haptic device to query. |
|
inline |
This is not supported on all platforms, but will always return a value.
haptic | the Haptic device to query maximum playing effects. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
haptic | haptic device to check for rumble support. |
|
inline |
|
inline |
|
inline |
joystick | the Joystick to test for haptic capabilities. |
|
inline |
|
inlinestatic |
The index passed as an argument refers to the N'th haptic device on this system.
When opening a haptic device, its gain will be set to maximum and autocenter will be disabled. To modify these values use Haptic.SetGain() and Haptic.SetAutocenter().
instance_id | the haptic device instance ID. |
|
inline |
You must still close the haptic device separately. It will not be closed with the joystick.
When opened from a joystick you should first close the haptic device before closing the joystick device. If not, on some implementations the haptic device will also get unallocated and you'll be unable to use force feedback on that device.
joystick | the Joystick to create a haptic device from. |
Error | on failure. |
|
inline |
|
inline |
Device must support the HAPTIC_PAUSE
feature. Call Haptic.Resume() to resume playback.
Do not modify the effects nor add new ones while the device is paused. That can cause all sorts of weird errors.
Error | on failure. |
|
inline |
Device must support the HAPTIC_PAUSE
feature. Call Haptic.Resume() to resume playback.
Do not modify the effects nor add new ones while the device is paused. That can cause all sorts of weird errors.
haptic | the Haptic device to pause. |
Error | on failure. |
|
inline |
haptic | the haptic device to play the rumble effect on. |
strength | strength of the rumble to play as a 0-1 float value. |
length | length of the rumble to play in milliseconds. |
Error | on failure. |
|
inline |
strength | strength of the rumble to play as a 0-1 float value. |
length | length of the rumble to play in milliseconds. |
Error | on failure. |
|
inline |
Call to unpause after Haptic.Pause().
Error | on failure. |
|
inline |
Call to unpause after Haptic.Pause().
haptic | the Haptic device to unpause. |
Error | on failure. |
|
inline |
|
inline |
To repeat the effect over and over indefinitely, set iterations
to HAPTIC_INFINITY
. (Repeats the envelope - attack and fade.) To make one instance of the effect last indefinitely (so the effect does not fade), set the effect's length
in its structure/union to HAPTIC_INFINITY
instead.
effect | the ID of the haptic effect to run. |
iterations | the number of iterations to run the effect; use HAPTIC_INFINITY to repeat forever. |
Error | on failure. |
|
inline |
To repeat the effect over and over indefinitely, set iterations
to HAPTIC_INFINITY
. (Repeats the envelope - attack and fade.) To make one instance of the effect last indefinitely (so the effect does not fade), set the effect's length
in its structure/union to HAPTIC_INFINITY
instead.
haptic | the Haptic device to run the effect on. |
effect | the ID of the haptic effect to run. |
iterations | the number of iterations to run the effect; use HAPTIC_INFINITY to repeat forever. |
Error | on failure. |
|
inline |
Autocenter should be between 0 and 100. Setting it to 0 will disable autocentering.
Device must support the HAPTIC_AUTOCENTER feature.
autocenter | value to set autocenter to (0-100). |
Error | on failure. |
|
inline |
Device must support the HAPTIC_GAIN feature.
The user may specify the maximum gain by setting the environment variable SDL_HAPTIC_GAIN_MAX
which should be between 0 and 100. All calls to Haptic.SetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX
as the maximum.
gain | value to set the gain to, should be between 0 and 100 (0 - 100). |
Error | on failure. |
|
inline |
Autocenter should be between 0 and 100. Setting it to 0 will disable autocentering.
Device must support the HAPTIC_AUTOCENTER feature.
haptic | the Haptic device to set autocentering on. |
autocenter | value to set autocenter to (0-100). |
Error | on failure. |
|
inline |
Device must support the HAPTIC_GAIN feature.
The user may specify the maximum gain by setting the environment variable SDL_HAPTIC_GAIN_MAX
which should be between 0 and 100. All calls to Haptic.SetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX
as the maximum.
haptic | the Haptic device to set the gain on. |
gain | value to set the gain to, should be between 0 and 100 (0 - 100). |
Error | on failure. |
|
inline |
effect | the ID of the haptic effect to stop. |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
haptic | the Haptic device to stop the effect on. |
effect | the ID of the haptic effect to stop. |
Error | on failure. |
|
inline |
haptic | the Haptic device to stop. |
Error | on failure. |
|
inline |
haptic | the haptic device to stop the rumble effect on. |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
Can be used dynamically, although behavior when dynamically changing direction may be strange. Specifically the effect may re-upload itself and start playing from the start. You also cannot change the type either when running Haptic.UpdateEffect().
effect | the identifier of the effect to update. |
data | an HapticEffect structure containing the new effect properties to use. |
Error | on failure. |
|
inline |
Can be used dynamically, although behavior when dynamically changing direction may be strange. Specifically the effect may re-upload itself and start playing from the start. You also cannot change the type either when running Haptic.UpdateEffect().
haptic | the Haptic device that has the effect. |
effect | the identifier of the effect to update. |
data | an HapticEffect structure containing the new effect properties to use. |
Error | on failure. |
|
constexpr |
Device supports setting autocenter.
|
constexpr |
|
constexpr |
|
constexpr |
User defined custom haptic effect.
|
constexpr |
Condition haptic effect that simulates dampening. Effect is based on the axes velocity.
|
constexpr |
Condition haptic effect that simulates friction. Effect is based on the axes movement.
|
constexpr |
Device supports setting the global gain.
|
constexpr |
Condition haptic effect that simulates inertia. Effect is based on the axes acceleration.
|
constexpr |
|
constexpr |
Haptic effect for direct control over high/low frequency motors.
|
constexpr |
Devices supports being paused.
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
Periodic haptic effect that simulates saw tooth down waves.
|
constexpr |
Periodic haptic effect that simulates saw tooth up waves.
|
constexpr |
Periodic haptic effect that simulates sine waves.
|
constexpr |
|
constexpr |
Condition haptic effect that simulates a spring. Effect is based on the axes position.
|
constexpr |
Periodic haptic effect that simulates square waves.
|
constexpr |
Device supports querying effect status.
|
constexpr |
This provides better compatibility across platforms and devices as SDL will guess the correct axis.
|
constexpr |
Periodic haptic effect that simulates triangular waves.