libgoatvr

changeset 12:b536bd21b37f

added vr_get_def functions
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 24 Sep 2014 23:50:40 +0300
parents 34d4643d61f9
children e4c5c9c0b6f6
files src/vr.c src/vr.h src/vr_openhmd.c
diffstat 3 files changed, 35 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/src/vr.c	Wed Sep 24 10:18:42 2014 +0300
     1.2 +++ b/src/vr.c	Wed Sep 24 23:50:40 2014 +0300
     1.3 @@ -153,6 +153,29 @@
     1.4  	return res;
     1.5  }
     1.6  
     1.7 +int vr_geti_def(const char *optname, int def_val)
     1.8 +{
     1.9 +	int res = 0;
    1.10 +
    1.11 +	if(!vrm || !vrm->get_option || vrm->get_option(optname, OTYPE_INT, &res) == -1) {
    1.12 +		if(get_option_int(defopt, optname, &res) == -1) {	/* fallback */
    1.13 +			return def_val;
    1.14 +		}
    1.15 +	}
    1.16 +	return res;
    1.17 +}
    1.18 +
    1.19 +float vr_getf_def(const char *optname, float def_val)
    1.20 +{
    1.21 +	float res = 0.0f;
    1.22 +
    1.23 +	if(!vrm || !vrm->get_option || vrm->get_option(optname, OTYPE_FLOAT, &res) == -1) {
    1.24 +		if(get_option_float(defopt, optname, &res) == -1) {	/* fallback */
    1.25 +			return def_val;
    1.26 +		}
    1.27 +	}
    1.28 +	return res;
    1.29 +}
    1.30  
    1.31  int vr_view_translation(int eye, float *vec)
    1.32  {
     2.1 --- a/src/vr.h	Wed Sep 24 10:18:42 2014 +0300
     2.2 +++ b/src/vr.h	Wed Sep 24 23:50:40 2014 +0300
     2.3 @@ -36,6 +36,11 @@
     2.4  void vr_setf(const char *optname, float val);
     2.5  int vr_geti(const char *optname);
     2.6  float vr_getf(const char *optname);
     2.7 +/* variants of the get functions, with an additional "default value"
     2.8 + * argument, which is returned if the requested option is missing
     2.9 + */
    2.10 +int vr_geti_def(const char *optname, int def_val);
    2.11 +float vr_getf_def(const char *optname, float def_val);
    2.12  
    2.13  int vr_view_translation(int eye, float *vec);
    2.14  int vr_view_rotation(int eye, float *quat);
     3.1 --- a/src/vr_openhmd.c	Wed Sep 24 10:18:42 2014 +0300
     3.2 +++ b/src/vr_openhmd.c	Wed Sep 24 23:50:40 2014 +0300
     3.3 @@ -60,14 +60,14 @@
     3.4  	ipd /= 100.0f; /* convert ipd to meters */
     3.5  
     3.6  	if((optdb = create_options())) {
     3.7 -		set_option_int(optdb, VR_OPT_DISPLAY_WIDTH, disp_width);
     3.8 -		set_option_int(optdb, VR_OPT_DISPLAY_HEIGHT, disp_height);
     3.9 -		set_option_float(optdb, VR_OPT_IPD, ipd);
    3.10 +		set_option_int(optdb, VR_DISPLAY_WIDTH, disp_width);
    3.11 +		set_option_int(optdb, VR_DISPLAY_HEIGHT, disp_height);
    3.12 +		set_option_float(optdb, VR_IPD, ipd);
    3.13  
    3.14 -		set_option_int(optdb, VR_OPT_LEYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN));
    3.15 -		set_option_int(optdb, VR_OPT_LEYE_YRES, (int)(disp_height * FB_EMBIGGEN));
    3.16 -		set_option_int(optdb, VR_OPT_REYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN));
    3.17 -		set_option_int(optdb, VR_OPT_REYE_YRES, (int)(disp_height * FB_EMBIGGEN));
    3.18 +		set_option_int(optdb, VR_LEYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN));
    3.19 +		set_option_int(optdb, VR_LEYE_YRES, (int)(disp_height * FB_EMBIGGEN));
    3.20 +		set_option_int(optdb, VR_REYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN));
    3.21 +		set_option_int(optdb, VR_REYE_YRES, (int)(disp_height * FB_EMBIGGEN));
    3.22  	}
    3.23  
    3.24  	ohmd_device_getf(dev, OHMD_DISTORTION_K, distort_k);