conworlds

diff src/vr/vr.c @ 7:bd8202d6d28d

some progress...
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Aug 2014 16:55:16 +0300
parents 3c36bc28c6c2
children 90abf4b93cc9
line diff
     1.1 --- a/src/vr/vr.c	Thu Aug 21 01:08:03 2014 +0300
     1.2 +++ b/src/vr/vr.c	Fri Aug 22 16:55:16 2014 +0300
     1.3 @@ -88,20 +88,72 @@
     1.4  	return -1;
     1.5  }
     1.6  
     1.7 +void vr_set_opti(const char *optname, int val)
     1.8 +{
     1.9 +	if(vrm && vrm->set_option) {
    1.10 +		vrm->set_option(optname, OTYPE_INT, &val);
    1.11 +	}
    1.12 +}
    1.13 +
    1.14 +void vr_set_optf(const char *optname, float val)
    1.15 +{
    1.16 +	if(vrm && vrm->set_option) {
    1.17 +		vrm->set_option(optname, OTYPE_FLOAT, &val);
    1.18 +	}
    1.19 +}
    1.20 +
    1.21 +int vr_get_opti(const char *optname)
    1.22 +{
    1.23 +	int res = 0;
    1.24 +
    1.25 +	if(vrm && vrm->get_option) {
    1.26 +		vrm->get_option(optname, OTYPE_INT, &res);
    1.27 +	}
    1.28 +	return res;
    1.29 +}
    1.30 +
    1.31 +float vr_get_optf(const char *optname)
    1.32 +{
    1.33 +	float res = 0.0f;
    1.34 +
    1.35 +	if(vrm && vrm->get_option) {
    1.36 +		vrm->get_option(optname, OTYPE_FLOAT, &res);
    1.37 +	}
    1.38 +	return res;
    1.39 +}
    1.40 +
    1.41 +
    1.42 +int vr_view_translation(int eye, float *vec)
    1.43 +{
    1.44 +	if(vrm && vrm->translation) {
    1.45 +		vrm->translation(eye, vec);
    1.46 +		return 0;
    1.47 +	}
    1.48 +	vec[0] = vec[1] = vec[2] = 0.0f;
    1.49 +	return -1;
    1.50 +}
    1.51 +
    1.52 +int vr_view_rotation(int eye, float *quat)
    1.53 +{
    1.54 +	if(vrm && vrm->rotation) {
    1.55 +		vrm->rotation(eye, quat);
    1.56 +		return 0;
    1.57 +	}
    1.58 +	quat[0] = quat[1] = quat[2] = 0.0f;
    1.59 +	quat[3] = 1.0f;
    1.60 +	return -1;
    1.61 +}
    1.62 +
    1.63  int vr_view_matrix(int eye, float *mat)
    1.64  {
    1.65 -	if(vrm && vrm->view_matrix) {
    1.66 -		vrm->view_matrix(eye, mat);
    1.67 -		return 1;
    1.68 -	}
    1.69 -	memcpy(mat, idmat, sizeof idmat);
    1.70 +	/* TODO combine vr_view_translation and vr_view_rotation */
    1.71  	return 0;
    1.72  }
    1.73  
    1.74 -int vr_proj_matrix(int eye, float *mat)
    1.75 +int vr_proj_matrix(int eye, float znear, float zfar, float *mat)
    1.76  {
    1.77  	if(vrm && vrm->proj_matrix) {
    1.78 -		vrm->proj_matrix(eye, mat);
    1.79 +		vrm->proj_matrix(eye, znear, zfar, mat);
    1.80  		return 1;
    1.81  	}
    1.82  	memcpy(mat, idmat, sizeof idmat);
    1.83 @@ -130,3 +182,25 @@
    1.84  	}
    1.85  	return 0;
    1.86  }
    1.87 +
    1.88 +void vr_output_texture(unsigned int tex, float umin, float vmin, float umax, float vmax)
    1.89 +{
    1.90 +	float halfu = (umax + umin) * 0.5f;
    1.91 +
    1.92 +	vr_output_texture_eye(VR_EYE_LEFT, tex, umin, vmin, halfu, vmax);
    1.93 +	vr_output_texture_eye(VR_EYE_RIGHT, tex, halfu, vmin, umax, vmax);
    1.94 +}
    1.95 +
    1.96 +void vr_output_texture_eye(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)
    1.97 +{
    1.98 +	if(vrm && vrm->set_eye_texture) {
    1.99 +		vrm->set_eye_texture(eye, tex, umin, vmin, umax, vmax);
   1.100 +	}
   1.101 +}
   1.102 +
   1.103 +void vr_recenter(void)
   1.104 +{
   1.105 +	if(vrm && vrm->recenter) {
   1.106 +		vrm->recenter();
   1.107 +	}
   1.108 +}
   1.109 \ No newline at end of file