diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index 2db6c2d..a8d86f3 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -26,7 +26,7 @@ void ImGuiVisitor::visit(Node &n) void ImGuiVisitor::visit(Group &n) { std::string id = std::to_string(n.id()); - if (ImGui::TreeNode(id.c_str(), "Group")) + if (ImGui::TreeNode(id.c_str(), "Group %d", n.id())) { // MODEL VIEW if (ImGuiToolkit::ButtonIcon(6, 15)) { @@ -82,7 +82,7 @@ void ImGuiVisitor::visit(Animation &n) void ImGuiVisitor::visit(Primitive &n) { ImGui::PushID(n.id()); - ImGui::Text("Primitive"); + ImGui::Text("Primitive %d", n.id()); n.shader()->accept(*this); diff --git a/PickingVisitor.cpp b/PickingVisitor.cpp index e009d98..5e58ae1 100644 --- a/PickingVisitor.cpp +++ b/PickingVisitor.cpp @@ -24,14 +24,12 @@ void PickingVisitor::visit(Node &n) 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) @@ -53,29 +51,42 @@ void PickingVisitor::visit(Primitive &n) void PickingVisitor::visit(Surface &n) { - // test if point is inside rectangle + // apply inverse transform to the point of interest + glm::vec4 P = glm::inverse(modelview_) * glm::vec4( point_, 0.f, 1.f ); // lower left corner - glm::vec4 LL = modelview_ * glm::vec4( -1.f, -1.f, 0.f, 0.f ); + glm::vec3 LL = glm::vec3( -1.f, -1.f, 0.f ); // up right corner - glm::vec4 UR = modelview_ * glm::vec4( 1.f, 1.f, 0.f, 0.f ); + glm::vec3 UR = glm::vec3( 1.f, 1.f, 0.f ); -// 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 ) + // if P is inside [LL UR] rectangle: + if ( P.x > LL.x && P.x < UR.x && P.y > LL.y && P.y < UR.y ) + // add this surface to the nodes picked nodes_.push_back(&n); } void PickingVisitor::visit(LineSquare &) { + // apply inverse transform to the point of interest + glm::vec4 P = glm::inverse(modelview_) * glm::vec4( point_, 0.f, 1.f ); + // lower left corner + glm::vec3 LL = glm::vec3( -1.f, -1.f, 0.f ); + // up right corner + glm::vec3 UR = glm::vec3( 1.f, 1.f, 0.f ); + + // if P is over a line [LL UR] rectangle: + // TODO } void PickingVisitor::visit(LineCircle &n) { + // apply inverse transform to the point of interest + glm::vec4 P = glm::inverse(modelview_) * glm::vec4( point_, 0.f, 1.f ); + float r = glm::length( glm::vec2(P) ); + if ( r < 1.02 && r > 0.98) + nodes_.push_back(&n); } void PickingVisitor::visit(Scene &n) diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index ff01428..8625473 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -207,7 +207,7 @@ void UserInterface::handleMouse() 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); +// Log::Info(" (%.1f,%.1f)", point.x, point.y); PickingVisitor pv(point); Mixer::manager().currentView()->scene.accept(pv); @@ -217,8 +217,7 @@ void UserInterface::handleMouse() current = pv.picked().back(); } - -// Log::Info(" %d picked", pv.picked().size()); + Log::Info(" %d picked", pv.picked().size()); } @@ -233,7 +232,8 @@ void UserInterface::handleMouse() } else { - Log::Info("Mouse drag (%.1f,%.1f)(%.1f,%.1f)", io.MouseClickedPos[0].x, io.MouseClickedPos[0].y, io.MousePos.x, io.MousePos.y); +// Log::Info("Mouse drag (%.1f,%.1f)(%.1f,%.1f)", io.MouseClickedPos[0].x, io.MouseClickedPos[0].y, io.MousePos.x, io.MousePos.y); + // Selection area ImGui::GetBackgroundDrawList()->AddRect(io.MouseClickedPos[0], io.MousePos, ImGui::GetColorU32(ImGuiCol_ResizeGripHovered)); ImGui::GetBackgroundDrawList()->AddRectFilled(io.MouseClickedPos[0], io.MousePos, diff --git a/main.cpp b/main.cpp index f892d62..c9aa218 100644 --- a/main.cpp +++ b/main.cpp @@ -182,8 +182,8 @@ void drawScene() // draw GUI tree scene ImGui::Begin(IMGUI_TITLE_MAINWINDOW); static ImGuiVisitor v; -// Mixer::manager().currentView()->scene.accept(v); - Mixer::manager().getView(View::RENDERING)->scene.accept(v); + Mixer::manager().currentView()->scene.accept(v); +// Mixer::manager().getView(View::RENDERING)->scene.accept(v); ImGui::End(); }