Merge branch 'master' of https://github.com/highfidelity/hifi into bilbo

This commit is contained in:
Andrzej Kapolka 2014-02-21 09:27:16 -08:00
commit 0d0e9565ff
3 changed files with 23 additions and 16 deletions

View file

@ -59,6 +59,7 @@ const float CHAT_MESSAGE_HEIGHT = 0.1f;
const float DISPLAYNAME_FADE_TIME = 0.5f;
const float DISPLAYNAME_FADE_FACTOR = pow(0.01f, 1.0f / DISPLAYNAME_FADE_TIME);
const float DISPLAYNAME_ALPHA = 0.95f;
const float DISPLAYNAME_BACKGROUND_ALPHA = 0.4f;
Avatar::Avatar() :
AvatarData(),
@ -217,7 +218,7 @@ void Avatar::render(bool forceRenderHead) {
glPopMatrix();
}
}
const float DISPLAYNAME_DISTANCE = 4.0f;
const float DISPLAYNAME_DISTANCE = 10.0f;
setShowDisplayName(lengthToTarget < DISPLAYNAME_DISTANCE);
renderDisplayName();
@ -300,7 +301,10 @@ void Avatar::renderDisplayName() {
glDisable(GL_LIGHTING);
glPushMatrix();
glm::vec3 textPosition = getPosition() + getBodyUpDirection() * ((getSkeletonHeight() + getHeadHeight()) / 1.5f);
glm::vec3 textPosition;
getSkeletonModel().getNeckPosition(textPosition);
textPosition += getBodyUpDirection() * getHeadHeight() * 1.1f;
glTranslatef(textPosition.x, textPosition.y, textPosition.z);
// we need "always facing camera": we must remove the camera rotation from the stack
@ -339,11 +343,17 @@ void Avatar::renderDisplayName() {
float scaleFactor = (textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f;
glScalef(scaleFactor, scaleFactor, 1.0);
glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis
int text_x = -_displayNameBoundingRect.width() / 2;
int text_y = -_displayNameBoundingRect.height() / 2;
// draw a gray background
QFontMetrics metrics = textRenderer(DISPLAYNAME)->metrics();
int bottom = -metrics.descent(), top = bottom + metrics.height();
int left = -_displayNameWidth/2, right = _displayNameWidth/2;
const int border = 5;
int left = text_x + _displayNameBoundingRect.x();
int right = left + _displayNameBoundingRect.width();
int bottom = text_y + _displayNameBoundingRect.y();
int top = bottom + _displayNameBoundingRect.height();
const int border = 8;
bottom -= border;
left -= border;
top += border;
@ -353,7 +363,7 @@ void Avatar::renderDisplayName() {
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha);
glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA);
glBegin(GL_QUADS);
glVertex2f(left, bottom);
glVertex2f(right, bottom);
@ -361,14 +371,14 @@ void Avatar::renderDisplayName() {
glVertex2f(left, top);
glEnd();
glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis
glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha);
QByteArray ba = _displayName.toLocal8Bit();
const char* text = ba.data();
glDisable(GL_POLYGON_OFFSET_FILL);
textRenderer(DISPLAYNAME)->draw(-_displayNameWidth / 2, 0, text);
textRenderer(DISPLAYNAME)->draw(text_x, text_y, text);
}
@ -489,11 +499,7 @@ void Avatar::setSkeletonModelURL(const QUrl &skeletonModelURL) {
void Avatar::setDisplayName(const QString& displayName) {
AvatarData::setDisplayName(displayName);
int width = 0;
for (int i = 0; i < displayName.size(); i++) {
width += (textRenderer(DISPLAYNAME)->computeWidth(displayName[i].toLatin1()));
}
_displayNameWidth = width;
_displayNameBoundingRect = textRenderer(DISPLAYNAME)->metrics().tightBoundingRect(displayName);
}
int Avatar::parseData(const QByteArray& packet) {

View file

@ -36,7 +36,7 @@ AvatarData::AvatarData() :
_isChatCirclingEnabled(false),
_headData(NULL),
_handData(NULL),
_displayNameWidth(0),
_displayNameBoundingRect(),
_displayNameTargetAlpha(0.0f),
_displayNameAlpha(0.0f)
{

View file

@ -33,6 +33,7 @@ typedef unsigned long long quint64;
#include <QtCore/QUrl>
#include <QtCore/QUuid>
#include <QtCore/QVariantMap>
#include <QRect>
#include <CollisionInfo.h>
#include <RegisteredMetaTypes.h>
@ -187,7 +188,7 @@ protected:
QUrl _skeletonModelURL;
QString _displayName;
int _displayNameWidth;
QRect _displayNameBoundingRect;
float _displayNameTargetAlpha;
float _displayNameAlpha;