oculus1
diff src/vr.cc @ 3:b069a5c27388
added a couple more stuff, fixed all the LibOVR line endings
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 15 Sep 2013 04:10:05 +0300 |
parents | e2f9e4603129 |
children | bb81990dc7c8 |
line diff
1.1 --- a/src/vr.cc Sat Sep 14 17:51:03 2013 +0300 1.2 +++ b/src/vr.cc Sun Sep 15 04:10:05 2013 +0300 1.3 @@ -4,7 +4,7 @@ 1.4 1.5 static bool init_ovr(); 1.6 1.7 -VRData vr_data; 1.8 +VRContext vr_ctx; 1.9 1.10 extern "C" int vr_init(enum vr_init_mode mode) 1.11 { 1.12 @@ -16,28 +16,26 @@ 1.13 1.14 extern "C" void vr_shutdown(void) 1.15 { 1.16 - System::Destroy(); 1.17 + //System::Destroy(); 1.18 } 1.19 1.20 - 1.21 - 1.22 static bool init_ovr() 1.23 { 1.24 // initialize Oculus SDK 1.25 System::Init(); 1.26 - if(!(vr_data.ovr_devman = DeviceManager::Create())) { 1.27 + if(!(vr_ctx.ovr_devman = DeviceManager::Create())) { 1.28 fprintf(stderr, "failed to create OVR device manager\n"); 1.29 return false; 1.30 } 1.31 1.32 // create the display device 1.33 - if(!(vr_data.ovr_hmd_dev = vr_data.ovr_devman->EnumerateDevices<HMDDevice>().CreateDevice())) { 1.34 + if(!(vr_ctx.ovr_hmd_dev = vr_ctx.ovr_devman->EnumerateDevices<HMDDevice>().CreateDevice())) { 1.35 fprintf(stderr, "no oculus rift devices found\n"); 1.36 return false; 1.37 } 1.38 1.39 HMDInfo info; 1.40 - if(vr_data.ovr_hmd_dev->GetDeviceInfo(&info)) { 1.41 + if(vr_ctx.ovr_hmd_dev->GetDeviceInfo(&info)) { 1.42 printf("oculus device info:\n"); 1.43 printf(" name: %s\n", info.DisplayDeviceName); 1.44 printf(" ipd: %f\n", info.InterpupillaryDistance); 1.45 @@ -46,16 +44,102 @@ 1.46 } 1.47 1.48 // get the sensor device 1.49 - if(!(vr_data.ovr_sensor_dev = vr_data.ovr_hmd_dev->GetSensor())) { 1.50 + if(!(vr_ctx.ovr_sensor_dev = vr_ctx.ovr_hmd_dev->GetSensor())) { 1.51 fprintf(stderr, "failed to get oculus sensor device\n"); 1.52 return false; 1.53 } 1.54 1.55 SensorInfo sinfo; 1.56 - if(vr_data.ovr_sensor_dev->GetDeviceInfo(&sinfo)) { 1.57 + if(vr_ctx.ovr_sensor_dev->GetDeviceInfo(&sinfo)) { 1.58 printf("oculus sensor device info:\n"); 1.59 printf(" name: %s\n", sinfo.ProductName); 1.60 } 1.61 1.62 + vr_ctx.ovr_sfusion.AttachToSensor(vr_ctx.ovr_sensor_dev); 1.63 + 1.64 + // calculate and store viewing parameters 1.65 + float vhalfsz = info.VScreenSize * 0.5; 1.66 + vr_ctx.info.fov = 2.0 * atan(vhalfsz / info.EyeToScreenDistance); 1.67 + 1.68 + vr_ctx.info.width = info.HResolution; 1.69 + vr_ctx.info.height = info.VResolution; 1.70 + vr_ctx.info.aspect = (float)vr_ctx.info.width / (float)vr_ctx.info.height; 1.71 + 1.72 + vr_ctx.info.ipd = info.InterpupillaryDistance; 1.73 + for(int i=0; i<4; i++) { 1.74 + vr_ctx.info.distort[i] = info.DistortionK[i]; 1.75 + } 1.76 + 1.77 return true; 1.78 } 1.79 + 1.80 +extern "C" int vr_get_width(void) 1.81 +{ 1.82 + return vr_ctx.info.width; 1.83 +} 1.84 + 1.85 +extern "C" int vr_get_height(void) 1.86 +{ 1.87 + return vr_ctx.info.height; 1.88 +} 1.89 + 1.90 +extern "C" float vr_get_fov(void) 1.91 +{ 1.92 + return vr_ctx.info.fov; 1.93 +} 1.94 + 1.95 +extern "C" float vr_get_aspect(void) 1.96 +{ 1.97 + return vr_ctx.info.aspect; 1.98 +} 1.99 + 1.100 +extern "C" void vr_set_eyedist(float ipd) 1.101 +{ 1.102 + vr_ctx.info.ipd = ipd; 1.103 +} 1.104 + 1.105 +extern "C" float vr_get_eyedist(void) 1.106 +{ 1.107 + return vr_ctx.info.ipd; 1.108 +} 1.109 + 1.110 +extern "C" void vr_set_distort(const float *coef) 1.111 +{ 1.112 + memcpy(vr_ctx.info.distort, coef, sizeof vr_ctx.info.distort); 1.113 +} 1.114 + 1.115 +extern "C" void vr_get_distort(float *coef) 1.116 +{ 1.117 + memcpy(coef, vr_ctx.info.distort, sizeof vr_ctx.info.distort); 1.118 +} 1.119 + 1.120 +extern "C" void vr_set_prediction_sec(float dt) 1.121 +{ 1.122 + vr_ctx.ovr_sfusion.SetPrediction(dt); 1.123 +} 1.124 + 1.125 +extern "C" float vr_get_prediction_sec(void) 1.126 +{ 1.127 + return vr_ctx.ovr_sfusion.GetPredictionDelta(); 1.128 +} 1.129 + 1.130 +extern "C" void vr_get_translation(float *offs) 1.131 +{ 1.132 + // current oculus devkit doesn't do translation 1.133 + offs[0] = offs[1] = offs[2] = 0.0f; 1.134 +} 1.135 + 1.136 +extern "C" void vr_get_rotation(float *quat) 1.137 +{ 1.138 + Quatf oq = vr_ctx.ovr_sfusion.GetPredictedOrientation(); 1.139 + quat[0] = oq.x; 1.140 + quat[1] = oq.y; 1.141 + quat[2] = oq.z; 1.142 + quat[3] = oq.w; 1.143 +} 1.144 + 1.145 +extern "C" void vr_get_rotation_euler(float *euler) 1.146 +{ 1.147 + Quatf oq = vr_ctx.ovr_sfusion.GetPredictedOrientation(); 1.148 + oq.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(euler + 1, euler, euler + 2); 1.149 +}