oculus1
diff src/vr.cc @ 4:bb81990dc7c8
getting sensor input
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 15 Sep 2013 04:47:12 +0300 |
parents | b069a5c27388 |
children | 681046a82ed2 |
line diff
1.1 --- a/src/vr.cc Sun Sep 15 04:10:05 2013 +0300 1.2 +++ b/src/vr.cc Sun Sep 15 04:47:12 2013 +0300 1.3 @@ -22,54 +22,59 @@ 1.4 static bool init_ovr() 1.5 { 1.6 // initialize Oculus SDK 1.7 - System::Init(); 1.8 + System::Init(Log::ConfigureDefaultLog(LogMask_All)); 1.9 if(!(vr_ctx.ovr_devman = DeviceManager::Create())) { 1.10 fprintf(stderr, "failed to create OVR device manager\n"); 1.11 return false; 1.12 } 1.13 1.14 // create the display device 1.15 + HMDInfo info; 1.16 if(!(vr_ctx.ovr_hmd_dev = vr_ctx.ovr_devman->EnumerateDevices<HMDDevice>().CreateDevice())) { 1.17 fprintf(stderr, "no oculus rift devices found\n"); 1.18 - return false; 1.19 - } 1.20 + } else { 1.21 + if(vr_ctx.ovr_hmd_dev->GetDeviceInfo(&info)) { 1.22 + printf("oculus device info:\n"); 1.23 + printf(" name: %s\n", info.DisplayDeviceName); 1.24 + printf(" ipd: %f\n", info.InterpupillaryDistance); 1.25 + printf(" distortion: %f %f %f %f\n", info.DistortionK[0], 1.26 + info.DistortionK[1], info.DistortionK[2], info.DistortionK[3]); 1.27 + } 1.28 1.29 - HMDInfo info; 1.30 - if(vr_ctx.ovr_hmd_dev->GetDeviceInfo(&info)) { 1.31 - printf("oculus device info:\n"); 1.32 - printf(" name: %s\n", info.DisplayDeviceName); 1.33 - printf(" ipd: %f\n", info.InterpupillaryDistance); 1.34 - printf(" distortion: %f %f %f %f\n", info.DistortionK[0], 1.35 - info.DistortionK[1], info.DistortionK[2], info.DistortionK[3]); 1.36 + // calculate and store viewing parameters 1.37 + float vhalfsz = info.VScreenSize * 0.5; 1.38 + vr_ctx.info.fov = 2.0 * atan(vhalfsz / info.EyeToScreenDistance); 1.39 + 1.40 + vr_ctx.info.width = info.HResolution; 1.41 + vr_ctx.info.height = info.VResolution; 1.42 + vr_ctx.info.aspect = (float)vr_ctx.info.width / (float)vr_ctx.info.height; 1.43 + 1.44 + vr_ctx.info.ipd = info.InterpupillaryDistance; 1.45 + for(int i=0; i<4; i++) { 1.46 + vr_ctx.info.distort[i] = info.DistortionK[i]; 1.47 + } 1.48 } 1.49 1.50 // get the sensor device 1.51 - if(!(vr_ctx.ovr_sensor_dev = vr_ctx.ovr_hmd_dev->GetSensor())) { 1.52 - fprintf(stderr, "failed to get oculus sensor device\n"); 1.53 - return false; 1.54 + if(vr_ctx.ovr_hmd_dev) { 1.55 + if(!(vr_ctx.ovr_sensor_dev = vr_ctx.ovr_hmd_dev->GetSensor())) { 1.56 + fprintf(stderr, "failed to get oculus sensor device\n"); 1.57 + } 1.58 + } else { 1.59 + if(!(vr_ctx.ovr_sensor_dev = vr_ctx.ovr_devman->EnumerateDevices<SensorDevice>().CreateDevice())) { 1.60 + fprintf(stderr, "failed to get oculus sensor device\n"); 1.61 + } 1.62 } 1.63 1.64 - SensorInfo sinfo; 1.65 - if(vr_ctx.ovr_sensor_dev->GetDeviceInfo(&sinfo)) { 1.66 - printf("oculus sensor device info:\n"); 1.67 - printf(" name: %s\n", sinfo.ProductName); 1.68 + if(vr_ctx.ovr_sensor_dev) { 1.69 + SensorInfo sinfo; 1.70 + if(vr_ctx.ovr_sensor_dev->GetDeviceInfo(&sinfo)) { 1.71 + printf("oculus sensor device info:\n"); 1.72 + printf(" name: %s\n", sinfo.ProductName); 1.73 + } 1.74 + 1.75 + vr_ctx.ovr_sfusion.AttachToSensor(vr_ctx.ovr_sensor_dev); 1.76 } 1.77 - 1.78 - vr_ctx.ovr_sfusion.AttachToSensor(vr_ctx.ovr_sensor_dev); 1.79 - 1.80 - // calculate and store viewing parameters 1.81 - float vhalfsz = info.VScreenSize * 0.5; 1.82 - vr_ctx.info.fov = 2.0 * atan(vhalfsz / info.EyeToScreenDistance); 1.83 - 1.84 - vr_ctx.info.width = info.HResolution; 1.85 - vr_ctx.info.height = info.VResolution; 1.86 - vr_ctx.info.aspect = (float)vr_ctx.info.width / (float)vr_ctx.info.height; 1.87 - 1.88 - vr_ctx.info.ipd = info.InterpupillaryDistance; 1.89 - for(int i=0; i<4; i++) { 1.90 - vr_ctx.info.distort[i] = info.DistortionK[i]; 1.91 - } 1.92 - 1.93 return true; 1.94 } 1.95