Fixed CMake for oculus. Gave Oculus its own camera for minimum latency.

This commit is contained in:
barnold1953 2014-06-26 17:10:53 -07:00
parent ea2d75addc
commit 67c5281205
6 changed files with 57 additions and 33 deletions

View file

@ -42,14 +42,11 @@ else (LIBOVR_LIBRARIES AND LIBOVR_INCLUDE_DIRS)
if (UDEV_LIBRARY AND XINERAMA_LIBRARY AND OVR_LIBRARY) if (UDEV_LIBRARY AND XINERAMA_LIBRARY AND OVR_LIBRARY)
set(LIBOVR_LIBRARIES "${OVR_LIBRARY};${UDEV_LIBRARY};${XINERAMA_LIBRARY}" CACHE INTERNAL "Oculus libraries") set(LIBOVR_LIBRARIES "${OVR_LIBRARY};${UDEV_LIBRARY};${XINERAMA_LIBRARY}" CACHE INTERNAL "Oculus libraries")
endif (UDEV_LIBRARY AND XINERAMA_LIBRARY AND OVR_LIBRARY) endif (UDEV_LIBRARY AND XINERAMA_LIBRARY AND OVR_LIBRARY)
elseif (WIN32) elseif (WIN32)
if (CMAKE_BUILD_TYPE MATCHES DEBUG) find_library(LIBOVR_RELEASE_LIBRARIES "Lib/Win32/libovr.lib" HINTS ${LIBOVR_SEARCH_DIRS})
set(WINDOWS_LIBOVR_NAME "libovrd.lib") find_library(LIBOVR_DEBUG_LIBRARIES "Lib/Win32/libovrd.lib" HINTS ${LIBOVR_SEARCH_DIRS})
else()
set(WINDOWS_LIBOVR_NAME "libovr.lib")
endif()
find_library(LIBOVR_LIBRARIES "Lib/Win32/${WINDOWS_LIBOVR_NAME}" HINTS ${LIBOVR_SEARCH_DIRS}) set(LIBOVR_LIBRARIES "${LIBOVR_RELEASE_LIBRARIES} ${LIBOVR_DEBUG_LIBRARIES}")
endif () endif ()
if (LIBOVR_INCLUDE_DIRS AND LIBOVR_LIBRARIES) if (LIBOVR_INCLUDE_DIRS AND LIBOVR_LIBRARIES)

View file

@ -183,7 +183,11 @@ if (LIBOVR_FOUND AND NOT DISABLE_LIBOVR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${LIBOVR_INCLUDE_DIRS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${LIBOVR_INCLUDE_DIRS}")
endif () endif ()
target_link_libraries(${TARGET_NAME} "${LIBOVR_LIBRARIES}") if (WIN32)
target_link_libraries(${TARGET_NAME} optimized "${LIBOVR_RELEASE_LIBRARIES}" debug "${LIBOVR_DEBUG_LIBRARIES}")
else()
target_link_libraries(${TARGET_NAME} "${LIBOVR_LIBRARIES}")
endif()
endif (LIBOVR_FOUND AND NOT DISABLE_LIBOVR) endif (LIBOVR_FOUND AND NOT DISABLE_LIBOVR)
# and with PrioVR library # and with PrioVR library

View file

@ -49,7 +49,6 @@ void main()
float timewarpMixFactor = color.a; float timewarpMixFactor = color.a;
mat4 mixedEyeRot = EyeRotationStart * mat4(1.0 - timewarpMixFactor) + EyeRotationEnd * mat4(timewarpMixFactor); mat4 mixedEyeRot = EyeRotationStart * mat4(1.0 - timewarpMixFactor) + EyeRotationEnd * mat4(timewarpMixFactor);
oTexCoord0 = TimewarpTexCoord(texCoord0, mixedEyeRot); oTexCoord0 = TimewarpTexCoord(texCoord0, mixedEyeRot);
oTexCoord1 = TimewarpTexCoord(texCoord1, mixedEyeRot); oTexCoord1 = TimewarpTexCoord(texCoord1, mixedEyeRot);
oTexCoord2 = TimewarpTexCoord(texCoord2, mixedEyeRot); oTexCoord2 = TimewarpTexCoord(texCoord2, mixedEyeRot);

View file

@ -3136,9 +3136,7 @@ void Application::resetSensors() {
_faceshift.reset(); _faceshift.reset();
_visage.reset(); _visage.reset();
if (OculusManager::isConnected()) { OculusManager::reset();
OculusManager::reset();
}
_prioVR.reset(); _prioVR.reset();

View file

@ -45,9 +45,11 @@ GLuint OculusManager::_vertices[ovrEye_Count] = { 0, 0 };
GLuint OculusManager::_indices[ovrEye_Count] = { 0, 0 }; GLuint OculusManager::_indices[ovrEye_Count] = { 0, 0 };
GLsizei OculusManager::_meshSize[ovrEye_Count] = { 0, 0 }; GLsizei OculusManager::_meshSize[ovrEye_Count] = { 0, 0 };
ovrFrameTiming OculusManager::_hmdFrameTiming; ovrFrameTiming OculusManager::_hmdFrameTiming;
ovrRecti OculusManager::_eyeRenderViewport[ovrEye_Count];
unsigned int OculusManager::_frameIndex = 0; unsigned int OculusManager::_frameIndex = 0;
bool OculusManager::_frameTimingActive = false; bool OculusManager::_frameTimingActive = false;
bool OculusManager::_programInitialized = false; bool OculusManager::_programInitialized = false;
Camera* OculusManager::_camera = NULL;
#endif #endif
@ -66,19 +68,25 @@ void OculusManager::connect() {
//Get texture size //Get texture size
ovrSizei recommendedTex0Size = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Left, ovrSizei recommendedTex0Size = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Left,
_ovrHmdDesc.DefaultEyeFov[0], 1.0f); _eyeFov[0], 1.0f);
ovrSizei recommendedTex1Size = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Right, ovrSizei recommendedTex1Size = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Right,
_ovrHmdDesc.DefaultEyeFov[1], 1.0f); _eyeFov[1], 1.0f);
_renderTargetSize.w = recommendedTex0Size.w + recommendedTex1Size.w; _renderTargetSize.w = recommendedTex0Size.w + recommendedTex1Size.w;
_renderTargetSize.h = recommendedTex0Size.h; _renderTargetSize.h = recommendedTex0Size.h;
if (_renderTargetSize.h < recommendedTex1Size.h) { if (_renderTargetSize.h < recommendedTex1Size.h) {
_renderTargetSize.h = recommendedTex1Size.h; _renderTargetSize.h = recommendedTex1Size.h;
} }
_renderTargetSize.w = Application::getInstance()->getGLWidget()->width();
_renderTargetSize.h = Application::getInstance()->getGLWidget()->height();
ovrHmd_StartSensor(_ovrHmd, ovrSensorCap_Orientation | ovrSensorCap_YawCorrection | ovrHmd_StartSensor(_ovrHmd, ovrSensorCap_Orientation | ovrSensorCap_YawCorrection |
ovrSensorCap_Position, ovrSensorCap_Position,
ovrSensorCap_Orientation); ovrSensorCap_Orientation);
if (!_camera) {
_camera = new Camera;
}
if (!_programInitialized) { if (!_programInitialized) {
// Shader program // Shader program
@ -146,18 +154,17 @@ void OculusManager::generateDistortionMesh() {
eyeDesc[0] = ovrHmd_GetRenderDesc(_ovrHmd, ovrEye_Left, _eyeFov[0]); eyeDesc[0] = ovrHmd_GetRenderDesc(_ovrHmd, ovrEye_Left, _eyeFov[0]);
eyeDesc[1] = ovrHmd_GetRenderDesc(_ovrHmd, ovrEye_Right, _eyeFov[1]); eyeDesc[1] = ovrHmd_GetRenderDesc(_ovrHmd, ovrEye_Right, _eyeFov[1]);
ovrRecti eyeRenderViewport[ovrEye_Count]; _eyeRenderViewport[0].Pos = Vector2i(0, 0);
eyeRenderViewport[0].Pos = Vector2i(0, 0); _eyeRenderViewport[0].Size = Sizei(_renderTargetSize.w / 2, _renderTargetSize.h);
eyeRenderViewport[0].Size = Sizei(_renderTargetSize.w / 2, _renderTargetSize.h); _eyeRenderViewport[1].Pos = Vector2i((_renderTargetSize.w + 1) / 2, 0);
eyeRenderViewport[1].Pos = Vector2i((_renderTargetSize.w + 1) / 2, 0); _eyeRenderViewport[1].Size = _eyeRenderViewport[0].Size;
eyeRenderViewport[1].Size = eyeRenderViewport[0].Size;
for (int eyeNum = 0; eyeNum < ovrEye_Count; eyeNum++) { for (int eyeNum = 0; eyeNum < ovrEye_Count; eyeNum++) {
// Allocate and generate distortion mesh vertices // Allocate and generate distortion mesh vertices
ovrDistortionMesh meshData; ovrDistortionMesh meshData;
ovrHmd_CreateDistortionMesh(_ovrHmd, eyeDesc[eyeNum].Eye, eyeDesc[eyeNum].Fov, _ovrHmdDesc.DistortionCaps, &meshData); ovrHmd_CreateDistortionMesh(_ovrHmd, eyeDesc[eyeNum].Eye, eyeDesc[eyeNum].Fov, _ovrHmdDesc.DistortionCaps, &meshData);
ovrHmd_GetRenderScaleAndOffset(eyeDesc[eyeNum].Fov, _renderTargetSize, eyeRenderViewport[eyeNum], ovrHmd_GetRenderScaleAndOffset(eyeDesc[eyeNum].Fov, _renderTargetSize, _eyeRenderViewport[eyeNum],
_UVScaleOffset[eyeNum]); _UVScaleOffset[eyeNum]);
// Parse the vertex data and create a render ready vertex buffer // Parse the vertex data and create a render ready vertex buffer
@ -235,9 +242,9 @@ void OculusManager::endFrameTiming() {
void OculusManager::configureCamera(Camera& camera, int screenWidth, int screenHeight) { void OculusManager::configureCamera(Camera& camera, int screenWidth, int screenHeight) {
#ifdef HAVE_LIBOVR #ifdef HAVE_LIBOVR
ovrSizei recommendedTex0Size = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Left, ovrSizei recommendedTex0Size = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Left,
_ovrHmdDesc.DefaultEyeFov[0], 1.0f); _eyeFov[0], 1.0f);
ovrSizei recommendedTex1Size = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Right, ovrSizei recommendedTex1Size = ovrHmd_GetFovTextureSize(_ovrHmd, ovrEye_Right,
_ovrHmdDesc.DefaultEyeFov[1], 1.0f); _eyeFov[1], 1.0f);
float width = recommendedTex0Size.w + recommendedTex1Size.w; float width = recommendedTex0Size.w + recommendedTex1Size.w;
float height = recommendedTex0Size.h; float height = recommendedTex0Size.h;
@ -273,37 +280,55 @@ void OculusManager::display(Camera& whichCamera) {
ovrPosef eyeRenderPose[ovrEye_Count]; ovrPosef eyeRenderPose[ovrEye_Count];
_camera->setTightness(0.0f); // In first person, camera follows (untweaked) head exactly without delay
_camera->setTargetPosition(whichCamera.getPosition());
if (!Menu::getInstance()->isOptionChecked(MenuOption::AllowOculusCameraModeChange) || whichCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
_camera->setDistance(0.0f);
}
_camera->setUpShift(0.0f);
_camera->setTightness(0.0f); // Cam
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); glPushMatrix();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
eyeRenderPose[0] = ovrHmd_GetEyePose(_ovrHmd, ovrEye_Left); glm::quat orientation;
eyeRenderPose[1] = ovrHmd_GetEyePose(_ovrHmd, ovrEye_Right);
for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++) { for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++) {
ovrEyeType eye = _ovrHmdDesc.EyeRenderOrder[eyeIndex]; ovrEyeType eye = _ovrHmdDesc.EyeRenderOrder[eyeIndex];
//Set the camera rotation for this eye
eyeRenderPose[eye] = ovrHmd_GetEyePose(_ovrHmd, eye);
orientation.x = eyeRenderPose[eye].Orientation.x;
orientation.y = eyeRenderPose[eye].Orientation.y;
orientation.z = eyeRenderPose[eye].Orientation.z;
orientation.w = eyeRenderPose[eye].Orientation.w;
_camera->setTargetRotation(orientation);
_camera->update(1.0f / Application::getInstance()->getFps());
Matrix4f proj = ovrMatrix4f_Projection(eyeDesc[eye].Fov, whichCamera.getNearClip(), whichCamera.getFarClip(), true); Matrix4f proj = ovrMatrix4f_Projection(eyeDesc[eye].Fov, whichCamera.getNearClip(), whichCamera.getFarClip(), true);
proj.Transpose(); proj.Transpose();
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glLoadMatrixf((GLfloat *)proj.M); glLoadMatrixf((GLfloat *)proj.M);
printf("%d %d\n", _renderTargetSize.w, _renderTargetSize.h);
glViewport(eyeDesc[eye].DistortedViewport.Pos.x, eyeDesc[eye].DistortedViewport.Pos.y, glViewport(_eyeRenderViewport[eye].Pos.x, _eyeRenderViewport[eye].Pos.y,
eyeDesc[eye].DistortedViewport.Size.w, eyeDesc[eye].DistortedViewport.Size.h); _eyeRenderViewport[eye].Size.w, _eyeRenderViewport[eye].Size.h);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(eyeDesc[eye].ViewAdjust.x, eyeDesc[eye].ViewAdjust.y, eyeDesc[eye].ViewAdjust.z); glTranslatef(eyeDesc[eye].ViewAdjust.x, eyeDesc[eye].ViewAdjust.y, eyeDesc[eye].ViewAdjust.z);
Application::getInstance()->displaySide(whichCamera); Application::getInstance()->displaySide(*_camera);
if (displayOverlays) { if (displayOverlays) {
applicationOverlay.displayOverlayTextureOculus(whichCamera); applicationOverlay.displayOverlayTextureOculus(*_camera);
} }
} }
@ -399,6 +424,7 @@ void OculusManager::getEulerAngles(float& yaw, float& pitch, float& roll) {
ovrPosef pose = ss.Predicted.Pose; ovrPosef pose = ss.Predicted.Pose;
Quatf orientation = Quatf(pose.Orientation); Quatf orientation = Quatf(pose.Orientation);
orientation.GetEulerAngles<Axis_Y, Axis_X, Axis_Z, Rotate_CCW, Handed_R>(&yaw, &pitch, &roll); orientation.GetEulerAngles<Axis_Y, Axis_X, Axis_Z, Rotate_CCW, Handed_R>(&yaw, &pitch, &roll);
printf("%f %f %f\n", yaw, pitch, roll);
} }
#endif #endif
} }

View file

@ -73,21 +73,21 @@ private:
static bool _isConnected; static bool _isConnected;
#ifdef HAVE_LIBOVR #ifdef HAVE_LIBOVR
static ovrHmd _ovrHmd; static ovrHmd _ovrHmd;
static ovrHmdDesc _ovrHmdDesc; static ovrHmdDesc _ovrHmdDesc;
static ovrFovPort _eyeFov[ovrEye_Count]; static ovrFovPort _eyeFov[ovrEye_Count];
static ovrSizei _renderTargetSize; static ovrSizei _renderTargetSize;
static ovrVector2f _UVScaleOffset[ovrEye_Count][2]; static ovrVector2f _UVScaleOffset[ovrEye_Count][2];
static GLuint _vbo[ovrEye_Count]; static GLuint _vertices[ovrEye_Count];
static GLuint _indicesVbo[ovrEye_Count]; static GLuint _indices[ovrEye_Count];
static GLsizei _meshSize[ovrEye_Count]; static GLsizei _meshSize[ovrEye_Count];
static ovrFrameTiming _hmdFrameTiming; static ovrFrameTiming _hmdFrameTiming;
static ovrRecti _eyeRenderViewport[ovrEye_Count];
static unsigned int _frameIndex; static unsigned int _frameIndex;
static bool _frameTimingActive; static bool _frameTimingActive;
static bool _programInitialized; static bool _programInitialized;
static Camera* _camera;
#endif #endif
}; };