libgoatvr

diff src/opt.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 ded3d0a74e19
children bd37285ba5b6
line diff
     1.1 --- a/src/opt.c	Fri Oct 03 23:07:27 2014 +0300
     1.2 +++ b/src/opt.c	Sat Oct 04 03:39:14 2014 +0300
     1.3 @@ -24,6 +24,7 @@
     1.4  
     1.5  void set_option_int(void *optdb, const char *key, int val)
     1.6  {
     1.7 +	int i;
     1.8  	struct option *opt = malloc(sizeof *opt);
     1.9  	if(!opt) {
    1.10  		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    1.11 @@ -32,6 +33,9 @@
    1.12  	opt->type = OTYPE_INT;
    1.13  	opt->ival = val;
    1.14  	opt->fval = (float)val;
    1.15 +	for(i=0; i<4; i++) {
    1.16 +		opt->vval[i] = opt->fval;
    1.17 +	}
    1.18  
    1.19  	if(rb_insert(optdb, (void*)key, opt) == -1) {
    1.20  		fprintf(stderr, "failed to set option: %s\n", key);
    1.21 @@ -40,6 +44,7 @@
    1.22  
    1.23  void set_option_float(void *optdb, const char *key, float val)
    1.24  {
    1.25 +	int i;
    1.26  	struct option *opt = malloc(sizeof *opt);
    1.27  	if(!opt) {
    1.28  		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    1.29 @@ -48,12 +53,55 @@
    1.30  	opt->type = OTYPE_FLOAT;
    1.31  	opt->fval = val;
    1.32  	opt->ival = (int)val;
    1.33 +	for(i=0; i<4; i++) {
    1.34 +		opt->vval[i] = val;
    1.35 +	}
    1.36  
    1.37  	if(rb_insert(optdb, (void*)key, opt) == -1) {
    1.38  		fprintf(stderr, "failed to set option: %s\n", key);
    1.39  	}
    1.40  }
    1.41  
    1.42 +void set_option_vec(void *optdb, const char *key, float *val)
    1.43 +{
    1.44 +	int i;
    1.45 +	struct option *opt = malloc(sizeof *opt);
    1.46 +	if(!opt) {
    1.47 +		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    1.48 +		return;
    1.49 +	}
    1.50 +	opt->type = OTYPE_VEC;
    1.51 +	for(i=0; i<4; i++) {
    1.52 +		opt->vval[i] = val[i];
    1.53 +	}
    1.54 +	opt->fval = val[0];
    1.55 +	opt->ival = (int)val[0];
    1.56 +
    1.57 +	if(rb_insert(optdb, (void*)key, opt) == -1) {
    1.58 +		fprintf(stderr, "failed to set option: %s\n", key);
    1.59 +	}
    1.60 +}
    1.61 +
    1.62 +void set_option_vec3f(void *optdb, const char *key, float x, float y, float z)
    1.63 +{
    1.64 +	float vec[4];
    1.65 +	vec[0] = x;
    1.66 +	vec[1] = y;
    1.67 +	vec[2] = z;
    1.68 +	vec[3] = 1.0f;
    1.69 +	set_option_vec(optdb, key, vec);
    1.70 +}
    1.71 +
    1.72 +void set_option_vec4f(void *optdb, const char *key, float x, float y, float z, float w)
    1.73 +{
    1.74 +	float vec[4];
    1.75 +	vec[0] = x;
    1.76 +	vec[1] = y;
    1.77 +	vec[2] = z;
    1.78 +	vec[3] = w;
    1.79 +	set_option_vec(optdb, key, vec);
    1.80 +}
    1.81 +
    1.82  int get_option_int(void *optdb, const char *key, int *val)
    1.83  {
    1.84  	struct option *opt = rb_find(optdb, (void*)key);
    1.85 @@ -75,3 +123,18 @@
    1.86  	*val = opt->fval;
    1.87  	return 0;
    1.88  }
    1.89 +
    1.90 +int get_option_vec(void *optdb, const char *key, float *val)
    1.91 +{
    1.92 +	int i;
    1.93 +	struct option *opt = rb_find(optdb, (void*)key);
    1.94 +	if(!opt) {
    1.95 +		val[0] = val[1] = val[2] = val[3] = 0.0f;
    1.96 +		return -1;
    1.97 +	}
    1.98 +
    1.99 +	for(i=0; i<4; i++) {
   1.100 +		val[i] = opt->vval[i];
   1.101 +	}
   1.102 +	return 0;
   1.103 +}
   1.104 \ No newline at end of file