openhmdi.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. ohmd_driver* driver_ptr;
  30. } ohmd_device_desc;
  31. typedef struct {
  32. int num_devices;
  33. ohmd_device_desc devices[OHMD_MAX_DEVICES];
  34. } ohmd_device_list;
  35. typedef struct {
  36. int idx;
  37. ohmd_button_state state;
  38. } ohmd_digital_input_event;
  39. struct ohmd_driver {
  40. void (*get_device_list)(ohmd_driver* driver, ohmd_device_list* list);
  41. ohmd_device* (*open_device)(ohmd_driver* driver, ohmd_device_desc* desc);
  42. void (*destroy)(ohmd_driver* driver);
  43. ohmd_context* ctx;
  44. };
  45. typedef struct {
  46. int hres;
  47. int vres;
  48. int digital_button_count;
  49. float hsize;
  50. float vsize;
  51. float lens_sep;
  52. float lens_vpos;
  53. float fov;
  54. float ratio;
  55. float ipd;
  56. float zfar;
  57. float znear;
  58. int accel_only; //bool-like for setting acceleration only fallback (android driver)
  59. mat4x4f proj_left; // adjusted projection matrix for left screen
  60. mat4x4f proj_right; // adjusted projection matrix for right screen
  61. float universal_distortion_k[4]; //PanoTools lens distiorion model [a,b,c,d]
  62. float universal_aberration_k[3]; //post-warp per channel scaling [r,g,b]
  63. } ohmd_device_properties;
  64. struct ohmd_device_settings
  65. {
  66. bool automatic_update;
  67. };
  68. struct ohmd_device {
  69. ohmd_device_properties properties;
  70. quatf rotation_correction;
  71. vec3f position_correction;
  72. int (*getf)(ohmd_device* device, ohmd_float_value type, float* out);
  73. int (*setf)(ohmd_device* device, ohmd_float_value type, const float* in);
  74. int (*seti)(ohmd_device* device, ohmd_int_value type, const int* in);
  75. int (*set_data)(ohmd_device* device, ohmd_data_value type, const void* in);
  76. void (*update)(ohmd_device* device);
  77. void (*close)(ohmd_device* device);
  78. ohmd_context* ctx;
  79. ohmd_device_settings settings;
  80. int active_device_idx; // index into ohmd_device->active_devices[]
  81. quatf rotation;
  82. vec3f position;
  83. ohmdq* digital_input_event_queue;
  84. };
  85. struct ohmd_context {
  86. ohmd_driver* drivers[16];
  87. int num_drivers;
  88. ohmd_device_list list;
  89. ohmd_device* active_devices[256];
  90. int num_active_devices;
  91. ohmd_thread* update_thread;
  92. ohmd_mutex* update_mutex;
  93. bool update_request_quit;
  94. char error_msg[OHMD_STR_SIZE];
  95. };
  96. // helper functions
  97. void ohmd_set_default_device_properties(ohmd_device_properties* props);
  98. void ohmd_calc_default_proj_matrices(ohmd_device_properties* props);
  99. void ohmd_set_universal_distortion_k(ohmd_device_properties* props, float a, float b, float c, float d);
  100. void ohmd_set_universal_aberration_k(ohmd_device_properties* props, float r, float g, float b);
  101. // drivers
  102. ohmd_driver* ohmd_create_dummy_drv(ohmd_context* ctx);
  103. ohmd_driver* ohmd_create_oculus_rift_drv(ohmd_context* ctx);
  104. ohmd_driver* ohmd_create_deepoon_drv(ohmd_context* ctx);
  105. ohmd_driver* ohmd_create_htc_vive_drv(ohmd_context* ctx);
  106. ohmd_driver* ohmd_create_psvr_drv(ohmd_context* ctx);
  107. ohmd_driver* ohmd_create_external_drv(ohmd_context* ctx);
  108. ohmd_driver* ohmd_create_android_drv(ohmd_context* ctx);
  109. #include "log.h"
  110. #include "omath.h"
  111. #include "fusion.h"
  112. #endif