libgoatvr

diff src/vr_libovr.c @ 19:437fe32ac633

ops... wasn't handling the stereo eye separation correctly. also fixed a bug in vr_libovr.c causing an assertion inside LibOVR when ovrHmd_GetEyePose was called as a result of calls to view_rotation or view_translation outside of vr_begin/vr_end
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 04 Oct 2014 03:39:14 +0300
parents b2d902fff68d
children 7f9cc8a4d3a5
line diff
     1.1 --- a/src/vr_libovr.c	Fri Oct 03 23:07:27 2014 +0300
     1.2 +++ b/src/vr_libovr.c	Sat Oct 04 03:39:14 2014 +0300
     1.3 @@ -17,6 +17,7 @@
     1.4  #include <OVR_CAPI.h>
     1.5  #include <OVR_CAPI_GL.h>
     1.6  
     1.7 +/* undef this if you want the retarded health and safety warning screen */
     1.8  #define DISABLE_RETARDED_HEALTH_WARNING
     1.9  
    1.10  /* just dropping the prototype here to avoid including CAPI_HSWDisplay.h */
    1.11 @@ -28,9 +29,14 @@
    1.12  static ovrSizei eye_res[2];
    1.13  static ovrGLTexture eye_tex[2];
    1.14  static ovrFovPort eye_fov[2];
    1.15 -static ovrPosef pose[2];
    1.16 +static ovrPosef pose[2] = {
    1.17 +		{ {0, 0, 0, 1}, {0, 0, 0} },
    1.18 +		{ {0, 0, 0, 1}, {0, 0, 0} }
    1.19 +};
    1.20  static int deferred_init_done;
    1.21  
    1.22 +static int inside_begin_end;
    1.23 +
    1.24  static int init(void)
    1.25  {
    1.26  	int i, num_hmds;
    1.27 @@ -107,6 +113,7 @@
    1.28  	union ovrGLConfig glcfg;
    1.29  	unsigned int dcaps;
    1.30  	void *win = 0;
    1.31 +	float leye_offs[3], reye_offs[3];
    1.32  
    1.33  	deferred_init_done = 1;
    1.34  
    1.35 @@ -137,6 +144,16 @@
    1.36  		fprintf(stderr, "failed to configure LibOVR distortion renderer\n");
    1.37  	}
    1.38  
    1.39 +	/* set the eye offset options */
    1.40 +	leye_offs[0] = eye_render_desc[ovrEye_Left].ViewAdjust.x;
    1.41 +	leye_offs[1] = eye_render_desc[ovrEye_Left].ViewAdjust.y;
    1.42 +	leye_offs[2] = eye_render_desc[ovrEye_Left].ViewAdjust.z;
    1.43 +	set_option_vec(optdb, VR_LEYE_OFFSET, leye_offs);
    1.44 +	reye_offs[0] = eye_render_desc[ovrEye_Right].ViewAdjust.x;
    1.45 +	reye_offs[1] = eye_render_desc[ovrEye_Right].ViewAdjust.y;
    1.46 +	reye_offs[2] = eye_render_desc[ovrEye_Right].ViewAdjust.z;
    1.47 +	set_option_vec(optdb, VR_REYE_OFFSET, reye_offs);
    1.48 +
    1.49  #ifdef DISABLE_RETARDED_HEALTH_WARNING
    1.50  	ovrhmd_EnableHSWDisplaySDKRender(hmd, 0);
    1.51  #endif
    1.52 @@ -198,10 +215,16 @@
    1.53  		return;
    1.54  	}
    1.55  
    1.56 -	pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right);
    1.57 -	vec[0] = pose[eye].Position.x + eye_render_desc[eye].ViewAdjust.x;
    1.58 -	vec[1] = pose[eye].Position.y + eye_render_desc[eye].ViewAdjust.y;
    1.59 -	vec[2] = pose[eye].Position.z + eye_render_desc[eye].ViewAdjust.z;
    1.60 +	/* if we're inside the begin-end block we can get a fresh pose, otherwise we'll just
    1.61 +	 * reuse the one we got last frame.
    1.62 +	 */
    1.63 +	if(inside_begin_end) {
    1.64 +		pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right);
    1.65 +	}
    1.66 +
    1.67 +	vec[0] = pose[eye].Position.x;
    1.68 +	vec[1] = pose[eye].Position.y;
    1.69 +	vec[2] = pose[eye].Position.z;
    1.70  }
    1.71  
    1.72  static void rotation(int eye, float *quat)
    1.73 @@ -212,7 +235,11 @@
    1.74  		return;
    1.75  	}
    1.76  
    1.77 -	pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right);
    1.78 +	/* same as above (translation) */
    1.79 +	if(inside_begin_end) {
    1.80 +		pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right);
    1.81 +	}
    1.82 +
    1.83  	quat[0] = pose[eye].Orientation.x;
    1.84  	quat[1] = pose[eye].Orientation.y;
    1.85  	quat[2] = pose[eye].Orientation.z;
    1.86 @@ -240,8 +267,6 @@
    1.87  	}
    1.88  }
    1.89  
    1.90 -static int new_frame = 1;
    1.91 -
    1.92  static void begin(int eye)
    1.93  {
    1.94  	if(!hmd) return;
    1.95 @@ -250,9 +275,9 @@
    1.96  		deferred_init();
    1.97  	}
    1.98  
    1.99 -	if(new_frame) {
   1.100 +	if(!inside_begin_end) {
   1.101  		ovrHmd_BeginFrame(hmd, 0);
   1.102 -		new_frame = 0;
   1.103 +		inside_begin_end = 1;
   1.104  	}
   1.105  }
   1.106  
   1.107 @@ -261,7 +286,7 @@
   1.108  	if(!hmd) return 0;
   1.109  
   1.110  	ovrHmd_EndFrame(hmd, pose, &eye_tex[0].Texture);
   1.111 -	new_frame = 1;
   1.112 +	inside_begin_end = 0;
   1.113  
   1.114  	return 1;
   1.115  }