vrchess

diff src/vr/vr.c @ 11:5dc4e2b8f6f5

LibOVR is broken
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 23 Aug 2014 00:24:20 +0300
parents e3f0ca1d008a
children
line diff
     1.1 --- a/src/vr/vr.c	Fri Aug 22 20:11:15 2014 +0300
     1.2 +++ b/src/vr/vr.c	Sat Aug 23 00:24:20 2014 +0300
     1.3 @@ -2,6 +2,7 @@
     1.4  #include <string.h>
     1.5  #include "vr.h"
     1.6  #include "vr_impl.h"
     1.7 +#include "mathutil.h"
     1.8  
     1.9  
    1.10  static void swap_buffers(void);
    1.11 @@ -133,37 +134,49 @@
    1.12  {
    1.13  	if(vrm && vrm->translation) {
    1.14  		vrm->translation(eye, vec);
    1.15 -		return 0;
    1.16 +		return 1;
    1.17  	}
    1.18  	vec[0] = vec[1] = vec[2] = 0.0f;
    1.19 -	return -1;
    1.20 +	return 0;
    1.21  }
    1.22  
    1.23  int vr_view_rotation(int eye, float *quat)
    1.24  {
    1.25  	if(vrm && vrm->rotation) {
    1.26  		vrm->rotation(eye, quat);
    1.27 -		return 0;
    1.28 +		return 1;
    1.29  	}
    1.30  	quat[0] = quat[1] = quat[2] = 0.0f;
    1.31  	quat[3] = 1.0f;
    1.32 -	return -1;
    1.33 +	return 0;
    1.34  }
    1.35  
    1.36  int vr_view_matrix(int eye, float *mat)
    1.37  {
    1.38 +	int have_trans, have_rot;
    1.39  	float offs[3], quat[4];
    1.40 +	float rmat[16], tmat[16];
    1.41  
    1.42  	if(vrm && vrm->view_matrix) {
    1.43  		vrm->view_matrix(eye, mat);
    1.44  		return 1;
    1.45  	}
    1.46  
    1.47 -	if(!vr_view_translation(eye, offs) && !vr_view_rotation(eye, quat)) {
    1.48 +	have_trans = vr_view_translation(eye, offs);
    1.49 +	have_rot = vr_view_rotation(eye, quat);
    1.50 +
    1.51 +	if(!have_trans && !have_rot) {
    1.52  		return 0;
    1.53  	}
    1.54 -	/* TODO construct matrix */
    1.55 -	return 0;
    1.56 +
    1.57 +	offs[0] = -offs[0];
    1.58 +	offs[1] = -offs[1];
    1.59 +	offs[2] = -offs[2];
    1.60 +
    1.61 +	translation_matrix(offs, tmat);
    1.62 +	rotation_matrix(quat, rmat);
    1.63 +	mult_matrix(mat, tmat, rmat);
    1.64 +	return 1;
    1.65  }
    1.66  
    1.67  int vr_proj_matrix(int eye, float znear, float zfar, float *mat)