libgoatvr

changeset 15:27fcd4c2969d

added VR_EYE_RES_SCALE option
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 25 Sep 2014 08:50:50 +0300
parents 604a9a0a8c37
children b2d902fff68d
files src/vr.c src/vr.h src/vr_libovr.c src/vr_openhmd.c
diffstat 4 files changed, 44 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/src/vr.c	Thu Sep 25 07:52:49 2014 +0300
     1.2 +++ b/src/vr.c	Thu Sep 25 08:50:50 2014 +0300
     1.3 @@ -36,6 +36,7 @@
     1.4  
     1.5  	/* create the default options database */
     1.6  	if(!defopt && (defopt = create_options())) {
     1.7 +		set_option_float(defopt, VR_EYE_RES_SCALE, 1.0);
     1.8  		set_option_float(defopt, VR_EYE_HEIGHT, 1.675);
     1.9  		set_option_float(defopt, VR_IPD, 0.064);
    1.10  	}
     2.1 --- a/src/vr.h	Thu Sep 25 07:52:49 2014 +0300
     2.2 +++ b/src/vr.h	Thu Sep 25 08:50:50 2014 +0300
     2.3 @@ -10,6 +10,7 @@
     2.4  #define VR_REYE_YRES		"right-eye-yres"
     2.5  #define VR_WIN_XOFFS		"win-xoffset"
     2.6  #define VR_WIN_YOFFS		"win-yoffset"
     2.7 +#define VR_EYE_RES_SCALE	"eye-res-scale"		/* default 1 */
     2.8  /* unit: meters */
     2.9  #define VR_EYE_HEIGHT		"eye-height"
    2.10  #define VR_IPD				"ipd"
     3.1 --- a/src/vr_libovr.c	Thu Sep 25 07:52:49 2014 +0300
     3.2 +++ b/src/vr_libovr.c	Thu Sep 25 08:50:50 2014 +0300
     3.3 @@ -91,6 +91,7 @@
     3.4  		set_option_int(optdb, VR_LEYE_YRES, eye_res[0].h);
     3.5  		set_option_int(optdb, VR_REYE_XRES, eye_res[1].w);
     3.6  		set_option_int(optdb, VR_REYE_YRES, eye_res[1].h);
     3.7 +		set_option_float(optdb, VR_EYE_RES_SCALE, 1.0);
     3.8  		set_option_float(optdb, VR_EYE_HEIGHT, ovrHmd_GetFloat(hmd, OVR_KEY_EYE_HEIGHT, OVR_DEFAULT_EYE_HEIGHT));
     3.9  		set_option_float(optdb, VR_IPD, ovrHmd_GetFloat(hmd, OVR_KEY_IPD, OVR_DEFAULT_IPD));
    3.10  		set_option_int(optdb, VR_WIN_XOFFS, hmd->WindowsPos.x);
    3.11 @@ -152,15 +153,30 @@
    3.12  
    3.13  static int set_option(const char *opt, enum opt_type type, void *valp)
    3.14  {
    3.15 +	float fval;
    3.16 +
    3.17  	switch(type) {
    3.18  	case OTYPE_INT:
    3.19 +		fval = (float)*(int*)valp;
    3.20  		set_option_int(optdb, opt, *(int*)valp);
    3.21  		break;
    3.22  
    3.23  	case OTYPE_FLOAT:
    3.24 -		set_option_float(optdb, opt, *(float*)valp);
    3.25 +		fval = *(float*)valp;
    3.26 +		set_option_float(optdb, opt, fval);
    3.27  		break;
    3.28  	}
    3.29 +
    3.30 +	if(hmd && strcmp(opt, VR_EYE_RES_SCALE) == 0) {
    3.31 +		eye_res[0] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, eye_fov[0], fval);
    3.32 +		eye_res[1] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, eye_fov[1], fval);
    3.33 +
    3.34 +		set_option_int(optdb, VR_LEYE_XRES, eye_res[0].w);
    3.35 +		set_option_int(optdb, VR_LEYE_YRES, eye_res[0].h);
    3.36 +		set_option_int(optdb, VR_REYE_XRES, eye_res[1].w);
    3.37 +		set_option_int(optdb, VR_REYE_YRES, eye_res[1].h);
    3.38 +	}
    3.39 +
    3.40  	return 0;
    3.41  }
    3.42  
     4.1 --- a/src/vr_openhmd.c	Thu Sep 25 07:52:49 2014 +0300
     4.2 +++ b/src/vr_openhmd.c	Thu Sep 25 08:50:50 2014 +0300
     4.3 @@ -3,6 +3,7 @@
     4.4  #ifdef USE_OPENHMD
     4.5  #include <stdio.h>
     4.6  #include <stdlib.h>
     4.7 +#include <string.h>
     4.8  #include <openhmd/openhmd.h>
     4.9  #include "opt.h"
    4.10  
    4.11 @@ -60,14 +61,18 @@
    4.12  	ipd /= 100.0f; /* convert ipd to meters */
    4.13  
    4.14  	if((optdb = create_options())) {
    4.15 +		int eye_width, eye_height;
    4.16 +
    4.17  		set_option_int(optdb, VR_DISPLAY_WIDTH, disp_width);
    4.18  		set_option_int(optdb, VR_DISPLAY_HEIGHT, disp_height);
    4.19  		set_option_float(optdb, VR_IPD, ipd);
    4.20  
    4.21 -		set_option_int(optdb, VR_LEYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN));
    4.22 -		set_option_int(optdb, VR_LEYE_YRES, (int)(disp_height * FB_EMBIGGEN));
    4.23 -		set_option_int(optdb, VR_REYE_XRES, (int)(disp_width / 2.0 * FB_EMBIGGEN));
    4.24 -		set_option_int(optdb, VR_REYE_YRES, (int)(disp_height * FB_EMBIGGEN));
    4.25 +		eye_width = (int)((float)(disp_width / 2) * FB_EMBIGGEN);
    4.26 +		eye_height = (int)((float)disp_height * FB_EMBIGGEN);
    4.27 +		set_option_int(optdb, VR_LEYE_XRES, eye_width);
    4.28 +		set_option_int(optdb, VR_LEYE_YRES, eye_height);
    4.29 +		set_option_int(optdb, VR_REYE_XRES, eye_width);
    4.30 +		set_option_int(optdb, VR_REYE_YRES, eye_height);
    4.31  	}
    4.32  
    4.33  	ohmd_device_getf(dev, OHMD_DISTORTION_K, distort_k);
    4.34 @@ -91,15 +96,30 @@
    4.35  
    4.36  static int set_option(const char *opt, enum opt_type type, void *valp)
    4.37  {
    4.38 +	float fval;
    4.39 +
    4.40  	switch(type) {
    4.41  	case OTYPE_INT:
    4.42 +		fval = (float)*(int*)valp;
    4.43  		set_option_int(optdb, opt, *(int*)valp);
    4.44  		break;
    4.45  
    4.46  	case OTYPE_FLOAT:
    4.47 -		set_option_float(optdb, opt, *(float*)valp);
    4.48 +		fval = *(float*)valp;
    4.49 +		set_option_float(optdb, opt, fval);
    4.50  		break;
    4.51  	}
    4.52 +
    4.53 +	if(strcmp(opt, VR_EYE_RES_SCALE) == 0) {
    4.54 +		int eye_width, eye_height;
    4.55 +		eye_width = (int)((float)(disp_width / 2) * FB_EMBIGGEN * fval);
    4.56 +		eye_height = (int)((float)disp_height * FB_EMBIGGEN * fval);
    4.57 +		set_option_int(optdb, VR_LEYE_XRES, eye_width);
    4.58 +		set_option_int(optdb, VR_LEYE_YRES, eye_height);
    4.59 +		set_option_int(optdb, VR_REYE_XRES, eye_width);
    4.60 +		set_option_int(optdb, VR_REYE_YRES, eye_height);
    4.61 +	}
    4.62 +
    4.63  	return 0;
    4.64  }
    4.65