OpenHMD
openhmd.h
Go to the documentation of this file.
1 /*
2  * OpenHMD - Free and Open Source API and drivers for immersive technology.
3  * Copyright (C) 2013 Fredrik Hultin.
4  * Copyright (C) 2013 Jakob Bornecrantz.
5  * Distributed under the Boost 1.0 licence, see LICENSE for full text.
6  */
7 
8 /**
9  * \file openhmd.h
10  * Main header for OpenHMD public API.
11  **/
12 
13 #ifndef OPENHMD_H
14 #define OPENHMD_H
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #ifdef _WIN32
21 #ifdef DLL_EXPORT
22 #define OHMD_APIENTRY __cdecl __declspec( dllexport )
23 #else
24 #ifdef OHMD_STATIC
25 #define OHMD_APIENTRY __cdecl
26 #else
27 #define OHMD_APIENTRY __cdecl __declspec( dllimport )
28 #endif
29 #endif
30 #else
31 #define OHMD_APIENTRY
32 #endif
33 
34 /** Maximum length of a string, including termination, in OpenHMD. */
35 #define OHMD_STR_SIZE 256
36 
37 /** A collection of string value information types, used for getting information with ohmd_list_gets(). */
38 typedef enum {
39  OHMD_VENDOR = 0,
40  OHMD_PRODUCT = 1,
41  OHMD_PATH = 2,
43 
44 /** A collection of float value information types, used for getting and setting information with
45  ohmd_device_getf() and ohmd_device_setf(). */
46 typedef enum {
47  /** float[4] (get): Absolute rotation of the device, in space, as a quaternion (x, y, z, w). */
49 
50  /** float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a modelview matrix for the
51  left eye of the HMD. */
53  /** float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a modelview matrix for the
54  right eye of the HMD. */
56 
57  /** float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a projection matrix for the
58  left eye of the HMD. */
60  /** float[16] (get): A "ready to use" OpenGL style 4x4 matrix with a projection matrix for the
61  right eye of the HMD. */
63 
64  /** float[3] (get): A 3-D vector representing the absolute position of the device, in space. */
66 
67  /** float[1] (get): Physical width of the device screen in metres. */
69  /** float[1] (get): Physical height of the device screen in metres. */
71 
72  /** float[1] (get): Physical separation of the device lenses in metres. */
74  /** float[1] (get): Physical vertical position of the lenses in metres. */
76 
77  /** float[1] (get): Physical field of view for the left eye in degrees. */
79  /** float[1] (get): Physical display aspect ratio for the left eye screen. */
81  /** float[1] (get): Physical field of view for the left right in degrees. */
83  /** float[1] (get): Physical display aspect ratio for the right eye screen. */
85 
86  /** float[1] (get, set): Physical interpupillary distance of the user in metres. */
88 
89  /** float[1] (get, set): Z-far value for the projection matrix calculations (i.e. drawing distance). */
91  /** float[1] (get, set): Z-near value for the projection matrix calculations (i.e. close clipping distance). */
93 
94  /** float[6] (get): Device specific distortion value. */
96 
98 
99 /** A collection of int value information types used for getting information with ohmd_device_geti(). */
100 typedef enum {
101  /** int[1] (get): Physical horizontal resolution of the device screen. */
103  /** int[1] (get): Physical vertical resolution of the device screen. */
105 
107 
108 /** An opaque pointer to a context structure. */
109 typedef struct ohmd_context ohmd_context;
110 
111 /** An opaque pointer to a structure representing a device, such as an HMD. */
112 typedef struct ohmd_device ohmd_device;
113 
114 /**
115  * Create an OpenHMD context.
116  *
117  * @return a pointer to an allocated ohmd_context on success or NULL if it fails.
118  **/
119 OHMD_APIENTRY ohmd_context* ohmd_ctx_create();
120 
121 /**
122  * Destroy an OpenHMD context.
123  *
124  * ohmd_ctx_destroy de-initializes and de-allocates an OpenHMD context allocated with ohmd_ctx_create.
125  *
126  * @param ctx The context to destroy.
127  **/
128 OHMD_APIENTRY void ohmd_ctx_destroy(ohmd_context* ctx);
129 
130 /**
131  * Get the last error as a human readable string.
132  *
133  * If a function taking a context as an argument (ohmd_context "methods") returns non-successfully,
134  * a human readable error message describing what went wrong can be retrieved with this function.
135  *
136  * @param ctx The context to retrieve the error message from.
137  * @return a pointer to the error message.
138  **/
139 OHMD_APIENTRY const char* ohmd_ctx_get_error(ohmd_context* ctx);
140 
141 /**
142  * Update a context.
143  *
144  * Performs tasks like pumping events from the device. The exact details are up to the driver
145  * but try to call it quite frequently.
146  * Once per frame in a "game loop" should be sufficient.
147  * If OpenHMD is handled in a background thread, calling ohmd_ctx_update and then sleeping for 10-20 ms
148  * is recommended.
149  *
150  * @param ctx The context that needs updating.
151  **/
152 OHMD_APIENTRY void ohmd_ctx_update(ohmd_context* ctx);
153 
154 /**
155  * Probe for devices.
156  *
157  * Probes for and enumerates supported devices attached to the system.
158  *
159  * @param ctx A context with no currently open devices.
160  * @return the number of devices found on the system.
161  **/
162 OHMD_APIENTRY int ohmd_ctx_probe(ohmd_context* ctx);
163 
164 /**
165  * Get device description from enumeration list index.
166  *
167  * Gets a human readable device description string from a zero indexed enumeration index
168  * between 0 and (max - 1), where max is the number ohmd_ctx_probe returned
169  * (i.e. if ohmd_ctx_probe returns 3, valid indices are 0, 1 and 2).
170  * The function can return three types of data. The vendor name, the product name and
171  * a driver specific path where the device is attached.
172  *
173  * ohmd_ctx_probe must be called before calling ohmd_list_gets.
174  *
175  * @param ctx A (probed) context.
176  * @param index An index, between 0 and the value returned from ohmd_ctx_probe.
177  * @param type The type of data to fetch. One of OHMD_VENDOR, OHMD_PRODUCT and OHMD_PATH.
178  * @return a string with a human readable device name.
179  **/
180 OHMD_APIENTRY const char* ohmd_list_gets(ohmd_context* ctx, int index, ohmd_string_value type);
181 
182 /**
183  * Open a device.
184  *
185  * Opens a device from a zero indexed enumeration index between 0 and (max - 1)
186  * where max is the number ohmd_ctx_probe returned (i.e. if ohmd_ctx_probe returns 3,
187  * valid indices are 0, 1 and 2).
188  *
189  * ohmd_ctx_probe must be called before calling ohmd_list_open_device.
190  *
191  * @param ctx A (probed) context.
192  * @param index An index, between 0 and the value returned from ohmd_ctx_probe.
193  * @return a pointer to an ohmd_device, which represents a hardware device, such as an HMD.
194  **/
195 OHMD_APIENTRY ohmd_device* ohmd_list_open_device(ohmd_context* ctx, int index);
196 
197 /**
198  * Get a floating point value from a device.
199  *
200  *
201  * @param device An open device to retrieve the value from.
202  * @param type What type of value to retrieve, see ohmd_float_value section for more information.
203  * @param[out] out A pointer to a float, or float array where the retrieved value should be written.
204  * @return 0 on success, <0 on failure.
205  **/
206 OHMD_APIENTRY int ohmd_device_getf(ohmd_device* device, ohmd_float_value type, float* out);
207 
208 /**
209  * Set a floating point value for a device.
210  *
211  * @param device An open device to set the value in.
212  * @param type What type of value to set, see ohmd_float_value section for more information.
213  * @param in A pointer to a float, or float array where the new value is stored.
214  * @return 0 on success, <0 on failure.
215  **/
216 OHMD_APIENTRY int ohmd_device_setf(ohmd_device* device, ohmd_float_value type, float* in);
217 
218 /**
219  * Get an integer value from a device.
220  *
221  * @param device An open device to retrieve the value from.
222  * @param type What type of value to retrieve, ohmd_int_value section for more information.
223  * @param[out] out A pointer to an integer, or integer array where the retrieved value should be written.
224  * @return 0 on success, <0 on failure.
225  **/
226 OHMD_APIENTRY int ohmd_device_geti(ohmd_device* device, ohmd_int_value type, int* out);
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif
Definition: openhmd.h:84
Definition: openhmd.h:68
Definition: openhmd.h:52
OHMD_APIENTRY void ohmd_ctx_destroy(ohmd_context *ctx)
OHMD_APIENTRY int ohmd_ctx_probe(ohmd_context *ctx)
Definition: openhmd.h:95
OHMD_APIENTRY ohmd_device * ohmd_list_open_device(ohmd_context *ctx, int index)
Definition: openhmd.h:75
OHMD_APIENTRY ohmd_context * ohmd_ctx_create()
Definition: openhmd.h:92
OHMD_APIENTRY void ohmd_ctx_update(ohmd_context *ctx)
ohmd_float_value
Definition: openhmd.h:46
OHMD_APIENTRY int ohmd_device_getf(ohmd_device *device, ohmd_float_value type, float *out)
Definition: openhmd.h:87
ohmd_int_value
Definition: openhmd.h:100
Definition: openhmd.h:70
Definition: openhmd.h:73
Definition: openhmd.h:80
Definition: openhmd.h:104
Definition: openhmd.h:78
Definition: openhmd.h:59
struct ohmd_device ohmd_device
Definition: openhmd.h:112
OHMD_APIENTRY const char * ohmd_list_gets(ohmd_context *ctx, int index, ohmd_string_value type)
struct ohmd_context ohmd_context
Definition: openhmd.h:109
Definition: openhmd.h:90
Definition: openhmd.h:62
Definition: openhmd.h:48
Definition: openhmd.h:82
OHMD_APIENTRY const char * ohmd_ctx_get_error(ohmd_context *ctx)
ohmd_string_value
Definition: openhmd.h:38
Definition: openhmd.h:102
Definition: openhmd.h:65
OHMD_APIENTRY int ohmd_device_setf(ohmd_device *device, ohmd_float_value type, float *in)
Definition: openhmd.h:55
OHMD_APIENTRY int ohmd_device_geti(ohmd_device *device, ohmd_int_value type, int *out)