diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 73ec791714..3d54b7d1cb 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -554,6 +554,78 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int } +void renderBeverCornersRect(int x, int y, int width, int height, int bevelDistance) { + glBegin(GL_POLYGON); + + // left side + glVertex2f(x, y + bevelDistance); + glVertex2f(x, y + height - bevelDistance); + + // top side + glVertex2f(x + bevelDistance, y + height); + glVertex2f(x + width - bevelDistance, y + height); + + // right + glVertex2f(x + width, y + height - bevelDistance); + glVertex2f(x + width, y + bevelDistance); + + // bottom + glVertex2f(x + width - bevelDistance, y); + glVertex2f(x +bevelDistance, y); + + glEnd(); +} + +void renderRoundedCornersRect(int x, int y, int width, int height, int radius, int numPointsCorner) { +#define MAX_POINTS_CORNER 50 + // At least "2" is needed + if (numPointsCorner <= 1) { + return; + } + if (numPointsCorner > MAX_POINTS_CORNER) { + numPointsCorner = MAX_POINTS_CORNER; + } + + // Precompute sin and cos for [0, pi/2) for the number of points (numPointCorner) + double radiusTimesSin[MAX_POINTS_CORNER]; + double radiusTimesCos[MAX_POINTS_CORNER]; + int i = 0; + for (int i = 0; i < numPointsCorner; i++) { + double t = i * PIf / (2.0f * (numPointsCorner - 1)); + radiusTimesSin[i] = radius * sin(t); + radiusTimesCos[i] = radius * cos(t); + } + + glm::dvec2 cornerCenter; + glBegin(GL_POINTS); + + // Top left corner + cornerCenter = glm::vec2(x + radius, y + height - radius); + for (i = 0; i < numPointsCorner; i++) { + glVertex2d(cornerCenter.x - radiusTimesCos[i], cornerCenter.y + radiusTimesSin[i]); + } + + // Top rigth corner + cornerCenter = glm::vec2(x + width - radius, y + height - radius); + for (i = 0; i < numPointsCorner; i++) { + glVertex2d(cornerCenter.x + radiusTimesSin[i], cornerCenter.y + radiusTimesCos[i]); + } + + // Bottom right + cornerCenter = glm::vec2(x + width - radius, y + radius); + for (i = 0; i < numPointsCorner; i++) { + glVertex2d(cornerCenter.x + radiusTimesCos[i], cornerCenter.y - radiusTimesSin[i]); + } + + // Bottom left + cornerCenter = glm::vec2(x + radius, y + radius); + for (i = 0; i < numPointsCorner; i++) { + glVertex2d(cornerCenter.x - radiusTimesSin[i], cornerCenter.y - radiusTimesCos[i]); + } + glEnd(); +} + + void renderOrientationDirections(glm::vec3 position, const glm::quat& orientation, float size) { glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; glm::vec3 pUp = position + orientation * IDENTITY_UP * size; diff --git a/interface/src/Util.h b/interface/src/Util.h index 0c762ccd79..967279ce5e 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -73,6 +73,8 @@ void renderOrientationDirections( glm::vec3 position, const glm::quat& orientati void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition); void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides ); +void renderRoundedCornersRect(int x, int y, int width, int height, int radius, int numPointsCorner); +void renderBeverCornersRect(int x, int y, int width, int height, int bevelDistance); void runTimingTests(); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index dcecd0258d..3bb1143598 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -307,10 +307,19 @@ void Avatar::renderDisplayName() { glTranslatef(textPosition.x, textPosition.y, textPosition.z); + glm::dmat4 modelViewMatrix2; + glGetDoublev(GL_MODELVIEW_MATRIX, (GLdouble*)&modelViewMatrix2); + modelViewMatrix2[0][0] = 1; + modelViewMatrix2[1][1] = 1; + modelViewMatrix2[2][2] = 1; + modelViewMatrix2[0][1] = modelViewMatrix2[0][2] = 0; + modelViewMatrix2[1][0] = modelViewMatrix2[1][2] = 0; + modelViewMatrix2[2][0] = modelViewMatrix2[2][1] = 0; + glLoadMatrixd((GLdouble*)&modelViewMatrix2); // 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::angle(rotation), axis.x, axis.y, axis.z); + // glm::quat rotation = Application::getInstance()->getCamera()->getRotation(); + // glm::vec3 axis = glm::axis(rotation); + // glRotatef(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 @@ -364,12 +373,10 @@ void Avatar::renderDisplayName() { glPolygonOffset(1.0f, 1.0f); glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA); - glBegin(GL_QUADS); - glVertex2f(left, bottom); - glVertex2f(right, bottom); - glVertex2f(right, top); - glVertex2f(left, top); - glEnd(); + // glColor4f(1.0f, 0.2f, 0.2f, 1.0f); + // glScalef(10,10, 1); + + renderBeverCornersRect(left, bottom, right - left, top - bottom, 3); glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha);