This documentation provides an overview of the functions available in the Interhaptics Engine API. The API allows developers to interact with the Interhaptics Engine and control haptic effects, manage body parts, and control haptic events.
This SDK provides a comprehensive set of tools and resources for integrating the Interhaptics Engine into a game application on the various supported platforms. The next pages outline the necessary components and recommended steps for integration within the game engine.
The Interhaptics Engine includes the following components required to do in-engine integration. Its two main components are the Haptic Engine and the Device Providers.
To successfully integrate the Interhaptics Engine into a game application, the following steps are recommended:
By following these recommended steps, the game engine will gain the following capabilities:
For detailed instructions and guidelines on each integration step, please refer to the accompanying documentation provided with the Interhaptics Engine SDK.
Please note that the Interhaptics Engine SDK supports all platforms officially supported by Interhaptics as shown in the image below. Ensure compatibility with the target platform and refer to the platform-specific documentation for any additional integration requirements or considerations.
The Interhaptics Engine Library is a precompiled C++ library that provides essential functionality for integrating haptic feedback into game applications. It is available for the following platforms:
Before utilizing the Interhaptics Engine Library, it must be properly loaded and initialized in the game application. The initialization process ensures the library is ready for use and enables access to the available APIs.
The Interhaptics Engine Library handles various aspects of haptic feedback, including:
Device Providers are a collection of precompiled libraries responsible for establishing communication between the Interhaptics Engine and haptic APIs of various devices. These libraries facilitate the integration and interoperability between the Interhaptics Engine and supported devices.
The device providers handle the following tasks:
Refer to the Key Concepts section of this documentation for more detailed information on loading, unloading, and rendering processes related to the Interhaptics Engine and device providers, respectively.
Please consult the accompanying documentation for comprehensive instructions and usage guidelines on integrating the Interhaptics Engine Library and supported device providers into your game application.
.haps files are standard text files that store haptic parameters for designed haptic effects. These files utilize the JSON (JavaScript Object Notation) format to represent the haptic effect’s configuration and properties. The Interhaptics Engine relies on .haps files to load and apply specific haptic effects during gameplay.
The structure and format of .haps files follows the guidelines specified in the Haptic Composer documentation. You can find comprehensive information about the structure and contents of .haps files by referring to the Interhaptics online documentation at the following link.
Please consult the online documentation to thoroughly understand the .haps file format and how to design haptic effects using the Haptic Composer tool.
Ensure that the .haps files in your game application adhere to the specified structure and format to guarantee proper loading and application of haptic effects by the Interhaptics Engine.
To use the Interhaptics Engine, it must be initialized. The following Engine API should be used for initialization:
///
/// Initializes the different components and modules of the Interhaptics Engine:
/// - Haptic Material Manager: module in charge of loading and storing haptic effects
/// - Human Avatar Manager: module in charge of mapping between device, human avatar, and experience
/// - Haptic Event Manager: module in charge of the control of haptic sources
///
/// Always true even if a module is not properly initialized.
DLLExport bool Init();
To properly finalize the usage of the Interhaptics Engine, it is essential to de-initialize it before quitting the application. The following Engine API is used for de-initialization:
///
/// Cleans the different components and modules of the Interhaptics Engine.
/// To be called before the application is quit.
///
DLLExport void Quit();
After initializing the Interhaptics Engine, the device providers must also be initialized. All Provider implementations follow a consistent interface that exposes the following APIs:
extern "C"
{
DLLExport bool ProviderInit();
DLLExport bool ProviderIsPresent();
DLLExport bool ProviderClean();
DLLExport void ProviderRenderHaptics();
}
ProviderInit handles the initialization process of the specific device’s COM , haptic settings for rendering, and subscription to the Interhaptics Engine. It returns false if the initialization process fails.
ProviderClean is responsible for de-initializing the device’s COM, if necessary, and unsubscribing the provider from the Interhaptics Engine. It returns false if the de-initialization process fails.
Please ensure that the Interhaptics Engine and device providers are initialized and de-initialized correctly to guarantee the proper functioning of the haptic system within the application.
Before the Interhaptics Engine can render a haptic effect, the corresponding .haps file must be loaded into the engine. This requires the ability of the game engine to open and read the contents of the .haps file during runtime. It is recommended to treat .haps files as game assets, similar to sound effects and graphical assets.
To load a haptic effect from a .haps file, use the following Engine API call:
///
/// Adds the content of an .haps file to the Interhaptics Engine for future use.
///
/// JSON content of the .haps file to be loaded. Needs to follow Interhaptics .haps format.
/// ID of the haptic effect to be used in other engine calls. -1 if loading failed.
DLLExport int AddHM(const char* _content);
The core logic of the Interhaptics Engine involves two main elements: haptic rendering and the device provider loop.
Haptic rendering refers to the computation of haptic buffers during each iteration of the rendering loop, based on the game events. To trigger the rendering of haptic buffers, use the following Engine API call:
///
/// To be called in the application main loop to trigger the rendering of all haptic buffers
/// at a specific time. The Interhaptics Engine will compare the current time with the last
/// know value to build buffers large enough to cover frame drops.
/// Can be called from the main thread or in a parallel loop.
/// Must be called at least once before triggering the device update event.
///
/// Current time in seconds.
///
DLLExport void ComputeAllEvents(double _curTime);
It is important to call ComputeAllEvents() every iteration of the rendering loop, either in the main thread or a parallel thread. This ensures that haptic buffers are generated in real-time based on the subscribed Providers. If no device has subscribed, no buffer will be generated. Refer to the section Interhaptics Engine and Providers Initialization for information on device subscription.
The provider loop is responsible for rendering the haptic buffers on the devices for playback. All provider implementations follow a common interface, exposing the following APIs:
extern "C"
{
DLLExport bool ProviderInit();
DLLExport bool ProviderIsPresent();
DLLExport bool ProviderClean();
DLLExport void ProviderRenderHaptics();
}
The ProviderRenderHaptics() API triggers the rendering process for the provider by retrieving the necessary haptic buffers, transcoding them if required, and playing them back on the associated device. This API must be called for all targeted devices.
It is mandatory to call ComputeAllEvents() from the Interhaptics Engine before calling ProviderRenderHaptics() for synchronized haptic rendering. Typically, both APIs are implemented in the same loop, with ComputeAllEvents() called before the ProviderRenderHaptics() calls.
Additionally, you can use ProviderIsPresent() to check the availability of the device before triggering haptic playback. This optional step can help improve performance.
Haptic Sources are essential for linking the Interhaptics Engine to the game mechanics. Similar to audio sources, Haptic sources contain references to haptic effects, a list of targets within range of the source, and parameters such as volumes and offsets.
A haptic source must be linked to a loaded haptic effect. Refer to the section Loading .haps Files for details on loading .haps files.
Stopping a source transitions it to an inactive state, where parameters and targets do not need to be redefined when restarting the source. To completely remove a source, use the related ClearEvent APIs.
A target represents a virtual reference to the location of the haptic event. Instead of targeting a specific device, a haptic source targets a region on the human avatar, which can be a single body part or a group of body parts. This system acts as a mapping layer between the haptic experience and the cross-platform ecosystem of haptic devices. It ensures that a implemented haptic experience can be ported to a different haptic system without the need for re-implementing the experience.
Providers declare to the game engine which targets they support. If a haptic source is playing on a target not referenced by any provider, the output can either be ignored or remapped based on requirements.
For more details on the control of haptic sources and construction of targets, please refer to section Engine Control of the documentation.
bool Init();
Initializes the different components and modules of the Interhaptics Engine. This function should be called before any other API function is used.
Returns: Always returns true, even if a module is not properly initialized.
void Quit();
Cleans up the different components and modules of the Interhaptics Engine. This function should be called before the application is quit.
int AddHM(const char* _content);
Parameters
Returns: The ID of the haptic effect if loading is successful, or -1 if loading failed.
int AddParametricEffect(double* _amplitude, int _amplitudeSize, double* _pitch, int _pitchSize, double _pitchMin, double _pitchMax, double* _transient, int _transientSize, bool _isLooping);
double* _amplitude
: An array of amplitude values. The array should be formatted as Time – Value pairs, where each Value is between 0 and 1.int _amplitudeSize
: The size of the amplitude array.double* _pitch
: An array of pitch values. The array should be formatted as Time – Value pairs, where each Value is between 0 and 1.int _pitchSize
: The size of the pitch array.double _freqMin
: The minimum value for the frequency range.double _freqMax
: The maximum value for the frequency range.double* _transient
: An array of transient values. The array should be formatted as Time – Amplitude – Pitch triplets, with both Amplitude and Pitch values ranging between 0 and 1.int _transientSize
: The size of the transient array.bool _isLooping
: Indicates whether the audio effect should loop.
bool UpdateHM(int _hMaterialID, const char* _content);
Replaces the content of an already loaded haptic effect. This function is useful when the ID of the haptic effect needs to be persistent.
Parameters
Returns: true if the effect was properly updated, false otherwise.
double GetGlobalIntensity();
Returns: The global intensity. -1 if mixer is not initialized.
void SetGlobalIntensity(double _intensity);
Parameters
The SharedTypes.h file defines various enumerations and a structure within the Interhaptics::HapticBodyMapping namespace. These types are used to represent shared types and constants related to haptic body mapping.
This enumeration represents operators used in the haptic body mapping. The possible values are:
This enumeration represents the lateral position of a body part. The possible values are:
The GroupID enumeration represents the group IDs for different body parts. Each group has a unique ID assigned to it for grouping purposes. The following are some of the groups and their corresponding IDs:
This enumeration consists of various group IDs that help categorize different body parts based on their grouping characteristics.
// recommended constructor
CommandData(Operator _sign, GroupID _group, LateralFlag _side = Global)
{
Sign = _sign;
Group = _group;
Side = _side;
}
This structure represents an instruction that is useful for finding the body part to render. It contains the following members:
The structure provides a recommended constructor to initialize the members.
void PlayEvent(int _hMaterialID, double _vibrationOffset, double _textureOffset, double _stiffnessOffset);
Starts the rendering playback of a haptic source. It sets the starting time to 0 plus different offsets. If the event is already playing, it restarts with the new offsets. If the source does not already exist, it will be created.
Parameters
void StopEvent(int _hMaterialID);
Stops the rendering playback of a haptic source.
Parameters
void StopAllEvents();
void AddTargetToEvent(int _hMaterialID, std::vector _target);
Adds a target within the range of the source. The Interhaptics Engine will remap device endpoints and in-range targets to the device management layer for haptic playback.
Parameters
void AddTargetToEventMarshal(int _hMaterialID, CommandData* _target, int _size);
Marshal version of the AddTargetToEvent function. Adds a target within the range of the source. The Interhaptics Engine will remap device endpoints and in-range targets to the device management layer for haptic playback.
Parameters
void RemoveTargetFromEvent(int _hMaterialID, std::vector _target);
Removes a target from a source range. The Interhaptics Engine will remap device endpoints and in-range targets to the device management layer for haptic playback.
Parameters
void RemoveTargetFromEventMarshal(int _hMaterialID, CommandData* _target, int _size);
Marshal version of the RemoveTargetFromEvent function. Removes a target from a source range. The Interhaptics Engine will remap device endpoints and in-range targets to the device management layer for haptic playback.
Parameters
void RemoveAllTargetsFromEvent(int _hMaterialID);
Removes all targets from a source range. The Interhaptics Engine will remap device endpoints and in-range targets to the device management layer for haptic playback.
Parameters
void ComputeAllEvents(double _curTime);
To be called in the application main loop to trigger the rendering of all haptic buffers at a specific time. The Interhaptics Engine will compare the current time with the last known value to build a buffer large enough to cover frame drops. This function can be called from the main thread or in a parallel loop. It must be called at least once before triggering the device update event.
Parameters
void UpdateEventPositions(int _hMaterialID, std::vector _target, double _texturePosition, double _stiffnessPosition);
Updates spatial positions for a specific source target.
Parameters
void UpdateEventPositionsMarshal(int _hMaterialID, CommandData* _target, int _size, double _texturePosition, double _stiffnessPosition);
Marshal version of the UpdateEventPositions function. Updates spatial positions for a specific source target.
Parameters
void SetEventIntensity(int _hMaterialID, double _intensity);
Parameters
int _hMaterialID
: The identifier of the haptic effect.double _intensity
: The new intensity factor for the haptic effect, which is always clamped to be above 0.
void SetTargetIntensity(int _hMaterialID, std::vector _target, double _intensity);
Sets the haptics intensity factor for a specific target within a haptic source.
int _hMaterialID
: The identifier of the haptic source.std::vector<CommandData> _target
: The target for the intensity change.double _intensity
: The new intensity factor for the target, always clamped to be above 0.
void SetTargetIntensityMarshal(int _hMaterialID, CommandData* _target, int _size, double _intensity);
Parameters
int _hMaterialID
: The identifier of the haptic source.CommandData* _target
: The pointer to the target data array.int _size
: The size of the target data array.double _intensity
: The new intensity factor for the target, always clamped to be above 0.
void SetEventLoop(int _hMaterialID, bool _isLooping);
Sets the loop flag for a specific haptic effect.
int _hMaterialID
: The identifier of the haptic effect.bool _isLooping
: A boolean value indicating whether the haptic effect should loop.
void SetEventOffsets(int _hMaterialID, double _vibrationOffset, double _textureOffset, double _stiffnessOffset);
Sets the offsets for a specific haptic source.
Parameters
void ClearInactiveEvents();
Clears all inactive sources from memory. Inactive sources are kept in memory to avoid deletion and re-creation when playing and stopping a source.
void ClearActiveEvents();
Clears all active sources from memory. Deleted sources can be recreated by calling the PlayEvent function.
void ClearEvent(int _hMaterialID);
Clears a specific haptic source, whether it is active or not.
Parameters: