This website uses cookies to improve our services and deliver relevant ads.
By interacting with this site, you agree to this use. For more information, see our Cookies Policy

Haptic Feedback

In addition to reporting input state, Oculus touch controllers can provide haptic feedback through vibration.

The SDK supports two types of haptics: buffered and non-buffered. Buffered haptics are designed to change rapidly (every 3.125ms) and work well for subtle effects. Non-buffered haptics are designed for simple effects that don't change often (every 33ms).

Note: The buffered and non-buffered functions should not be used together, as they will result in unpredictable haptic feedback.

Buffer-Based Haptics

Running at 320Hz, each sample is 3.125 milliseconds. Because these samples are added to a buffer that holds 256 samples, the buffer can hold up to 800 milliseconds of samples.

To check the status of the buffer, call ovr_GetControllerVibrationState:

ovr_GetControllerVibrationState(ovrSession session, ovrControllerType controllerType, ovrHapticsPlaybackState* outState);

To submit to the buffer, call ovr_SubmitControllerVibration:

ovr_SubmitControllerVibration(ovrSession session, ovrControllerType controllerType, const ovrHapticsBuffer* buffer);

The following code sample shows basic haptic submission as part of a game loop:

    uint8_t amplitude = (uint8_t)round(handTrigger[t] * 255);

    result = ovr_GetControllerVibrationState(Session, touchController[t], &state);
    if (result != ovrSuccess || state.SamplesQueued >= kLowLatencyBufferSizeInSamples)
    {
        DefaultChannel.LogWarningF("%s Haptics skipped. Queue size %d", kTouchStr[t], state.SamplesQueued);
        continue;
    }

    for (int32_t i = 0; i < kLowLatencyBufferSizeInSamples; ++i)
        samples.push_back(amplitude);

    if (samples.size() > 0)
    {
        ovrHapticsBuffer buffer;
        buffer.SubmitMode = ovrHapticsBufferSubmit_Enqueue;
        buffer.SamplesCount = (uint32_t)samples.size();
        buffer.Samples = samples.data();
        result = ovr_SubmitControllerVibration(Session, touchController[t], &buffer);
        if (result != ovrSuccess)
        {
            // Something bad happened
            DefaultChannel.LogErrorF("%s: Haptics submit failed %d", kTouchStr[t], result);
        }
    }

Non-Buffered Haptics

Vibration can be enabled by calling ovr_SetControllerVibration:

ovr_SetControllerVibration( Hmd, ovrControllerType_LTouch, freq, trigger);

Vibration is enabled by specifying the frequency. Specifying 0.0f will vibrate at 160Hz. Specifying 1.0f will vibrate at 320Hz.