OpenHMD - Free and Open Source API and drivers for immersive technology. Copyright (C) 2013 Fredrik Hultin. Copyright (C) 2013 Jakob Bornecrantz. Distributed under the Boost 1.0 licence, see src/charge/license.volt for full text.
Code Map
//! OpenHMD - Free and Open Source API and drivers for immersive
//! technology. Copyright (C) 2013 Fredrik Hultin. Copyright (C) 2013 Jakob
//! Bornecrantz. Distributed under the Boost 1.0 licence, see
//! src/charge/license.volt for full text.
module lib.ohmd;
//! \file openhmd.h Main header for OpenHMD public API. Maximum length of a
//! string, including termination, in OpenHMD. *
enum OHMD_STR_SIZE;
//! Return status codes, used for all functions that can return an error.
//! *
enum ohmd_status
{
OK,
UNKNOWN_ERROR,
INVALID_PARAMETER,
UNSUPPORTED,
INVALID_OPERATION,
//! USER_RESERVED and below can be used for user purposes, such as errors
//! within ohmd wrappers, etc. *
USER_RESERVED,
}
//! A collection of string value information types, used for getting
//! information with ohmd_list_gets(). *
enum ohmd_string_value
{
VENDOR,
PRODUCT,
PATH,
}
//! A collection of string descriptions, used for getting strings with
//! ohmd_gets(). *
enum ohmd_string_description
{
GLSL_DISTORTION_VERT_SRC,
GLSL_DISTORTION_FRAG_SRC,
}
//! A collection of float value information types, used for getting and
//! setting information with ohmd_device_getf() and ohmd_device_setf(). *
enum ohmd_float_value
{
//! float[4] (get): Absolute rotation of the device, in space, as a
//! quaternion (x, y, z, w). *
ROTATION_QUAT,
//! float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a
//! modelview matrix for the left eye of the HMD. *
LEFT_EYE_GL_MODELVIEW_MATRIX,
//! float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a
//! modelview matrix for the right eye of the HMD. *
RIGHT_EYE_GL_MODELVIEW_MATRIX,
//! float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a
//! projection matrix for the left eye of the HMD. *
LEFT_EYE_GL_PROJECTION_MATRIX,
//! float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a
//! projection matrix for the right eye of the HMD. *
RIGHT_EYE_GL_PROJECTION_MATRIX,
//! float[3] (get): A 3-D vector representing the absolute position of the
//! device, in space. *
POSITION_VECTOR,
//! float[1] (get): Physical width of the device screen in metres. *
SCREEN_HORIZONTAL_SIZE,
//! float[1] (get): Physical height of the device screen in metres. *
SCREEN_VERTICAL_SIZE,
//! float[1] (get): Physical separation of the device lenses in metres. *
LENS_HORIZONTAL_SEPARATION,
//! float[1] (get): Physical vertical position of the lenses in metres. *
LENS_VERTICAL_POSITION,
//! float[1] (get): Physical field of view for the left eye in degrees. *
LEFT_EYE_FOV,
//! float[1] (get): Physical display aspect ratio for the left eye screen.
//! *
LEFT_EYE_ASPECT_RATIO,
//! float[1] (get): Physical field of view for the left right in degrees.
//! *
RIGHT_EYE_FOV,
//! float[1] (get): Physical display aspect ratio for the right eye
//! screen. *
RIGHT_EYE_ASPECT_RATIO,
//! float[1] (get, set): Physical interpupillary distance of the user in
//! metres. *
EYE_IPD,
//! float[1] (get, set): Z-far value for the projection matrix
//! calculations (i.e. drawing distance). *
PROJECTION_ZFAR,
//! float[1] (get, set): Z-near value for the projection matrix
//! calculations (i.e. close clipping distance). *
PROJECTION_ZNEAR,
//! float[6] (get): Device specific distortion value. *
DISTORTION_K,
//! float[10] (set): Perform sensor fusion on values from external
//! sensors.
EXTERNAL_SENSOR_FUSION,
//! float[4] (get): Universal shader distortion coefficients (PanoTools
//! model . *
UNIVERSAL_DISTORTION_K,
//! float[3] (get): Universal shader aberration coefficients (post warp
//! scaling . *
UNIVERSAL_ABERRATION_K,
}
//! A collection of int value information types used for getting
//! information with ohmd_device_geti(). *
enum ohmd_int_value
{
//! int[1] (get): Physical horizontal resolution of the device screen. *
SCREEN_HORIZONTAL_RESOLUTION,
//! int[1] (get): Physical vertical resolution of the device screen. *
SCREEN_VERTICAL_RESOLUTION,
//! int[1] (get): Get number of events waiting in digital input event
//! queue. *
BUTTON_EVENT_COUNT,
//! int[1] (get): Get if the there was an overflow in the event queue
//! causing events to be dropped. *
BUTTON_EVENT_OVERFLOW,
//! int[1] (get): Get the number of physical digital input buttons on the
//! device. *
BUTTON_COUNT,
//! int[2] (get): Performs an event pop action. Format: [button_index,
//! button_state], where button_state is either OHMD_BUTTON_DOWN or
//! OHMD_BUTTON_UP *
BUTTON_POP_EVENT,
}
//! A collection of data information types used for setting information
//! with ohmd_set_data(). *
enum ohmd_data_value
{
//! void* (set): Set void* data for use in the internal drivers. *
DRIVER_DATA,
//! ohmd_device_properties* (set): Set the device properties based on the
//! ohmd_device_properties struct for use in the internal drivers.
DRIVER_PROPERTIES,
}
enum ohmd_int_settings
{
//! int[1] (set, default: 1): Set this to 0 to prevent OpenHMD from
//! creating background threads to do automatic device ticking. Call
//! ohmd_update(); must be called frequently, at least 10 times per
//! second, if the background threads are disabled. *
IDS_AUTOMATIC_UPDATE,
}
//! Button states for digital input events. *
enum ohmd_button_state
{
//! Button was pressed. *
BUTTON_DOWN,
//! Button was released. *
BUTTON_UP,
}
//! An opaque pointer to a context structure. *
struct ohmd_context
{
public:
fn destroy() { }
fn probe() i32 { }
fn update() { }
fn list_gets(index: i32, type: ohmd_string_value) const(char)* { }
fn list_open_device(index: i32) ohmd_device* { }
fn list_open_device_s(index: i32, settings: ohmd_device_settings*) ohmd_device* { }
}
//! An opaque pointer to a structure representing a device, such as an
//! HMD. *
struct ohmd_device
{
public:
fn close() { }
fn get_rot(vec: f32[4]) i32 { }
fn get_pos(vec: f32[3]) i32 { }
fn getf(type: ohmd_float_value, _out: f32*) i32 { }
fn setf(type: ohmd_float_value, _in: const(f32)*) i32 { }
fn geti(type: ohmd_float_value, _out: i32*) i32 { }
fn seti(type: ohmd_float_value, _in: const(i32)*) i32 { }
}
//! An opaque pointer to a structure representing arguments for a device.
//! *
struct ohmd_device_settings
{
}
//! Create an OpenHMD context.
fn ohmd_ctx_create() ohmd_context*;
//! Destroy an OpenHMD context.
fn ohmd_ctx_destroy(ctx: ohmd_context*);
//! Get the last error as a human readable string.
fn ohmd_ctx_get_error(ctx: ohmd_context*, const(char)*);
//! Update a context.
fn ohmd_ctx_update(ctx: ohmd_context*);
//! Probe for devices.
fn ohmd_ctx_probe(ctx: ohmd_context*) i32;
//! Get string from openhmd.
fn ohmd_gets(type: ohmd_string_description, _out: const(char)**) i32;
//! Get device description from enumeration list index.
fn ohmd_list_gets(ctx: ohmd_context*, index: i32, type: ohmd_string_value) const(char)*;
//! Open a device.
fn ohmd_list_open_device(ctx: ohmd_context*, index: i32) ohmd_device*;
//! Open a device with additional settings provided.
fn ohmd_list_open_device_s(ctx: ohmd_context*, index: i32, settings: ohmd_device_settings*) ohmd_device*;
//! Specify int settings in a device settings struct.
fn ohmd_device_settings_seti(settings: ohmd_device_settings*, key: ohmd_int_settings, val: const(i32)*) ohmd_status;
//! Create a device settings instance.
fn ohmd_device_settings_create(ctx: ohmd_context*) ohmd_device_settings*;
//! Destroy a device settings instance.
fn ohmd_device_settings_destroy(settings: ohmd_device_settings*);
//! Close a device.
fn ohmd_close_device(device: ohmd_device*) i32;
//! Get a floating point value from a device.
fn ohmd_device_getf(device: ohmd_device*, type: ohmd_float_value, _out: f32*) i32;
//! Set a floating point value for a device.
fn ohmd_device_setf(device: ohmd_device*, type: ohmd_float_value, _in: const(f32)*) i32;
//! Get an integer value from a device.
fn ohmd_device_geti(device: ohmd_device*, type: ohmd_int_value, _out: i32*) i32;
//! Set an integer value for a device.
fn ohmd_device_seti(device: ohmd_device*, type: ohmd_int_value, _in: const(i32)*) i32;
//! Set an void* data value for a device.
fn ohmd_device_set_data(device: ohmd_device*, type: ohmd_data_value, _in: const(void)*) i32;
\file openhmd.h Main header for OpenHMD public API. Maximum length of a string, including termination, in OpenHMD. *
Return status codes, used for all functions that can return an error. *
USER_RESERVED and below can be used for user purposes, such as errors within ohmd wrappers, etc. *
A collection of string value information types, used for getting information with ohmd_list_gets(). *
A collection of string descriptions, used for getting strings with ohmd_gets(). *
A collection of float value information types, used for getting and setting information with ohmd_device_getf() and ohmd_device_setf(). *
float[4] (get): Absolute rotation of the device, in space, as a quaternion (x, y, z, w). *
float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a modelview matrix for the left eye of the HMD. *
float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a modelview matrix for the right eye of the HMD. *
float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a projection matrix for the left eye of the HMD. *
float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a projection matrix for the right eye of the HMD. *
float[3] (get): A 3-D vector representing the absolute position of the device, in space. *
float[1] (get): Physical width of the device screen in metres. *
float[1] (get): Physical height of the device screen in metres. *
float[1] (get): Physical separation of the device lenses in metres. *
float[1] (get): Physical vertical position of the lenses in metres. *
float[1] (get): Physical field of view for the left eye in degrees. *
float[1] (get): Physical display aspect ratio for the left eye screen. *
float[1] (get): Physical field of view for the left right in degrees. *
float[1] (get): Physical display aspect ratio for the right eye screen. *
float[1] (get, set): Physical interpupillary distance of the user in metres. *
float[1] (get, set): Z-far value for the projection matrix calculations (i.e. drawing distance). *
float[1] (get, set): Z-near value for the projection matrix calculations (i.e. close clipping distance). *
float[6] (get): Device specific distortion value. *
float[10] (set): Perform sensor fusion on values from external sensors.
Values are: dt (time since last update in seconds) X, Y, Z gyro, X, Y, Z accelerometer and X, Y, Z magnetometer.
float[4] (get): Universal shader distortion coefficients (PanoTools model <a,b,c,d>. *
float[3] (get): Universal shader aberration coefficients (post warp scaling <r,g,b>. *
A collection of int value information types used for getting information with ohmd_device_geti(). *
int[1] (get): Physical horizontal resolution of the device screen. *
int[1] (get): Physical vertical resolution of the device screen. *
int[1] (get): Get number of events waiting in digital input event queue. *
int[1] (get): Get if the there was an overflow in the event queue causing events to be dropped. *
int[1] (get): Get the number of physical digital input buttons on the device. *
int[2] (get): Performs an event pop action. Format: [button_index, button_state], where button_state is either OHMD_BUTTON_DOWN or OHMD_BUTTON_UP *
A collection of data information types used for setting information with ohmd_set_data(). *
void* (set): Set void* data for use in the internal drivers. *
ohmd_device_properties* (set): Set the device properties based on the ohmd_device_properties struct for use in the internal drivers.
This can be used to fill in information about the device internally, such as Android, or for setting profiles.
Button states for digital input events. *
Button was pressed. *
Button was released. *
An opaque pointer to a context structure. *
An opaque pointer to a structure representing a device, such as an HMD. *
An opaque pointer to a structure representing arguments for a device. *
Create an OpenHMD context.
Return
a pointer to an allocated ohmd_context on success or NULL if it fails.
Destroy an OpenHMD context.
ohmd_ctx_destroy de-initializes and de-allocates an OpenHMD context allocated with ohmd_ctx_create. All devices associated with the context are automatically closed.
Parameters
ctx |
The context to destroy. |
Get the last error as a human readable string.
If a function taking a context as an argument (ohmd_context "methods") returns non-successfully, a human readable error message describing what went wrong can be retrieved with this function.
Parameters
ctx |
The context to retrieve the error message from. |
Return
a pointer to the error message.
Update a context.
Update the values for the devices handled by a context.
If background threads are disabled, this performs tasks like pumping events from the device. The exact details are up to the driver but try to call it quite frequently. Once per frame in a "game loop" should be sufficient. If OpenHMD is handled in a background thread in your program, calling ohmd_ctx_update and then sleeping for 10-20 ms is recommended.
Parameters
ctx |
The context that needs updating. |
Probe for devices.
Probes for and enumerates supported devices attached to the system.
Parameters
ctx |
A context with no currently open devices. |
Return
the number of devices found on the system.
Get string from openhmd.
Gets a string from OpenHMD. This is where non-device specific strings reside. This is where the distortion shader sources can be retrieved.
Parameters
type |
The name of the string to fetch. One of OHMD_GLSL_DISTORTION_FRAG_SRC, and OHMD_GLSL_DISTORTION_FRAG_SRC. |
_out |
The location to return a const char* |
Return
0 on success, <0 on failure.
Get device description from enumeration list index.
Gets a human readable device description string from a zero indexed enumeration index between 0 and (max - 1), where max is the number ohmd_ctx_probe returned (i.e. if ohmd_ctx_probe returns 3, valid indices are 0, 1 and 2). The function can return three types of data. The vendor name, the product name and a driver specific path where the device is attached.
ohmd_ctx_probe must be called before calling ohmd_list_gets.
Parameters
ctx |
A (probed) context. |
index | |
type |
The type of data to fetch. One of OHMD_VENDOR, OHMD_PRODUCT and OHMD_PATH. |
Return
a string with a human readable device name.
Open a device.
Opens a device from a zero indexed enumeration index between 0 and (max - 1) where max is the number ohmd_ctx_probe returned (i.e. if ohmd_ctx_probe returns 3, valid indices are 0, 1 and 2).
ohmd_ctx_probe must be called before calling ohmd_list_open_device.
Parameters
ctx |
A (probed) context. |
index |
Return
a pointer to an ohmd_device, which represents a hardware device, such as an HMD.
Open a device with additional settings provided.
Opens a device from a zero indexed enumeration index between 0 and (max - 1) where max is the number ohmd_ctx_probe returned (i.e. if ohmd_ctx_probe returns 3, valid indices are 0, 1 and 2).
ohmd_ctx_probe must be called before calling ohmd_list_open_device.
Parameters
ctx |
A (probed) context. |
index | |
settings |
A pointer to a device settings struct. |
Return
a pointer to an ohmd_device, which represents a hardware device, such as an HMD.
Specify int settings in a device settings struct.
Parameters
settings |
The device settings struct to set values to. |
key |
The specefic setting you wish to set. |
val |
Create a device settings instance.
Parameters
ctx |
A pointer to a valid ohmd_context. |
Return
a pointer to an allocated ohmd_context on success or NULL if it fails.
Destroy a device settings instance.
Close a device.
Closes a device opened by ohmd_list_open_device. Note that ohmd_ctx_destroy automatically closes any open devices associated with the context being destroyed.
Parameters
device |
The open device. |
Return
0 on success, < 0 on failure.
Get a floating point value from a device.
Parameters
device |
An open device to retrieve the value from. |
type |
What type of value to retrieve, see ohmd_float_value section for more information. |
_out |
A pointer to a float, or float array where the retrieved value should be written. |
Return
0 on success, < 0 on failure.
Set a floating point value for a device.
Parameters
device |
An open device to set the value in. |
type |
What type of value to set, see ohmd_float_value section for more information. |
_in |
A pointer to a float, or float array where the new value is stored. |
Return
0 on success, < 0 on failure.
Get an integer value from a device.
Parameters
device |
An open device to retrieve the value from. |
type |
What type of value to retrieve, ohmd_int_value section for more information. |
_out |
A pointer to an integer, or integer array where the retrieved value should be written. |
Return
0 on success, < 0 on failure.
Set an integer value for a device.
Parameters
device |
An open device to set the value in. |
type |
What type of value to set, see ohmd_float_value section for more information. |
_in |
A pointer to a int, or int array where the new value is stored. |
Return
0 on success, < 0 on failure.
Set an void* data value for a device.
Parameters
device |
An open device to set the value in. |
type |
What type of value to set, see ohmd_float_value section for more information. |
_in |
A pointer to the void* casted object. |
Return
0 on success, < 0 on failure.