PickingVisitor first draft, with prototype integration in UserInterface

This commit is contained in:
brunoherbelin
2020-04-19 23:59:21 +02:00
parent 0d87aa8bf6
commit 4930cc41c7
8 changed files with 78 additions and 40 deletions

View File

@@ -7,28 +7,38 @@
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_access.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/string_cast.hpp>
PickingVisitor::PickingVisitor(glm::vec2 coordinates) : Visitor(), point_(coordinates), node_(nullptr)
PickingVisitor::PickingVisitor(glm::vec2 coordinates) : Visitor(), point_(coordinates)
{
modelview_ = glm::mat4(1.f);
}
void PickingVisitor::visit(Node &n)
{
modelview_ *= n.transform_;
// Log::Info("Node %d", n.id());
// Log::Info("%s", glm::to_string(modelview_).c_str());
}
void PickingVisitor::visit(Group &n)
{
// Log::Info("Group %d", n.id());
glm::mat4 mv = modelview_;
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
(*node)->accept(*this);
modelview_ = mv;
}
}
void PickingVisitor::visit(Switch &n)
{
glm::mat4 mv = modelview_;
(*n.activeChild())->accept(*this);
modelview_ = mv;
}
void PickingVisitor::visit(Animation &n)
@@ -41,24 +51,21 @@ void PickingVisitor::visit(Primitive &n)
}
void PickingVisitor::visit(ImageSurface &n)
void PickingVisitor::visit(Surface &n)
{
// test if point is inside rectangle
}
// lower left corner
glm::vec4 LL = modelview_ * glm::vec4( -1.f, -1.f, 0.f, 0.f );
// up right corner
glm::vec4 UR = modelview_ * glm::vec4( 1.f, 1.f, 0.f, 0.f );
void PickingVisitor::visit(FrameBufferSurface &n)
{
}
void PickingVisitor::visit(MediaSurface &n)
{
}
void PickingVisitor::visit(LineStrip &n)
{
// Log::Info("Surface %d", n.id());
// Log::Info("LL %s", glm::to_string(LL).c_str());
// Log::Info("UR %s", glm::to_string(UR).c_str());
if ( point_.x > LL.x && point_.x < UR.x && point_.y > LL.y && point_.y < UR.y )
nodes_.push_back(&n);
}
void PickingVisitor::visit(LineSquare &)
@@ -71,11 +78,6 @@ void PickingVisitor::visit(LineCircle &n)
}
void PickingVisitor::visit(Mesh &n)
{
}
void PickingVisitor::visit(Scene &n)
{
n.root()->accept(*this);