Atlas - SDL_haptic.h
Home / ext / SDL / include / SDL3 Lines: 4 | Size: 45076 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22/** 23 * # CategoryHaptic 24 * 25 * The SDL haptic subsystem manages haptic (force feedback) devices. 26 * 27 * The basic usage is as follows: 28 * 29 * - Initialize the subsystem (SDL_INIT_HAPTIC). 30 * - Open a haptic device. 31 * - SDL_OpenHaptic() to open from index. 32 * - SDL_OpenHapticFromJoystick() to open from an existing joystick. 33 * - Create an effect (SDL_HapticEffect). 34 * - Upload the effect with SDL_CreateHapticEffect(). 35 * - Run the effect with SDL_RunHapticEffect(). 36 * - (optional) Free the effect with SDL_DestroyHapticEffect(). 37 * - Close the haptic device with SDL_CloseHaptic(). 38 * 39 * Simple rumble example: 40 * 41 * ```c 42 * SDL_Haptic *haptic = NULL; 43 * 44 * // Open the device 45 * SDL_HapticID *haptics = SDL_GetHaptics(NULL); 46 * if (haptics) { 47 * haptic = SDL_OpenHaptic(haptics[0]); 48 * SDL_free(haptics); 49 * } 50 * if (haptic == NULL) 51 * return; 52 * 53 * // Initialize simple rumble 54 * if (!SDL_InitHapticRumble(haptic)) 55 * return; 56 * 57 * // Play effect at 50% strength for 2 seconds 58 * if (!SDL_PlayHapticRumble(haptic, 0.5, 2000)) 59 * return; 60 * SDL_Delay(2000); 61 * 62 * // Clean up 63 * SDL_CloseHaptic(haptic); 64 * ``` 65 * 66 * Complete example: 67 * 68 * ```c 69 * bool test_haptic(SDL_Joystick *joystick) 70 * { 71 * SDL_Haptic *haptic; 72 * SDL_HapticEffect effect; 73 * SDL_HapticEffectID effect_id; 74 * 75 * // Open the device 76 * haptic = SDL_OpenHapticFromJoystick(joystick); 77 * if (haptic == NULL) return false; // Most likely joystick isn't haptic 78 * 79 * // See if it can do sine waves 80 * if ((SDL_GetHapticFeatures(haptic) & SDL_HAPTIC_SINE)==0) { 81 * SDL_CloseHaptic(haptic); // No sine effect 82 * return false; 83 * } 84 * 85 * // Create the effect 86 * SDL_memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default 87 * effect.type = SDL_HAPTIC_SINE; 88 * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates 89 * effect.periodic.direction.dir[0] = 18000; // Force comes from south 90 * effect.periodic.period = 1000; // 1000 ms 91 * effect.periodic.magnitude = 20000; // 20000/32767 strength 92 * effect.periodic.length = 5000; // 5 seconds long 93 * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength 94 * effect.periodic.fade_length = 1000; // Takes 1 second to fade away 95 * 96 * // Upload the effect 97 * effect_id = SDL_CreateHapticEffect(haptic, &effect); 98 * 99 * // Test the effect 100 * SDL_RunHapticEffect(haptic, effect_id, 1); 101 * SDL_Delay(5000); // Wait for the effect to finish 102 * 103 * // We destroy the effect, although closing the device also does this 104 * SDL_DestroyHapticEffect(haptic, effect_id); 105 * 106 * // Close the device 107 * SDL_CloseHaptic(haptic); 108 * 109 * return true; // Success 110 * } 111 * ``` 112 * 113 * Note that the SDL haptic subsystem is not thread-safe. 114 */ 115 116 117#ifndef SDL_haptic_h_ 118#define SDL_haptic_h_ 119 120#include <SDL3/SDL_stdinc.h> 121#include <SDL3/SDL_error.h> 122#include <SDL3/SDL_joystick.h> 123 124#include <SDL3/SDL_begin_code.h> 125/* Set up for C function definitions, even when using C++ */ 126#ifdef __cplusplus 127extern "C" { 128#endif /* __cplusplus */ 129 130/* FIXME: 131 * 132 * At the moment the magnitude variables are mixed between signed/unsigned, and 133 * it is also not made clear that ALL of those variables expect a max of 0x7FFF. 134 * 135 * Some platforms may have higher precision than that (Linux FF, Windows XInput) 136 * so we should fix the inconsistency in favor of higher possible precision, 137 * adjusting for platforms that use different scales. 138 * -flibit 139 */ 140 141/** 142 * The haptic structure used to identify an SDL haptic. 143 * 144 * \since This struct is available since SDL 3.2.0. 145 * 146 * \sa SDL_OpenHaptic 147 * \sa SDL_OpenHapticFromJoystick 148 * \sa SDL_CloseHaptic 149 */ 150typedef struct SDL_Haptic SDL_Haptic; 151 152/* 153 * Misc defines. 154 */ 155 156/** 157 * Used to play a device an infinite number of times. 158 * 159 * \since This macro is available since SDL 3.2.0. 160 * 161 * \sa SDL_RunHapticEffect 162 */ 163#define SDL_HAPTIC_INFINITY 4294967295U 164 165 166/** 167 * \name Haptic features 168 * 169 * Different haptic features a device can have. 170 */ 171/* @{ */ 172 173/** 174 * \name Haptic effects 175 */ 176/* @{ */ 177 178/** 179 * Type of haptic effect. 180 */ 181typedef Uint16 SDL_HapticEffectType; 182 183/** 184 * Constant effect supported. 185 * 186 * Constant haptic effect. 187 * 188 * \since This macro is available since SDL 3.2.0. 189 * 190 * \sa SDL_HapticCondition 191 */ 192#define SDL_HAPTIC_CONSTANT (1u<<0) 193 194/** 195 * Sine wave effect supported. 196 * 197 * Periodic haptic effect that simulates sine waves. 198 * 199 * \since This macro is available since SDL 3.2.0. 200 * 201 * \sa SDL_HapticPeriodic 202 */ 203#define SDL_HAPTIC_SINE (1u<<1) 204 205/** 206 * Square wave effect supported. 207 * 208 * Periodic haptic effect that simulates square waves. 209 * 210 * \since This macro is available since SDL 3.2.0. 211 * 212 * \sa SDL_HapticPeriodic 213 */ 214#define SDL_HAPTIC_SQUARE (1u<<2) 215 216/** 217 * Triangle wave effect supported. 218 * 219 * Periodic haptic effect that simulates triangular waves. 220 * 221 * \since This macro is available since SDL 3.2.0. 222 * 223 * \sa SDL_HapticPeriodic 224 */ 225#define SDL_HAPTIC_TRIANGLE (1u<<3) 226 227/** 228 * Sawtoothup wave effect supported. 229 * 230 * Periodic haptic effect that simulates saw tooth up waves. 231 * 232 * \since This macro is available since SDL 3.2.0. 233 * 234 * \sa SDL_HapticPeriodic 235 */ 236#define SDL_HAPTIC_SAWTOOTHUP (1u<<4) 237 238/** 239 * Sawtoothdown wave effect supported. 240 * 241 * Periodic haptic effect that simulates saw tooth down waves. 242 * 243 * \since This macro is available since SDL 3.2.0. 244 * 245 * \sa SDL_HapticPeriodic 246 */ 247#define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5) 248 249/** 250 * Ramp effect supported. 251 * 252 * Ramp haptic effect. 253 * 254 * \since This macro is available since SDL 3.2.0. 255 * 256 * \sa SDL_HapticRamp 257 */ 258#define SDL_HAPTIC_RAMP (1u<<6) 259 260/** 261 * Spring effect supported - uses axes position. 262 * 263 * Condition haptic effect that simulates a spring. Effect is based on the 264 * axes position. 265 * 266 * \since This macro is available since SDL 3.2.0. 267 * 268 * \sa SDL_HapticCondition 269 */ 270#define SDL_HAPTIC_SPRING (1u<<7) 271 272/** 273 * Damper effect supported - uses axes velocity. 274 * 275 * Condition haptic effect that simulates dampening. Effect is based on the 276 * axes velocity. 277 * 278 * \since This macro is available since SDL 3.2.0. 279 * 280 * \sa SDL_HapticCondition 281 */ 282#define SDL_HAPTIC_DAMPER (1u<<8) 283 284/** 285 * Inertia effect supported - uses axes acceleration. 286 * 287 * Condition haptic effect that simulates inertia. Effect is based on the axes 288 * acceleration. 289 * 290 * \since This macro is available since SDL 3.2.0. 291 * 292 * \sa SDL_HapticCondition 293 */ 294#define SDL_HAPTIC_INERTIA (1u<<9) 295 296/** 297 * Friction effect supported - uses axes movement. 298 * 299 * Condition haptic effect that simulates friction. Effect is based on the 300 * axes movement. 301 * 302 * \since This macro is available since SDL 3.2.0. 303 * 304 * \sa SDL_HapticCondition 305 */ 306#define SDL_HAPTIC_FRICTION (1u<<10) 307 308/** 309 * Left/Right effect supported. 310 * 311 * Haptic effect for direct control over high/low frequency motors. 312 * 313 * \since This macro is available since SDL 3.2.0. 314 * 315 * \sa SDL_HapticLeftRight 316 */ 317#define SDL_HAPTIC_LEFTRIGHT (1u<<11) 318 319/** 320 * Reserved for future use. 321 * 322 * \since This macro is available since SDL 3.2.0. 323 */ 324#define SDL_HAPTIC_RESERVED1 (1u<<12) 325 326/** 327 * Reserved for future use. 328 * 329 * \since This macro is available since SDL 3.2.0. 330 */ 331#define SDL_HAPTIC_RESERVED2 (1u<<13) 332 333/** 334 * Reserved for future use. 335 * 336 * \since This macro is available since SDL 3.2.0. 337 */ 338#define SDL_HAPTIC_RESERVED3 (1u<<14) 339 340/** 341 * Custom effect is supported. 342 * 343 * User defined custom haptic effect. 344 * 345 * \since This macro is available since SDL 3.2.0. 346 */ 347#define SDL_HAPTIC_CUSTOM (1u<<15) 348 349/* @} *//* Haptic effects */ 350 351/* These last few are features the device has, not effects */ 352 353/** 354 * Device can set global gain. 355 * 356 * Device supports setting the global gain. 357 * 358 * \since This macro is available since SDL 3.2.0. 359 * 360 * \sa SDL_SetHapticGain 361 */ 362#define SDL_HAPTIC_GAIN (1u<<16) 363 364/** 365 * Device can set autocenter. 366 * 367 * Device supports setting autocenter. 368 * 369 * \since This macro is available since SDL 3.2.0. 370 * 371 * \sa SDL_SetHapticAutocenter 372 */ 373#define SDL_HAPTIC_AUTOCENTER (1u<<17) 374 375/** 376 * Device can be queried for effect status. 377 * 378 * Device supports querying effect status. 379 * 380 * \since This macro is available since SDL 3.2.0. 381 * 382 * \sa SDL_GetHapticEffectStatus 383 */ 384#define SDL_HAPTIC_STATUS (1u<<18) 385 386/** 387 * Device can be paused. 388 * 389 * Devices supports being paused. 390 * 391 * \since This macro is available since SDL 3.2.0. 392 * 393 * \sa SDL_PauseHaptic 394 * \sa SDL_ResumeHaptic 395 */ 396#define SDL_HAPTIC_PAUSE (1u<<19) 397 398 399/** 400 * \name Direction encodings 401 */ 402/* @{ */ 403 404/** 405 * Type of coordinates used for haptic direction. 406 */ 407typedef Uint8 SDL_HapticDirectionType; 408 409/** 410 * Uses polar coordinates for the direction. 411 * 412 * \since This macro is available since SDL 3.2.0. 413 * 414 * \sa SDL_HapticDirection 415 */ 416#define SDL_HAPTIC_POLAR 0 417 418/** 419 * Uses cartesian coordinates for the direction. 420 * 421 * \since This macro is available since SDL 3.2.0. 422 * 423 * \sa SDL_HapticDirection 424 */ 425#define SDL_HAPTIC_CARTESIAN 1 426 427/** 428 * Uses spherical coordinates for the direction. 429 * 430 * \since This macro is available since SDL 3.2.0. 431 * 432 * \sa SDL_HapticDirection 433 */ 434#define SDL_HAPTIC_SPHERICAL 2 435 436/** 437 * Use this value to play an effect on the steering wheel axis. 438 * 439 * This provides better compatibility across platforms and devices as SDL will 440 * guess the correct axis. 441 * 442 * \since This macro is available since SDL 3.2.0. 443 * 444 * \sa SDL_HapticDirection 445 */ 446#define SDL_HAPTIC_STEERING_AXIS 3 447 448/* @} *//* Direction encodings */ 449 450/* @} *//* Haptic features */ 451 452 453/** 454 * ID for haptic effects. 455 * 456 * This is -1 if the ID is invalid. 457 * 458 * \sa SDL_CreateHapticEffect 459 */ 460typedef int SDL_HapticEffectID; 461 462 463/** 464 * Structure that represents a haptic direction. 465 * 466 * This is the direction where the force comes from, instead of the direction 467 * in which the force is exerted. 468 * 469 * Directions can be specified by: 470 * 471 * - SDL_HAPTIC_POLAR : Specified by polar coordinates. 472 * - SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates. 473 * - SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates. 474 * 475 * Cardinal directions of the haptic device are relative to the positioning of 476 * the device. North is considered to be away from the user. 477 * 478 * The following diagram represents the cardinal directions: 479 * 480 * ``` 481 * .--. 482 * |__| .-------. 483 * |=.| |.-----.| 484 * |--| || || 485 * | | |'-----'| 486 * |__|~')_____(' 487 * [ COMPUTER ] 488 * 489 * 490 * North (0,-1) 491 * ^ 492 * | 493 * | 494 * (-1,0) West <----[ HAPTIC ]----> East (1,0) 495 * | 496 * | 497 * v 498 * South (0,1) 499 * 500 * 501 * [ USER ] 502 * \|||/ 503 * (o o) 504 * ---ooO-(_)-Ooo--- 505 * ``` 506 * 507 * If type is SDL_HAPTIC_POLAR, direction is encoded by hundredths of a degree 508 * starting north and turning clockwise. SDL_HAPTIC_POLAR only uses the first 509 * `dir` parameter. The cardinal directions would be: 510 * 511 * - North: 0 (0 degrees) 512 * - East: 9000 (90 degrees) 513 * - South: 18000 (180 degrees) 514 * - West: 27000 (270 degrees) 515 * 516 * If type is SDL_HAPTIC_CARTESIAN, direction is encoded by three positions (X 517 * axis, Y axis and Z axis (with 3 axes)). SDL_HAPTIC_CARTESIAN uses the first 518 * three `dir` parameters. The cardinal directions would be: 519 * 520 * - North: 0,-1, 0 521 * - East: 1, 0, 0 522 * - South: 0, 1, 0 523 * - West: -1, 0, 0 524 * 525 * The Z axis represents the height of the effect if supported, otherwise it's 526 * unused. In cartesian encoding (1, 2) would be the same as (2, 4), you can 527 * use any multiple you want, only the direction matters. 528 * 529 * If type is SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations. The 530 * first two `dir` parameters are used. The `dir` parameters are as follows 531 * (all values are in hundredths of degrees): 532 * 533 * - Degrees from (1, 0) rotated towards (0, 1). 534 * - Degrees towards (0, 0, 1) (device needs at least 3 axes). 535 * 536 * Example of force coming from the south with all encodings (force coming 537 * from the south means the user will have to pull the stick to counteract): 538 * 539 * ```c 540 * SDL_HapticDirection direction; 541 * 542 * // Cartesian directions 543 * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding. 544 * direction.dir[0] = 0; // X position 545 * direction.dir[1] = 1; // Y position 546 * // Assuming the device has 2 axes, we don't need to specify third parameter. 547 * 548 * // Polar directions 549 * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding. 550 * direction.dir[0] = 18000; // Polar only uses first parameter 551 * 552 * // Spherical coordinates 553 * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding 554 * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters. 555 * ``` 556 * 557 * \since This struct is available since SDL 3.2.0. 558 * 559 * \sa SDL_HAPTIC_POLAR 560 * \sa SDL_HAPTIC_CARTESIAN 561 * \sa SDL_HAPTIC_SPHERICAL 562 * \sa SDL_HAPTIC_STEERING_AXIS 563 * \sa SDL_HapticEffect 564 * \sa SDL_GetNumHapticAxes 565 */ 566typedef struct SDL_HapticDirection 567{ 568 SDL_HapticDirectionType type; /**< The type of encoding. */ 569 Sint32 dir[3]; /**< The encoded direction. */ 570} SDL_HapticDirection; 571 572 573/** 574 * A structure containing a template for a Constant effect. 575 * 576 * This struct is exclusively for the SDL_HAPTIC_CONSTANT effect. 577 * 578 * A constant effect applies a constant force in the specified direction to 579 * the joystick. 580 * 581 * \since This struct is available since SDL 3.2.0. 582 * 583 * \sa SDL_HAPTIC_CONSTANT 584 * \sa SDL_HapticEffect 585 */ 586typedef struct SDL_HapticConstant 587{ 588 /* Header */ 589 SDL_HapticEffectType type; /**< SDL_HAPTIC_CONSTANT */ 590 SDL_HapticDirection direction; /**< Direction of the effect. */ 591 592 /* Replay */ 593 Uint32 length; /**< Duration of the effect. */ 594 Uint16 delay; /**< Delay before starting the effect. */ 595 596 /* Trigger */ 597 Uint16 button; /**< Button that triggers the effect. */ 598 Uint16 interval; /**< How soon it can be triggered again after button. */ 599 600 /* Constant */ 601 Sint16 level; /**< Strength of the constant effect. */ 602 603 /* Envelope */ 604 Uint16 attack_length; /**< Duration of the attack. */ 605 Uint16 attack_level; /**< Level at the start of the attack. */ 606 Uint16 fade_length; /**< Duration of the fade. */ 607 Uint16 fade_level; /**< Level at the end of the fade. */ 608} SDL_HapticConstant; 609 610/** 611 * A structure containing a template for a Periodic effect. 612 * 613 * The struct handles the following effects: 614 * 615 * - SDL_HAPTIC_SINE 616 * - SDL_HAPTIC_SQUARE 617 * - SDL_HAPTIC_TRIANGLE 618 * - SDL_HAPTIC_SAWTOOTHUP 619 * - SDL_HAPTIC_SAWTOOTHDOWN 620 * 621 * A periodic effect consists in a wave-shaped effect that repeats itself over 622 * time. The type determines the shape of the wave and the parameters 623 * determine the dimensions of the wave. 624 * 625 * Phase is given by hundredth of a degree meaning that giving the phase a 626 * value of 9000 will displace it 25% of its period. Here are sample values: 627 * 628 * - 0: No phase displacement. 629 * - 9000: Displaced 25% of its period. 630 * - 18000: Displaced 50% of its period. 631 * - 27000: Displaced 75% of its period. 632 * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred. 633 * 634 * Examples: 635 * 636 * ``` 637 * SDL_HAPTIC_SINE 638 * __ __ __ __ 639 * / \ / \ / \ / 640 * / \__/ \__/ \__/ 641 * 642 * SDL_HAPTIC_SQUARE 643 * __ __ __ __ __ 644 * | | | | | | | | | | 645 * | |__| |__| |__| |__| | 646 * 647 * SDL_HAPTIC_TRIANGLE 648 * /\ /\ /\ /\ /\ 649 * / \ / \ / \ / \ / 650 * / \/ \/ \/ \/ 651 * 652 * SDL_HAPTIC_SAWTOOTHUP 653 * /| /| /| /| /| /| /| 654 * / | / | / | / | / | / | / | 655 * / |/ |/ |/ |/ |/ |/ | 656 * 657 * SDL_HAPTIC_SAWTOOTHDOWN 658 * \ |\ |\ |\ |\ |\ |\ | 659 * \ | \ | \ | \ | \ | \ | \ | 660 * \| \| \| \| \| \| \| 661 * ``` 662 * 663 * \since This struct is available since SDL 3.2.0. 664 * 665 * \sa SDL_HAPTIC_SINE 666 * \sa SDL_HAPTIC_SQUARE 667 * \sa SDL_HAPTIC_TRIANGLE 668 * \sa SDL_HAPTIC_SAWTOOTHUP 669 * \sa SDL_HAPTIC_SAWTOOTHDOWN 670 * \sa SDL_HapticEffect 671 */ 672typedef struct SDL_HapticPeriodic 673{ 674 /* Header */ 675 SDL_HapticEffectType type; /**< SDL_HAPTIC_SINE, SDL_HAPTIC_SQUARE 676 SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP or 677 SDL_HAPTIC_SAWTOOTHDOWN */ 678 SDL_HapticDirection direction; /**< Direction of the effect. */ 679 680 /* Replay */ 681 Uint32 length; /**< Duration of the effect. */ 682 Uint16 delay; /**< Delay before starting the effect. */ 683 684 /* Trigger */ 685 Uint16 button; /**< Button that triggers the effect. */ 686 Uint16 interval; /**< How soon it can be triggered again after button. */ 687 688 /* Periodic */ 689 Uint16 period; /**< Period of the wave. */ 690 Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */ 691 Sint16 offset; /**< Mean value of the wave. */ 692 Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */ 693 694 /* Envelope */ 695 Uint16 attack_length; /**< Duration of the attack. */ 696 Uint16 attack_level; /**< Level at the start of the attack. */ 697 Uint16 fade_length; /**< Duration of the fade. */ 698 Uint16 fade_level; /**< Level at the end of the fade. */ 699} SDL_HapticPeriodic; 700 701/** 702 * A structure containing a template for a Condition effect. 703 * 704 * The struct handles the following effects: 705 * 706 * - SDL_HAPTIC_SPRING: Effect based on axes position. 707 * - SDL_HAPTIC_DAMPER: Effect based on axes velocity. 708 * - SDL_HAPTIC_INERTIA: Effect based on axes acceleration. 709 * - SDL_HAPTIC_FRICTION: Effect based on axes movement. 710 * 711 * Direction is handled by condition internals instead of a direction member. 712 * The condition effect specific members have three parameters. The first 713 * refers to the X axis, the second refers to the Y axis and the third refers 714 * to the Z axis. The right terms refer to the positive side of the axis and 715 * the left terms refer to the negative side of the axis. Please refer to the 716 * SDL_HapticDirection diagram for which side is positive and which is 717 * negative. 718 * 719 * \since This struct is available since SDL 3.2.0. 720 * 721 * \sa SDL_HapticDirection 722 * \sa SDL_HAPTIC_SPRING 723 * \sa SDL_HAPTIC_DAMPER 724 * \sa SDL_HAPTIC_INERTIA 725 * \sa SDL_HAPTIC_FRICTION 726 * \sa SDL_HapticEffect 727 */ 728typedef struct SDL_HapticCondition 729{ 730 /* Header */ 731 SDL_HapticEffectType type; /**< SDL_HAPTIC_SPRING, SDL_HAPTIC_DAMPER, 732 SDL_HAPTIC_INERTIA or SDL_HAPTIC_FRICTION */ 733 SDL_HapticDirection direction; /**< Direction of the effect. */ 734 735 /* Replay */ 736 Uint32 length; /**< Duration of the effect. */ 737 Uint16 delay; /**< Delay before starting the effect. */ 738 739 /* Trigger */ 740 Uint16 button; /**< Button that triggers the effect. */ 741 Uint16 interval; /**< How soon it can be triggered again after button. */ 742 743 /* Condition */ 744 Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */ 745 Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */ 746 Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */ 747 Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */ 748 Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */ 749 Sint16 center[3]; /**< Position of the dead zone. */ 750} SDL_HapticCondition; 751 752/** 753 * A structure containing a template for a Ramp effect. 754 * 755 * This struct is exclusively for the SDL_HAPTIC_RAMP effect. 756 * 757 * The ramp effect starts at start strength and ends at end strength. It 758 * augments in linear fashion. If you use attack and fade with a ramp the 759 * effects get added to the ramp effect making the effect become quadratic 760 * instead of linear. 761 * 762 * \since This struct is available since SDL 3.2.0. 763 * 764 * \sa SDL_HAPTIC_RAMP 765 * \sa SDL_HapticEffect 766 */ 767typedef struct SDL_HapticRamp 768{ 769 /* Header */ 770 SDL_HapticEffectType type; /**< SDL_HAPTIC_RAMP */ 771 SDL_HapticDirection direction; /**< Direction of the effect. */ 772 773 /* Replay */ 774 Uint32 length; /**< Duration of the effect. */ 775 Uint16 delay; /**< Delay before starting the effect. */ 776 777 /* Trigger */ 778 Uint16 button; /**< Button that triggers the effect. */ 779 Uint16 interval; /**< How soon it can be triggered again after button. */ 780 781 /* Ramp */ 782 Sint16 start; /**< Beginning strength level. */ 783 Sint16 end; /**< Ending strength level. */ 784 785 /* Envelope */ 786 Uint16 attack_length; /**< Duration of the attack. */ 787 Uint16 attack_level; /**< Level at the start of the attack. */ 788 Uint16 fade_length; /**< Duration of the fade. */ 789 Uint16 fade_level; /**< Level at the end of the fade. */ 790} SDL_HapticRamp; 791 792/** 793 * A structure containing a template for a Left/Right effect. 794 * 795 * This struct is exclusively for the SDL_HAPTIC_LEFTRIGHT effect. 796 * 797 * The Left/Right effect is used to explicitly control the large and small 798 * motors, commonly found in modern game controllers. The small (right) motor 799 * is high frequency, and the large (left) motor is low frequency. 800 * 801 * \since This struct is available since SDL 3.2.0. 802 * 803 * \sa SDL_HAPTIC_LEFTRIGHT 804 * \sa SDL_HapticEffect 805 */ 806typedef struct SDL_HapticLeftRight 807{ 808 /* Header */ 809 SDL_HapticEffectType type; /**< SDL_HAPTIC_LEFTRIGHT */ 810 811 /* Replay */ 812 Uint32 length; /**< Duration of the effect in milliseconds. */ 813 814 /* Rumble */ 815 Uint16 large_magnitude; /**< Control of the large controller motor. */ 816 Uint16 small_magnitude; /**< Control of the small controller motor. */ 817} SDL_HapticLeftRight; 818 819/** 820 * A structure containing a template for the SDL_HAPTIC_CUSTOM effect. 821 * 822 * This struct is exclusively for the SDL_HAPTIC_CUSTOM effect. 823 * 824 * A custom force feedback effect is much like a periodic effect, where the 825 * application can define its exact shape. You will have to allocate the data 826 * yourself. Data should consist of channels * samples Uint16 samples. 827 * 828 * If channels is one, the effect is rotated using the defined direction. 829 * Otherwise it uses the samples in data for the different axes. 830 * 831 * \since This struct is available since SDL 3.2.0. 832 * 833 * \sa SDL_HAPTIC_CUSTOM 834 * \sa SDL_HapticEffect 835 */ 836typedef struct SDL_HapticCustom 837{ 838 /* Header */ 839 SDL_HapticEffectType type; /**< SDL_HAPTIC_CUSTOM */ 840 SDL_HapticDirection direction; /**< Direction of the effect. */ 841 842 /* Replay */ 843 Uint32 length; /**< Duration of the effect. */ 844 Uint16 delay; /**< Delay before starting the effect. */ 845 846 /* Trigger */ 847 Uint16 button; /**< Button that triggers the effect. */ 848 Uint16 interval; /**< How soon it can be triggered again after button. */ 849 850 /* Custom */ 851 Uint8 channels; /**< Axes to use, minimum of one. */ 852 Uint16 period; /**< Sample periods. */ 853 Uint16 samples; /**< Amount of samples. */ 854 Uint16 *data; /**< Should contain channels*samples items. */ 855 856 /* Envelope */ 857 Uint16 attack_length; /**< Duration of the attack. */ 858 Uint16 attack_level; /**< Level at the start of the attack. */ 859 Uint16 fade_length; /**< Duration of the fade. */ 860 Uint16 fade_level; /**< Level at the end of the fade. */ 861} SDL_HapticCustom; 862 863/** 864 * The generic template for any haptic effect. 865 * 866 * All values max at 32767 (0x7FFF). Signed values also can be negative. Time 867 * values unless specified otherwise are in milliseconds. 868 * 869 * You can also pass SDL_HAPTIC_INFINITY to length instead of a 0-32767 value. 870 * Neither delay, interval, attack_length nor fade_length support 871 * SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends. 872 * 873 * Additionally, the SDL_HAPTIC_RAMP effect does not support a duration of 874 * SDL_HAPTIC_INFINITY. 875 * 876 * Button triggers may not be supported on all devices, it is advised to not 877 * use them if possible. Buttons start at index 1 instead of index 0 like the 878 * joystick. 879 * 880 * If both attack_length and fade_level are 0, the envelope is not used, 881 * otherwise both values are used. 882 * 883 * Common parts: 884 * 885 * ```c 886 * // Replay - All effects have this 887 * Uint32 length; // Duration of effect (ms). 888 * Uint16 delay; // Delay before starting effect. 889 * 890 * // Trigger - All effects have this 891 * Uint16 button; // Button that triggers effect. 892 * Uint16 interval; // How soon before effect can be triggered again. 893 * 894 * // Envelope - All effects except condition effects have this 895 * Uint16 attack_length; // Duration of the attack (ms). 896 * Uint16 attack_level; // Level at the start of the attack. 897 * Uint16 fade_length; // Duration of the fade out (ms). 898 * Uint16 fade_level; // Level at the end of the fade. 899 * ``` 900 * 901 * Here we have an example of a constant effect evolution in time: 902 * 903 * ``` 904 * Strength 905 * ^ 906 * | 907 * | effect level --> _________________ 908 * | / \ 909 * | / \ 910 * | / \ 911 * | / \ 912 * | attack_level --> | \ 913 * | | | <--- fade_level 914 * | 915 * +--------------------------------------------------> Time 916 * [--] [---] 917 * attack_length fade_length 918 * 919 * [------------------][-----------------------] 920 * delay length 921 * ``` 922 * 923 * Note either the attack_level or the fade_level may be above the actual 924 * effect level. 925 * 926 * \since This struct is available since SDL 3.2.0. 927 * 928 * \sa SDL_HapticConstant 929 * \sa SDL_HapticPeriodic 930 * \sa SDL_HapticCondition 931 * \sa SDL_HapticRamp 932 * \sa SDL_HapticLeftRight 933 * \sa SDL_HapticCustom 934 */ 935typedef union SDL_HapticEffect 936{ 937 /* Common for all force feedback effects */ 938 SDL_HapticEffectType type; /**< Effect type. */ 939 SDL_HapticConstant constant; /**< Constant effect. */ 940 SDL_HapticPeriodic periodic; /**< Periodic effect. */ 941 SDL_HapticCondition condition; /**< Condition effect. */ 942 SDL_HapticRamp ramp; /**< Ramp effect. */ 943 SDL_HapticLeftRight leftright; /**< Left/Right effect. */ 944 SDL_HapticCustom custom; /**< Custom effect. */ 945} SDL_HapticEffect; 946 947/** 948 * This is a unique ID for a haptic device for the time it is connected to the 949 * system, and is never reused for the lifetime of the application. 950 * 951 * If the haptic device is disconnected and reconnected, it will get a new ID. 952 * 953 * The value 0 is an invalid ID. 954 * 955 * \since This datatype is available since SDL 3.2.0. 956 */ 957typedef Uint32 SDL_HapticID; 958 959 960/* Function prototypes */ 961 962/** 963 * Get a list of currently connected haptic devices. 964 * 965 * \param count a pointer filled in with the number of haptic devices 966 * returned, may be NULL. 967 * \returns a 0 terminated array of haptic device instance IDs or NULL on 968 * failure; call SDL_GetError() for more information. This should be 969 * freed with SDL_free() when it is no longer needed. 970 * 971 * \since This function is available since SDL 3.2.0. 972 * 973 * \sa SDL_OpenHaptic 974 */ 975extern SDL_DECLSPEC SDL_HapticID * SDLCALL SDL_GetHaptics(int *count); 976 977/** 978 * Get the implementation dependent name of a haptic device. 979 * 980 * This can be called before any haptic devices are opened. 981 * 982 * \param instance_id the haptic device instance ID. 983 * \returns the name of the selected haptic device. If no name can be found, 984 * this function returns NULL; call SDL_GetError() for more 985 * information. 986 * 987 * \since This function is available since SDL 3.2.0. 988 * 989 * \sa SDL_GetHapticName 990 * \sa SDL_OpenHaptic 991 */ 992extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID instance_id); 993 994/** 995 * Open a haptic device for use. 996 * 997 * The index passed as an argument refers to the N'th haptic device on this 998 * system. 999 * 1000 * When opening a haptic device, its gain will be set to maximum and 1001 * autocenter will be disabled. To modify these values use SDL_SetHapticGain() 1002 * and SDL_SetHapticAutocenter(). 1003 * 1004 * \param instance_id the haptic device instance ID. 1005 * \returns the device identifier or NULL on failure; call SDL_GetError() for 1006 * more information. 1007 * 1008 * \since This function is available since SDL 3.2.0. 1009 * 1010 * \sa SDL_CloseHaptic 1011 * \sa SDL_GetHaptics 1012 * \sa SDL_OpenHapticFromJoystick 1013 * \sa SDL_OpenHapticFromMouse 1014 * \sa SDL_SetHapticAutocenter 1015 * \sa SDL_SetHapticGain 1016 */ 1017extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHaptic(SDL_HapticID instance_id); 1018 1019 1020/** 1021 * Get the SDL_Haptic associated with an instance ID, if it has been opened. 1022 * 1023 * \param instance_id the instance ID to get the SDL_Haptic for. 1024 * \returns an SDL_Haptic on success or NULL on failure or if it hasn't been 1025 * opened yet; call SDL_GetError() for more information. 1026 * 1027 * \since This function is available since SDL 3.2.0. 1028 */ 1029extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_GetHapticFromID(SDL_HapticID instance_id); 1030 1031/** 1032 * Get the instance ID of an opened haptic device. 1033 * 1034 * \param haptic the SDL_Haptic device to query. 1035 * \returns the instance ID of the specified haptic device on success or 0 on 1036 * failure; call SDL_GetError() for more information. 1037 * 1038 * \since This function is available since SDL 3.2.0. 1039 */ 1040extern SDL_DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticID(SDL_Haptic *haptic); 1041 1042/** 1043 * Get the implementation dependent name of a haptic device. 1044 * 1045 * \param haptic the SDL_Haptic obtained from SDL_OpenJoystick(). 1046 * \returns the name of the selected haptic device. If no name can be found, 1047 * this function returns NULL; call SDL_GetError() for more 1048 * information. 1049 * 1050 * \since This function is available since SDL 3.2.0. 1051 * 1052 * \sa SDL_GetHapticNameForID 1053 */ 1054extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic); 1055 1056/** 1057 * Query whether or not the current mouse has haptic capabilities. 1058 * 1059 * \returns true if the mouse is haptic or false if it isn't. 1060 * 1061 * \since This function is available since SDL 3.2.0. 1062 * 1063 * \sa SDL_OpenHapticFromMouse 1064 */ 1065extern SDL_DECLSPEC bool SDLCALL SDL_IsMouseHaptic(void); 1066 1067/** 1068 * Try to open a haptic device from the current mouse. 1069 * 1070 * \returns the haptic device identifier or NULL on failure; call 1071 * SDL_GetError() for more information. 1072 * 1073 * \since This function is available since SDL 3.2.0. 1074 * 1075 * \sa SDL_CloseHaptic 1076 * \sa SDL_IsMouseHaptic 1077 */ 1078extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromMouse(void); 1079 1080/** 1081 * Query if a joystick has haptic features. 1082 * 1083 * \param joystick the SDL_Joystick to test for haptic capabilities. 1084 * \returns true if the joystick is haptic or false if it isn't. 1085 * 1086 * \since This function is available since SDL 3.2.0. 1087 * 1088 * \sa SDL_OpenHapticFromJoystick 1089 */ 1090extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickHaptic(SDL_Joystick *joystick); 1091 1092/** 1093 * Open a haptic device for use from a joystick device. 1094 * 1095 * You must still close the haptic device separately. It will not be closed 1096 * with the joystick. 1097 * 1098 * When opened from a joystick you should first close the haptic device before 1099 * closing the joystick device. If not, on some implementations the haptic 1100 * device will also get unallocated and you'll be unable to use force feedback 1101 * on that device. 1102 * 1103 * \param joystick the SDL_Joystick to create a haptic device from. 1104 * \returns a valid haptic device identifier on success or NULL on failure; 1105 * call SDL_GetError() for more information. 1106 * 1107 * \since This function is available since SDL 3.2.0. 1108 * 1109 * \sa SDL_CloseHaptic 1110 * \sa SDL_IsJoystickHaptic 1111 */ 1112extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromJoystick(SDL_Joystick *joystick); 1113 1114/** 1115 * Close a haptic device previously opened with SDL_OpenHaptic(). 1116 * 1117 * \param haptic the SDL_Haptic device to close. 1118 * 1119 * \since This function is available since SDL 3.2.0. 1120 * 1121 * \sa SDL_OpenHaptic 1122 */ 1123extern SDL_DECLSPEC void SDLCALL SDL_CloseHaptic(SDL_Haptic *haptic); 1124 1125/** 1126 * Get the number of effects a haptic device can store. 1127 * 1128 * On some platforms this isn't fully supported, and therefore is an 1129 * approximation. Always check to see if your created effect was actually 1130 * created and do not rely solely on SDL_GetMaxHapticEffects(). 1131 * 1132 * \param haptic the SDL_Haptic device to query. 1133 * \returns the number of effects the haptic device can store or a negative 1134 * error code on failure; call SDL_GetError() for more information. 1135 * 1136 * \since This function is available since SDL 3.2.0. 1137 * 1138 * \sa SDL_GetMaxHapticEffectsPlaying 1139 * \sa SDL_GetHapticFeatures 1140 */ 1141extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffects(SDL_Haptic *haptic); 1142 1143/** 1144 * Get the number of effects a haptic device can play at the same time. 1145 * 1146 * This is not supported on all platforms, but will always return a value. 1147 * 1148 * \param haptic the SDL_Haptic device to query maximum playing effects. 1149 * \returns the number of effects the haptic device can play at the same time 1150 * or -1 on failure; call SDL_GetError() for more information. 1151 * 1152 * \since This function is available since SDL 3.2.0. 1153 * 1154 * \sa SDL_GetMaxHapticEffects 1155 * \sa SDL_GetHapticFeatures 1156 */ 1157extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffectsPlaying(SDL_Haptic *haptic); 1158 1159/** 1160 * Get the haptic device's supported features in bitwise manner. 1161 * 1162 * \param haptic the SDL_Haptic device to query. 1163 * \returns a list of supported haptic features in bitwise manner (OR'd), or 0 1164 * on failure; call SDL_GetError() for more information. 1165 * 1166 * \since This function is available since SDL 3.2.0. 1167 * 1168 * \sa SDL_HapticEffectSupported 1169 * \sa SDL_GetMaxHapticEffects 1170 */ 1171extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetHapticFeatures(SDL_Haptic *haptic); 1172 1173/** 1174 * Get the number of haptic axes the device has. 1175 * 1176 * The number of haptic axes might be useful if working with the 1177 * SDL_HapticDirection effect. 1178 * 1179 * \param haptic the SDL_Haptic device to query. 1180 * \returns the number of axes on success or -1 on failure; call 1181 * SDL_GetError() for more information. 1182 * 1183 * \since This function is available since SDL 3.2.0. 1184 */ 1185extern SDL_DECLSPEC int SDLCALL SDL_GetNumHapticAxes(SDL_Haptic *haptic); 1186 1187/** 1188 * Check to see if an effect is supported by a haptic device. 1189 * 1190 * \param haptic the SDL_Haptic device to query. 1191 * \param effect the desired effect to query. 1192 * \returns true if the effect is supported or false if it isn't. 1193 * 1194 * \since This function is available since SDL 3.2.0. 1195 * 1196 * \sa SDL_CreateHapticEffect 1197 * \sa SDL_GetHapticFeatures 1198 */ 1199extern SDL_DECLSPEC bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect); 1200 1201/** 1202 * Create a new haptic effect on a specified device. 1203 * 1204 * \param haptic an SDL_Haptic device to create the effect on. 1205 * \param effect an SDL_HapticEffect structure containing the properties of 1206 * the effect to create. 1207 * \returns the ID of the effect on success or -1 on failure; call 1208 * SDL_GetError() for more information. 1209 * 1210 * \since This function is available since SDL 3.2.0. 1211 * 1212 * \sa SDL_DestroyHapticEffect 1213 * \sa SDL_RunHapticEffect 1214 * \sa SDL_UpdateHapticEffect 1215 */ 1216extern SDL_DECLSPEC SDL_HapticEffectID SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect); 1217 1218/** 1219 * Update the properties of an effect. 1220 * 1221 * Can be used dynamically, although behavior when dynamically changing 1222 * direction may be strange. Specifically the effect may re-upload itself and 1223 * start playing from the start. You also cannot change the type either when 1224 * running SDL_UpdateHapticEffect(). 1225 * 1226 * \param haptic the SDL_Haptic device that has the effect. 1227 * \param effect the identifier of the effect to update. 1228 * \param data an SDL_HapticEffect structure containing the new effect 1229 * properties to use. 1230 * \returns true on success or false on failure; call SDL_GetError() for more 1231 * information. 1232 * 1233 * \since This function is available since SDL 3.2.0. 1234 * 1235 * \sa SDL_CreateHapticEffect 1236 * \sa SDL_RunHapticEffect 1237 */ 1238extern SDL_DECLSPEC bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, const SDL_HapticEffect *data); 1239 1240/** 1241 * Run the haptic effect on its associated haptic device. 1242 * 1243 * To repeat the effect over and over indefinitely, set `iterations` to 1244 * `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make 1245 * one instance of the effect last indefinitely (so the effect does not fade), 1246 * set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY` 1247 * instead. 1248 * 1249 * \param haptic the SDL_Haptic device to run the effect on. 1250 * \param effect the ID of the haptic effect to run. 1251 * \param iterations the number of iterations to run the effect; use 1252 * `SDL_HAPTIC_INFINITY` to repeat forever. 1253 * \returns true on success or false on failure; call SDL_GetError() for more 1254 * information. 1255 * 1256 * \since This function is available since SDL 3.2.0. 1257 * 1258 * \sa SDL_GetHapticEffectStatus 1259 * \sa SDL_StopHapticEffect 1260 * \sa SDL_StopHapticEffects 1261 */ 1262extern SDL_DECLSPEC bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, Uint32 iterations); 1263 1264/** 1265 * Stop the haptic effect on its associated haptic device. 1266 * 1267 * \param haptic the SDL_Haptic device to stop the effect on. 1268 * \param effect the ID of the haptic effect to stop. 1269 * \returns true on success or false on failure; call SDL_GetError() for more 1270 * information. 1271 * 1272 * \since This function is available since SDL 3.2.0. 1273 * 1274 * \sa SDL_RunHapticEffect 1275 * \sa SDL_StopHapticEffects 1276 */ 1277extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect); 1278 1279/** 1280 * Destroy a haptic effect on the device. 1281 * 1282 * This will stop the effect if it's running. Effects are automatically 1283 * destroyed when the device is closed. 1284 * 1285 * \param haptic the SDL_Haptic device to destroy the effect on. 1286 * \param effect the ID of the haptic effect to destroy. 1287 * 1288 * \since This function is available since SDL 3.2.0. 1289 * 1290 * \sa SDL_CreateHapticEffect 1291 */ 1292extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect); 1293 1294/** 1295 * Get the status of the current effect on the specified haptic device. 1296 * 1297 * Device must support the SDL_HAPTIC_STATUS feature. 1298 * 1299 * \param haptic the SDL_Haptic device to query for the effect status on. 1300 * \param effect the ID of the haptic effect to query its status. 1301 * \returns true if it is playing, false if it isn't playing or haptic status 1302 * isn't supported. 1303 * 1304 * \since This function is available since SDL 3.2.0. 1305 * 1306 * \sa SDL_GetHapticFeatures 1307 */ 1308extern SDL_DECLSPEC bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, SDL_HapticEffectID effect); 1309 1310/** 1311 * Set the global gain of the specified haptic device. 1312 * 1313 * Device must support the SDL_HAPTIC_GAIN feature. 1314 * 1315 * The user may specify the maximum gain by setting the environment variable 1316 * `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to 1317 * SDL_SetHapticGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the 1318 * maximum. 1319 * 1320 * \param haptic the SDL_Haptic device to set the gain on. 1321 * \param gain value to set the gain to, should be between 0 and 100 (0 - 1322 * 100). 1323 * \returns true on success or false on failure; call SDL_GetError() for more 1324 * information. 1325 * 1326 * \since This function is available since SDL 3.2.0. 1327 * 1328 * \sa SDL_GetHapticFeatures 1329 */ 1330extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain); 1331 1332/** 1333 * Set the global autocenter of the device. 1334 * 1335 * Autocenter should be between 0 and 100. Setting it to 0 will disable 1336 * autocentering. 1337 * 1338 * Device must support the SDL_HAPTIC_AUTOCENTER feature. 1339 * 1340 * \param haptic the SDL_Haptic device to set autocentering on. 1341 * \param autocenter value to set autocenter to (0-100). 1342 * \returns true on success or false on failure; call SDL_GetError() for more 1343 * information. 1344 * 1345 * \since This function is available since SDL 3.2.0. 1346 * 1347 * \sa SDL_GetHapticFeatures 1348 */ 1349extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter); 1350 1351/** 1352 * Pause a haptic device. 1353 * 1354 * Device must support the `SDL_HAPTIC_PAUSE` feature. Call SDL_ResumeHaptic() 1355 * to resume playback. 1356 * 1357 * Do not modify the effects nor add new ones while the device is paused. That 1358 * can cause all sorts of weird errors. 1359 * 1360 * \param haptic the SDL_Haptic device to pause. 1361 * \returns true on success or false on failure; call SDL_GetError() for more 1362 * information. 1363 * 1364 * \since This function is available since SDL 3.2.0. 1365 * 1366 * \sa SDL_ResumeHaptic 1367 */ 1368extern SDL_DECLSPEC bool SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic); 1369 1370/** 1371 * Resume a haptic device. 1372 * 1373 * Call to unpause after SDL_PauseHaptic(). 1374 * 1375 * \param haptic the SDL_Haptic device to unpause. 1376 * \returns true on success or false on failure; call SDL_GetError() for more 1377 * information. 1378 * 1379 * \since This function is available since SDL 3.2.0. 1380 * 1381 * \sa SDL_PauseHaptic 1382 */ 1383extern SDL_DECLSPEC bool SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic); 1384 1385/** 1386 * Stop all the currently playing effects on a haptic device. 1387 * 1388 * \param haptic the SDL_Haptic device to stop. 1389 * \returns true on success or false on failure; call SDL_GetError() for more 1390 * information. 1391 * 1392 * \since This function is available since SDL 3.2.0. 1393 * 1394 * \sa SDL_RunHapticEffect 1395 * \sa SDL_StopHapticEffects 1396 */ 1397extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic); 1398 1399/** 1400 * Check whether rumble is supported on a haptic device. 1401 * 1402 * \param haptic haptic device to check for rumble support. 1403 * \returns true if the effect is supported or false if it isn't. 1404 * 1405 * \since This function is available since SDL 3.2.0. 1406 * 1407 * \sa SDL_InitHapticRumble 1408 */ 1409extern SDL_DECLSPEC bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic); 1410 1411/** 1412 * Initialize a haptic device for simple rumble playback. 1413 * 1414 * \param haptic the haptic device to initialize for simple rumble playback. 1415 * \returns true on success or false on failure; call SDL_GetError() for more 1416 * information. 1417 * 1418 * \since This function is available since SDL 3.2.0. 1419 * 1420 * \sa SDL_PlayHapticRumble 1421 * \sa SDL_StopHapticRumble 1422 * \sa SDL_HapticRumbleSupported 1423 */ 1424extern SDL_DECLSPEC bool SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic); 1425 1426/** 1427 * Run a simple rumble effect on a haptic device. 1428 * 1429 * \param haptic the haptic device to play the rumble effect on. 1430 * \param strength strength of the rumble to play as a 0-1 float value. 1431 * \param length length of the rumble to play in milliseconds. 1432 * \returns true on success or false on failure; call SDL_GetError() for more 1433 * information. 1434 * 1435 * \since This function is available since SDL 3.2.0. 1436 * 1437 * \sa SDL_InitHapticRumble 1438 * \sa SDL_StopHapticRumble 1439 */ 1440extern SDL_DECLSPEC bool SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length); 1441 1442/** 1443 * Stop the simple rumble on a haptic device. 1444 * 1445 * \param haptic the haptic device to stop the rumble effect on. 1446 * \returns true on success or false on failure; call SDL_GetError() for more 1447 * information. 1448 * 1449 * \since This function is available since SDL 3.2.0. 1450 * 1451 * \sa SDL_PlayHapticRumble 1452 */ 1453extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic); 1454 1455/* Ends C function definitions when using C++ */ 1456#ifdef __cplusplus 1457} 1458#endif 1459#include <SDL3/SDL_close_code.h> 1460 1461#endif /* SDL_haptic_h_ */ 1462[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.