goat3dgfx

diff src/vr/vr.cc @ 25:6236080aaea4

LIBOVR conditional compilation fix
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 27 Feb 2014 01:40:12 +0200
parents 7d6b667821cf
children
line diff
     1.1 --- a/src/vr/vr.cc	Tue Feb 25 23:47:48 2014 +0200
     1.2 +++ b/src/vr/vr.cc	Thu Feb 27 01:40:12 2014 +0200
     1.3 @@ -1,5 +1,11 @@
     1.4 +#include "config.h"
     1.5 +
     1.6  #include <stdio.h>
     1.7 +#include <string.h>
     1.8 +#define _USE_MATH_DEFINES
     1.9 +#include <math.h>
    1.10  #include <GL/glew.h>
    1.11 +#include "vmath/vmath.h"
    1.12  #include "vr.h"
    1.13  #include "vr_impl.h"
    1.14  #include "vr_sdr.h"
    1.15 @@ -35,8 +41,10 @@
    1.16  extern "C" void vr_shutdown(void)
    1.17  {
    1.18  	delete [] vr_ctx.info.display;
    1.19 +#ifdef USE_LIBOVR
    1.20  	delete vr_ctx.ovr_sfusion;
    1.21  	//System::Destroy();
    1.22 +#endif
    1.23  
    1.24  	memset(&vr_ctx, 0, sizeof vr_ctx);
    1.25  }
    1.26 @@ -53,6 +61,7 @@
    1.27  
    1.28  static bool init_ovr()
    1.29  {
    1.30 +#ifdef USE_LIBOVR
    1.31  	LogMaskConstants log_level = LogMask_All;
    1.32  	// initialize Oculus SDK
    1.33  	const char *logenv = getenv("VR_LOGLEVEL");
    1.34 @@ -150,6 +159,7 @@
    1.35  		vr_ctx.ovr_sfusion = new SensorFusion;
    1.36  		vr_ctx.ovr_sfusion->AttachToSensor(vr_ctx.ovr_sensor_dev);
    1.37  	}
    1.38 +#endif	// USE_LIBOVR
    1.39  	return true;
    1.40  }
    1.41  
    1.42 @@ -289,12 +299,16 @@
    1.43  
    1.44  extern "C" void vr_set_prediction_sec(float dt)
    1.45  {
    1.46 +#ifdef USE_LIBOVR
    1.47  	vr_ctx.ovr_sfusion->SetPrediction(dt);
    1.48 +#endif
    1.49  }
    1.50  
    1.51  extern "C" float vr_get_prediction_sec(void)
    1.52  {
    1.53 +#ifdef USE_LIBOVR
    1.54  	return vr_ctx.ovr_sfusion->GetPredictionDelta();
    1.55 +#endif
    1.56  }
    1.57  
    1.58  extern "C" void vr_get_view_matrix(float *res, int eye)
    1.59 @@ -304,12 +318,19 @@
    1.60  
    1.61  extern "C" void vr_get_proj_matrix(float *res, int eye)
    1.62  {
    1.63 +#ifdef USE_LIBOVR
    1.64  	static float eye_scale[] = {0.0, 1.0, -1.0};
    1.65  
    1.66  	Matrix4f proj = Matrix4f::PerspectiveRH(vr_ctx.info.fov, vr_ctx.info.aspect / 2.0, 0.3, 1000.0);
    1.67  	proj = Matrix4f::Translation(vr_ctx.info.proj_center_offset * eye_scale[eye], 0, 0) * proj;
    1.68  
    1.69  	memcpy(res, proj.M[0], 16 * sizeof(float));
    1.70 +#else
    1.71 +	Matrix4x4 proj;
    1.72 +	proj.set_perspective(vr_ctx.info.fov, vr_ctx.info.aspect, 0.3, 1000.0);
    1.73 +	proj.transpose();
    1.74 +	memcpy(res, proj[0], 16 * sizeof(float));
    1.75 +#endif
    1.76  }
    1.77  
    1.78  extern "C" void vr_get_translation(float *offs)
    1.79 @@ -320,17 +341,26 @@
    1.80  
    1.81  extern "C" void vr_get_rotation(float *quat)
    1.82  {
    1.83 +#ifdef USE_LIBOVR
    1.84  	Quatf oq = vr_ctx.ovr_sfusion->GetPredictedOrientation();
    1.85  	quat[0] = oq.x;
    1.86  	quat[1] = oq.y;
    1.87  	quat[2] = oq.z;
    1.88  	quat[3] = oq.w;
    1.89 +#else
    1.90 +	quat[0] = quat[1] = quat[2] = 0.0;
    1.91 +	quat[3] = 1.0;
    1.92 +#endif
    1.93  }
    1.94  
    1.95  extern "C" void vr_get_rotation_euler(float *euler)
    1.96  {
    1.97 +#ifdef USE_LIBOVR
    1.98  	Quatf oq = vr_ctx.ovr_sfusion->GetPredictedOrientation();
    1.99  	oq.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(euler + 1, euler, euler + 2);
   1.100 +#else
   1.101 +	euler[0] = euler[1] = euler[2] = 0.0;
   1.102 +#endif
   1.103  }
   1.104  
   1.105  extern "C" void vr_draw_eye(int eye, unsigned int tex, float tex_scale_x, float tex_scale_y)