libgoatvr

diff src/vr.c @ 18:1067274dc780

fixed the fallback vr_view_translation and vr_view_matrix to include stereo separation
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 03 Oct 2014 23:07:27 +0300
parents 3de7339841d0
children 437fe32ac633
line diff
     1.1 --- a/src/vr.c	Thu Sep 25 17:14:04 2014 +0300
     1.2 +++ b/src/vr.c	Fri Oct 03 23:07:27 2014 +0300
     1.3 @@ -158,7 +158,7 @@
     1.4  
     1.5  static float def_option_float(const char *optname)
     1.6  {
     1.7 -	int res = 0;
     1.8 +	float res = 0.0f;
     1.9  
    1.10  	if(strcmp(optname, VR_RENDER_XRES) == 0 || strcmp(optname, VR_RENDER_YRES) == 0) {
    1.11  		return (float)def_option_int(optname);
    1.12 @@ -214,12 +214,17 @@
    1.13  
    1.14  int vr_view_translation(int eye, float *vec)
    1.15  {
    1.16 +	float eye_offset;
    1.17 +
    1.18  	if(vrm && vrm->translation) {
    1.19  		vrm->translation(eye, vec);
    1.20  		return 1;
    1.21  	}
    1.22 -	vec[0] = vec[1] = vec[2] = 0.0f;
    1.23 -	return 0;
    1.24 +
    1.25 +	eye_offset = vr_getf(VR_IPD) / 2.0;
    1.26 +	vec[0] = eye == VR_EYE_LEFT ? -eye_offset : eye_offset;
    1.27 +	vec[1] = vec[2] = 0.0f;
    1.28 +	return 1;
    1.29  }
    1.30  
    1.31  int vr_view_rotation(int eye, float *quat)
    1.32 @@ -235,7 +240,6 @@
    1.33  
    1.34  int vr_view_matrix(int eye, float *mat)
    1.35  {
    1.36 -	int have_trans, have_rot;
    1.37  	float offs[3], quat[4];
    1.38  	float rmat[16], tmat[16];
    1.39  
    1.40 @@ -244,12 +248,14 @@
    1.41  		return 1;
    1.42  	}
    1.43  
    1.44 -	have_trans = vr_view_translation(eye, offs);
    1.45 -	have_rot = vr_view_rotation(eye, quat);
    1.46 -
    1.47 -	if(!have_trans && !have_rot) {
    1.48 -		memcpy(mat, idmat, sizeof idmat);
    1.49 -		return 0;
    1.50 +	if(!vr_view_translation(eye, offs)) {
    1.51 +		float eye_offset = vr_getf(VR_IPD) / 2.0;
    1.52 +		offs[0] = eye == VR_EYE_LEFT ? -eye_offset : eye_offset;
    1.53 +		offs[1] = offs[2];
    1.54 +	}
    1.55 +	if(!vr_view_rotation(eye, quat)) {
    1.56 +		quat[0] = quat[1] = quat[2] = 0.0f;
    1.57 +		quat[3] = 1.0f;
    1.58  	}
    1.59  
    1.60  	offs[0] = -offs[0];