'''Include File(s):''' [http://hg.libsdl.org/SDL/file/default/include/SDL_haptic.h SDL_haptic.h]
The SDL haptic subsystem allows you to control haptic (force feedback) devices.
The basic usage is as follows:
a. [SDL_HapticOpen] to open from index
a. [SDL_HapticOpenFromJoystick] to open from an existing joystick
Simple rumble example:
// Open the device haptic = SDL_HapticOpen( 0 ); if (haptic == NULL) return -1;
// Initialize simple rumble if (SDL_HapticRumbleInit( haptic ) != 0) return -1;
// Play effect at 50% strength for 2 seconds if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0) return -1; SDL_Delay( 2000 );
// Clean up SDL_HapticClose( haptic );
Complete example:
// Open the device haptic = SDL_HapticOpenFromJoystick( joystick ); if (haptic == NULL) return -1; // Most likely joystick isn't haptic
// See if it can do sine waves if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) { SDL_HapticClose(haptic); // No sine effect return -1; }
// Create the effect SDL_memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default effect.type = SDL_HAPTIC_SINE; effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates effect.periodic.direction.dir[0] = 18000; // Force comes from south effect.periodic.period = 1000; // 1000 ms effect.periodic.magnitude = 20000; // 20000/32767 strength effect.periodic.length = 5000; // 5 seconds long effect.periodic.attack_length = 1000; // Takes 1 second to get max strength effect.periodic.fade_length = 1000; // Takes 1 second to fade away
// Upload the effect effect_id = SDL_HapticNewEffect( haptic, &effect );
// Test the effect SDL_HapticRunEffect( haptic, effect_id, 1 ); SDL_Delay( 5000); // Wait for the effect to finish
// We destroy the effect, although closing the device also does this SDL_HapticDestroyEffect( haptic, effect_id );
// Close the device SDL_HapticClose(haptic);
return 0; // Success } You can find more information in this blog by Edgar Simo Serra: http://bobbens.dyndns.org/journal/2010/sdl_haptic/ SDL Haptic In Depth
<<FullSearchCached(category:CategoryStruct CategoryForceFeedback -title:SGStructures)>>
<<FullSearchCached(category:CategoryForceFeedback -CategoryEnum -CategoryStruct -title:SGFunctions)>>