WIP inheriting from renderablelabels

This commit is contained in:
Lovisa Hassler
2020-01-09 09:59:38 +01:00
parent fb2ae7f18a
commit 4ffc5595d9
5 changed files with 84 additions and 33 deletions
+25 -25
View File
@@ -701,31 +701,31 @@ void RenderableLabels::render(const RenderData& data, RendererTasks&) {
//}
}
void RenderableLabels::update(const UpdateData& data) {
if (global::renderEngine.scene()->sceneGraphNode(_nodeLine)) {
// Calculate distance
SceneGraphNode* nodelineNode = global::renderEngine.scene()->sceneGraphNode(_nodeLine);
RenderableNodeLine* nodeline = dynamic_cast<RenderableNodeLine*>(nodelineNode->renderable());
double myDistance = nodeline->getDistance();
// format string
float scale = getUnit(Kilometer);
std::string distanceText = std::to_string(std::round(myDistance / scale));
int pos = distanceText.find(".");
std::string subStr = distanceText.substr(pos);
distanceText.erase(pos, subStr.size());
std::string finalText = distanceText + " " + KilometerUnit;
setLabelText(finalText);
// Update placement of label with transformation matrix
glm::dvec3 start = global::renderEngine.scene()->sceneGraphNode(nodeline->_start)->worldPosition();
glm::dvec3 end = global::renderEngine.scene()->sceneGraphNode(nodeline->_end)->worldPosition();
glm::dvec3 goalPos = start + (end - start) / 2.0;
_transformationMatrix = glm::translate(glm::dmat4(1.0), goalPos);
}
}
//void RenderableLabels::update(const UpdateData& data) {
//
// if (global::renderEngine.scene()->sceneGraphNode(_nodeLine)) {
//
// // Calculate distance
// SceneGraphNode* nodelineNode = global::renderEngine.scene()->sceneGraphNode(_nodeLine);
// RenderableNodeLine* nodeline = dynamic_cast<RenderableNodeLine*>(nodelineNode->renderable());
// double myDistance = nodeline->getDistance();
//
// // format string
// float scale = getUnit(Kilometer);
// std::string distanceText = std::to_string(std::round(myDistance / scale));
// int pos = distanceText.find(".");
// std::string subStr = distanceText.substr(pos);
// distanceText.erase(pos, subStr.size());
// std::string finalText = distanceText + " " + KilometerUnit;
// setLabelText(finalText);
//
// // Update placement of label with transformation matrix
// glm::dvec3 start = global::renderEngine.scene()->sceneGraphNode(nodeline->_start)->worldPosition();
// glm::dvec3 end = global::renderEngine.scene()->sceneGraphNode(nodeline->_end)->worldPosition();
// glm::dvec3 goalPos = start + (end - start) / 2.0;
// _transformationMatrix = glm::translate(glm::dmat4(1.0), goalPos);
// }
//}
void RenderableLabels::setLabelText(const std::string & newText) {
_labelText = newText;
@@ -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();
@@ -24,10 +24,55 @@
#include <modules/vislab/rendering/renderabledistancelabel.h>
#include <openspace/documentation/documentation.h>
//#include <openspace/documentation/verifier.h>
namespace openspace {
//RenderableDistanceLabel::RenderableDistanceLabel(const ghoul::Dictionary& dictionary)
//{
documentation::Documentation RenderableDistanceLabel::Documentation() {
using namespace documentation;
return {
"Renderable Distance Label",
"vislab_renderable_distance_label",
{
}
};
}
RenderableDistanceLabel::RenderableDistanceLabel(const ghoul::Dictionary& dictionary)
: RenderableLabels(dictionary)
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"RenderableDistanceLabel"
);
}
//void RenderableDistanceLabel::update(const UpdateData& data) {
//
// if (global::renderEngine.scene()->sceneGraphNode(_nodeLine)) {
//
// // Calculate distance
// SceneGraphNode* nodelineNode = global::renderEngine.scene()->sceneGraphNode(_nodeLine);
// RenderableNodeLine* nodeline = dynamic_cast<RenderableNodeLine*>(nodelineNode->renderable());
// double myDistance = nodeline->getDistance();
//
// // format string
// float scale = getUnit(Kilometer);
// std::string distanceText = std::to_string(std::round(myDistance / scale));
// int pos = distanceText.find(".");
// std::string subStr = distanceText.substr(pos);
// distanceText.erase(pos, subStr.size());
// std::string finalText = distanceText + " " + KilometerUnit;
// setLabelText(finalText);
//
// // Update placement of label with transformation matrix
// glm::dvec3 start = global::renderEngine.scene()->sceneGraphNode(nodeline->_start)->worldPosition();
// glm::dvec3 end = global::renderEngine.scene()->sceneGraphNode(nodeline->_end)->worldPosition();
// glm::dvec3 goalPos = start + (end - start) / 2.0;
// _transformationMatrix = glm::translate(glm::dmat4(1.0), goalPos);
// }
//}
} // namespace openspace
@@ -26,12 +26,19 @@
#ifndef __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__
#define __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__
#include <modules/base/rendering/renderablelabels.h>
namespace openspace {
namespace documentation { struct Documentation; }
class RenderableDistanceLabel {
class RenderableDistanceLabel : public RenderableLabels {
public:
// RenderableDistanceLabel(const ghoul::Dictionary& dictionary);
RenderableDistanceLabel(const ghoul::Dictionary& dictionary);
// void update(const UpdateData& data) override;
static documentation::Documentation Documentation();
private:
};
+3 -3
View File
@@ -31,10 +31,10 @@ VisLabModule::VisLabModule() : OpenSpaceModule(Name) {
}
void VisLabModule::internalInitialize(const ghoul::Dictionary&) {
//auto renderableFactory = FactoryManager::ref().factory<Renderable>();
//ghoul_assert(renderableFactory, "No renderable factory existed");
auto renderableFactory = FactoryManager::ref().factory<Renderable>();
ghoul_assert(renderableFactory, "No renderable factory existed");
//renderableFactory->registerClass<RenderableDistanceLabel>("RenderableDistanceLabel");
renderableFactory->registerClass<RenderableDistanceLabel>("RenderableDistanceLabel");
}
} // namespace openspace