engine.openvr Functions
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScript (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.
The plugin is deprecated. VR functionality is available out of the box since 2.18 for all supported graphics APIs except OpenGL.
This set of functions is available when the OpenVRplugin is loaded.
If OpenVR is loaded together with the engine, the HAS_OPENVR definition is set. This definition can be used, for example, to avoid errors if the plugin is not loaded; the code in which the plugin functions are executed can be wrapped around as follows:
#ifdef HAS_OPENVR
// engine.openvr functions
#endif
The source code of OpenVR can be found here.
The full set of Vive devices is described here.
See also#
A UnigineScript API sample <UnigineSDK>/data/samples/plugins/VIVE_00
OpenVR Class
Members
vec2 engine.openvr.getControllerAxis ( int device_num, int axis_num ) #
Returns the coordinates of the specified controller axis along the X and Y axes.Arguments
- int device_num - Device ID.
- int axis_num - Axis number.
Return value
X and Y in the range of [-1;1] ([0;1] for a trigger).bool engine.openvr.getControllerButtonPressed ( int device_num, int button ) #
Returns the value indicating if the specified button is pressed.Arguments
- int device_num - Device ID.
- int button - A button, one of the VIVE_BUTTON_ variables.
Return value
true if the button is pressed; otherwise - false.bool engine.openvr.getControllerButtonTouched ( int device_num, int button ) #
Returns the value indicating if the specified button is touched.Arguments
- int device_num - Device ID.
- int button - A button, one of the VIVE_BUTTON_ variables.
Return value
true if the button is pressed; otherwise - false.int engine.openvr.getControllerPacketNum ( int device_num ) #
Returns the number of the controller packet.Arguments
- int device_num - Device ID.
Return value
Number of the controller packet.void engine.openvr.setControllerVibration ( int device_num, int duration ) #
Sets the vibration of the given duration and amplitude.Arguments
- int device_num - Device ID.
- int duration - Duration of the vibration.
vec3 engine.openvr.getDeviceAngularVelocity ( int device_num ) #
Returns a device angular velocity, in radians per second.Arguments
- int device_num - Device ID.
Return value
Angular velocity.bool engine.openvr.isDeviceConnected ( int device_num ) #
Returns a value indicating if the device connected to the slot.Arguments
- int device_num - Device ID.
Return value
true - connected; false - not connected.mat4 engine.openvr.getDeviceTransform ( int device_num ) #
Returns a single pose for a tracked device.Arguments
- int device_num - Device ID.
Return value
Identity matrix.int engine.openvr.getDeviceType ( int device_num ) #
Returns the device type.Arguments
- int device_num - Device ID.
Return value
Device type, one of the VIVE_DEVICE_ variables.vec3 engine.openvr.getDeviceVelocity ( int device_num ) #
Returns a device velocity in tracker space, in meters per second.Arguments
- int device_num - Device ID.
Return value
Velocity.void engine.openvr.setHeadPositionLock ( int lock ) #
Locks the head position.Arguments
- int lock - 1 to lock the head position.
int engine.openvr.isHeadPositionLock ( ) #
Returns the value indicating if the head position is locked.Return value
1 if the head position is locked; otherwise - 0.void engine.openvr.setHeadRotationLock ( int lock ) #
Locks the head rotation.Arguments
- int lock - 1 to lock the head rotation.
int engine.openvr.isHeadRotationLock ( ) #
Returns the value indicating if the head rotation is locked.Return value
1 if the head rotation is locked; otherwise - 0.bool engine.openvr.isPoseValid ( int device_num ) #
Returns a value indicating if the device pose is valid.Arguments
- int device_num - Device ID.
Return value
true - valid; false - invalid.int engine.openvr.getTrackingResult ( int device_num ) #
Returns the value indicating the tracking result:- Uninitialized
- Calibrating in progress
- Calibrating out of range
- Running correctly
- Running out of range
Arguments
- int device_num - Device ID.
Return value
Tracking result.int engine.openvr.getViewportMode ( ) #
Returns a value indicating the current viewport mode, that determines the type of image to be displayed in the viewport.Return value
Current viewport mode. One of the VIVE_VIEWPORT_ variables.void engine.openvr.setViewportMode ( int mode ) #
Sets the viewport mode, that determines the type of image to be displayed in the viewport.Arguments
- int mode - Viewport mode. One of the VIVE_VIEWPORT_ variables.
int engine.openvr.getMaxTrackedDeviceCount ( ) #
Returns the maximum value of tracked devices.Return value
The maximum value of tracked devices.int engine.openvr.getControllerStateAxisCount ( ) #
Returns a number of axes.Return value
Number of axes.int engine.openvr.getDeviceAxisType ( int device_num, int axis_num ) #
Returns the value that identifies what type of axis is on the indicated controller.Arguments
- int device_num - Device ID.
- int axis_num - Axis number.
Return value
Axis of a corresponding type. One of the VIVE_AXIS_ variables.String engine.openvr.getDeviceManufacturerName ( int device ) #
Returns the manufacturer name of the specified device.Arguments
- int device - Device ID.
Return value
Manufacturer name.String engine.openvr.getDeviceModelNumber ( int device ) #
Returns the model of the specified device.Arguments
- int device - Device ID.
Return value
Model.int engine.openvr.getControllerRole ( int device_num ) #
Returns a specific role associated with a tracked device.Arguments
- int device_num - Device ID.
Return value
Role associated with a tracked device. One of the VIVE_CONTROLLER_ROLE_ variables.void engine.openvr.render ( Player player, ivec2 size, bool render_window ) #
Calls OpenVR rendering logic.Arguments
- Player player - The player camera.
- ivec2 size - The window size, in pixels.
- bool render_window - true to enable rendering of a copy to the current render target window; false — to disable it.
void engine.openvr.fadeToColor ( float time, vec4 color, bool background = false ) #
Fades the view on the head-mounted display to the specified color.Arguments
- float time - Time in seconds that the fade will take.
- vec4 color - Fade color.
- bool background -
vec4 engine.openvr.getCurrentFadeColor ( bool background = false ) #
Returns the current fade color.Arguments
- bool background -
Return value
Fade color.void engine.openvr.fadeToGrid ( float time, bool grid ) #
Fades the grid in or out.Arguments
- float time - Time in seconds that the fade will take.
- bool grid - true to fade the grid in, false to fade the grid out.
float engine.openvr.getCurrentGridAlpha ( ) #
Returns the current alpha value of the grid.Return value
Grid alpha value.void engine.openvr.setTrackingSpace ( int space ) #
Sets a zero pose for the tracking origin.Arguments
- int space - Zero pose of the tracking origin.
int engine.openvr.getTrackingSpace ( ) #
Returns the current zero pose of the tracking origin.Return value
Zero pose of the tracking origin.void engine.openvr.resetZeroPose ( int space ) #
Sets the zero pose of the given tracker coordinate system to the current tracker position.Arguments
- int space - Tracker coordinate system.
Last update:
2023-11-16
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)