oculus2

changeset 13:4c08bc24ef0a

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 28 Oct 2014 06:57:31 +0200
parents 92acd335620e 256d8fcf02f1
children 8a80bb153582
files src/main.c
diffstat 2 files changed, 25 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Tue Oct 28 06:57:06 2014 +0200
     1.2 +++ b/Makefile	Tue Oct 28 06:57:31 2014 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  bin = oculus2
     1.5  
     1.6  CFLAGS = -pedantic -Wall -g `pkg-config --cflags sdl2`
     1.7 -LDFLAGS = $(libgl) `pkg-config --libs sdl2`
     1.8 +LDFLAGS = $(libgl) `pkg-config --libs sdl2` -lovr -lX11
     1.9  
    1.10  ifeq ($(shell uname -s), Darwin)
    1.11  	libgl = -framework OpenGL -lGLEW
     2.1 --- a/src/main.c	Tue Oct 28 06:57:06 2014 +0200
     2.2 +++ b/src/main.c	Tue Oct 28 06:57:31 2014 +0200
     2.3 @@ -11,12 +11,15 @@
     2.4  #include <assert.h>
     2.5  #include <SDL2/SDL.h>
     2.6  #include <GL/glew.h>
     2.7 +#include <X11/Xlib.h>
     2.8 +#include <GL/glx.h>
     2.9  
    2.10  #ifdef WIN32
    2.11  #define OVR_OS_WIN32
    2.12 -#endif
    2.13 -#ifdef __APPLE__
    2.14 +#elif defined(__APPLE__)
    2.15  #define OVR_OS_MAC
    2.16 +#else
    2.17 +#define OVR_OS_LINUX
    2.18  #endif
    2.19  
    2.20  #include <OVR_CAPI.h>
    2.21 @@ -116,8 +119,8 @@
    2.22  	win_width = hmd->Resolution.w;
    2.23  	win_height = hmd->Resolution.h;
    2.24  
    2.25 -	/* enable position and rotation tracking (and anything else they might add in the future) */
    2.26 -	ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0);
    2.27 +	/* enable position and rotation tracking */
    2.28 +	ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0);
    2.29  	/* retrieve the optimal render target resolution for each eye */
    2.30  	eyeres[0] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, hmd->DefaultEyeFov[0], 1.0);
    2.31  	eyeres[1] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, hmd->DefaultEyeFov[1], 1.0);
    2.32 @@ -148,6 +151,14 @@
    2.33  	glcfg.OGL.Header.RTSize = hmd->Resolution;
    2.34  	glcfg.OGL.Header.Multisample = 1;
    2.35  
    2.36 +#ifdef WIN32
    2.37 +	glcfg.OGL.Window = GetActiveWindow();
    2.38 +	glcfg.OGL.DC = wglGetCurrentDC();
    2.39 +#else
    2.40 +	glcfg.OGL.Disp = glXGetCurrentDisplay();
    2.41 +	glcfg.OGL.Win = glXGetCurrentDrawable();
    2.42 +#endif
    2.43 +
    2.44  	if(hmd->HmdCaps & ovrHmdCap_ExtendDesktop) {
    2.45  		printf("running in \"extended desktop\" mode\n");
    2.46  	} else {
    2.47 @@ -156,10 +167,9 @@
    2.48  		 * XXX: this doesn't work properly yet due to bugs in the oculus 0.4.1 sdk/driver
    2.49  		 */
    2.50  #ifdef WIN32
    2.51 -		HWND sys_win = GetActiveWindow();
    2.52 -		glcfg.OGL.Window = sys_win;
    2.53 -		glcfg.OGL.DC = wglGetCurrentDC();
    2.54 -		ovrHmd_AttachToWindow(hmd, sys_win, 0, 0);
    2.55 +		ovrHmd_AttachToWindow(hmd, glcfg.OGL.Window, 0, 0);
    2.56 +#else
    2.57 +		ovrHmd_AttachToWindow(hmd, (void*)glcfg.OGL.Win, 0, 0);
    2.58  #endif
    2.59  		printf("running in \"direct-hmd\" mode\n");
    2.60  	}
    2.61 @@ -260,10 +270,13 @@
    2.62  		 * we need to construct a view matrix by combining all the information provided by the oculus
    2.63  		 * SDK, about the position and orientation of the user's head in the world.
    2.64  		 */
    2.65 -		pose[eye] = ovrHmd_GetEyePose(hmd, eye);
    2.66 +		/* TODO: use ovrHmd_GetEyePoses out of the loop instead */
    2.67 +		pose[eye] = ovrHmd_GetHmdPosePerEye(hmd, eye);
    2.68  		glMatrixMode(GL_MODELVIEW);
    2.69  		glLoadIdentity();
    2.70 -		glTranslatef(eye_rdesc[eye].ViewAdjust.x, eye_rdesc[eye].ViewAdjust.y, eye_rdesc[eye].ViewAdjust.z);
    2.71 +		glTranslatef(eye_rdesc[eye].HmdToEyeViewOffset.x,
    2.72 +				eye_rdesc[eye].HmdToEyeViewOffset.y,
    2.73 +				eye_rdesc[eye].HmdToEyeViewOffset.z);
    2.74  		/* retrieve the orientation quaternion and convert it to a rotation matrix */
    2.75  		quat_to_matrix(&pose[eye].Orientation.x, rot_mat);
    2.76  		glMultMatrixf(rot_mat);
    2.77 @@ -552,4 +565,4 @@
    2.78  	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, img);
    2.79  
    2.80  	return tex;
    2.81 -}
    2.82 \ No newline at end of file
    2.83 +}