Added dotted line rendering

This commit is contained in:
Bruno Herbelin
2022-04-16 01:31:55 +02:00
parent 739559783b
commit 0aed9fc306
2 changed files with 67 additions and 0 deletions

View File

@@ -659,3 +659,54 @@ void Glyph::setChar(char c)
} }
} }
} }
Mesh *DotLine::dot_ = nullptr;
DotLine::DotLine() : Node()
{
if (DotLine::dot_ == nullptr)
DotLine::dot_ = new Mesh("mesh/point.ply");
spacing = 0.2f;
target = glm::vec3( 0.f, 0.f, 0.f);
color = glm::vec4( 1.f, 1.f, 1.f, 1.f);
}
void DotLine::draw(glm::mat4 modelview, glm::mat4 projection)
{
if ( !initialized() ) {
if (!DotLine::dot_->initialized())
DotLine::dot_->init();
init();
}
if ( visible_ ) {
// set color
DotLine::dot_->shader()->color = color;
// draw start point
DotLine::dot_->draw( modelview, projection);
// draw equally spaced intermediate points
glm::vec3 inc = target;
glm::vec3 space = spacing * glm::normalize(target);
glm::mat4 ctm = modelview;
while ( glm::length(inc) > spacing ) {
inc -= space;
ctm *= glm::translate(glm::identity<glm::mat4>(), space);
DotLine::dot_->draw( ctm, projection);
}
// draw target point
ctm = modelview * glm::translate(glm::identity<glm::mat4>(), target);
DotLine::dot_->draw( ctm, projection);
}
}
void DotLine::accept(Visitor& v)
{
Node::accept(v);
v.visit(*this);
}

View File

@@ -115,4 +115,20 @@ protected:
}; };
class DotLine : public Node
{
public:
DotLine();
void draw (glm::mat4 modelview, glm::mat4 projection) override;
void accept (Visitor& v) override;
float spacing;
glm::vec4 color;
glm::vec3 target;
protected:
static Mesh *dot_;
};
#endif // DECORATIONS_H #endif // DECORATIONS_H