mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 09:17:29 +02:00
commit
df7ffb35e1
3 changed files with 23 additions and 16 deletions
|
@ -59,6 +59,7 @@ const float CHAT_MESSAGE_HEIGHT = 0.1f;
|
||||||
const float DISPLAYNAME_FADE_TIME = 0.5f;
|
const float DISPLAYNAME_FADE_TIME = 0.5f;
|
||||||
const float DISPLAYNAME_FADE_FACTOR = pow(0.01f, 1.0f / DISPLAYNAME_FADE_TIME);
|
const float DISPLAYNAME_FADE_FACTOR = pow(0.01f, 1.0f / DISPLAYNAME_FADE_TIME);
|
||||||
const float DISPLAYNAME_ALPHA = 0.95f;
|
const float DISPLAYNAME_ALPHA = 0.95f;
|
||||||
|
const float DISPLAYNAME_BACKGROUND_ALPHA = 0.4f;
|
||||||
|
|
||||||
Avatar::Avatar() :
|
Avatar::Avatar() :
|
||||||
AvatarData(),
|
AvatarData(),
|
||||||
|
@ -217,7 +218,7 @@ void Avatar::render(bool forceRenderHead) {
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const float DISPLAYNAME_DISTANCE = 4.0f;
|
const float DISPLAYNAME_DISTANCE = 10.0f;
|
||||||
setShowDisplayName(lengthToTarget < DISPLAYNAME_DISTANCE);
|
setShowDisplayName(lengthToTarget < DISPLAYNAME_DISTANCE);
|
||||||
renderDisplayName();
|
renderDisplayName();
|
||||||
|
|
||||||
|
@ -300,7 +301,10 @@ void Avatar::renderDisplayName() {
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
glPushMatrix();
|
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);
|
glTranslatef(textPosition.x, textPosition.y, textPosition.z);
|
||||||
|
|
||||||
// we need "always facing camera": we must remove the camera rotation from the stack
|
// 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;
|
float scaleFactor = (textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f;
|
||||||
glScalef(scaleFactor, scaleFactor, 1.0);
|
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
|
// draw a gray background
|
||||||
QFontMetrics metrics = textRenderer(DISPLAYNAME)->metrics();
|
int left = text_x + _displayNameBoundingRect.x();
|
||||||
int bottom = -metrics.descent(), top = bottom + metrics.height();
|
int right = left + _displayNameBoundingRect.width();
|
||||||
int left = -_displayNameWidth/2, right = _displayNameWidth/2;
|
int bottom = text_y + _displayNameBoundingRect.y();
|
||||||
const int border = 5;
|
int top = bottom + _displayNameBoundingRect.height();
|
||||||
|
const int border = 8;
|
||||||
bottom -= border;
|
bottom -= border;
|
||||||
left -= border;
|
left -= border;
|
||||||
top += border;
|
top += border;
|
||||||
|
@ -353,7 +363,7 @@ void Avatar::renderDisplayName() {
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
glPolygonOffset(1.0f, 1.0f);
|
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);
|
glBegin(GL_QUADS);
|
||||||
glVertex2f(left, bottom);
|
glVertex2f(left, bottom);
|
||||||
glVertex2f(right, bottom);
|
glVertex2f(right, bottom);
|
||||||
|
@ -361,14 +371,14 @@ void Avatar::renderDisplayName() {
|
||||||
glVertex2f(left, top);
|
glVertex2f(left, top);
|
||||||
glEnd();
|
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);
|
glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha);
|
||||||
|
|
||||||
QByteArray ba = _displayName.toLocal8Bit();
|
QByteArray ba = _displayName.toLocal8Bit();
|
||||||
const char* text = ba.data();
|
const char* text = ba.data();
|
||||||
|
|
||||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
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) {
|
void Avatar::setDisplayName(const QString& displayName) {
|
||||||
AvatarData::setDisplayName(displayName);
|
AvatarData::setDisplayName(displayName);
|
||||||
int width = 0;
|
_displayNameBoundingRect = textRenderer(DISPLAYNAME)->metrics().tightBoundingRect(displayName);
|
||||||
for (int i = 0; i < displayName.size(); i++) {
|
|
||||||
width += (textRenderer(DISPLAYNAME)->computeWidth(displayName[i].toLatin1()));
|
|
||||||
}
|
|
||||||
_displayNameWidth = width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Avatar::parseData(const QByteArray& packet) {
|
int Avatar::parseData(const QByteArray& packet) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ AvatarData::AvatarData() :
|
||||||
_isChatCirclingEnabled(false),
|
_isChatCirclingEnabled(false),
|
||||||
_headData(NULL),
|
_headData(NULL),
|
||||||
_handData(NULL),
|
_handData(NULL),
|
||||||
_displayNameWidth(0),
|
_displayNameBoundingRect(),
|
||||||
_displayNameTargetAlpha(0.0f),
|
_displayNameTargetAlpha(0.0f),
|
||||||
_displayNameAlpha(0.0f)
|
_displayNameAlpha(0.0f)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,7 @@ typedef unsigned long long quint64;
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtCore/QUuid>
|
#include <QtCore/QUuid>
|
||||||
#include <QtCore/QVariantMap>
|
#include <QtCore/QVariantMap>
|
||||||
|
#include <QRect>
|
||||||
|
|
||||||
#include <CollisionInfo.h>
|
#include <CollisionInfo.h>
|
||||||
#include <RegisteredMetaTypes.h>
|
#include <RegisteredMetaTypes.h>
|
||||||
|
@ -187,7 +188,7 @@ protected:
|
||||||
QUrl _skeletonModelURL;
|
QUrl _skeletonModelURL;
|
||||||
QString _displayName;
|
QString _displayName;
|
||||||
|
|
||||||
int _displayNameWidth;
|
QRect _displayNameBoundingRect;
|
||||||
float _displayNameTargetAlpha;
|
float _displayNameTargetAlpha;
|
||||||
float _displayNameAlpha;
|
float _displayNameAlpha;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue