mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 18:59:59 +01:00
BugFix search visitor in GeometryView.
This commit is contained in:
@@ -19,15 +19,12 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
static int global_index_ = 0;
|
|
||||||
|
|
||||||
// Node
|
// Node
|
||||||
Node::Node() : initialized_(false), visible_(true), refcount_(0)
|
Node::Node() : initialized_(false), visible_(true), refcount_(0)
|
||||||
{
|
{
|
||||||
// create unique id
|
// create unique id
|
||||||
// auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
|
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
|
||||||
// id_ = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count() % 100000000;
|
id_ = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count() % 100000000;
|
||||||
id_ = global_index_ < INT_MAX ? global_index_++ : 0;
|
|
||||||
|
|
||||||
transform_ = glm::identity<glm::mat4>();
|
transform_ = glm::identity<glm::mat4>();
|
||||||
scale_ = glm::vec3(1.f);
|
scale_ = glm::vec3(1.f);
|
||||||
|
|||||||
@@ -2,24 +2,16 @@
|
|||||||
|
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
SearchVisitor::SearchVisitor(Node *node) : Visitor(), node_(node), id_(0), found_(false)
|
SearchVisitor::SearchVisitor(Node *node) : Visitor(), node_(node), found_(false)
|
||||||
{
|
|
||||||
if (node != nullptr)
|
|
||||||
id_ = node->id();
|
|
||||||
else
|
|
||||||
id_ = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SearchVisitor::SearchVisitor(int id) : Visitor(), node_(nullptr), id_(id), found_(false)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SearchVisitor::visit(Node &n)
|
void SearchVisitor::visit(Node &n)
|
||||||
{
|
{
|
||||||
if ( n.id() == id_ ){
|
if ( node_ == &n ){
|
||||||
found_ = true;
|
found_ = true;
|
||||||
node_ = &n;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +32,6 @@ void SearchVisitor::visit(Switch &n)
|
|||||||
|
|
||||||
void SearchVisitor::visit(Scene &n)
|
void SearchVisitor::visit(Scene &n)
|
||||||
{
|
{
|
||||||
// TODO maybe search only forground?
|
// search only in workspace
|
||||||
n.root()->accept(*this);
|
n.ws()->accept(*this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,10 @@
|
|||||||
class SearchVisitor: public Visitor
|
class SearchVisitor: public Visitor
|
||||||
{
|
{
|
||||||
Node *node_;
|
Node *node_;
|
||||||
int id_;
|
|
||||||
bool found_;
|
bool found_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SearchVisitor(Node *node);
|
SearchVisitor(Node *node);
|
||||||
SearchVisitor(int id);
|
|
||||||
inline bool found() const { return found_; }
|
inline bool found() const { return found_; }
|
||||||
inline Node *node() const { return found_ ? node_ : nullptr; }
|
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> 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
|
// picking visitor traverses the scene
|
||||||
PickingVisitor pv(point);
|
PickingVisitor pv(point);
|
||||||
@@ -322,7 +322,7 @@ std::pair<Node *, glm::vec2> GeometryView::pick(glm::vec3 point)
|
|||||||
auto itp = pv.picked().begin();
|
auto itp = pv.picked().begin();
|
||||||
for (; itp != pv.picked().end(); itp++){
|
for (; itp != pv.picked().end(); itp++){
|
||||||
if ( s->contains( (*itp).first ) ){
|
if ( s->contains( (*itp).first ) ){
|
||||||
picked = *itp;
|
pick = *itp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,11 +334,11 @@ std::pair<Node *, glm::vec2> GeometryView::pick(glm::vec3 point)
|
|||||||
if (s == nullptr)
|
if (s == nullptr)
|
||||||
{
|
{
|
||||||
// select top-most Node picked
|
// 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)
|
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