openhmdi.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. /* Internal interface */
  8. #ifndef OPENHMDI_H
  9. #define OPENHMDI_H
  10. #include <stdbool.h>
  11. #include <stdint.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include "openhmd.h"
  15. #include "omath.h"
  16. #include "platform.h"
  17. #include "queue.h"
  18. #define OHMD_MAX_DEVICES 16
  19. #define OHMD_MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b))
  20. #define OHMD_MIN(_a, _b) ((_a) < (_b) ? (_a) : (_b))
  21. #define OHMD_STRINGIFY(_what) #_what
  22. typedef struct ohmd_driver ohmd_driver;
  23. typedef struct {
  24. char driver[OHMD_STR_SIZE];
  25. char vendor[OHMD_STR_SIZE];
  26. char product[OHMD_STR_SIZE];
  27. char path[OHMD_STR_SIZE];
  28. int revision;
  29. int id;
  30. ohmd_device_flags device_flags;
  31. ohmd_device_class device_class;
  32. ohmd_driver* driver_ptr;
  33. } ohmd_device_desc;
  34. typedef struct {
  35. int num_devices;
  36. ohmd_device_desc devices[OHMD_MAX_DEVICES];
  37. } ohmd_device_list;
  38. typedef struct {
  39. int idx;
  40. ohmd_button_state state;
  41. } ohmd_digital_input_event;
  42. struct ohmd_driver {
  43. void (*get_device_list)(ohmd_driver* driver, ohmd_device_list* list);
  44. ohmd_device* (*open_device)(ohmd_driver* driver, ohmd_device_desc* desc);
  45. void (*destroy)(ohmd_driver* driver);
  46. ohmd_context* ctx;
  47. };
  48. typedef struct {
  49. int hres;
  50. int vres;
  51. int digital_button_count;
  52. int control_count;
  53. int controls_functions[64];
  54. int controls_types[64];
  55. float hsize;
  56. float vsize;
  57. float lens_sep;
  58. float lens_vpos;
  59. float fov;
  60. float ratio;
  61. float ipd;
  62. float zfar;
  63. float znear;
  64. int accel_only; //bool-like for setting acceleration only fallback (android driver)
  65. mat4x4f proj_left; // adjusted projection matrix for left screen
  66. mat4x4f proj_right; // adjusted projection matrix for right screen
  67. float universal_distortion_k[4]; //PanoTools lens distiorion model [a,b,c,d]
  68. float universal_aberration_k[3]; //post-warp per channel scaling [r,g,b]
  69. } ohmd_device_properties;
  70. struct ohmd_device_settings
  71. {
  72. bool automatic_update;
  73. };
  74. struct ohmd_device {
  75. ohmd_device_properties properties;
  76. quatf rotation_correction;
  77. vec3f position_correction;
  78. int (*getf)(ohmd_device* device, ohmd_float_value type, float* out);
  79. int (*setf)(ohmd_device* device, ohmd_float_value type, const float* in);
  80. int (*seti)(ohmd_device* device, ohmd_int_value type, const int* in);
  81. int (*set_data)(ohmd_device* device, ohmd_data_value type, const void* in);
  82. void (*update)(ohmd_device* device);
  83. void (*close)(ohmd_device* device);
  84. ohmd_context* ctx;
  85. ohmd_device_settings settings;
  86. int active_device_idx; // index into ohmd_device->active_devices[]
  87. quatf rotation;
  88. vec3f position;
  89. ohmdq* digital_input_event_queue;
  90. };
  91. struct ohmd_context {
  92. ohmd_driver* drivers[16];
  93. int num_drivers;
  94. ohmd_device_list list;
  95. ohmd_device* active_devices[256];
  96. int num_active_devices;
  97. ohmd_thread* update_thread;
  98. ohmd_mutex* update_mutex;
  99. bool update_request_quit;
  100. uint64_t monotonic_ticks_per_sec;
  101. char error_msg[OHMD_STR_SIZE];
  102. };
  103. // helper functions
  104. void ohmd_monotonic_init(ohmd_context* ctx);
  105. uint64_t ohmd_monotonic_get(ohmd_context* ctx);
  106. uint64_t ohmd_monotonic_per_sec(ohmd_context* ctx);
  107. uint64_t ohmd_monotonic_conv(uint64_t ticks, uint64_t srcTicksPerSecond, uint64_t dstTicksPerSecond);
  108. void ohmd_set_default_device_properties(ohmd_device_properties* props);
  109. void ohmd_calc_default_proj_matrices(ohmd_device_properties* props);
  110. void ohmd_set_universal_distortion_k(ohmd_device_properties* props, float a, float b, float c, float d);
  111. void ohmd_set_universal_aberration_k(ohmd_device_properties* props, float r, float g, float b);
  112. // drivers
  113. ohmd_driver* ohmd_create_dummy_drv(ohmd_context* ctx);
  114. ohmd_driver* ohmd_create_oculus_rift_drv(ohmd_context* ctx);
  115. ohmd_driver* ohmd_create_deepoon_drv(ohmd_context* ctx);
  116. ohmd_driver* ohmd_create_htc_vive_drv(ohmd_context* ctx);
  117. ohmd_driver* ohmd_create_psvr_drv(ohmd_context* ctx);
  118. ohmd_driver* ohmd_create_nolo_drv(ohmd_context* ctx);
  119. ohmd_driver* ohmd_create_external_drv(ohmd_context* ctx);
  120. ohmd_driver* ohmd_create_android_drv(ohmd_context* ctx);
  121. #include "log.h"
  122. #include "omath.h"
  123. #include "fusion.h"
  124. #endif