# HG changeset patch # User John Tsiombikas # Date 1411591840 -10800 # Node ID b536bd21b37fde4d5363aa767e22a616829a70b4 # Parent 34d4643d61f9af94004ed1ed6266ebe2dc00efcc added vr_get_def functions diff -r 34d4643d61f9 -r b536bd21b37f src/vr.c --- a/src/vr.c Wed Sep 24 10:18:42 2014 +0300 +++ b/src/vr.c Wed Sep 24 23:50:40 2014 +0300 @@ -153,6 +153,29 @@ return res; } +int vr_geti_def(const char *optname, int def_val) +{ + int res = 0; + + if(!vrm || !vrm->get_option || vrm->get_option(optname, OTYPE_INT, &res) == -1) { + if(get_option_int(defopt, optname, &res) == -1) { /* fallback */ + return def_val; + } + } + return res; +} + +float vr_getf_def(const char *optname, float def_val) +{ + float res = 0.0f; + + if(!vrm || !vrm->get_option || vrm->get_option(optname, OTYPE_FLOAT, &res) == -1) { + if(get_option_float(defopt, optname, &res) == -1) { /* fallback */ + return def_val; + } + } + return res; +} int vr_view_translation(int eye, float *vec) { diff -r 34d4643d61f9 -r b536bd21b37f src/vr.h --- a/src/vr.h Wed Sep 24 10:18:42 2014 +0300 +++ b/src/vr.h Wed Sep 24 23:50:40 2014 +0300 @@ -36,6 +36,11 @@ void vr_setf(const char *optname, float val); int vr_geti(const char *optname); float vr_getf(const char *optname); +/* variants of the get functions, with an additional "default value" + * argument, which is returned if the requested option is missing + */ +int vr_geti_def(const char *optname, int def_val); +float vr_getf_def(const char *optname, float def_val); int vr_view_translation(int eye, float *vec); int vr_view_rotation(int eye, float *quat); diff -r 34d4643d61f9 -r b536bd21b37f src/vr_openhmd.c --- a/src/vr_openhmd.c Wed Sep 24 10:18:42 2014 +0300 +++ b/src/vr_openhmd.c Wed Sep 24 23:50:40 2014 +0300 @@ -60,14 +60,14 @@ ipd /= 100.0f; /* convert ipd to meters */ if((optdb = create_options())) { - set_option_int(optdb, VR_OPT_DISPLAY_WIDTH, disp_width); - set_option_int(optdb, VR_OPT_DISPLAY_HEIGHT, disp_height); - set_option_float(optdb, VR_OPT_IPD, ipd); + set_option_int(optdb, VR_DISPLAY_WIDTH, disp_width); + set_option_int(optdb, VR_DISPLAY_HEIGHT, disp_height); + set_option_float(optdb, VR_IPD, ipd); - set_option_int(optdb, VR_OPT_LEYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN)); - set_option_int(optdb, VR_OPT_LEYE_YRES, (int)(disp_height * FB_EMBIGGEN)); - set_option_int(optdb, VR_OPT_REYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN)); - set_option_int(optdb, VR_OPT_REYE_YRES, (int)(disp_height * FB_EMBIGGEN)); + set_option_int(optdb, VR_LEYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN)); + set_option_int(optdb, VR_LEYE_YRES, (int)(disp_height * FB_EMBIGGEN)); + set_option_int(optdb, VR_REYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN)); + set_option_int(optdb, VR_REYE_YRES, (int)(disp_height * FB_EMBIGGEN)); } ohmd_device_getf(dev, OHMD_DISTORTION_K, distort_k);