void test_highlevel_open_close_device() { ohmd_context* ctx = ohmd_ctx_create(); TAssert(ctx); // Probe for devices int num_devices = ohmd_ctx_probe(ctx); TAssert(num_devices > 0); // Open dummy device (num_devices - 1) ohmd_device* hmd = ohmd_list_open_device(ctx, num_devices - 1); TAssert(hmd); // Close the device int ret = ohmd_close_device(hmd); TAssert(ret == 0); ohmd_ctx_destroy(ctx); }
void hmd_init() { hres = video.device_w; vres = video.device_h; /* Start up OpenHMD. */ if ((ctx = ohmd_ctx_create())) { if (ohmd_ctx_probe(ctx) > 0) { if ((dev = ohmd_list_open_device(ctx, 0))) { /* Create the off-screen frame buffers. */ ohmd_device_geti(dev, OHMD_SCREEN_HORIZONTAL_RESOLUTION, &hres); ohmd_device_geti(dev, OHMD_SCREEN_VERTICAL_RESOLUTION, &vres); } } } hmd_common_init(hres, vres); }
void test_highlevel_open_close_many_devices() { ohmd_context* ctx = ohmd_ctx_create(); TAssert(ctx); // Probe for devices int num_devices = ohmd_ctx_probe(ctx); TAssert(num_devices > 0); ohmd_device* hmds[16]; for(int i = 0; i < 8; i++){ // Open dummy device (num_devices - 1) hmds[i] = ohmd_list_open_device(ctx, num_devices - 1); TAssert(hmds[i]); } for(int i = 4; i < 8; i++){ // Close the device int ret = ohmd_close_device(hmds[i]); TAssert(ret == 0); } for(int i = 4; i < 16; i++){ // Open dummy device (num_devices - 1) hmds[i] = ohmd_list_open_device(ctx, num_devices - 1); TAssert(hmds[i]); } for(int i = 0; i < 16; i++){ // Close the device int ret = ohmd_close_device(hmds[i]); TAssert(ret == 0); } ohmd_ctx_destroy(ctx); }
void Context::init() { gHMDCTX = ohmd_ctx_create(); int num_devices = ohmd_ctx_probe(gHMDCTX); if(num_devices < 0){ printf("failed to probe devices: %s\n", ohmd_ctx_get_error(gHMDCTX)); exit(-1); } if( num_devices==0 ) { printf( "no HMD present!, goodbye!\n"); exit(-1); } printf( "num_devices<%d>\n", num_devices ); for( int i=0; i<num_devices; i++ ) { auto vendor = GetDevString(i,OHMD_VENDOR); auto product = GetDevString(i,OHMD_PRODUCT); auto path = GetDevString(i,OHMD_PATH); printf("hmd<%d> vendor<%s>\n", i, vendor.c_str() ); printf("hmd<%d> product<%s>\n", i, product.c_str() ); printf("hmd<%d> path<%s>\n", i, path.c_str() ); } static const int khmddevno = 0; auto vendor = GetDevString(khmddevno,OHMD_VENDOR); auto product = GetDevString(khmddevno,OHMD_PRODUCT); auto path = GetDevString(khmddevno,OHMD_PATH); printf("hmd vendor<%s>\n", vendor.c_str() ); printf("hmd product<%s>\n", product.c_str() ); printf("hmd path<%s>\n", path.c_str() ); gHMDDEV = ohmd_list_open_device(gHMDCTX, khmddevno); if(!gHMDDEV){ printf("failed to open device: %s\n", ohmd_ctx_get_error(gHMDCTX)); exit(-1); } Resolution res = GetResolution(); DistortionK dk = GetDistortionK(); float lens_sep = GetFloat(OHMD_LENS_HORIZONTAL_SEPARATION); float lens_vctr = GetFloat(OHMD_LENS_VERTICAL_POSITION); float fov_l = GetFloat(OHMD_LEFT_EYE_FOV); float fov_r = GetFloat(OHMD_RIGHT_EYE_FOV); float asp_l = GetFloat(OHMD_LEFT_EYE_ASPECT_RATIO); float asp_r = GetFloat(OHMD_RIGHT_EYE_ASPECT_RATIO); printf("hmd resolution<%d %d>\n", res.x, res.y ); printf("hmd lens separation<%f>\n", lens_sep ); printf("hmd lens vcenter<%f>\n", lens_vctr ); printf("hmd left FOV<%f>\n", fov_l ); printf("hmd left ASPECT<%f>\n", asp_l ); printf("hmd right FOV<%f>\n", fov_r ); printf("hmd right ASPECT<%f>\n", asp_r ); const auto&k = dk.k; printf("hmd distortion K<%f %f %f %f %f %f>\n", k[0], k[1], k[2], k[3], k[4], k[5] ); ohmd_device_getf(gHMDDEV, OHMD_EYE_IPD, &gIPD); gIPD = 0.043f; printf( "IPD<%f>\n", gIPD ); }
int main(int argc, char** argv) { float fval; int ival; (void)argc; (void)argv; ohmd_context* ctx = ohmd_ctx_create(); 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", num_devices); for(int i = 0; i < num_devices; 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", ohmd_list_gets(ctx, i, OHMD_PATH)); } ohmd_device* hmd = ohmd_list_open_device(ctx, 0); ohmd_device_geti(hmd, OHMD_SCREEN_HORIZONTAL_RESOLUTION, &ival); printf("hres: %i\n", ival); ohmd_device_geti(hmd, OHMD_SCREEN_VERTICAL_RESOLUTION, &ival); printf("vres: %i\n", ival); ohmd_device_getf(hmd, OHMD_SCREEN_HORIZONTAL_SIZE, &fval); printf("hsize: %f\n", fval); ohmd_device_getf(hmd, OHMD_SCREEN_VERTICAL_SIZE, &fval); printf("vsize: %f\n", fval); ohmd_device_getf(hmd, OHMD_LENS_HORIZONTAL_SEPERATION, &fval); printf("lens seperation: %f\n", fval); ohmd_device_getf(hmd, OHMD_LENS_VERTICAL_POSITION, &fval); printf("lens vcenter: %f\n", fval); ohmd_device_getf(hmd, OHMD_LEFT_EYE_FOV, &fval); printf("fov: %f\n", fval); ohmd_device_getf(hmd, OHMD_LEFT_EYE_ASPECT_RATIO, &fval); printf("aspect: %f\n", fval); if(!hmd){ printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx)); return -1; } for(int i = 0; i < 10000; i++){ float q[4]; ohmd_ctx_update(ctx); ohmd_device_getf(hmd, OHMD_ROTATION_QUAT, q); printf("quat: % 4.4f, % 4.4f, % 4.4f, % 4.4f\n", q[0], q[1], q[2], q[3]); ohmd_sleep(.01); } ohmd_ctx_destroy(ctx); return 0; }