diff options
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | Makefile | 15 | ||||
m--------- | contrib/OpenHMD | 0 | ||||
-rw-r--r-- | simple.c | 83 |
4 files changed, 101 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..efdd16d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "contrib/OpenHMD"] + path = contrib/OpenHMD + url = git://github.com/OpenHMD/OpenHMD.git @@ -2,3 +2,18 @@ client2: client2.cpp lib.cpp ringbuf.h g++ -std=c++11 -g client2.cpp lib.cpp -lglfw -lGLEW -lGLU -lGL `pkg-config --libs opencv` -lm -o client2 client: client.c gcc client.c -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm -o client + +simple: simple.o contrib/OpenHMD/src/.libs/libopenhmd.a + gcc -std=gnu99 -g -O2 -o simple simple.o contrib/OpenHMD/src/.libs/libopenhmd.a -lhidapi-libusb -lrt -lpthread -lm + +simple.o: simple.c + gcc -std=gnu99 -Wall -DOHMD_STATIC -Icontrib/OpenHMD/include/ -g -O2 -c -o simple.o simple.c + +contrib/OpenHMD/src/.libs/libopenhmd.a: + cd contrib/OpenHMD && ./configure --enable-static=yes && make -j5 + +clean: + rm -f simple.o simple + +distclean: clean + cd contrib/OpenHMD && make distclean diff --git a/contrib/OpenHMD b/contrib/OpenHMD new file mode 160000 +Subproject 3f60c2061e4e40c40d714724ccc05354a8a9930 diff --git a/simple.c b/simple.c new file mode 100644 index 0000000..538d536 --- /dev/null +++ b/simple.c @@ -0,0 +1,83 @@ +/* + * OpenHMD - Free and Open Source API and drivers for immersive technology. + * Copyright (C) 2013 Fredrik Hultin. + * Copyright (C) 2013 Jakob Bornecrantz. + * Distributed under the Boost 1.0 licence, see LICENSE for full text. + */ + +/* Simple Test */ + +#include <openhmd.h> +#include <stdio.h> + +void ohmd_sleep(double); + +// gets float values from the device and prints them +void print_infof(ohmd_device* hmd, const char* name, int len, ohmd_float_value val) +{ + float f[len]; + ohmd_device_getf(hmd, val, f); + printf("%-20s", name); + for(int i = 0; i < len; i++) + printf("%f ", f[i]); + printf("\n"); +} + +int main(int argc, char** argv) +{ + ohmd_context* ctx = ohmd_ctx_create(); + + // Probe for devices + int num_devices = ohmd_ctx_probe(ctx); + if(num_devices < 0){ + printf("failed to probe devices: %s\n", ohmd_ctx_get_error(ctx)); + return -1; + } + + printf("num devices: %d\n\n", num_devices); + + // Print device information + for(int i = 0; i < num_devices; i++){ + printf("device %d\n", i); + printf(" vendor: %s\n", ohmd_list_gets(ctx, i, OHMD_VENDOR)); + printf(" product: %s\n", ohmd_list_gets(ctx, i, OHMD_PRODUCT)); + printf(" path: %s\n\n", ohmd_list_gets(ctx, i, OHMD_PATH)); + } + + // Open default device (0) + ohmd_device* hmd = ohmd_list_open_device(ctx, 0); + + if(!hmd){ + printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx)); + return -1; + } + + // Print hardware information for the opened device + int ivals[2]; + ohmd_device_geti(hmd, OHMD_SCREEN_HORIZONTAL_RESOLUTION, ivals); + ohmd_device_geti(hmd, OHMD_SCREEN_VERTICAL_RESOLUTION, ivals + 1); + printf("resolution: %i x %i\n", ivals[0], ivals[1]); + + print_infof(hmd, "hsize:", 1, OHMD_SCREEN_HORIZONTAL_SIZE); + print_infof(hmd, "vsize:", 1, OHMD_SCREEN_VERTICAL_SIZE); + print_infof(hmd, "lens separation:", 1, OHMD_LENS_HORIZONTAL_SEPARATION); + print_infof(hmd, "lens vcenter:", 1, OHMD_LENS_VERTICAL_POSITION); + print_infof(hmd, "left eye fov:", 1, OHMD_LEFT_EYE_FOV); + print_infof(hmd, "right eye fov:", 1, OHMD_RIGHT_EYE_FOV); + print_infof(hmd, "left eye aspect:", 1, OHMD_LEFT_EYE_ASPECT_RATIO); + print_infof(hmd, "right eye aspect:", 1, OHMD_RIGHT_EYE_ASPECT_RATIO); + print_infof(hmd, "distortion k:", 6, OHMD_DISTORTION_K); + + printf("\n"); + + // Ask for n rotation quaternions + for(int i = 0; i < 10000; i++){ + ohmd_ctx_update(ctx); + print_infof(hmd, "rotation quat:", 4, OHMD_ROTATION_QUAT); + ohmd_sleep(.01); + } + + ohmd_ctx_destroy(ctx); + + return 0; +} |