simple.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /* Simple Test */
  8. #include <openhmd.h>
  9. #include <stdio.h>
  10. void ohmd_sleep(double);
  11. double ohmd_get_tick();
  12. int main(int argc, char** argv)
  13. {
  14. (void)argc; (void)argv;
  15. ohmd_context* ctx = ohmd_ctx_create();
  16. int num_devices = ohmd_ctx_probe(ctx);
  17. if(num_devices < 0){
  18. printf("failed to probe devices: %s\n", ohmd_ctx_get_error(ctx));
  19. return -1;
  20. }
  21. printf("num devices: %d\n", num_devices);
  22. for(int i = 0; i < num_devices; i++){
  23. printf("vendor: %s\n", ohmd_list_gets(ctx, i, OHMD_VENDOR));
  24. printf("product: %s\n", ohmd_list_gets(ctx, i, OHMD_PRODUCT));
  25. printf("path: %s\n", ohmd_list_gets(ctx, i, OHMD_PATH));
  26. }
  27. ohmd_device* hmd = ohmd_list_open_device(ctx, 0);
  28. if(!hmd){
  29. printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx));
  30. return -1;
  31. }
  32. for(int i = 0; i < 10000; i++){
  33. float q[4];
  34. ohmd_ctx_update(ctx);
  35. ohmd_device_getf(hmd, OHMD_ROTATION_QUAT, q);
  36. printf("quat: % 4.4f, % 4.4f, % 4.4f, % 4.4f\n", q[0], q[1], q[2], q[3]);
  37. ohmd_sleep(.01);
  38. }
  39. ohmd_ctx_destroy(ctx);
  40. return 0;
  41. }