refining the avatar display name rendering with different behavior if in HMD mode or not

This commit is contained in:
dev 2014-11-19 11:46:59 -08:00
parent c2adc6256e
commit fc54ad93b8
3 changed files with 35 additions and 13 deletions

View file

@ -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()
//

View file

@ -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.

View file

@ -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