From 4028e66c084d62de7e29933f650885559cf0198b Mon Sep 17 00:00:00 2001 From: dev Date: Tue, 18 Nov 2014 18:59:54 -0800 Subject: [PATCH 1/2] trying to fix the lighting issue in stereo and fix the display name size and orientation --- interface/src/Application.cpp | 7 +++++++ interface/src/avatar/Avatar.cpp | 15 ++++++++++++--- interface/src/devices/OculusManager.cpp | 8 +++++--- interface/src/ui/TextRenderer.cpp | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 31be016380..4160883848 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2926,6 +2926,13 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr if (whichCamera.getMode() == CAMERA_MODE_MIRROR) { viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f)); } + if (renderSide != RenderArgs::MONO) { + glm::mat4 invView = glm::inverse(_untranslatedViewMatrix); + + viewTransform.evalFromRawMatrix(invView); + viewTransform.preTranslate(_viewMatrixTranslation); + } + setViewTransform(viewTransform); glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index e29f68e585..549a33c856 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -664,8 +665,15 @@ void Avatar::renderDisplayName() { // we need "always facing camera": we must remove the camera rotation from the stack glm::quat rotation = Application::getInstance()->getCamera()->getRotation(); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + + glm::vec3 frontAxis(0.f, 0.f, 1.f); + frontAxis = glm::rotate(rotation, frontAxis); + frontAxis = glm::normalize(glm::vec3(frontAxis.x, 0.f, frontAxis.z)); + glm::vec3 euler = glm::eulerAngles(rotation); + float angle = acos(frontAxis.z) * ((frontAxis.y < 0) ? 1.f : -1.f); + //glm::vec3 axis = glm::axis(rotation); + glRotatef(glm::degrees(-euler.y), 0.0f, 1.0f, 0.0f); + //angleglRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates // We project a unit vector and check the difference in screen coordinates, to check which is the @@ -695,7 +703,8 @@ void Avatar::renderDisplayName() { if (success) { double textWindowHeight = abs(result1[1] - result0[1]); - float scaleFactor = Application::getInstance()->getRenderResolutionScale() * + float scaleFactor = Application::getInstance()->getRenderResolutionScale() * // Scale compensate for the resolution + QApplication::desktop()->windowHandle()->devicePixelRatio() * // And the device pixel ratio ((textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f); glScalef(scaleFactor, scaleFactor, 1.0); diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 80ad9e5ef5..8d6d11dd68 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -524,13 +524,15 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p glViewport(_eyeRenderViewport[eye].Pos.x, _eyeRenderViewport[eye].Pos.y, _eyeRenderViewport[eye].Size.w, _eyeRenderViewport[eye].Size.h); - // Apply the offset for the left or right eye on the projection matrix - glTranslatef(_eyeRenderDesc[eye].ViewAdjust.x, _eyeRenderDesc[eye].ViewAdjust.y, _eyeRenderDesc[eye].ViewAdjust.z); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + + // HACK: instead of passing the stereo eye offset directly in the matrix, pass it in the camera offset + //glTranslatef(_eyeRenderDesc[eye].ViewAdjust.x, _eyeRenderDesc[eye].ViewAdjust.y, _eyeRenderDesc[eye].ViewAdjust.z); - Application::getInstance()->displaySide(*_camera, false, renderSide); + _camera->setEyeOffsetPosition(glm::vec3(-_eyeRenderDesc[eye].ViewAdjust.x, -_eyeRenderDesc[eye].ViewAdjust.y, -_eyeRenderDesc[eye].ViewAdjust.z)); + Application::getInstance()->displaySide(*_camera, false, RenderArgs::MONO); applicationOverlay.displayOverlayTextureOculus(*_camera); _activeEyeIndex = -1; diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp index 65725ab4ec..395847f265 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/interface/src/ui/TextRenderer.cpp @@ -95,7 +95,7 @@ int TextRenderer::draw(int x, int y, const char* str, float alpha) { maxHeight = glyph.bounds().height(); } //glBindTexture(GL_TEXTURE_2D, glyph.textureID()); - + int left = x + glyph.bounds().x(); int right = x + glyph.bounds().x() + glyph.bounds().width(); int bottom = y + glyph.bounds().y(); From 2e19ad48a79dee20aa4003fc958a55664349c6ca Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 19 Nov 2014 00:50:59 -0800 Subject: [PATCH 2/2] ready for pull request --- interface/src/avatar/Avatar.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 549a33c856..5741d6b265 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -666,14 +666,17 @@ void Avatar::renderDisplayName() { // we need "always facing camera": we must remove the camera rotation from the stack glm::quat rotation = Application::getInstance()->getCamera()->getRotation(); - glm::vec3 frontAxis(0.f, 0.f, 1.f); + glm::vec3 frontAxis(1.f, 0.f, 0.f); frontAxis = glm::rotate(rotation, frontAxis); frontAxis = glm::normalize(glm::vec3(frontAxis.x, 0.f, frontAxis.z)); - glm::vec3 euler = glm::eulerAngles(rotation); - float angle = acos(frontAxis.z) * ((frontAxis.y < 0) ? 1.f : -1.f); - //glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(-euler.y), 0.0f, 1.0f, 0.0f); - //angleglRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + + // TODO : test this secodn solution which should be better wfor occulus + //glm::vec3 camPosition = Application::getInstance()->getCamera()->getPosition(); + //glm::vec3 frontAxis = camPosition - textPosition; + //frontAxis = glm::normalize(glm::vec3(frontAxis.z, 0.f, -frontAxis.x)); + + float angle = acos(frontAxis.x) * ((frontAxis.z < 0) ? 1.f : -1.f); + glRotatef(glm::degrees(angle), 0.0f, 1.0f, 0.0f); // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates // We project a unit vector and check the difference in screen coordinates, to check which is the