Merge pull request #1048 from OpenSpace/feature/distancelabels

Feature/distancelabels
This commit is contained in:
Alexander Bock
2020-01-24 21:09:16 +01:00
committed by GitHub
9 changed files with 415 additions and 95 deletions
+22 -51
View File
@@ -31,19 +31,19 @@
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/glm.h>
#include <ghoul/filesystem/cachemanager.h>
#include <ghoul/misc/crc32.h>
#include <ghoul/misc/templatefactory.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/font/fontmanager.h>
#include <ghoul/font/fontrenderer.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/crc32.h>
#include <ghoul/misc/defer.h>
#include <ghoul/misc/templatefactory.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/glm.h>
#include <glm/gtx/string_cast.hpp>
namespace {
@@ -640,8 +640,8 @@ void RenderableLabels::render(const RenderData& data, RendererTasks&) {
data.camera.positionVec3(),
data.modelTransform.translation
);
float sUnit = getUnit(_fadeStartUnitOption);
float eUnit = getUnit(_fadeEndUnitOption);
float sUnit = unit(_fadeStartUnitOption);
float eUnit = unit(_fadeEndUnitOption);
float startX = _fadeStartDistance * sUnit;
float endX = _fadeEndDistance * eUnit;
//fadeInVariable = changedPerlinSmoothStepFunc(distanceNodeToCamera, startX, endX);
@@ -683,8 +683,6 @@ void RenderableLabels::render(const RenderData& data, RendererTasks&) {
//}
}
void RenderableLabels::update(const UpdateData&) {
}
void RenderableLabels::setLabelText(const std::string & newText) {
_labelText = newText;
@@ -768,49 +766,22 @@ float RenderableLabels::linearSmoothStepFunc(float x, float startX, float endX,
}
}
float RenderableLabels::getUnit(int unit) const {
float scale = 0.f;
float RenderableLabels::unit(int unit) const {
switch (static_cast<Unit>(unit)) {
case Meter:
scale = 1.f;
break;
case Kilometer:
scale = 1e3;
break;
case Megameter:
scale = 1e6;
break;
case Gigameter:
scale = 1e9;
break;
case AU:
scale = 149597870700.f;
break;
case Terameter:
scale = 1e12;
break;
case Petameter:
scale = 1e15;
break;
case Parsec:
scale = static_cast<float>(PARSEC);
break;
case Kiloparsec:
scale = static_cast<float>(1e3 * PARSEC);
break;
case Megaparsec:
scale = static_cast<float>(1e6 * PARSEC);
break;
case Gigaparsec:
scale = static_cast<float>(1e9 * PARSEC);
break;
case GigalightYears:
scale = static_cast<float>(306391534.73091 * PARSEC);
break;
case Meter: return 1.f;
case Kilometer: return 1e3;
case Megameter: return 1e6;
case Gigameter: return 1e9;
case AU: return 149597870700.f;
case Terameter: return 1e12;
case Petameter: return 1e15;
case Parsec: return static_cast<float>(PARSEC);
case Kiloparsec: return static_cast<float>(1e3 * PARSEC);
case Megaparsec: return static_cast<float>(1e6 * PARSEC);
case Gigaparsec: return static_cast<float>(1e9 * PARSEC);
case GigalightYears: return static_cast<float>(306391534.73091 * PARSEC);
default: throw std::logic_error("Missing case label");
}
return scale;
}
} // namespace openspace
+7 -8
View File
@@ -64,7 +64,6 @@ public:
bool isReady() const override;
void render(const RenderData& data, RendererTasks& rendererTask) override;
void update(const UpdateData& data) override;
static documentation::Documentation Documentation();
@@ -73,7 +72,12 @@ public:
protected:
properties::OptionProperty _blendMode;
private:
float unit(int unit) const;
// Data may require some type of transformation prior the spice transformation being
// applied.
glm::dmat4 _transformationMatrix = glm::dmat4(1.0);
enum Unit {
Meter = 0,
Kilometer,
@@ -89,6 +93,7 @@ private:
GigalightYears
};
private:
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable);
@@ -97,8 +102,6 @@ private:
float linearSmoothStepFunc(float x, float startX, float endX, float sUnit,
float eUnit) const;
float getUnit(int unit) const;
properties::Vec4Property _labelColor;
properties::FloatProperty _labelSize;
properties::FloatProperty _fontSize;
@@ -123,10 +126,6 @@ private:
std::string _labelFile;
std::string _colorOptionString;
std::string _datavarSizeOptionString;
// Data may require some type of transformation prior the spice transformation being
// applied.
glm::dmat4 _transformationMatrix = glm::dmat4(1.0);
};
} // namespace openspace
+75 -31
View File
@@ -34,9 +34,11 @@
#include <openspace/scene/translation.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/programobject.h>
namespace {
constexpr const char* _loggerCat = "RenderableNodeLine";
constexpr const char* ProgramName = "NodeLineProgram";
constexpr const char* Root = "Root";
@@ -44,12 +46,14 @@ namespace {
"StartNode",
"Start Node",
"The identifier of the node the line starts from. "
"Defaults to 'Root' if not specified. "
};
constexpr openspace::properties::Property::PropertyInfo EndNodeInfo = {
"EndNode",
"End Node",
"The identifier of the node the line ends at. "
"Defaults to 'Root' if not specified. "
};
constexpr openspace::properties::Property::PropertyInfo LineColorInfo = {
@@ -63,6 +67,22 @@ namespace {
"Line Width",
"This value specifies the line width."
};
// Returns a position that is relative to the current anchor node. This is a method to
// handle precision problems that occur when approaching a line end point
glm::dvec3 coordinatePosFromAnchorNode(const glm::dvec3& worldPos) {
using namespace openspace;
glm::dvec3 anchorNodePos(0.0);
const interaction::OrbitalNavigator& nav =
global::navigationHandler.orbitalNavigator();
if (nav.anchorNode()) {
anchorNodePos = nav.anchorNode()->worldPosition();
}
glm::dvec3 diffPos = worldPos - anchorNodePos;
return diffPos;
}
} // namespace
namespace openspace {
@@ -76,13 +96,13 @@ documentation::Documentation RenderableNodeLine::Documentation() {
{
StartNodeInfo.identifier,
new StringVerifier,
Optional::No,
Optional::Yes,
StartNodeInfo.description
},
{
EndNodeInfo.identifier,
new StringVerifier,
Optional::No,
Optional::Yes,
EndNodeInfo.description
},
{
@@ -114,8 +134,13 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
"RenderableNodeLine"
);
_start = dictionary.value<std::string>(StartNodeInfo.identifier);
_end = dictionary.value<std::string>(EndNodeInfo.identifier);
if (dictionary.hasKey(StartNodeInfo.identifier)) {
_start = dictionary.value<std::string>(StartNodeInfo.identifier);
}
if (dictionary.hasKey(EndNodeInfo.identifier)) {
_end = dictionary.value<std::string>(EndNodeInfo.identifier);
}
if (dictionary.hasKey(LineColorInfo.identifier)) {
_lineColor = dictionary.value<glm::vec3>(LineColorInfo.identifier);
@@ -124,6 +149,9 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
_lineWidth = static_cast<float>(dictionary.value<double>(LineWidthInfo.identifier));
}
_start.onChange([&]() { validateNodes(); });
_end.onChange([&]() { validateNodes(); });
addProperty(_start);
addProperty(_end);
addProperty(_lineColor);
@@ -131,6 +159,18 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
addProperty(_opacity);
}
double RenderableNodeLine::distance() const {
return glm::distance(_startPos, _endPos);
}
std::string RenderableNodeLine::start() const {
return _start;
}
std::string RenderableNodeLine::end() const {
return _end;
}
void RenderableNodeLine::initializeGL() {
_program = BaseModule::ProgramObjectManager.request(
ProgramName,
@@ -156,7 +196,6 @@ void RenderableNodeLine::initializeGL() {
}
void RenderableNodeLine::deinitializeGL() {
glDeleteVertexArrays(1, &_vaoId);
_vaoId = 0;
@@ -183,19 +222,21 @@ void RenderableNodeLine::unbindGL() {
glBindVertexArray(0);
}
void RenderableNodeLine::bindGL()
{
void RenderableNodeLine::bindGL() {
glBindVertexArray(_vaoId);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferId);
}
void RenderableNodeLine::updateVertexData()
{
void RenderableNodeLine::updateVertexData() {
_vertexArray.clear();
// Update the positions of the nodes
_startPos = getCoordinatePosFromAnchorNode(global::renderEngine.scene()->sceneGraphNode(_start)->worldPosition());
_endPos = getCoordinatePosFromAnchorNode(global::renderEngine.scene()->sceneGraphNode(_end)->worldPosition());
_startPos = coordinatePosFromAnchorNode(
global::renderEngine.scene()->sceneGraphNode(_start)->worldPosition()
);
_endPos = coordinatePosFromAnchorNode(
global::renderEngine.scene()->sceneGraphNode(_end)->worldPosition()
);
_vertexArray.push_back(_startPos.x);
_vertexArray.push_back(_startPos.y);
@@ -215,14 +256,13 @@ void RenderableNodeLine::updateVertexData()
GL_DYNAMIC_DRAW
);
//update vertex attributes
// update vertex attributes
glVertexAttribPointer(_locVertex, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
unbindGL();
}
void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
updateVertexData();
_program->activate();
@@ -230,7 +270,10 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
glm::dmat4 anchorTranslation(1.0);
// Update anchor node information, used to counter precision problems
if (global::navigationHandler.orbitalNavigator().anchorNode()) {
anchorTranslation = glm::translate(glm::dmat4(1.0), global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition());
anchorTranslation = glm::translate(
glm::dmat4(1.0),
global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition()
);
}
const glm::dmat4 modelTransform =
@@ -251,8 +294,12 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLenum blendEquationRGB, blendEquationAlpha, blendDestAlpha,
blendDestRGB, blendSrcAlpha, blendSrcRGB;
GLenum blendEquationRGB;
GLenum blendEquationAlpha;
GLenum blendDestAlpha;
GLenum blendDestRGB;
GLenum blendSrcAlpha;
GLenum blendSrcRGB;
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
@@ -284,22 +331,19 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
}
}
/* Returns a position that is relative to the current
anchor node. This is a method to handle precision
problems that occur when approaching a line end point */
glm::dvec3 RenderableNodeLine::getCoordinatePosFromAnchorNode(glm::dvec3 worldPos) {
glm::dvec3 anchorNodePos(0);
if (global::navigationHandler.orbitalNavigator().anchorNode()) {
anchorNodePos = global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition();
void RenderableNodeLine::validateNodes() {
if (!global::renderEngine.scene()->sceneGraphNode(_start)) {
LERROR(fmt::format(
"There is no scenegraph node with id {}, defaults to 'Root'", _start
));
_start = Root;
}
if (!global::renderEngine.scene()->sceneGraphNode(_end)) {
LERROR(fmt::format(
"There is no scenegraph node with id {}, defaults to 'Root'", _end
));
_end = Root;
}
glm::dvec3 diffPos = glm::dvec3(worldPos.x - anchorNodePos.x, worldPos.y - anchorNodePos.y,
worldPos.z - anchorNodePos.z);
return diffPos;
}
} // namespace openspace
+9 -5
View File
@@ -34,11 +34,10 @@
#include <ghoul/glm.h>
namespace ghoul::opengl { class ProgramObject; }
namespace openspace::documentation { struct Documentation; }
namespace openspace {
namespace documentation { struct Documentation; }
class Translation;
/**
@@ -50,7 +49,13 @@ public:
~RenderableNodeLine() = default;
static documentation::Documentation Documentation();
// Get the distance between the start and end node
double distance() const;
std::string start() const;
std::string end() const;
private:
void initializeGL() override;
void deinitializeGL() override;
@@ -58,12 +63,11 @@ private:
bool isReady() const override;
void updateVertexData();
void render(const RenderData& data, RendererTasks& rendererTask) override;
void validateNodes();
void unbindGL();
void bindGL();
glm::dvec3 getCoordinatePosFromAnchorNode(glm::dvec3 worldPos);
ghoul::opengl::ProgramObject* _program;
/// The vertex attribute location for position
/// must correlate to layout location in vertex shader