oculus1
diff src/vr.cc @ 1:e2f9e4603129
added LibOVR and started a simple vr wrapper.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Sep 2013 16:14:59 +0300 |
parents | |
children | b069a5c27388 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/vr.cc Sat Sep 14 16:14:59 2013 +0300 1.3 @@ -0,0 +1,61 @@ 1.4 +#include <stdio.h> 1.5 +#include "vr.h" 1.6 +#include "vr_impl.h" 1.7 + 1.8 +static bool init_ovr(); 1.9 + 1.10 +VRData vr_data; 1.11 + 1.12 +extern "C" int vr_init(enum vr_init_mode mode) 1.13 +{ 1.14 + if(!init_ovr()) { 1.15 + return -1; 1.16 + } 1.17 + return 0; 1.18 +} 1.19 + 1.20 +extern "C" void vr_shutdown(void) 1.21 +{ 1.22 + System::Destroy(); 1.23 +} 1.24 + 1.25 + 1.26 + 1.27 +static bool init_ovr() 1.28 +{ 1.29 + // initialize Oculus SDK 1.30 + System::Init(); 1.31 + if(!(vr_data.ovr_devman = DeviceManager::Create())) { 1.32 + fprintf(stderr, "failed to create OVR device manager\n"); 1.33 + return false; 1.34 + } 1.35 + 1.36 + // create the display device 1.37 + if(!(vr_data.ovr_hmd_dev = vr_data.ovr_devman->EnumerateDevices<HMDDevice>().CreateDevice())) { 1.38 + fprintf(stderr, "no oculus rift devices found\n"); 1.39 + return false; 1.40 + } 1.41 + 1.42 + HMDInfo info; 1.43 + if(vr_data.ovr_hmd_dev->GetDeviceInfo(&info)) { 1.44 + printf("oculus device info:\n"); 1.45 + printf(" name: %s\n", info.DisplayDeviceName); 1.46 + printf(" ipd: %f\n", info.InterpupillaryDistance); 1.47 + printf(" distortion: %f %f %f %f\n", info.DistortionK[0], 1.48 + info.DistortionK[1], info.DistortionK[2], info.DistortionK[3]); 1.49 + } 1.50 + 1.51 + // get the sensor device 1.52 + if(!(vr_data.ovr_sensor_dev = vr_data.ovr_hmd_dev->GetSensor())) { 1.53 + fprintf(stderr, "failed to get oculus sensor device\n"); 1.54 + return false; 1.55 + } 1.56 + 1.57 + SensorInfo sinfo; 1.58 + if(vr_data.ovr_sensor_dev->GetDeviceInfo(&sinfo)) { 1.59 + printf("oculus sensor device info:\n"); 1.60 + printf(" name: %s\n", sinfo.ProductName); 1.61 + } 1.62 + 1.63 + return true; 1.64 +}