mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Fixed Picking visitor for Mixing View (but should work in all views)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
4
main.cpp
4
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user