oculus1

changeset 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
files src/main.cc src/vr.cc
diffstat 2 files changed, 46 insertions(+), 35 deletions(-) [+]
line diff
     1.1 --- a/src/main.cc	Sun Sep 15 04:10:05 2013 +0300
     1.2 +++ b/src/main.cc	Sun Sep 15 04:47:12 2013 +0300
     1.3 @@ -75,14 +75,20 @@
     1.4  
     1.5  static void disp()
     1.6  {
     1.7 +	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
     1.8 +
     1.9  	// test rift sensor
    1.10  	float quat[4], euler[3];
    1.11  
    1.12  	vr_get_rotation(quat);
    1.13  	vr_get_rotation_euler(euler);
    1.14  
    1.15 -	printf("q(%.3f + %.3fi + %.3fj %.3fk)", quat[3], quat[0], quat[1], quat[2]);
    1.16 -	printf(" - euler(%.3f %.3f %.3f)\n", euler[0], euler[1], euler[2]);
    1.17 +	static unsigned int prev_print;
    1.18 +	if(msec - prev_print > 1000) {
    1.19 +		printf("q(%.3f + %.3fi + %.3fj %.3fk)", quat[3], quat[0], quat[1], quat[2]);
    1.20 +		printf(" - euler(%.3f %.3f %.3f)\n", euler[0], euler[1], euler[2]);
    1.21 +		prev_print = msec;
    1.22 +	}
    1.23  
    1.24  	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.25  
     2.1 --- a/src/vr.cc	Sun Sep 15 04:10:05 2013 +0300
     2.2 +++ b/src/vr.cc	Sun Sep 15 04:47:12 2013 +0300
     2.3 @@ -22,54 +22,59 @@
     2.4  static bool init_ovr()
     2.5  {
     2.6  	// initialize Oculus SDK
     2.7 -	System::Init();
     2.8 +	System::Init(Log::ConfigureDefaultLog(LogMask_All));
     2.9  	if(!(vr_ctx.ovr_devman = DeviceManager::Create())) {
    2.10  		fprintf(stderr, "failed to create OVR device manager\n");
    2.11  		return false;
    2.12  	}
    2.13  
    2.14  	// create the display device
    2.15 +	HMDInfo info;
    2.16  	if(!(vr_ctx.ovr_hmd_dev = vr_ctx.ovr_devman->EnumerateDevices<HMDDevice>().CreateDevice())) {
    2.17  		fprintf(stderr, "no oculus rift devices found\n");
    2.18 -		return false;
    2.19 -	}
    2.20 +	} else {
    2.21 +		if(vr_ctx.ovr_hmd_dev->GetDeviceInfo(&info)) {
    2.22 +			printf("oculus device info:\n");
    2.23 +			printf("  name: %s\n", info.DisplayDeviceName);
    2.24 +			printf("  ipd: %f\n", info.InterpupillaryDistance);
    2.25 +			printf("  distortion: %f %f %f %f\n", info.DistortionK[0],
    2.26 +					info.DistortionK[1], info.DistortionK[2], info.DistortionK[3]);
    2.27 +		}
    2.28  
    2.29 -	HMDInfo info;
    2.30 -	if(vr_ctx.ovr_hmd_dev->GetDeviceInfo(&info)) {
    2.31 -		printf("oculus device info:\n");
    2.32 -		printf("  name: %s\n", info.DisplayDeviceName);
    2.33 -		printf("  ipd: %f\n", info.InterpupillaryDistance);
    2.34 -		printf("  distortion: %f %f %f %f\n", info.DistortionK[0],
    2.35 -				info.DistortionK[1], info.DistortionK[2], info.DistortionK[3]);
    2.36 +		// calculate and store viewing parameters
    2.37 +		float vhalfsz = info.VScreenSize * 0.5;
    2.38 +		vr_ctx.info.fov = 2.0 * atan(vhalfsz / info.EyeToScreenDistance);
    2.39 +
    2.40 +		vr_ctx.info.width = info.HResolution;
    2.41 +		vr_ctx.info.height = info.VResolution;
    2.42 +		vr_ctx.info.aspect = (float)vr_ctx.info.width / (float)vr_ctx.info.height;
    2.43 +
    2.44 +		vr_ctx.info.ipd = info.InterpupillaryDistance;
    2.45 +		for(int i=0; i<4; i++) {
    2.46 +			vr_ctx.info.distort[i] = info.DistortionK[i];
    2.47 +		}
    2.48  	}
    2.49  
    2.50  	// get the sensor device
    2.51 -	if(!(vr_ctx.ovr_sensor_dev = vr_ctx.ovr_hmd_dev->GetSensor())) {
    2.52 -		fprintf(stderr, "failed to get oculus sensor device\n");
    2.53 -		return false;
    2.54 +	if(vr_ctx.ovr_hmd_dev) {
    2.55 +		if(!(vr_ctx.ovr_sensor_dev = vr_ctx.ovr_hmd_dev->GetSensor())) {
    2.56 +			fprintf(stderr, "failed to get oculus sensor device\n");
    2.57 +		}
    2.58 +	} else {
    2.59 +		if(!(vr_ctx.ovr_sensor_dev = vr_ctx.ovr_devman->EnumerateDevices<SensorDevice>().CreateDevice())) {
    2.60 +			fprintf(stderr, "failed to get oculus sensor device\n");
    2.61 +		}
    2.62  	}
    2.63  
    2.64 -	SensorInfo sinfo;
    2.65 -	if(vr_ctx.ovr_sensor_dev->GetDeviceInfo(&sinfo)) {
    2.66 -		printf("oculus sensor device info:\n");
    2.67 -		printf("  name: %s\n", sinfo.ProductName);
    2.68 +	if(vr_ctx.ovr_sensor_dev) {
    2.69 +		SensorInfo sinfo;
    2.70 +		if(vr_ctx.ovr_sensor_dev->GetDeviceInfo(&sinfo)) {
    2.71 +			printf("oculus sensor device info:\n");
    2.72 +			printf("  name: %s\n", sinfo.ProductName);
    2.73 +		}
    2.74 +
    2.75 +		vr_ctx.ovr_sfusion.AttachToSensor(vr_ctx.ovr_sensor_dev);
    2.76  	}
    2.77 -
    2.78 -	vr_ctx.ovr_sfusion.AttachToSensor(vr_ctx.ovr_sensor_dev);
    2.79 -
    2.80 -	// calculate and store viewing parameters
    2.81 -	float vhalfsz = info.VScreenSize * 0.5;
    2.82 -	vr_ctx.info.fov = 2.0 * atan(vhalfsz / info.EyeToScreenDistance);
    2.83 -
    2.84 -	vr_ctx.info.width = info.HResolution;
    2.85 -	vr_ctx.info.height = info.VResolution;
    2.86 -	vr_ctx.info.aspect = (float)vr_ctx.info.width / (float)vr_ctx.info.height;
    2.87 -
    2.88 -	vr_ctx.info.ipd = info.InterpupillaryDistance;
    2.89 -	for(int i=0; i<4; i++) {
    2.90 -		vr_ctx.info.distort[i] = info.DistortionK[i];
    2.91 -	}
    2.92 -
    2.93  	return true;
    2.94  }
    2.95