SDL_HapticPeriodic(3type)
π SDL_HapticPeriodic β a datatype from the SDL3 haptics fam π
okay bestie, sit DOWN, because we're about to talk about the single most fun struct in all of SDL3: the one that makes your controller go brrrrr in a wavy little pattern. it's SDL_HapticPeriodic, it lives in the SDL3 datatypes section, and honestly? it's giving main character energy. π
β¨ NAME β¨
SDL_HapticPeriodic β a structure containing a template for a Periodic effect. yes, a whole struct whose entire job is "vibrate in a shape." iconic. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_haptic.h>
typedef struct SDL_HapticPeriodic
{
/* Header */
SDL_HapticEffectType type; /**< SDL_HAPTIC_SINE, SDL_HAPTIC_SQUARE
SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP or
SDL_HAPTIC_SAWTOOTHDOWN */
SDL_HapticDirection direction; /**< Direction of the effect. */
/* Replay */
Uint32 length; /**< Duration of the effect. */
Uint16 delay; /**< Delay before starting the effect. */
/* Trigger */
Uint16 button; /**< Button that triggers the effect. */
Uint16 interval; /**< How soon it can be triggered again after button. */
/* Periodic */
Uint16 period; /**< Period of the wave. */
Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
Sint16 offset; /**< Mean value of the wave. */
Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
/* Envelope */
Uint16 attack_length; /**< Duration of the attack. */
Uint16 attack_level; /**< Level at the start of the attack. */
Uint16 fade_length; /**< Duration of the fade. */
Uint16 fade_level; /**< Level at the end of the fade. */
} SDL_HapticPeriodic;
like. look at those little commented sections. Header, Replay, Trigger, Periodic, Envelope. the organization?? the way it just tells you what each chunk is for?? obsessed. ππ
π¦ DESCRIPTION π¦
so here's the tea. this struct handles the following effects, and ONLY these five:
SDL_HAPTIC_SINESDL_HAPTIC_SQUARESDL_HAPTIC_TRIANGLESDL_HAPTIC_SAWTOOTHUPSDL_HAPTIC_SAWTOOTHDOWN
a periodic effect is, like, literally what it sounds like: a wave-shaped effect that repeats itself over time. the type decides which shape the wave is, and the other parameters decide the dimensions of that wave. shape + size = your vibe. periodt. β¨
π phase, explained (iykyk)
phase is measured in hundredths of a degree. meaning if you hand phase a value of 9000, you've displaced it by 25% of its period. here are the sample values, bestie, memorize them:
0: No phase displacement.9000: Displaced 25% of its period.18000: Displaced 50% of its period.27000: Displaced 75% of its period.36000: Displaced 100% of its period, same as0, but0is preferred.
lowkey important:36000and0are the same thing, but the docs want you to use0. so just use0. don't be extra about it. π
π the wave shapes (visualize it, bestie)
Examples:
SDL_HAPTIC_SINE
__ __ __ __
/ \ / \ / \ /
/ \__/ \__/ \__/
SDL_HAPTIC_SQUARE
__ __ __ __ __
| | | | | | | | | |
| |__| |__| |__| |__| |
SDL_HAPTIC_TRIANGLE
/\ /\ /\ /\ /\
/ \ / \ / \ / \ /
/ \/ \/ \/ \/
SDL_HAPTIC_SAWTOOTHUP
/| /| /| /| /| /| /|
/ | / | / | / | / | / | / |
/ |/ |/ |/ |/ |/ |/ |
SDL_HAPTIC_SAWTOOTHDOWN
\ |\ |\ |\ |\ |\ |\ |
\ | \ | \ | \ | \ | \ | \ |
\| \| \| \| \| \| \|
not the ASCII art eating down, honestly. the sawtooth ones are so dramatic for no reason. π
β AVAILABILITY β
This struct is available since SDL 3.2.0. so if you're on anything older, sorry babe, no periodic haptics for you. upgrade time. π«Ά
π SEE ALSO π
go read these next, they're all in the group chat:
SDL_HAPTIC_SINE(3)SDL_HAPTIC_SQUARE(3)SDL_HAPTIC_TRIANGLE(3)SDL_HAPTIC_SAWTOOTHUP(3)SDL_HAPTIC_SAWTOOTHDOWN(3)SDL_HapticEffect(3type)
and that's the whole page, bestie!! this lil manual came to you from Simple Directmedia Layer, version SDL 3.4.18, dated SDL_HapticPeriodic(3type). go forth and make things shake. slay, no cap, fr fr. πβ¨ππ¦πΈπ π«Άπ₯ππβπ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms