mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
BugFix search visitor in GeometryView.
This commit is contained in:
@@ -19,15 +19,12 @@
|
||||
#include <ctime>
|
||||
#include <algorithm>
|
||||
|
||||
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<std::chrono::nanoseconds>(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<std::chrono::nanoseconds>(duration).count() % 100000000;
|
||||
|
||||
transform_ = glm::identity<glm::mat4>();
|
||||
scale_ = glm::vec3(1.f);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
8
View.cpp
8
View.cpp
@@ -307,7 +307,7 @@ void GeometryView::draw()
|
||||
|
||||
std::pair<Node *, glm::vec2> GeometryView::pick(glm::vec3 point)
|
||||
{
|
||||
std::pair<Node *, glm::vec2> picked = { nullptr, glm::vec2(0.f) };
|
||||
std::pair<Node *, glm::vec2> pick = { nullptr, glm::vec2(0.f) };
|
||||
|
||||
// picking visitor traverses the scene
|
||||
PickingVisitor pv(point);
|
||||
@@ -322,7 +322,7 @@ std::pair<Node *, glm::vec2> GeometryView::pick(glm::vec3 point)
|
||||
auto itp = pv.picked().begin();
|
||||
for (; itp != pv.picked().end(); itp++){
|
||||
if ( s->contains( (*itp).first ) ){
|
||||
picked = *itp;
|
||||
pick = *itp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -334,11 +334,11 @@ std::pair<Node *, glm::vec2> 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<Node *, glm::vec2> pick)
|
||||
|
||||
Reference in New Issue
Block a user