openhmd.h 9.0 KB

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