mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-01 08:19:51 -05:00
Coding style fixes
This commit is contained in:
@@ -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 {
|
||||
@@ -175,7 +175,6 @@ namespace {
|
||||
"Fade-In/-Out ending speed.",
|
||||
"Fade-In/-Out ending speed."
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -641,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);
|
||||
@@ -767,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
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
protected:
|
||||
properties::OptionProperty _blendMode;
|
||||
|
||||
float getUnit(int unit) const;
|
||||
float unit(int unit) const;
|
||||
|
||||
// Data may require some type of transformation prior the spice transformation being
|
||||
// applied.
|
||||
|
||||
@@ -67,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 {
|
||||
@@ -143,19 +159,16 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_opacity);
|
||||
}
|
||||
|
||||
double RenderableNodeLine::getDistance()
|
||||
{
|
||||
double RenderableNodeLine::distance() const {
|
||||
return glm::distance(_startPos, _endPos);
|
||||
}
|
||||
|
||||
const std::string RenderableNodeLine::getStart()
|
||||
{
|
||||
return _start.value();
|
||||
std::string RenderableNodeLine::start() const {
|
||||
return _start;
|
||||
}
|
||||
|
||||
const std::string RenderableNodeLine::getEnd()
|
||||
{
|
||||
return _end.value();
|
||||
std::string RenderableNodeLine::end() const {
|
||||
return _end;
|
||||
}
|
||||
|
||||
void RenderableNodeLine::initializeGL() {
|
||||
@@ -183,7 +196,6 @@ void RenderableNodeLine::initializeGL() {
|
||||
}
|
||||
|
||||
void RenderableNodeLine::deinitializeGL() {
|
||||
|
||||
glDeleteVertexArrays(1, &_vaoId);
|
||||
_vaoId = 0;
|
||||
|
||||
@@ -210,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);
|
||||
@@ -242,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();
|
||||
@@ -257,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 =
|
||||
@@ -278,8 +294,12 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
|
||||
GLfloat currentLineWidth;
|
||||
glGetFloatv(GL_LINE_WIDTH, ¤tLineWidth);
|
||||
|
||||
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);
|
||||
@@ -311,34 +331,19 @@ void RenderableNodeLine::render(const RenderData& data, RendererTasks&) {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableNodeLine::validateNodes()
|
||||
{
|
||||
void RenderableNodeLine::validateNodes() {
|
||||
if (!global::renderEngine.scene()->sceneGraphNode(_start)) {
|
||||
LERROR(fmt::format("There is no scenegraph node with id {}, defaults to 'Root'", _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));
|
||||
LERROR(fmt::format(
|
||||
"There is no scenegraph node with id {}, defaults to 'Root'", _end
|
||||
));
|
||||
_end = Root;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 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();
|
||||
}
|
||||
glm::dvec3 diffPos = glm::dvec3(worldPos.x - anchorNodePos.x, worldPos.y - anchorNodePos.y,
|
||||
worldPos.z - anchorNodePos.z);
|
||||
|
||||
return diffPos;
|
||||
}
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
@@ -52,10 +51,10 @@ public:
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
// Get the distance between the start and end node
|
||||
double getDistance();
|
||||
double distance() const;
|
||||
|
||||
const std::string getStart();
|
||||
const std::string getEnd();
|
||||
std::string start() const;
|
||||
std::string end() const;
|
||||
|
||||
private:
|
||||
void initializeGL() override;
|
||||
@@ -69,8 +68,6 @@ private:
|
||||
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
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
#include <modules/vislab/rendering/renderabledistancelabel.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <modules/base/rendering/renderablenodeline.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
@@ -39,8 +39,8 @@ namespace {
|
||||
constexpr openspace::properties::Property::PropertyInfo NodeLineInfo = {
|
||||
"NodeLine",
|
||||
"Node Line",
|
||||
"Property to track a nodeline. When tracking the label text will be updating the distance "
|
||||
"from the nodeline start and end. "
|
||||
"Property to track a nodeline. When tracking the label text will be updating the "
|
||||
"distance from the nodeline start and end."
|
||||
};
|
||||
}
|
||||
|
||||
@@ -78,38 +78,45 @@ RenderableDistanceLabel::RenderableDistanceLabel(const ghoul::Dictionary& dictio
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableDistanceLabel::update(const UpdateData& data) {
|
||||
void RenderableDistanceLabel::update(const UpdateData&) {
|
||||
if (_errorThrown) {
|
||||
return;
|
||||
}
|
||||
|
||||
SceneGraphNode* nodelineNode = global::renderEngine.scene()->sceneGraphNode(_nodelineId);
|
||||
|
||||
if (nodelineNode && !_errorThrown) {
|
||||
RenderEngine& RE = global::renderEngine;
|
||||
|
||||
SceneGraphNode* nodelineNode = RE.scene()->sceneGraphNode(_nodelineId);
|
||||
if (nodelineNode) {
|
||||
// Calculate distance
|
||||
RenderableNodeLine* nodeline = dynamic_cast<RenderableNodeLine*>(nodelineNode->renderable());
|
||||
RenderableNodeLine* nodeline = dynamic_cast<RenderableNodeLine*>(
|
||||
nodelineNode->renderable()
|
||||
);
|
||||
if (!nodeline) {
|
||||
LERROR("Expected renderable to be of type 'RenderableNodeLine'");
|
||||
_errorThrown = true;
|
||||
return;
|
||||
}
|
||||
|
||||
double myDistance = nodeline->getDistance();
|
||||
double myDistance = nodeline->distance();
|
||||
|
||||
// Format string
|
||||
float scale = getUnit(Kilometer);
|
||||
float scale = unit(Kilometer);
|
||||
std::string distanceText = std::to_string(std::round(myDistance / scale));
|
||||
int pos = distanceText.find(".");
|
||||
int pos = static_cast<int>(distanceText.find("."));
|
||||
std::string subStr = distanceText.substr(pos);
|
||||
distanceText.erase(pos, subStr.size());
|
||||
std::string finalText = distanceText + " Km";
|
||||
setLabelText(finalText);
|
||||
|
||||
// Update placement of label with transformation matrix
|
||||
glm::dvec3 start = global::renderEngine.scene()->sceneGraphNode(nodeline->getStart())->worldPosition();
|
||||
glm::dvec3 end = global::renderEngine.scene()->sceneGraphNode(nodeline->getEnd())->worldPosition();
|
||||
SceneGraphNode* startNode = RE.scene()->sceneGraphNode(nodeline->start());
|
||||
glm::dvec3 start = startNode->worldPosition();
|
||||
SceneGraphNode* endNode = RE.scene()->sceneGraphNode(nodeline->end());
|
||||
glm::dvec3 end = endNode->worldPosition();
|
||||
glm::dvec3 goalPos = start + (end - start) / 2.0;
|
||||
_transformationMatrix = glm::translate(glm::dmat4(1.0), goalPos);
|
||||
}
|
||||
else if (!_errorThrown) {
|
||||
else {
|
||||
LERROR(fmt::format("There is no scenegraph node with id {}", _nodelineId));
|
||||
_errorThrown = true;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__
|
||||
#define __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__
|
||||
|
||||
@@ -38,6 +37,7 @@ public:
|
||||
|
||||
void update(const UpdateData& data) override;
|
||||
static documentation::Documentation Documentation();
|
||||
private:
|
||||
|
||||
properties::StringProperty _nodelineId;
|
||||
bool _errorThrown = false;
|
||||
|
||||
@@ -25,14 +25,13 @@
|
||||
#include <modules/vislab/vislabmodule.h>
|
||||
|
||||
#include <modules/vislab/rendering/renderabledistancelabel.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
VisLabModule::VisLabModule() : OpenSpaceModule(Name) {
|
||||
}
|
||||
VisLabModule::VisLabModule() : OpenSpaceModule(Name) {}
|
||||
|
||||
void VisLabModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
auto renderableFactory = FactoryManager::ref().factory<Renderable>();
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#ifndef __OPENSPACE_MODULE_VISLAB___VISLABMODULE___H__
|
||||
#define __OPENSPACE_MODULE_VISLAB___VISLABMODULE___H__
|
||||
|
||||
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
|
||||
namespace openspace {
|
||||
@@ -38,7 +37,6 @@ public:
|
||||
|
||||
private:
|
||||
void internalInitialize(const ghoul::Dictionary&) override;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user