diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 66b96cf132..4e8b95862a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2673,6 +2673,14 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node } } +bool Application::isHMDMode() const { + if (OculusManager::isConnected()) { + return true; + } else { + return false; + } +} + ///////////////////////////////////////////////////////////////////////////////////// // loadViewFrustum() // diff --git a/interface/src/Application.h b/interface/src/Application.h index 2c70249b32..c75202d96f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -316,6 +316,11 @@ public: void registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine); + // the isHMDmode is true whenever we use the interface from an HMD and not a standard flat display + // rendering of several elements depend on that + // TODO: carry that information on the Camera as a setting + bool isHMDMode() const; + signals: /// Fired when we're simulating; allows external parties to hook in. diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 5741d6b265..9dcfb37fb7 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -655,7 +655,10 @@ void Avatar::renderDisplayName() { if (_displayName.isEmpty() || _displayNameAlpha == 0.0f) { return; } - + + // which viewing mode? + bool inHMD = Application::getInstance()->isHMDMode(); + glDisable(GL_LIGHTING); glPushMatrix(); @@ -664,17 +667,17 @@ void Avatar::renderDisplayName() { glTranslatef(textPosition.x, textPosition.y, textPosition.z); // we need "always facing camera": we must remove the camera rotation from the stack - glm::quat rotation = Application::getInstance()->getCamera()->getRotation(); - 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)); - - // 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)); + glm::vec3 frontAxis(0.f, 0.f, 1.f); + if (inHMD) { + glm::vec3 camPosition = Application::getInstance()->getCamera()->getPosition(); + frontAxis = camPosition - textPosition; + } else { + glm::quat rotation = Application::getInstance()->getCamera()->getRotation(); + frontAxis = glm::rotate(rotation, frontAxis); + } + 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); @@ -706,10 +709,16 @@ void Avatar::renderDisplayName() { if (success) { double textWindowHeight = abs(result1[1] - result0[1]); - float scaleFactor = Application::getInstance()->getRenderResolutionScale() * // Scale compensate for the resolution - QApplication::desktop()->windowHandle()->devicePixelRatio() * // And the device pixel ratio + // need to scale to compensate for the font resolution due to the device + float scaleFactor = QApplication::desktop()->windowHandle()->devicePixelRatio() * ((textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f); - glScalef(scaleFactor, scaleFactor, 1.0); + if (inHMD) { + const float HMDMODE_NAME_SCALE = 0.65f; + scaleFactor *= HMDMODE_NAME_SCALE; + } else { + scaleFactor *= Application::getInstance()->getRenderResolutionScale(); + } + glScalef(scaleFactor, scaleFactor, 1.0); glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis