diff --git a/ImGuiVisitor.h b/ImGuiVisitor.h index d26ba4b..0ed9aaf 100644 --- a/ImGuiVisitor.h +++ b/ImGuiVisitor.h @@ -15,6 +15,7 @@ public: void visit(Switch& n); void visit(Animation& n); void visit(Primitive& n); + void visit(Surface&) {} void visit(ImageSurface&) {} void visit(MediaSurface& n); void visit(FrameBufferSurface& n); diff --git a/PickingVisitor.cpp b/PickingVisitor.cpp index 1054d56..e009d98 100644 --- a/PickingVisitor.cpp +++ b/PickingVisitor.cpp @@ -7,28 +7,38 @@ #include #include #include +#include -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); diff --git a/PickingVisitor.h b/PickingVisitor.h index 0315450..325c8fa 100644 --- a/PickingVisitor.h +++ b/PickingVisitor.h @@ -2,17 +2,19 @@ #define PICKINGVISITOR_H #include +#include + #include "Visitor.h" class PickingVisitor: public Visitor { glm::vec2 point_; glm::mat4 modelview_; - Node *node_; + std::vector nodes_; public: PickingVisitor(glm::vec2 coordinates); - Node *picked() { return node_; } + std::vector picked() { return nodes_; } // Elements of Scene void visit(Scene& n); @@ -21,13 +23,14 @@ public: void visit(Switch& n); void visit(Animation& n); void visit(Primitive& n); - void visit(ImageSurface& n); - void visit(MediaSurface& n); - void visit(FrameBufferSurface& n); - void visit(LineStrip& n); + void visit(Surface& n); + void visit(ImageSurface&){} + void visit(MediaSurface&){} + void visit(FrameBufferSurface&){} + void visit(LineStrip&){} void visit(LineSquare&); void visit(LineCircle& n); - void visit(Mesh& n); + void visit(Mesh&){} // not picking other Elements with attributes void visit(MediaPlayer&) {} diff --git a/Primitives.cpp b/Primitives.cpp index 78fd7d4..bfb5eee 100644 --- a/Primitives.cpp +++ b/Primitives.cpp @@ -104,7 +104,7 @@ void ImageSurface::draw(glm::mat4 modelview, glm::mat4 projection) void ImageSurface::accept(Visitor& v) { - Primitive::accept(v); + Surface::accept(v); v.visit(*this); } @@ -154,7 +154,7 @@ void MediaSurface::update( float dt ) void MediaSurface::accept(Visitor& v) { - Primitive::accept(v); + Surface::accept(v); v.visit(*this); } @@ -189,7 +189,7 @@ void FrameBufferSurface::draw(glm::mat4 modelview, glm::mat4 projection) void FrameBufferSurface::accept(Visitor& v) { - Primitive::accept(v); + Surface::accept(v); v.visit(*this); } diff --git a/SessionVisitor.cpp b/SessionVisitor.cpp index 9fff509..37bfd29 100644 --- a/SessionVisitor.cpp +++ b/SessionVisitor.cpp @@ -98,6 +98,11 @@ void SessionVisitor::visit(Primitive &n) } +void SessionVisitor::visit(Surface &n) +{ + +} + void SessionVisitor::visit(ImageSurface &n) { // Node of a different type diff --git a/SessionVisitor.h b/SessionVisitor.h index 40d5b64..5609ce0 100644 --- a/SessionVisitor.h +++ b/SessionVisitor.h @@ -22,6 +22,7 @@ public: void visit(Switch& n); void visit(Animation& n); void visit(Primitive& n); + void visit(Surface& n); void visit(ImageSurface& n); void visit(MediaSurface& n); void visit(FrameBufferSurface& n); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 5266213..ff01428 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -40,6 +40,7 @@ #include "ImGuiToolkit.h" #include "GstToolkit.h" #include "Mixer.h" +#include "PickingVisitor.h" static std::thread loadThread; static bool loadThreadDone = false; @@ -195,31 +196,54 @@ void UserInterface::handleMouse() ImGui::SetMouseCursor(ImGuiMouseCursor_Arrow); // - // RIGHT Mouse button + // LEFT Mouse button // + static Node *current = nullptr; + if ( ImGui::IsMouseDown(ImGuiMouseButton_Left)) { - Log::Info("Mouse press (%.1f,%.1f)", io.MousePos.x, io.MousePos.y); +// Log::Info("Mouse press (%.1f,%.1f)", io.MousePos.x, io.MousePos.y); glm::vec3 point = Rendering::manager().unProject(glm::vec2(io.MousePos.x, io.MousePos.y), Mixer::manager().currentView()->scene.root()->transform_ ); Log::Info(" (%.1f,%.1f)", point.x, point.y); + PickingVisitor pv(point); + Mixer::manager().currentView()->scene.accept(pv); + + if (pv.picked().empty()) + current = nullptr; + else { + current = pv.picked().back(); + } + + +// Log::Info(" %d picked", pv.picked().size()); } if ( ImGui::IsMouseDragging(ImGuiMouseButton_Left, 10.0f) ) { - Log::Info("Mouse drag (%.1f,%.1f)(%.1f,%.1f)", io.MouseClickedPos[0].x, io.MouseClickedPos[0].y, io.MousePos.x, io.MousePos.y); - ImGui::GetBackgroundDrawList()->AddRect(io.MouseClickedPos[0], io.MousePos, - ImGui::GetColorU32(ImGuiCol_ResizeGripHovered)); - ImGui::GetBackgroundDrawList()->AddRectFilled(io.MouseClickedPos[0], io.MousePos, - ImGui::GetColorU32(ImGuiCol_ResizeGripHovered, 0.3f)); + if (current) + { +// // drag current +// Log::Info("Dragging %d", current->id()); +// current->translation_.x += io.MouseDelta.x * 0.1f; + + } + else { + + Log::Info("Mouse drag (%.1f,%.1f)(%.1f,%.1f)", io.MouseClickedPos[0].x, io.MouseClickedPos[0].y, io.MousePos.x, io.MousePos.y); + ImGui::GetBackgroundDrawList()->AddRect(io.MouseClickedPos[0], io.MousePos, + ImGui::GetColorU32(ImGuiCol_ResizeGripHovered)); + ImGui::GetBackgroundDrawList()->AddRectFilled(io.MouseClickedPos[0], io.MousePos, + ImGui::GetColorU32(ImGuiCol_ResizeGripHovered, 0.3f)); + } } if ( ImGui::IsMouseReleased(ImGuiMouseButton_Left) ) { - + current = nullptr; } } diff --git a/Visitor.h b/Visitor.h index 5789656..63a71a7 100644 --- a/Visitor.h +++ b/Visitor.h @@ -10,6 +10,7 @@ class Switch; class Animation; class Primitive; class Scene; +class Surface; class ImageSurface; class MediaSurface; class FrameBufferSurface; @@ -32,6 +33,7 @@ public: virtual void visit (Switch&) = 0; virtual void visit (Animation&) = 0; virtual void visit (Primitive&) = 0; + virtual void visit (Surface&) = 0; virtual void visit (ImageSurface&) = 0; virtual void visit (MediaSurface&) = 0; virtual void visit (FrameBufferSurface&) = 0;