oculus2

diff src/main.c @ 13:4c08bc24ef0a

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 28 Oct 2014 06:57:31 +0200
parents 92acd335620e 256d8fcf02f1
children 8a80bb153582
line diff
     1.1 --- a/src/main.c	Tue Oct 28 06:57:06 2014 +0200
     1.2 +++ b/src/main.c	Tue Oct 28 06:57:31 2014 +0200
     1.3 @@ -11,12 +11,15 @@
     1.4  #include <assert.h>
     1.5  #include <SDL2/SDL.h>
     1.6  #include <GL/glew.h>
     1.7 +#include <X11/Xlib.h>
     1.8 +#include <GL/glx.h>
     1.9  
    1.10  #ifdef WIN32
    1.11  #define OVR_OS_WIN32
    1.12 -#endif
    1.13 -#ifdef __APPLE__
    1.14 +#elif defined(__APPLE__)
    1.15  #define OVR_OS_MAC
    1.16 +#else
    1.17 +#define OVR_OS_LINUX
    1.18  #endif
    1.19  
    1.20  #include <OVR_CAPI.h>
    1.21 @@ -116,8 +119,8 @@
    1.22  	win_width = hmd->Resolution.w;
    1.23  	win_height = hmd->Resolution.h;
    1.24  
    1.25 -	/* enable position and rotation tracking (and anything else they might add in the future) */
    1.26 -	ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0);
    1.27 +	/* enable position and rotation tracking */
    1.28 +	ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0);
    1.29  	/* retrieve the optimal render target resolution for each eye */
    1.30  	eyeres[0] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, hmd->DefaultEyeFov[0], 1.0);
    1.31  	eyeres[1] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, hmd->DefaultEyeFov[1], 1.0);
    1.32 @@ -148,6 +151,14 @@
    1.33  	glcfg.OGL.Header.RTSize = hmd->Resolution;
    1.34  	glcfg.OGL.Header.Multisample = 1;
    1.35  
    1.36 +#ifdef WIN32
    1.37 +	glcfg.OGL.Window = GetActiveWindow();
    1.38 +	glcfg.OGL.DC = wglGetCurrentDC();
    1.39 +#else
    1.40 +	glcfg.OGL.Disp = glXGetCurrentDisplay();
    1.41 +	glcfg.OGL.Win = glXGetCurrentDrawable();
    1.42 +#endif
    1.43 +
    1.44  	if(hmd->HmdCaps & ovrHmdCap_ExtendDesktop) {
    1.45  		printf("running in \"extended desktop\" mode\n");
    1.46  	} else {
    1.47 @@ -156,10 +167,9 @@
    1.48  		 * XXX: this doesn't work properly yet due to bugs in the oculus 0.4.1 sdk/driver
    1.49  		 */
    1.50  #ifdef WIN32
    1.51 -		HWND sys_win = GetActiveWindow();
    1.52 -		glcfg.OGL.Window = sys_win;
    1.53 -		glcfg.OGL.DC = wglGetCurrentDC();
    1.54 -		ovrHmd_AttachToWindow(hmd, sys_win, 0, 0);
    1.55 +		ovrHmd_AttachToWindow(hmd, glcfg.OGL.Window, 0, 0);
    1.56 +#else
    1.57 +		ovrHmd_AttachToWindow(hmd, (void*)glcfg.OGL.Win, 0, 0);
    1.58  #endif
    1.59  		printf("running in \"direct-hmd\" mode\n");
    1.60  	}
    1.61 @@ -260,10 +270,13 @@
    1.62  		 * we need to construct a view matrix by combining all the information provided by the oculus
    1.63  		 * SDK, about the position and orientation of the user's head in the world.
    1.64  		 */
    1.65 -		pose[eye] = ovrHmd_GetEyePose(hmd, eye);
    1.66 +		/* TODO: use ovrHmd_GetEyePoses out of the loop instead */
    1.67 +		pose[eye] = ovrHmd_GetHmdPosePerEye(hmd, eye);
    1.68  		glMatrixMode(GL_MODELVIEW);
    1.69  		glLoadIdentity();
    1.70 -		glTranslatef(eye_rdesc[eye].ViewAdjust.x, eye_rdesc[eye].ViewAdjust.y, eye_rdesc[eye].ViewAdjust.z);
    1.71 +		glTranslatef(eye_rdesc[eye].HmdToEyeViewOffset.x,
    1.72 +				eye_rdesc[eye].HmdToEyeViewOffset.y,
    1.73 +				eye_rdesc[eye].HmdToEyeViewOffset.z);
    1.74  		/* retrieve the orientation quaternion and convert it to a rotation matrix */
    1.75  		quat_to_matrix(&pose[eye].Orientation.x, rot_mat);
    1.76  		glMultMatrixf(rot_mat);
    1.77 @@ -552,4 +565,4 @@
    1.78  	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, img);
    1.79  
    1.80  	return tex;
    1.81 -}
    1.82 \ No newline at end of file
    1.83 +}