diff --git a/Decorations.cpp b/Decorations.cpp index 95b7da8..d5a1ee0 100644 --- a/Decorations.cpp +++ b/Decorations.cpp @@ -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(), space); + DotLine::dot_->draw( ctm, projection); + } + + // draw target point + ctm = modelview * glm::translate(glm::identity(), target); + DotLine::dot_->draw( ctm, projection); + } +} + +void DotLine::accept(Visitor& v) +{ + Node::accept(v); + v.visit(*this); +} diff --git a/Decorations.h b/Decorations.h index 697affa..c845ada 100644 --- a/Decorations.h +++ b/Decorations.h @@ -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