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)
|
void ImGuiVisitor::visit(Group &n)
|
||||||
{
|
{
|
||||||
std::string id = std::to_string(n.id());
|
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
|
// MODEL VIEW
|
||||||
if (ImGuiToolkit::ButtonIcon(6, 15)) {
|
if (ImGuiToolkit::ButtonIcon(6, 15)) {
|
||||||
@@ -82,7 +82,7 @@ void ImGuiVisitor::visit(Animation &n)
|
|||||||
void ImGuiVisitor::visit(Primitive &n)
|
void ImGuiVisitor::visit(Primitive &n)
|
||||||
{
|
{
|
||||||
ImGui::PushID(n.id());
|
ImGui::PushID(n.id());
|
||||||
ImGui::Text("Primitive");
|
ImGui::Text("Primitive %d", n.id());
|
||||||
|
|
||||||
n.shader()->accept(*this);
|
n.shader()->accept(*this);
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,12 @@ void PickingVisitor::visit(Node &n)
|
|||||||
|
|
||||||
void PickingVisitor::visit(Group &n)
|
void PickingVisitor::visit(Group &n)
|
||||||
{
|
{
|
||||||
// Log::Info("Group %d", n.id());
|
|
||||||
glm::mat4 mv = modelview_;
|
glm::mat4 mv = modelview_;
|
||||||
|
|
||||||
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
|
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
|
||||||
(*node)->accept(*this);
|
(*node)->accept(*this);
|
||||||
modelview_ = mv;
|
modelview_ = mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PickingVisitor::visit(Switch &n)
|
void PickingVisitor::visit(Switch &n)
|
||||||
@@ -53,29 +51,42 @@ void PickingVisitor::visit(Primitive &n)
|
|||||||
|
|
||||||
void PickingVisitor::visit(Surface &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
|
// 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
|
// 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());
|
// if P is inside [LL UR] rectangle:
|
||||||
// Log::Info("LL %s", glm::to_string(LL).c_str());
|
if ( P.x > LL.x && P.x < UR.x && P.y > LL.y && P.y < UR.y )
|
||||||
// Log::Info("UR %s", glm::to_string(UR).c_str());
|
// add this surface to the nodes picked
|
||||||
|
|
||||||
if ( point_.x > LL.x && point_.x < UR.x && point_.y > LL.y && point_.y < UR.y )
|
|
||||||
nodes_.push_back(&n);
|
nodes_.push_back(&n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PickingVisitor::visit(LineSquare &)
|
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)
|
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)
|
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),
|
glm::vec3 point = Rendering::manager().unProject(glm::vec2(io.MousePos.x, io.MousePos.y),
|
||||||
Mixer::manager().currentView()->scene.root()->transform_ );
|
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);
|
PickingVisitor pv(point);
|
||||||
Mixer::manager().currentView()->scene.accept(pv);
|
Mixer::manager().currentView()->scene.accept(pv);
|
||||||
|
|
||||||
@@ -217,8 +217,7 @@ void UserInterface::handleMouse()
|
|||||||
current = pv.picked().back();
|
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 {
|
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::GetBackgroundDrawList()->AddRect(io.MouseClickedPos[0], io.MousePos,
|
||||||
ImGui::GetColorU32(ImGuiCol_ResizeGripHovered));
|
ImGui::GetColorU32(ImGuiCol_ResizeGripHovered));
|
||||||
ImGui::GetBackgroundDrawList()->AddRectFilled(io.MouseClickedPos[0], io.MousePos,
|
ImGui::GetBackgroundDrawList()->AddRectFilled(io.MouseClickedPos[0], io.MousePos,
|
||||||
|
|||||||
4
main.cpp
4
main.cpp
@@ -182,8 +182,8 @@ void drawScene()
|
|||||||
// draw GUI tree scene
|
// draw GUI tree scene
|
||||||
ImGui::Begin(IMGUI_TITLE_MAINWINDOW);
|
ImGui::Begin(IMGUI_TITLE_MAINWINDOW);
|
||||||
static ImGuiVisitor v;
|
static ImGuiVisitor v;
|
||||||
// Mixer::manager().currentView()->scene.accept(v);
|
Mixer::manager().currentView()->scene.accept(v);
|
||||||
Mixer::manager().getView(View::RENDERING)->scene.accept(v);
|
// Mixer::manager().getView(View::RENDERING)->scene.accept(v);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user