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

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;