OpenXRHapticVibration
Pulse parameters: nanoseconds, Hz and amplitude.
OpenXRHapticVibration describes a pulse for modifier OnHaptic/OffHaptic. Constructing the resource sends no vibration. Duration uses nanoseconds (long), Frequency Hz and Amplitude 0…1. Initially Duration=-1 requests a minimum pulse, Frequency=0 leaves frequency selection to the runtime and Amplitude=1. OpenXR units and limits.
Do not confuse Duration with TriggerHapticPulse duration, which uses seconds. This complete executed helper accepts milliseconds, rounds to a nanosecond and rejects nonfinite, out-of-range or too-small inputs before constructing a resource:
using System;
using Reckfell;
public static class XrFeedback
{
// Builds a resource for a modifier. This does not send a pulse to a device.
// The caller owns the returned resource.
public static OpenXRHapticVibration PulseMilliseconds(
double milliseconds, float amplitude, float frequencyHz = 0)
{
double nanoseconds = Math.Round(milliseconds * 1_000_000.0);
if (!double.IsFinite(nanoseconds) || nanoseconds < 1 || nanoseconds >= long.MaxValue)
throw new ArgumentOutOfRangeException(nameof(milliseconds));
if (!float.IsFinite(amplitude) || amplitude < 0 || amplitude > 1)
throw new ArgumentOutOfRangeException(nameof(amplitude));
if (!float.IsFinite(frequencyHz) || frequencyHz < 0)
throw new ArgumentOutOfRangeException(nameof(frequencyHz));
return new OpenXRHapticVibration
{
Duration = checked((long)nanoseconds),
Amplitude = amplitude,
Frequency = frequencyHz
};
}
}PulseMilliseconds(20,0.5f) returns Duration=20000000, Amplitude=0.5 and Frequency=0. The caller owns the resource; assign it to the intended modifier and retain it while used. The helper creates an explicit positive request rather than the special Duration=-1.
Native setters validate no ranges. They emit Changed even for repeated values. Stored frequency or duration does not guarantee the physical result: the runtime may constrain requests to device capabilities.
Defaults, setters/getters, notifications, the exact helper, its boundaries and shared references from modifiers were checked. Vibration, extension behavior and perceived pulse strength on a device were not tested.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
OpenXRHapticVibrationConstructor
public OpenXRHapticVibration();Creates vibration parameters with Duration=-1 ns, Frequency=0 Hz and Amplitude=1. A parameter resource: construction sends no vibration to a device.
Properties3
AmplitudeProperty
public float Amplitude { get; set; }Normalized amplitude 0…1, initially 1. The setter does not enforce the Inspector range as a clamp or validate finiteness. Validate input before assignment. Changed is emitted even on repetition; property readback does not measure physical vibration strength.
DurationProperty
public long Duration { get; set; }Duration in nanoseconds as a long. Initially -1, requesting a short pulse of the minimum supported duration. Not seconds or milliseconds. The setter performs no validation and emits Changed even on repetition. Use a positive duration for an explicit pulse; the runtime determines actual limits.
FrequencyProperty
public float Frequency { get; set; }Frequency in Hz, initially 0 to let the runtime choose an optimal frequency. Use a finite nonnegative value; the setter neither validates nor clamps it. Changed is emitted even on repetition. Supported device frequency may differ from the stored request.
Methods6
GetAmplitudefloat
public float GetAmplitude();Stored normalized amplitude, initially 1; not a device measurement.
floatStored normalized amplitude, initially 1; not a device measurement.
GetDurationlong
public long GetDuration();Stored duration long in nanoseconds; -1 requests the runtime minimum pulse.
longStored duration long in nanoseconds; -1 requests the runtime minimum pulse.
GetFrequencyfloat
public float GetFrequency();Stored frequency in Hz; 0 leaves the choice to the runtime.
floatStored frequency in Hz; 0 leaves the choice to the runtime.
SetAmplitudevoid
public void SetAmplitude(float amplitude);Normalized amplitude 0…1, initially 1. The setter does not enforce the Inspector range as a clamp or validate finiteness. Validate input before assignment. Changed is emitted even on repetition; property readback does not measure physical vibration strength.
| Name | Type | Default |
|---|---|---|
amplitude | float | — |
amplitudeFinite normalized amplitude in the range 0…1.
SetDurationvoid
public void SetDuration(long duration);Duration in nanoseconds as a long. Initially -1, requesting a short pulse of the minimum supported duration. Not seconds or milliseconds. The setter performs no validation and emits Changed even on repetition. Use a positive duration for an explicit pulse; the runtime determines actual limits.
| Name | Type | Default |
|---|---|---|
duration | long | — |
durationPositive duration in nanoseconds, or -1 for the runtime minimum pulse. Not milliseconds.
SetFrequencyvoid
public void SetFrequency(float frequency);Frequency in Hz, initially 0 to let the runtime choose an optimal frequency. Use a finite nonnegative value; the setter neither validates nor clamps it. Changed is emitted even on repetition. Supported device frequency may differ from the stored request.
| Name | Type | Default |
|---|---|---|
frequency | float | — |
frequencyFinite nonnegative frequency in Hz; 0 for runtime selection.