diff --git a/Scene.cpp b/Scene.cpp index b2012e3..e438b07 100644 --- a/Scene.cpp +++ b/Scene.cpp @@ -19,15 +19,12 @@ #include #include -static int global_index_ = 0; - // Node Node::Node() : initialized_(false), visible_(true), refcount_(0) { // create unique id -// auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); -// id_ = std::chrono::duration_cast(duration).count() % 100000000; - id_ = global_index_ < INT_MAX ? global_index_++ : 0; + auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); + id_ = std::chrono::duration_cast(duration).count() % 100000000; transform_ = glm::identity(); scale_ = glm::vec3(1.f); diff --git a/SearchVisitor.cpp b/SearchVisitor.cpp index 881e7e2..d894a4f 100644 --- a/SearchVisitor.cpp +++ b/SearchVisitor.cpp @@ -2,24 +2,16 @@ #include "Scene.h" -SearchVisitor::SearchVisitor(Node *node) : Visitor(), node_(node), id_(0), found_(false) -{ - if (node != nullptr) - id_ = node->id(); - else - id_ = -1; -} - -SearchVisitor::SearchVisitor(int id) : Visitor(), node_(nullptr), id_(id), found_(false) +SearchVisitor::SearchVisitor(Node *node) : Visitor(), node_(node), found_(false) { } + void SearchVisitor::visit(Node &n) { - if ( n.id() == id_ ){ + if ( node_ == &n ){ found_ = true; - node_ = &n; } } @@ -40,6 +32,6 @@ void SearchVisitor::visit(Switch &n) void SearchVisitor::visit(Scene &n) { - // TODO maybe search only forground? - n.root()->accept(*this); + // search only in workspace + n.ws()->accept(*this); } diff --git a/SearchVisitor.h b/SearchVisitor.h index 128fd64..20a6642 100644 --- a/SearchVisitor.h +++ b/SearchVisitor.h @@ -6,12 +6,10 @@ class SearchVisitor: public Visitor { Node *node_; - int id_; bool found_; public: SearchVisitor(Node *node); - SearchVisitor(int id); inline bool found() const { return found_; } inline Node *node() const { return found_ ? node_ : nullptr; } diff --git a/View.cpp b/View.cpp index d58df30..64d311f 100644 --- a/View.cpp +++ b/View.cpp @@ -307,7 +307,7 @@ void GeometryView::draw() std::pair GeometryView::pick(glm::vec3 point) { - std::pair picked = { nullptr, glm::vec2(0.f) }; + std::pair pick = { nullptr, glm::vec2(0.f) }; // picking visitor traverses the scene PickingVisitor pv(point); @@ -321,8 +321,8 @@ std::pair GeometryView::pick(glm::vec3 point) // find if the current source was picked auto itp = pv.picked().begin(); for (; itp != pv.picked().end(); itp++){ - if (s->contains( (*itp).first )){ - picked = *itp; + if ( s->contains( (*itp).first ) ){ + pick = *itp; break; } } @@ -334,11 +334,11 @@ std::pair GeometryView::pick(glm::vec3 point) if (s == nullptr) { // select top-most Node picked - picked = pv.picked().back(); + pick = pv.picked().back(); } } - return picked; + return pick; } View::Cursor GeometryView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair pick)